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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List userIds = new ArrayList<>(); userIds.add(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_courtship_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据 List courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(courtshipPurchaseIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds); requestMap.put("itemIds", itemIds); } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据 List courtshipPurchaseIds = new ArrayList<>(); courtshipPurchaseIds.add(userId); List 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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List userIds = new ArrayList<>(); userIds.add(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据 List courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(courtshipPurchaseIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds); requestMap.put("itemIds", itemIds); } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据 List courtshipPurchaseIds = new ArrayList<>(); courtshipPurchaseIds.add(userId); List 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 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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List userIds = new ArrayList<>(); userIds.add(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据 List courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(courtshipPurchaseIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds); requestMap.put("itemIds", itemIds); } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据 List courtshipPurchaseIds = new ArrayList<>(); courtshipPurchaseIds.add(userId); List itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds); requestMap.put("itemIds", itemIds); } String nowDate = DateUtils.getNowDate("yyyy-MM-dd"); requestMap.put("date", DateUtils.strDateToInt(nowDate)); List 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 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 dataList, String type) { List newDayList = new ArrayList<>(); for (JSONObject data : dataList) { newDayList.add(data.getInteger("time")); } List 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 list) { Collections.sort(list, new Comparator() { @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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List userIds = new ArrayList<>(); userIds.add(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds); requestMap.put("itemIds", itemIds); } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据 List courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(courtshipPurchaseIds)) { throw new Exception("此用户未查询到部门成员信息"); } List itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds); requestMap.put("itemIds", itemIds); } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据 List courtshipPurchaseIds = new ArrayList<>(); courtshipPurchaseIds.add(userId); List 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 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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } requestMap.put("userIds", userIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List 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 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 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 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 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 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 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 userIds = kwaixiaodianItemGetService.getUserIds(userId); if (Check.isNull(userIds)) { throw new Exception("此用户未查询到部门成员信息"); } requestMap.put("userIds", userIds); } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据 List 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 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 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 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 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 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 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 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 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 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 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 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 list = kwaiXiaoDianReportService.getSaleReport(requestMap); List> exportList = new ArrayList<>(); if (!Check.isNull(list)) { for (int i = 0; i < list.size(); i++) { JSONObject data = list.get(i); List 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 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 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 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 list = kwaiXiaoDianReportService.getSaleDetail(requestMap); List> exportList = new ArrayList<>(); if (!Check.isNull(list)) { for (int i = 0; i < list.size(); i++) { JSONObject data = list.get(i); List 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 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 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 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 list = kwaiXiaoDianReportService.getPurchaserReport(requestMap); List> exportList = new ArrayList<>(); if (!Check.isNull(list)) { for (int i = 0; i < list.size(); i++) { JSONObject data = list.get(i); List 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 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 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 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 list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap); List> exportList = new ArrayList<>(); if (!Check.isNull(list)) { for (int i = 0; i < list.size(); i++) { JSONObject data = list.get(i); List 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(); } } }