123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191 |
- package com.ruixuan.isc.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.PageInfo;
- import com.ruixuan.common.constant.HttpStatus;
- import com.ruixuan.common.core.page.TableDataInfo;
- import com.ruixuan.common.utils.Check;
- import com.ruixuan.common.utils.DateUtils;
- import com.ruixuan.data.utils.ExportExcelUtils;
- import com.ruixuan.isc.service.IKwaiXiaoDianReportService;
- import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
- import com.ruixuan.system.service.ISysRoleService;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import static com.ruixuan.common.utils.PageUtils.startPage;
- @RestController
- @RequestMapping("/kwaixiaodian/report")
- public class KwaiXiaoDianReportController {
- @Autowired
- private IKwaiXiaoDianReportService kwaiXiaoDianReportService;
- @Autowired
- private ISysRoleService sysRoleService;
- @Autowired
- private IKwaixiaodianItemGetService kwaixiaodianItemGetService;
- // 供应链盯盘数据
- @GetMapping("/getSumInfo")
- public JSONObject getSumInfo(Long userId, String startDate, String endDate, Long companyId) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_courtship_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) {
- Integer nowHour = DateUtils.getNowHour();
- requestMap.put("nowHour", nowHour);
- }
- JSONObject date = kwaiXiaoDianReportService.getSumInfo(requestMap);
- returnJson.put("code", 200);
- returnJson.put("data", date);
- returnJson.put("success", true);
- } catch (Exception e) {
- e.printStackTrace();
- returnJson.put("code", 500);
- returnJson.put("message", e.getMessage());
- }
- return returnJson;
- }
- @GetMapping("/getMonthData")
- public JSONObject getMonthData(Long userId, String startDate, String endDate, Long companyId) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- }
- String monthEndDate = DateUtils.getNowDate("yyyy-MM-dd");
- String monthStartDay = DateUtils.getMonthStartDay(monthEndDate);
- Long monthStart = DateUtils.strDateToInt(monthStartDay);
- Long monthEnd = DateUtils.strDateToInt(monthEndDate);
- requestMap.put("monthStart", monthStart);
- requestMap.put("monthEnd", monthEnd);
- String lastMonthFirstDate = DateUtils.getLastMonthFirstDayByDate(monthEndDate);// 上个月开始时间
- String lastMonthEndDate = DateUtils.getLastMonthNowDay(monthEndDate);// 上个月结束时间
- requestMap.put("lastMonthStart", DateUtils.strDateToInt(lastMonthFirstDate));
- requestMap.put("lastMonthEnd", DateUtils.strDateToInt(lastMonthEndDate));
- JSONObject monthDate = kwaiXiaoDianReportService.getMonthInfo(requestMap);
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) { // 如果传入时间为当天,取当前月的数据
- requestMap.put("echartStart", monthStart);
- requestMap.put("echartEnd", monthEnd);
- } else {
- requestMap.put("echartStart", start);
- requestMap.put("echartEnd", end);
- }
- List<JSONObject> list = kwaiXiaoDianReportService.getEchartData(requestMap);
- monthDate.put("list", list);
- returnJson.put("code", 200);
- returnJson.put("data", monthDate);
- returnJson.put("success", true);
- } catch (Exception e) {
- e.printStackTrace();
- returnJson.put("code", 500);
- returnJson.put("message", e.getMessage());
- }
- return returnJson;
- }
- @GetMapping("/getGmvHours")
- public JSONObject getGmvHours(Long userId, Long companyId, Integer hourType) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- }
- String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
- requestMap.put("date", DateUtils.strDateToInt(nowDate));
- List<JSONObject> today = kwaiXiaoDianReportService.getGmvHours(requestMap);
- String lastDate = null;
- if (hourType == 1) {
- lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 日期 -1
- } else if (hourType == 2) {
- lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -7); // 日期 -7
- }
- requestMap.put("date", DateUtils.strDateToInt(lastDate));
- List<JSONObject> yesterday = kwaiXiaoDianReportService.getGmvHours(requestMap);
- JSONObject data = new JSONObject();
- completionTime(today, "charge");
- completionTime(yesterday, "charge");
- data.put("today", today);
- data.put("yesterday", yesterday);
- returnJson.put("code", 200);
- returnJson.put("data", data);
- returnJson.put("success", true);
- } catch (Exception e) {
- e.printStackTrace();
- returnJson.put("code", 500);
- returnJson.put("message", e.getMessage());
- }
- return returnJson;
- }
- /**
- * 补全时辰
- * 时辰补全
- */
- private void completionTime(List<JSONObject> dataList, String type) {
- List<Integer> newDayList = new ArrayList<>();
- for (JSONObject data : dataList) {
- newDayList.add(data.getInteger("time"));
- }
- List<Integer> dayList = new ArrayList<>();
- for (int i = 0; i <= 23; i++) {
- dayList.add(i);
- }
- for (Integer hour : dayList) {
- if (!newDayList.contains(hour)) {
- JSONObject obj = new JSONObject();
- obj.put("time", hour);
- obj.put(type, 0.00);
- dataList.add(obj);
- }
- }
- statHourListSort(dataList);
- }
- //排序
- private static void statHourListSort(List<JSONObject> list) {
- Collections.sort(list, new Comparator<JSONObject>() {
- @Override
- public int compare(JSONObject o1, JSONObject o2) {
- try {
- Integer dt1 = o1.getInteger("time");
- Integer dt2 = o2.getInteger("time");
- return dt1.compareTo(dt2);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return 0;
- }
- });
- }
- @GetMapping("/getShopListData")
- public TableDataInfo getShopListData(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
- requestMap.put("itemIds", itemIds);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) {
- Integer nowHour = DateUtils.getNowHour();
- requestMap.put("nowHour", nowHour);
- }
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getShopListData(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/getTeamList")
- public TableDataInfo getTeamList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(courtshipPurchaseIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", courtshipPurchaseIds);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- requestMap.put("userIds", courtshipPurchaseIds);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) {
- Integer nowHour = DateUtils.getNowHour();
- requestMap.put("nowHour", nowHour);
- }
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getTeamList(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/getTeamDetail")
- public JSONObject getTeamDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long deptId, String type) {
- JSONObject rspData = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- if (Check.isNull(deptId)) {
- throw new Exception("请传入部门ID");
- }
- if (Check.isNull(type)) {
- throw new Exception("请传入类型");
- }
- Map<String, Object> requestMap = new HashMap<>();
- requestMap.put("deptId", deptId);
- requestMap.put("type", type);
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- requestMap.put("userId", userId);
- }
- if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) {
- requestMap.put("courtshipPurchaseId", userId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) {
- Integer nowHour = DateUtils.getNowHour();
- requestMap.put("nowHour", nowHour);
- }
- List<JSONObject> list = kwaiXiaoDianReportService.getTeamDetail(requestMap);
- rspData.put("code", 200);
- rspData.put("message", "查询成功");
- rspData.put("data", list);
- } catch (Exception e) {
- e.printStackTrace();
- rspData.put("code", 500);
- rspData.put("message", "查询失败");
- }
- return rspData;
- }
- @GetMapping("/getItemList")
- public TableDataInfo getItemList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
- List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
- List<Long> userIds = new ArrayList<>();
- userIds.add(userId);
- if (Check.isNull(userIds)) {
- throw new Exception("此用户未查询到部门成员信息");
- }
- requestMap.put("userIds", userIds);
- } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
- // List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
- // if (Check.isNull(courtshipPurchaseIds)) {
- // throw new Exception("此用户未查询到部门成员信息");
- // }
- // requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
- List<Long> courtshipPurchaseIds = new ArrayList<>();
- courtshipPurchaseIds.add(userId);
- requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
- }
- if (!Check.isNull(itemType)) {
- if (itemType != 0) {
- requestMap.put("itemType", itemType);
- }
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
- if (start.equals(nowDate) && end.equals(nowDate)) {
- Integer nowHour = DateUtils.getNowHour();
- requestMap.put("nowHour", nowHour);
- }
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getItemList(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/getCostTotal")
- public JSONObject getCostTotal(Long userId, String startDate, String endDate, Long companyId) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
- String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
- String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
- requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
- requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
- JSONObject data = kwaiXiaoDianReportService.getCostTotal(requestMap);
- returnJson.put("code", 200);
- returnJson.put("data", data);
- returnJson.put("success", true);
- } catch (Exception e) {
- e.printStackTrace();
- returnJson.put("code", 500);
- returnJson.put("message", e.getMessage());
- }
- return returnJson;
- }
- @GetMapping("/getCostDate")
- public JSONObject getCostDate(Long userId, String startDate, String endDate, Long companyId) {
- JSONObject returnJson = new JSONObject();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- List<JSONObject> data = kwaiXiaoDianReportService.getCostDate(requestMap);
- returnJson.put("code", 200);
- returnJson.put("data", data);
- returnJson.put("success", true);
- } catch (Exception e) {
- e.printStackTrace();
- returnJson.put("code", 500);
- returnJson.put("message", e.getMessage());
- }
- return returnJson;
- }
- @GetMapping("/getItemCostList")
- public TableDataInfo getItemCostList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getItemCostList(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/getSaleReport")
- public TableDataInfo getSaleReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("此用户未查询到归属公司");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
- requestMap.put("userId", userId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/exportSaleReport")
- public void exportSaleReport(HttpServletRequest request, HttpServletResponse response, Long companyId, Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle, Integer itemType) throws IOException, ParseException {
- if (Check.isNull(userId)) {
- return;
- }
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- return;
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
- requestMap.put("userId", userId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
- List<List<Object>> exportList = new ArrayList<>();
- if (!Check.isNull(list)) {
- for (int i = 0; i < list.size(); i++) {
- JSONObject data = list.get(i);
- List<Object> export = new ArrayList();
- export.add(data.getString("userId"));
- export.add(data.getString("userName"));
- export.add(data.getString("itemCount"));
- export.add(data.getString("orderNum"));
- export.add(data.getString("totalFee"));
- export.add(data.getString("costPrice"));
- exportList.add(export);
- }
- }
- String[] headers = {"销售ID", "销售", "商品数", "订单数", "收入", "成本"};
- OutputStream os = response.getOutputStream();
- ExportExcelUtils eeu = new ExportExcelUtils();
- XSSFWorkbook workbook = new XSSFWorkbook();
- eeu.exportExcel(workbook, 0, "销售管理", headers, exportList);
- this.setResponseHeader(response, "销售管理.xls");
- try {
- workbook.write(os);
- } catch (IOException e) {
- e.printStackTrace();
- }
- os.flush();
- os.close();
- }
- @GetMapping("/getSaleDetail")
- public TableDataInfo getSaleDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long loginUserId, Long itemId, String itemTitle) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- Map<String, Object> requestMap = new HashMap<>();
- if (!Check.isNull(userId)) {
- requestMap.put("userId", userId);
- } else {
- requestMap.put("userId", null);
- String roleId = sysRoleService.getRoleBYUserId(loginUserId);
- if ("admin".equals(roleId)) {
- requestMap.put("companyId", null);
- } else {
- Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
- requestMap.put("companyId", companyId);
- }
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- if (!Check.isNull(itemId)) {
- requestMap.put("itemId", itemId);
- }
- if (!Check.isNull(itemTitle)) {
- requestMap.put("itemTitle", itemTitle);
- }
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/exportSaleDetail")
- public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- if (!Check.isNull(userId)) {
- requestMap.put("userId", userId);
- } else {
- requestMap.put("userId", null);
- String roleId = sysRoleService.getRoleBYUserId(loginUserId);
- if ("admin".equals(roleId)) {
- requestMap.put("companyId", null);
- } else {
- Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
- requestMap.put("companyId", companyId);
- }
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
- List<List<Object>> exportList = new ArrayList<>();
- if (!Check.isNull(list)) {
- for (int i = 0; i < list.size(); i++) {
- JSONObject data = list.get(i);
- List<Object> export = new ArrayList();
- export.add(data.getString("itemId"));
- export.add(data.getString("itemTitle"));
- export.add(data.getString("userId"));
- export.add(data.getString("userName"));
- export.add(data.getString("orderNum"));
- export.add(data.getString("totalFee"));
- export.add(data.getString("costPrice"));
- exportList.add(export);
- }
- }
- String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
- OutputStream os = response.getOutputStream();
- ExportExcelUtils eeu = new ExportExcelUtils();
- XSSFWorkbook workbook = new XSSFWorkbook();
- eeu.exportExcel(workbook, 0, "销售详情", headers, exportList);
- this.setResponseHeader(response, "销售详情.xls");
- try {
- workbook.write(os);
- } catch (IOException e) {
- e.printStackTrace();
- }
- os.flush();
- os.close();
- }
- @GetMapping("/getPurchaserReport")
- public TableDataInfo getPurchaserReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- throw new Exception("请传入公司ID");
- }
- requestMap.put("companyId", companyId);
- } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
- requestMap.put("userId", userId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/exportPurchaserReport")
- public void exportPurchaserReport(HttpServletRequest request, HttpServletResponse response, Long companyId, Long userId, String startDate, String endDate, String shopId, Long itemId, String itemTitle, Integer itemType) throws IOException, ParseException {
- if (Check.isNull(userId)) {
- return;
- }
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- String roleId = sysRoleService.getRoleBYUserId(userId);
- if ("admin".equals(roleId)) { // 管理员查看所有
- if (!Check.isNull(companyId)) {
- requestMap.put("companyId", companyId);
- }
- } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
- companyId = kwaixiaodianItemGetService.getCompanyId(userId);
- if (Check.isNull(companyId)) {
- return;
- }
- requestMap.put("companyId", companyId);
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
- List<List<Object>> exportList = new ArrayList<>();
- if (!Check.isNull(list)) {
- for (int i = 0; i < list.size(); i++) {
- JSONObject data = list.get(i);
- List<Object> export = new ArrayList();
- export.add(data.getString("userId"));
- export.add(data.getString("userName"));
- export.add(data.getString("orderNum"));
- export.add(data.getString("totalFee"));
- export.add(data.getString("costPrice"));
- export.add(data.getString("purchaseCost"));
- exportList.add(export);
- }
- }
- String[] headers = {"采购ID", "采购", "订单数", "收入", "成本", "采购金额"};
- OutputStream os = response.getOutputStream();
- ExportExcelUtils eeu = new ExportExcelUtils();
- XSSFWorkbook workbook = new XSSFWorkbook();
- eeu.exportExcel(workbook, 0, "采购管理", headers, exportList);
- this.setResponseHeader(response, "采购管理.xls");
- try {
- workbook.write(os);
- } catch (IOException e) {
- e.printStackTrace();
- }
- os.flush();
- os.close();
- }
- @GetMapping("/getPurchaseDetail")
- public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long loginUserId, Long itemId, String itemTitle) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- Map<String, Object> requestMap = new HashMap<>();
- if (!Check.isNull(userId)) {
- requestMap.put("userId", userId);
- } else {
- requestMap.put("userId", null);
- String roleId = sysRoleService.getRoleBYUserId(loginUserId);
- if ("admin".equals(roleId)) {
- requestMap.put("companyId", null);
- } else {
- Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
- requestMap.put("companyId", companyId);
- }
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- if (!Check.isNull(itemId)) {
- requestMap.put("itemId", itemId);
- }
- if (!Check.isNull(itemTitle)) {
- requestMap.put("itemTitle", itemTitle);
- }
- startPage(pageNum, pageSize);
- List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
- rspData.setCode(HttpStatus.SUCCESS);
- rspData.setMsg("查询成功");
- rspData.setRows(list);
- rspData.setTotal(new PageInfo(list).getTotal());
- } catch (Exception e) {
- e.printStackTrace();
- rspData.setCode(HttpStatus.ERROR);
- rspData.setMsg(e.getMessage());
- }
- return rspData;
- }
- @GetMapping("/exportPurchaseDetail")
- public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- if (!Check.isNull(userId)) {
- requestMap.put("userId", userId);
- } else {
- requestMap.put("userId", null);
- String roleId = sysRoleService.getRoleBYUserId(loginUserId);
- if ("admin".equals(roleId)) {
- requestMap.put("companyId", null);
- } else {
- Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
- requestMap.put("companyId", companyId);
- }
- }
- Long start = DateUtils.strDateToInt(startDate);
- Long end = DateUtils.strDateToInt(endDate);
- requestMap.put("start", start);
- requestMap.put("end", end);
- List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
- List<List<Object>> exportList = new ArrayList<>();
- if (!Check.isNull(list)) {
- for (int i = 0; i < list.size(); i++) {
- JSONObject data = list.get(i);
- List<Object> export = new ArrayList();
- export.add(data.getString("itemId"));
- export.add(data.getString("itemTitle"));
- export.add(data.getString("saleName"));
- export.add(data.getString("userId"));
- export.add(data.getString("purchaseName"));
- export.add(data.getString("orderNum"));
- export.add(data.getString("totalFee"));
- export.add(data.getString("costPrice"));
- exportList.add(export);
- }
- }
- String[] headers = {"商品ID", "商品名称", "销售", "采购ID", "采购", "订单数", "收入", "成本"};
- OutputStream os = response.getOutputStream();
- ExportExcelUtils eeu = new ExportExcelUtils();
- XSSFWorkbook workbook = new XSSFWorkbook();
- eeu.exportExcel(workbook, 0, "采购详情", headers, exportList);
- this.setResponseHeader(response, "采购详情.xls");
- try {
- workbook.write(os);
- } catch (IOException e) {
- e.printStackTrace();
- }
- os.flush();
- os.close();
- }
- public void setResponseHeader(HttpServletResponse response, String fileName) {
- try {
- try {
- fileName = new String(fileName.getBytes(), "ISO8859-1");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- response.setContentType("application/octet-stream;charset=ISO8859-1");
- response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
- response.addHeader("Pargam", "no-cache");
- response.addHeader("Cache-Control", "no-cache");
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
|