KwaiXiaoDianReportController.java 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. package com.ruixuan.isc.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.PageInfo;
  4. import com.ruixuan.common.constant.HttpStatus;
  5. import com.ruixuan.common.core.page.TableDataInfo;
  6. import com.ruixuan.common.utils.Check;
  7. import com.ruixuan.common.utils.DateUtils;
  8. import com.ruixuan.data.utils.ExportExcelUtils;
  9. import com.ruixuan.isc.service.IKwaiXiaoDianReportService;
  10. import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
  11. import com.ruixuan.system.service.ISysRoleService;
  12. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.io.UnsupportedEncodingException;
  22. import java.text.ParseException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.Collections;
  26. import java.util.Comparator;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. import static com.ruixuan.common.utils.PageUtils.startPage;
  31. @RestController
  32. @RequestMapping("/kwaixiaodian/report")
  33. public class KwaiXiaoDianReportController {
  34. @Autowired
  35. private IKwaiXiaoDianReportService kwaiXiaoDianReportService;
  36. @Autowired
  37. private ISysRoleService sysRoleService;
  38. @Autowired
  39. private IKwaixiaodianItemGetService kwaixiaodianItemGetService;
  40. // 供应链盯盘数据
  41. @GetMapping("/getSumInfo")
  42. public JSONObject getSumInfo(Long userId, String startDate, String endDate, Long companyId) {
  43. JSONObject returnJson = new JSONObject();
  44. try {
  45. if (Check.isNull(userId)) {
  46. throw new Exception("请传入用户ID");
  47. }
  48. Map<String, Object> requestMap = new HashMap<>();
  49. String roleId = sysRoleService.getRoleBYUserId(userId);
  50. if ("admin".equals(roleId)) { // 管理员查看所有
  51. if (!Check.isNull(companyId)) {
  52. requestMap.put("companyId", companyId);
  53. }
  54. } else if ("industry_admin".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
  55. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  56. if (Check.isNull(companyId)) {
  57. throw new Exception("此用户未查询到归属公司");
  58. }
  59. requestMap.put("companyId", companyId);
  60. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  61. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  62. if (Check.isNull(userIds)) {
  63. throw new Exception("此用户未查询到部门成员信息");
  64. }
  65. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  66. requestMap.put("itemIds", itemIds);
  67. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  68. List<Long> userIds = new ArrayList<>();
  69. userIds.add(userId);
  70. if (Check.isNull(userIds)) {
  71. throw new Exception("此用户未查询到部门成员信息");
  72. }
  73. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  74. requestMap.put("itemIds", itemIds);
  75. } else if ("industry_courtship_manager".equals(roleId) ) { // 招商、采购经理角色查看部门下所有成员数据
  76. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  77. if (Check.isNull(courtshipPurchaseIds)) {
  78. throw new Exception("此用户未查询到部门成员信息");
  79. }
  80. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  81. requestMap.put("itemIds", itemIds);
  82. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  83. List<Long> courtshipPurchaseIds = new ArrayList<>();
  84. courtshipPurchaseIds.add(userId);
  85. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  86. requestMap.put("itemIds", itemIds);
  87. }
  88. Long start = DateUtils.strDateToInt(startDate);
  89. Long end = DateUtils.strDateToInt(endDate);
  90. requestMap.put("start", start);
  91. requestMap.put("end", end);
  92. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  93. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  94. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  95. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  96. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  97. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  98. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  99. if (start.equals(nowDate) && end.equals(nowDate)) {
  100. Integer nowHour = DateUtils.getNowHour();
  101. requestMap.put("nowHour", nowHour);
  102. }
  103. JSONObject date = kwaiXiaoDianReportService.getSumInfo(requestMap);
  104. returnJson.put("code", 200);
  105. returnJson.put("data", date);
  106. returnJson.put("success", true);
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. returnJson.put("code", 500);
  110. returnJson.put("message", e.getMessage());
  111. }
  112. return returnJson;
  113. }
  114. @GetMapping("/getMonthData")
  115. public JSONObject getMonthData(Long userId, String startDate, String endDate, Long companyId) {
  116. JSONObject returnJson = new JSONObject();
  117. try {
  118. if (Check.isNull(userId)) {
  119. throw new Exception("请传入用户ID");
  120. }
  121. Map<String, Object> requestMap = new HashMap<>();
  122. String roleId = sysRoleService.getRoleBYUserId(userId);
  123. if ("admin".equals(roleId)) { // 管理员查看所有
  124. if (!Check.isNull(companyId)) {
  125. requestMap.put("companyId", companyId);
  126. }
  127. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  128. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  129. if (Check.isNull(companyId)) {
  130. throw new Exception("此用户未查询到归属公司");
  131. }
  132. requestMap.put("companyId", companyId);
  133. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  134. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  135. if (Check.isNull(userIds)) {
  136. throw new Exception("此用户未查询到部门成员信息");
  137. }
  138. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  139. requestMap.put("itemIds", itemIds);
  140. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  141. List<Long> userIds = new ArrayList<>();
  142. userIds.add(userId);
  143. if (Check.isNull(userIds)) {
  144. throw new Exception("此用户未查询到部门成员信息");
  145. }
  146. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  147. requestMap.put("itemIds", itemIds);
  148. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  149. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  150. if (Check.isNull(courtshipPurchaseIds)) {
  151. throw new Exception("此用户未查询到部门成员信息");
  152. }
  153. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  154. requestMap.put("itemIds", itemIds);
  155. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  156. List<Long> courtshipPurchaseIds = new ArrayList<>();
  157. courtshipPurchaseIds.add(userId);
  158. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  159. requestMap.put("itemIds", itemIds);
  160. }
  161. String monthEndDate = DateUtils.getNowDate("yyyy-MM-dd");
  162. String monthStartDay = DateUtils.getMonthStartDay(monthEndDate);
  163. Long monthStart = DateUtils.strDateToInt(monthStartDay);
  164. Long monthEnd = DateUtils.strDateToInt(monthEndDate);
  165. requestMap.put("monthStart", monthStart);
  166. requestMap.put("monthEnd", monthEnd);
  167. String lastMonthFirstDate = DateUtils.getLastMonthFirstDayByDate(monthEndDate);// 上个月开始时间
  168. String lastMonthEndDate = DateUtils.getLastMonthNowDay(monthEndDate);// 上个月结束时间
  169. requestMap.put("lastMonthStart", DateUtils.strDateToInt(lastMonthFirstDate));
  170. requestMap.put("lastMonthEnd", DateUtils.strDateToInt(lastMonthEndDate));
  171. JSONObject monthDate = kwaiXiaoDianReportService.getMonthInfo(requestMap);
  172. Long start = DateUtils.strDateToInt(startDate);
  173. Long end = DateUtils.strDateToInt(endDate);
  174. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  175. if (start.equals(nowDate) && end.equals(nowDate)) { // 如果传入时间为当天,取当前月的数据
  176. requestMap.put("echartStart", monthStart);
  177. requestMap.put("echartEnd", monthEnd);
  178. } else {
  179. requestMap.put("echartStart", start);
  180. requestMap.put("echartEnd", end);
  181. }
  182. List<JSONObject> list = kwaiXiaoDianReportService.getEchartData(requestMap);
  183. monthDate.put("list", list);
  184. returnJson.put("code", 200);
  185. returnJson.put("data", monthDate);
  186. returnJson.put("success", true);
  187. } catch (Exception e) {
  188. e.printStackTrace();
  189. returnJson.put("code", 500);
  190. returnJson.put("message", e.getMessage());
  191. }
  192. return returnJson;
  193. }
  194. @GetMapping("/getGmvHours")
  195. public JSONObject getGmvHours(Long userId, Long companyId, Integer hourType) {
  196. JSONObject returnJson = new JSONObject();
  197. try {
  198. if (Check.isNull(userId)) {
  199. throw new Exception("请传入用户ID");
  200. }
  201. Map<String, Object> requestMap = new HashMap<>();
  202. String roleId = sysRoleService.getRoleBYUserId(userId);
  203. if ("admin".equals(roleId)) { // 管理员查看所有
  204. if (!Check.isNull(companyId)) {
  205. requestMap.put("companyId", companyId);
  206. }
  207. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  208. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  209. if (Check.isNull(companyId)) {
  210. throw new Exception("此用户未查询到归属公司");
  211. }
  212. requestMap.put("companyId", companyId);
  213. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  214. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  215. if (Check.isNull(userIds)) {
  216. throw new Exception("此用户未查询到部门成员信息");
  217. }
  218. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  219. requestMap.put("itemIds", itemIds);
  220. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  221. List<Long> userIds = new ArrayList<>();
  222. userIds.add(userId);
  223. if (Check.isNull(userIds)) {
  224. throw new Exception("此用户未查询到部门成员信息");
  225. }
  226. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  227. requestMap.put("itemIds", itemIds);
  228. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  229. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  230. if (Check.isNull(courtshipPurchaseIds)) {
  231. throw new Exception("此用户未查询到部门成员信息");
  232. }
  233. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  234. requestMap.put("itemIds", itemIds);
  235. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  236. List<Long> courtshipPurchaseIds = new ArrayList<>();
  237. courtshipPurchaseIds.add(userId);
  238. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  239. requestMap.put("itemIds", itemIds);
  240. }
  241. String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
  242. requestMap.put("date", DateUtils.strDateToInt(nowDate));
  243. List<JSONObject> today = kwaiXiaoDianReportService.getGmvHours(requestMap);
  244. String lastDate = null;
  245. if (hourType == 1) {
  246. lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 日期 -1
  247. } else if (hourType == 2) {
  248. lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -7); // 日期 -7
  249. }
  250. requestMap.put("date", DateUtils.strDateToInt(lastDate));
  251. List<JSONObject> yesterday = kwaiXiaoDianReportService.getGmvHours(requestMap);
  252. JSONObject data = new JSONObject();
  253. completionTime(today, "charge");
  254. completionTime(yesterday, "charge");
  255. data.put("today", today);
  256. data.put("yesterday", yesterday);
  257. returnJson.put("code", 200);
  258. returnJson.put("data", data);
  259. returnJson.put("success", true);
  260. } catch (Exception e) {
  261. e.printStackTrace();
  262. returnJson.put("code", 500);
  263. returnJson.put("message", e.getMessage());
  264. }
  265. return returnJson;
  266. }
  267. /**
  268. * 补全时辰
  269. * 时辰补全
  270. */
  271. private void completionTime(List<JSONObject> dataList, String type) {
  272. List<Integer> newDayList = new ArrayList<>();
  273. for (JSONObject data : dataList) {
  274. newDayList.add(data.getInteger("time"));
  275. }
  276. List<Integer> dayList = new ArrayList<>();
  277. for (int i = 0; i <= 23; i++) {
  278. dayList.add(i);
  279. }
  280. for (Integer hour : dayList) {
  281. if (!newDayList.contains(hour)) {
  282. JSONObject obj = new JSONObject();
  283. obj.put("time", hour);
  284. obj.put(type, 0.00);
  285. dataList.add(obj);
  286. }
  287. }
  288. statHourListSort(dataList);
  289. }
  290. //排序
  291. private static void statHourListSort(List<JSONObject> list) {
  292. Collections.sort(list, new Comparator<JSONObject>() {
  293. @Override
  294. public int compare(JSONObject o1, JSONObject o2) {
  295. try {
  296. Integer dt1 = o1.getInteger("time");
  297. Integer dt2 = o2.getInteger("time");
  298. return dt1.compareTo(dt2);
  299. } catch (Exception e) {
  300. e.printStackTrace();
  301. }
  302. return 0;
  303. }
  304. });
  305. }
  306. @GetMapping("/getShopListData")
  307. public TableDataInfo getShopListData(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  308. TableDataInfo rspData = new TableDataInfo();
  309. try {
  310. if (Check.isNull(userId)) {
  311. throw new Exception("请传入用户ID");
  312. }
  313. Map<String, Object> requestMap = new HashMap<>();
  314. String roleId = sysRoleService.getRoleBYUserId(userId);
  315. if ("admin".equals(roleId)) { // 管理员查看所有
  316. if (!Check.isNull(companyId)) {
  317. requestMap.put("companyId", companyId);
  318. }
  319. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  320. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  321. if (Check.isNull(companyId)) {
  322. throw new Exception("此用户未查询到归属公司");
  323. }
  324. requestMap.put("companyId", companyId);
  325. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  326. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  327. if (Check.isNull(userIds)) {
  328. throw new Exception("此用户未查询到部门成员信息");
  329. }
  330. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  331. requestMap.put("itemIds", itemIds);
  332. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  333. List<Long> userIds = new ArrayList<>();
  334. userIds.add(userId);
  335. if (Check.isNull(userIds)) {
  336. throw new Exception("此用户未查询到部门成员信息");
  337. }
  338. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  339. requestMap.put("itemIds", itemIds);
  340. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  341. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  342. if (Check.isNull(courtshipPurchaseIds)) {
  343. throw new Exception("此用户未查询到部门成员信息");
  344. }
  345. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  346. requestMap.put("itemIds", itemIds);
  347. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  348. List<Long> courtshipPurchaseIds = new ArrayList<>();
  349. courtshipPurchaseIds.add(userId);
  350. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  351. requestMap.put("itemIds", itemIds);
  352. }
  353. Long start = DateUtils.strDateToInt(startDate);
  354. Long end = DateUtils.strDateToInt(endDate);
  355. requestMap.put("start", start);
  356. requestMap.put("end", end);
  357. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  358. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  359. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  360. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  361. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  362. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  363. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  364. if (start.equals(nowDate) && end.equals(nowDate)) {
  365. Integer nowHour = DateUtils.getNowHour();
  366. requestMap.put("nowHour", nowHour);
  367. }
  368. startPage(pageNum, pageSize);
  369. List<JSONObject> list = kwaiXiaoDianReportService.getShopListData(requestMap);
  370. rspData.setCode(HttpStatus.SUCCESS);
  371. rspData.setMsg("查询成功");
  372. rspData.setRows(list);
  373. rspData.setTotal(new PageInfo(list).getTotal());
  374. } catch (Exception e) {
  375. e.printStackTrace();
  376. rspData.setCode(HttpStatus.ERROR);
  377. rspData.setMsg(e.getMessage());
  378. }
  379. return rspData;
  380. }
  381. @GetMapping("/getTeamList")
  382. public TableDataInfo getTeamList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  383. TableDataInfo rspData = new TableDataInfo();
  384. try {
  385. if (Check.isNull(userId)) {
  386. throw new Exception("请传入用户ID");
  387. }
  388. Map<String, Object> requestMap = new HashMap<>();
  389. String roleId = sysRoleService.getRoleBYUserId(userId);
  390. if ("admin".equals(roleId)) { // 管理员查看所有
  391. if (!Check.isNull(companyId)) {
  392. requestMap.put("companyId", companyId);
  393. }
  394. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  395. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  396. if (Check.isNull(companyId)) {
  397. throw new Exception("此用户未查询到归属公司");
  398. }
  399. requestMap.put("companyId", companyId);
  400. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  401. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  402. if (Check.isNull(userIds)) {
  403. throw new Exception("此用户未查询到部门成员信息");
  404. }
  405. requestMap.put("userIds", userIds);
  406. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  407. List<Long> userIds = new ArrayList<>();
  408. userIds.add(userId);
  409. if (Check.isNull(userIds)) {
  410. throw new Exception("此用户未查询到部门成员信息");
  411. }
  412. requestMap.put("userIds", userIds);
  413. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  414. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  415. if (Check.isNull(courtshipPurchaseIds)) {
  416. throw new Exception("此用户未查询到部门成员信息");
  417. }
  418. requestMap.put("userIds", courtshipPurchaseIds);
  419. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  420. List<Long> courtshipPurchaseIds = new ArrayList<>();
  421. courtshipPurchaseIds.add(userId);
  422. requestMap.put("userIds", courtshipPurchaseIds);
  423. }
  424. Long start = DateUtils.strDateToInt(startDate);
  425. Long end = DateUtils.strDateToInt(endDate);
  426. requestMap.put("start", start);
  427. requestMap.put("end", end);
  428. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  429. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  430. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  431. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  432. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  433. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  434. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  435. if (start.equals(nowDate) && end.equals(nowDate)) {
  436. Integer nowHour = DateUtils.getNowHour();
  437. requestMap.put("nowHour", nowHour);
  438. }
  439. startPage(pageNum, pageSize);
  440. List<JSONObject> list = kwaiXiaoDianReportService.getTeamList(requestMap);
  441. rspData.setCode(HttpStatus.SUCCESS);
  442. rspData.setMsg("查询成功");
  443. rspData.setRows(list);
  444. rspData.setTotal(new PageInfo(list).getTotal());
  445. } catch (Exception e) {
  446. e.printStackTrace();
  447. rspData.setCode(HttpStatus.ERROR);
  448. rspData.setMsg(e.getMessage());
  449. }
  450. return rspData;
  451. }
  452. @GetMapping("/getTeamDetail")
  453. public JSONObject getTeamDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long deptId, String type) {
  454. JSONObject rspData = new JSONObject();
  455. try {
  456. if (Check.isNull(userId)) {
  457. throw new Exception("请传入用户ID");
  458. }
  459. if (Check.isNull(deptId)) {
  460. throw new Exception("请传入部门ID");
  461. }
  462. if (Check.isNull(type)) {
  463. throw new Exception("请传入类型");
  464. }
  465. Map<String, Object> requestMap = new HashMap<>();
  466. requestMap.put("deptId", deptId);
  467. requestMap.put("type", type);
  468. String roleId = sysRoleService.getRoleBYUserId(userId);
  469. if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  470. requestMap.put("userId", userId);
  471. }
  472. if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) {
  473. requestMap.put("courtshipPurchaseId", userId);
  474. }
  475. Long start = DateUtils.strDateToInt(startDate);
  476. Long end = DateUtils.strDateToInt(endDate);
  477. requestMap.put("start", start);
  478. requestMap.put("end", end);
  479. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  480. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  481. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  482. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  483. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  484. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  485. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  486. if (start.equals(nowDate) && end.equals(nowDate)) {
  487. Integer nowHour = DateUtils.getNowHour();
  488. requestMap.put("nowHour", nowHour);
  489. }
  490. List<JSONObject> list = kwaiXiaoDianReportService.getTeamDetail(requestMap);
  491. rspData.put("code", 200);
  492. rspData.put("message", "查询成功");
  493. rspData.put("data", list);
  494. } catch (Exception e) {
  495. e.printStackTrace();
  496. rspData.put("code", 500);
  497. rspData.put("message", "查询失败");
  498. }
  499. return rspData;
  500. }
  501. @GetMapping("/getItemList")
  502. public TableDataInfo getItemList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
  503. TableDataInfo rspData = new TableDataInfo();
  504. try {
  505. if (Check.isNull(userId)) {
  506. throw new Exception("请传入用户ID");
  507. }
  508. Map<String, Object> requestMap = new HashMap<>();
  509. String roleId = sysRoleService.getRoleBYUserId(userId);
  510. if ("admin".equals(roleId)) { // 管理员查看所有
  511. if (!Check.isNull(companyId)) {
  512. requestMap.put("companyId", companyId);
  513. }
  514. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  515. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  516. if (Check.isNull(companyId)) {
  517. throw new Exception("此用户未查询到归属公司");
  518. }
  519. requestMap.put("companyId", companyId);
  520. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  521. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  522. if (Check.isNull(userIds)) {
  523. throw new Exception("此用户未查询到部门成员信息");
  524. }
  525. requestMap.put("userIds", userIds);
  526. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  527. List<Long> userIds = new ArrayList<>();
  528. userIds.add(userId);
  529. if (Check.isNull(userIds)) {
  530. throw new Exception("此用户未查询到部门成员信息");
  531. }
  532. requestMap.put("userIds", userIds);
  533. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  534. // List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  535. // if (Check.isNull(courtshipPurchaseIds)) {
  536. // throw new Exception("此用户未查询到部门成员信息");
  537. // }
  538. // requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
  539. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  540. if (Check.isNull(companyId)) {
  541. throw new Exception("此用户未查询到归属公司");
  542. }
  543. requestMap.put("companyId", companyId);
  544. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  545. List<Long> courtshipPurchaseIds = new ArrayList<>();
  546. courtshipPurchaseIds.add(userId);
  547. requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
  548. }
  549. if (!Check.isNull(itemType)) {
  550. if (itemType != 0) {
  551. requestMap.put("itemType", itemType);
  552. }
  553. }
  554. Long start = DateUtils.strDateToInt(startDate);
  555. Long end = DateUtils.strDateToInt(endDate);
  556. requestMap.put("start", start);
  557. requestMap.put("end", end);
  558. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  559. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  560. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  561. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  562. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  563. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  564. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  565. if (start.equals(nowDate) && end.equals(nowDate)) {
  566. Integer nowHour = DateUtils.getNowHour();
  567. requestMap.put("nowHour", nowHour);
  568. }
  569. startPage(pageNum, pageSize);
  570. List<JSONObject> list = kwaiXiaoDianReportService.getItemList(requestMap);
  571. rspData.setCode(HttpStatus.SUCCESS);
  572. rspData.setMsg("查询成功");
  573. rspData.setRows(list);
  574. rspData.setTotal(new PageInfo(list).getTotal());
  575. } catch (Exception e) {
  576. e.printStackTrace();
  577. rspData.setCode(HttpStatus.ERROR);
  578. rspData.setMsg(e.getMessage());
  579. }
  580. return rspData;
  581. }
  582. @GetMapping("/getCostTotal")
  583. public JSONObject getCostTotal(Long userId, String startDate, String endDate, Long companyId) {
  584. JSONObject returnJson = new JSONObject();
  585. try {
  586. if (Check.isNull(userId)) {
  587. throw new Exception("请传入用户ID");
  588. }
  589. Map<String, Object> requestMap = new HashMap<>();
  590. String roleId = sysRoleService.getRoleBYUserId(userId);
  591. if ("admin".equals(roleId)) { // 管理员查看所有
  592. if (!Check.isNull(companyId)) {
  593. requestMap.put("companyId", companyId);
  594. }
  595. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  596. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  597. if (Check.isNull(companyId)) {
  598. throw new Exception("此用户未查询到归属公司");
  599. }
  600. requestMap.put("companyId", companyId);
  601. }
  602. Long start = DateUtils.strDateToInt(startDate);
  603. Long end = DateUtils.strDateToInt(endDate);
  604. requestMap.put("start", start);
  605. requestMap.put("end", end);
  606. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  607. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  608. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  609. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  610. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  611. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  612. JSONObject data = kwaiXiaoDianReportService.getCostTotal(requestMap);
  613. returnJson.put("code", 200);
  614. returnJson.put("data", data);
  615. returnJson.put("success", true);
  616. } catch (Exception e) {
  617. e.printStackTrace();
  618. returnJson.put("code", 500);
  619. returnJson.put("message", e.getMessage());
  620. }
  621. return returnJson;
  622. }
  623. @GetMapping("/getCostDate")
  624. public JSONObject getCostDate(Long userId, String startDate, String endDate, Long companyId) {
  625. JSONObject returnJson = new JSONObject();
  626. try {
  627. if (Check.isNull(userId)) {
  628. throw new Exception("请传入用户ID");
  629. }
  630. Map<String, Object> requestMap = new HashMap<>();
  631. String roleId = sysRoleService.getRoleBYUserId(userId);
  632. if ("admin".equals(roleId)) { // 管理员查看所有
  633. if (!Check.isNull(companyId)) {
  634. requestMap.put("companyId", companyId);
  635. }
  636. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  637. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  638. if (Check.isNull(companyId)) {
  639. throw new Exception("此用户未查询到归属公司");
  640. }
  641. requestMap.put("companyId", companyId);
  642. }
  643. Long start = DateUtils.strDateToInt(startDate);
  644. Long end = DateUtils.strDateToInt(endDate);
  645. requestMap.put("start", start);
  646. requestMap.put("end", end);
  647. List<JSONObject> data = kwaiXiaoDianReportService.getCostDate(requestMap);
  648. returnJson.put("code", 200);
  649. returnJson.put("data", data);
  650. returnJson.put("success", true);
  651. } catch (Exception e) {
  652. e.printStackTrace();
  653. returnJson.put("code", 500);
  654. returnJson.put("message", e.getMessage());
  655. }
  656. return returnJson;
  657. }
  658. @GetMapping("/getItemCostList")
  659. public TableDataInfo getItemCostList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
  660. TableDataInfo rspData = new TableDataInfo();
  661. try {
  662. if (Check.isNull(userId)) {
  663. throw new Exception("请传入用户ID");
  664. }
  665. Map<String, Object> requestMap = new HashMap<>();
  666. String roleId = sysRoleService.getRoleBYUserId(userId);
  667. if ("admin".equals(roleId)) { // 管理员查看所有
  668. if (!Check.isNull(companyId)) {
  669. requestMap.put("companyId", companyId);
  670. }
  671. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  672. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  673. if (Check.isNull(companyId)) {
  674. throw new Exception("此用户未查询到归属公司");
  675. }
  676. requestMap.put("companyId", companyId);
  677. }
  678. Long start = DateUtils.strDateToInt(startDate);
  679. Long end = DateUtils.strDateToInt(endDate);
  680. requestMap.put("start", start);
  681. requestMap.put("end", end);
  682. startPage(pageNum, pageSize);
  683. List<JSONObject> list = kwaiXiaoDianReportService.getItemCostList(requestMap);
  684. rspData.setCode(HttpStatus.SUCCESS);
  685. rspData.setMsg("查询成功");
  686. rspData.setRows(list);
  687. rspData.setTotal(new PageInfo(list).getTotal());
  688. } catch (Exception e) {
  689. e.printStackTrace();
  690. rspData.setCode(HttpStatus.ERROR);
  691. rspData.setMsg(e.getMessage());
  692. }
  693. return rspData;
  694. }
  695. @GetMapping("/getSaleReport")
  696. public TableDataInfo getSaleReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  697. TableDataInfo rspData = new TableDataInfo();
  698. try {
  699. if (Check.isNull(userId)) {
  700. throw new Exception("请传入用户ID");
  701. }
  702. Map<String, Object> requestMap = new HashMap<>();
  703. String roleId = sysRoleService.getRoleBYUserId(userId);
  704. if ("admin".equals(roleId)) { // 管理员查看所有
  705. if (!Check.isNull(companyId)) {
  706. requestMap.put("companyId", companyId);
  707. }
  708. } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
  709. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  710. if (Check.isNull(companyId)) {
  711. throw new Exception("此用户未查询到归属公司");
  712. }
  713. requestMap.put("companyId", companyId);
  714. } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
  715. requestMap.put("userId", userId);
  716. }
  717. Long start = DateUtils.strDateToInt(startDate);
  718. Long end = DateUtils.strDateToInt(endDate);
  719. requestMap.put("start", start);
  720. requestMap.put("end", end);
  721. startPage(pageNum, pageSize);
  722. List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
  723. rspData.setCode(HttpStatus.SUCCESS);
  724. rspData.setMsg("查询成功");
  725. rspData.setRows(list);
  726. rspData.setTotal(new PageInfo(list).getTotal());
  727. } catch (Exception e) {
  728. e.printStackTrace();
  729. rspData.setCode(HttpStatus.ERROR);
  730. rspData.setMsg(e.getMessage());
  731. }
  732. return rspData;
  733. }
  734. @GetMapping("/exportSaleReport")
  735. 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 {
  736. if (Check.isNull(userId)) {
  737. return;
  738. }
  739. if (Check.isNull(startDate)) {
  740. return;
  741. }
  742. if (Check.isNull(endDate)) {
  743. return;
  744. }
  745. Map<String, Object> requestMap = new HashMap<>();
  746. String roleId = sysRoleService.getRoleBYUserId(userId);
  747. if ("admin".equals(roleId)) { // 管理员查看所有
  748. if (!Check.isNull(companyId)) {
  749. requestMap.put("companyId", companyId);
  750. }
  751. } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
  752. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  753. if (Check.isNull(companyId)) {
  754. return;
  755. }
  756. requestMap.put("companyId", companyId);
  757. } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
  758. requestMap.put("userId", userId);
  759. }
  760. Long start = DateUtils.strDateToInt(startDate);
  761. Long end = DateUtils.strDateToInt(endDate);
  762. requestMap.put("start", start);
  763. requestMap.put("end", end);
  764. List<JSONObject> list = kwaiXiaoDianReportService.getSaleReport(requestMap);
  765. List<List<Object>> exportList = new ArrayList<>();
  766. if (!Check.isNull(list)) {
  767. for (int i = 0; i < list.size(); i++) {
  768. JSONObject data = list.get(i);
  769. List<Object> export = new ArrayList();
  770. export.add(data.getString("userId"));
  771. export.add(data.getString("userName"));
  772. export.add(data.getString("itemCount"));
  773. export.add(data.getString("orderNum"));
  774. export.add(data.getString("totalFee"));
  775. export.add(data.getString("costPrice"));
  776. exportList.add(export);
  777. }
  778. }
  779. String[] headers = {"销售ID", "销售", "商品数", "订单数", "收入", "成本"};
  780. OutputStream os = response.getOutputStream();
  781. ExportExcelUtils eeu = new ExportExcelUtils();
  782. XSSFWorkbook workbook = new XSSFWorkbook();
  783. eeu.exportExcel(workbook, 0, "销售管理", headers, exportList);
  784. this.setResponseHeader(response, "销售管理.xls");
  785. try {
  786. workbook.write(os);
  787. } catch (IOException e) {
  788. e.printStackTrace();
  789. }
  790. os.flush();
  791. os.close();
  792. }
  793. @GetMapping("/getSaleDetail")
  794. public TableDataInfo getSaleDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
  795. TableDataInfo rspData = new TableDataInfo();
  796. try {
  797. if (Check.isNull(userId)) {
  798. throw new Exception("请传入用户ID");
  799. }
  800. Map<String, Object> requestMap = new HashMap<>();
  801. requestMap.put("userId", userId);
  802. Long start = DateUtils.strDateToInt(startDate);
  803. Long end = DateUtils.strDateToInt(endDate);
  804. requestMap.put("start", start);
  805. requestMap.put("end", end);
  806. startPage(pageNum, pageSize);
  807. List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
  808. rspData.setCode(HttpStatus.SUCCESS);
  809. rspData.setMsg("查询成功");
  810. rspData.setRows(list);
  811. rspData.setTotal(new PageInfo(list).getTotal());
  812. } catch (Exception e) {
  813. e.printStackTrace();
  814. rspData.setCode(HttpStatus.ERROR);
  815. rspData.setMsg(e.getMessage());
  816. }
  817. return rspData;
  818. }
  819. @GetMapping("/exportSaleDetail")
  820. public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
  821. if (Check.isNull(userId)) {
  822. return;
  823. }
  824. if (Check.isNull(startDate)) {
  825. return;
  826. }
  827. if (Check.isNull(endDate)) {
  828. return;
  829. }
  830. Map<String, Object> requestMap = new HashMap<>();
  831. requestMap.put("userId", userId);
  832. Long start = DateUtils.strDateToInt(startDate);
  833. Long end = DateUtils.strDateToInt(endDate);
  834. requestMap.put("start", start);
  835. requestMap.put("end", end);
  836. List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
  837. List<List<Object>> exportList = new ArrayList<>();
  838. if (!Check.isNull(list)) {
  839. for (int i = 0; i < list.size(); i++) {
  840. JSONObject data = list.get(i);
  841. List<Object> export = new ArrayList();
  842. export.add(data.getString("itemId"));
  843. export.add(data.getString("itemTitle"));
  844. export.add(data.getString("userId"));
  845. export.add(data.getString("userName"));
  846. export.add(data.getString("orderNum"));
  847. export.add(data.getString("totalFee"));
  848. export.add(data.getString("costPrice"));
  849. exportList.add(export);
  850. }
  851. }
  852. String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
  853. OutputStream os = response.getOutputStream();
  854. ExportExcelUtils eeu = new ExportExcelUtils();
  855. XSSFWorkbook workbook = new XSSFWorkbook();
  856. eeu.exportExcel(workbook, 0, "销售详情", headers, exportList);
  857. this.setResponseHeader(response, "销售详情.xls");
  858. try {
  859. workbook.write(os);
  860. } catch (IOException e) {
  861. e.printStackTrace();
  862. }
  863. os.flush();
  864. os.close();
  865. }
  866. @GetMapping("/getPurchaserReport")
  867. public TableDataInfo getPurchaserReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  868. TableDataInfo rspData = new TableDataInfo();
  869. try {
  870. if (Check.isNull(userId)) {
  871. throw new Exception("请传入用户ID");
  872. }
  873. Map<String, Object> requestMap = new HashMap<>();
  874. String roleId = sysRoleService.getRoleBYUserId(userId);
  875. if ("admin".equals(roleId)) { // 管理员查看所有
  876. if (!Check.isNull(companyId)) {
  877. requestMap.put("companyId", companyId);
  878. }
  879. } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
  880. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  881. if (Check.isNull(companyId)) {
  882. throw new Exception("请传入公司ID");
  883. }
  884. requestMap.put("companyId", companyId);
  885. } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
  886. requestMap.put("userId", userId);
  887. }
  888. Long start = DateUtils.strDateToInt(startDate);
  889. Long end = DateUtils.strDateToInt(endDate);
  890. requestMap.put("start", start);
  891. requestMap.put("end", end);
  892. startPage(pageNum, pageSize);
  893. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
  894. rspData.setCode(HttpStatus.SUCCESS);
  895. rspData.setMsg("查询成功");
  896. rspData.setRows(list);
  897. rspData.setTotal(new PageInfo(list).getTotal());
  898. } catch (Exception e) {
  899. e.printStackTrace();
  900. rspData.setCode(HttpStatus.ERROR);
  901. rspData.setMsg(e.getMessage());
  902. }
  903. return rspData;
  904. }
  905. @GetMapping("/exportPurchaserReport")
  906. 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 {
  907. if (Check.isNull(userId)) {
  908. return;
  909. }
  910. if (Check.isNull(startDate)) {
  911. return;
  912. }
  913. if (Check.isNull(endDate)) {
  914. return;
  915. }
  916. Map<String, Object> requestMap = new HashMap<>();
  917. String roleId = sysRoleService.getRoleBYUserId(userId);
  918. if ("admin".equals(roleId)) { // 管理员查看所有
  919. if (!Check.isNull(companyId)) {
  920. requestMap.put("companyId", companyId);
  921. }
  922. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  923. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  924. if (Check.isNull(companyId)) {
  925. return;
  926. }
  927. requestMap.put("companyId", companyId);
  928. }
  929. Long start = DateUtils.strDateToInt(startDate);
  930. Long end = DateUtils.strDateToInt(endDate);
  931. requestMap.put("start", start);
  932. requestMap.put("end", end);
  933. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
  934. List<List<Object>> exportList = new ArrayList<>();
  935. if (!Check.isNull(list)) {
  936. for (int i = 0; i < list.size(); i++) {
  937. JSONObject data = list.get(i);
  938. List<Object> export = new ArrayList();
  939. export.add(data.getString("userId"));
  940. export.add(data.getString("userName"));
  941. export.add(data.getString("orderNum"));
  942. export.add(data.getString("totalFee"));
  943. export.add(data.getString("costPrice"));
  944. export.add(data.getString("purchaseCost"));
  945. exportList.add(export);
  946. }
  947. }
  948. String[] headers = {"采购ID", "采购", "订单数", "收入", "成本", "采购金额"};
  949. OutputStream os = response.getOutputStream();
  950. ExportExcelUtils eeu = new ExportExcelUtils();
  951. XSSFWorkbook workbook = new XSSFWorkbook();
  952. eeu.exportExcel(workbook, 0, "采购管理", headers, exportList);
  953. this.setResponseHeader(response, "采购管理.xls");
  954. try {
  955. workbook.write(os);
  956. } catch (IOException e) {
  957. e.printStackTrace();
  958. }
  959. os.flush();
  960. os.close();
  961. }
  962. @GetMapping("/getPurchaseDetail")
  963. public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
  964. TableDataInfo rspData = new TableDataInfo();
  965. try {
  966. if (Check.isNull(userId)) {
  967. throw new Exception("请传入用户ID");
  968. }
  969. Map<String, Object> requestMap = new HashMap<>();
  970. requestMap.put("userId", userId);
  971. Long start = DateUtils.strDateToInt(startDate);
  972. Long end = DateUtils.strDateToInt(endDate);
  973. requestMap.put("start", start);
  974. requestMap.put("end", end);
  975. startPage(pageNum, pageSize);
  976. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
  977. rspData.setCode(HttpStatus.SUCCESS);
  978. rspData.setMsg("查询成功");
  979. rspData.setRows(list);
  980. rspData.setTotal(new PageInfo(list).getTotal());
  981. } catch (Exception e) {
  982. e.printStackTrace();
  983. rspData.setCode(HttpStatus.ERROR);
  984. rspData.setMsg(e.getMessage());
  985. }
  986. return rspData;
  987. }
  988. @GetMapping("/exportPurchaseDetail")
  989. public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
  990. if (Check.isNull(userId)) {
  991. return;
  992. }
  993. if (Check.isNull(startDate)) {
  994. return;
  995. }
  996. if (Check.isNull(endDate)) {
  997. return;
  998. }
  999. Map<String, Object> requestMap = new HashMap<>();
  1000. requestMap.put("userId", userId);
  1001. Long start = DateUtils.strDateToInt(startDate);
  1002. Long end = DateUtils.strDateToInt(endDate);
  1003. requestMap.put("start", start);
  1004. requestMap.put("end", end);
  1005. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
  1006. List<List<Object>> exportList = new ArrayList<>();
  1007. if (!Check.isNull(list)) {
  1008. for (int i = 0; i < list.size(); i++) {
  1009. JSONObject data = list.get(i);
  1010. List<Object> export = new ArrayList();
  1011. export.add(data.getString("itemId"));
  1012. export.add(data.getString("itemTitle"));
  1013. export.add(data.getString("userId"));
  1014. export.add(data.getString("userName"));
  1015. export.add(data.getString("orderNum"));
  1016. export.add(data.getString("totalFee"));
  1017. export.add(data.getString("costPrice"));
  1018. exportList.add(export);
  1019. }
  1020. }
  1021. String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
  1022. OutputStream os = response.getOutputStream();
  1023. ExportExcelUtils eeu = new ExportExcelUtils();
  1024. XSSFWorkbook workbook = new XSSFWorkbook();
  1025. eeu.exportExcel(workbook, 0, "采购详情", headers, exportList);
  1026. this.setResponseHeader(response, "采购详情.xls");
  1027. try {
  1028. workbook.write(os);
  1029. } catch (IOException e) {
  1030. e.printStackTrace();
  1031. }
  1032. os.flush();
  1033. os.close();
  1034. }
  1035. public void setResponseHeader(HttpServletResponse response, String fileName) {
  1036. try {
  1037. try {
  1038. fileName = new String(fileName.getBytes(), "ISO8859-1");
  1039. } catch (UnsupportedEncodingException e) {
  1040. e.printStackTrace();
  1041. }
  1042. response.setContentType("application/octet-stream;charset=ISO8859-1");
  1043. response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
  1044. response.addHeader("Pargam", "no-cache");
  1045. response.addHeader("Cache-Control", "no-cache");
  1046. } catch (Exception ex) {
  1047. ex.printStackTrace();
  1048. }
  1049. }
  1050. }