1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156 |
- 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) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- 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.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) throws IOException, ParseException {
- if (Check.isNull(userId)) {
- return;
- }
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- 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.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) {
- TableDataInfo rspData = new TableDataInfo();
- try {
- if (Check.isNull(userId)) {
- throw new Exception("请传入用户ID");
- }
- Map<String, Object> requestMap = new HashMap<>();
- 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.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) throws IOException, ParseException {
- if (Check.isNull(userId)) {
- return;
- }
- if (Check.isNull(startDate)) {
- return;
- }
- if (Check.isNull(endDate)) {
- return;
- }
- Map<String, Object> requestMap = new HashMap<>();
- 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.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("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();
- }
- 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();
- }
- }
- }
|