KwaiXiaoDianReportController.java 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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, Long loginUserId, Long itemId, String itemTitle) {
  795. TableDataInfo rspData = new TableDataInfo();
  796. try {
  797. Map<String, Object> requestMap = new HashMap<>();
  798. if (!Check.isNull(userId)) {
  799. requestMap.put("userId", userId);
  800. } else {
  801. requestMap.put("userId", null);
  802. String roleId = sysRoleService.getRoleBYUserId(loginUserId);
  803. if ("admin".equals(roleId)) {
  804. requestMap.put("companyId", null);
  805. } else {
  806. Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
  807. requestMap.put("companyId", companyId);
  808. }
  809. }
  810. Long start = DateUtils.strDateToInt(startDate);
  811. Long end = DateUtils.strDateToInt(endDate);
  812. requestMap.put("start", start);
  813. requestMap.put("end", end);
  814. if (!Check.isNull(itemId)) {
  815. requestMap.put("itemId", itemId);
  816. }
  817. if (!Check.isNull(itemTitle)) {
  818. requestMap.put("itemTitle", itemTitle);
  819. }
  820. startPage(pageNum, pageSize);
  821. List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
  822. rspData.setCode(HttpStatus.SUCCESS);
  823. rspData.setMsg("查询成功");
  824. rspData.setRows(list);
  825. rspData.setTotal(new PageInfo(list).getTotal());
  826. } catch (Exception e) {
  827. e.printStackTrace();
  828. rspData.setCode(HttpStatus.ERROR);
  829. rspData.setMsg(e.getMessage());
  830. }
  831. return rspData;
  832. }
  833. @GetMapping("/exportSaleDetail")
  834. public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
  835. if (Check.isNull(startDate)) {
  836. return;
  837. }
  838. if (Check.isNull(endDate)) {
  839. return;
  840. }
  841. Map<String, Object> requestMap = new HashMap<>();
  842. if (!Check.isNull(userId)) {
  843. requestMap.put("userId", userId);
  844. } else {
  845. requestMap.put("userId", null);
  846. String roleId = sysRoleService.getRoleBYUserId(loginUserId);
  847. if ("admin".equals(roleId)) {
  848. requestMap.put("companyId", null);
  849. } else {
  850. Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
  851. requestMap.put("companyId", companyId);
  852. }
  853. }
  854. Long start = DateUtils.strDateToInt(startDate);
  855. Long end = DateUtils.strDateToInt(endDate);
  856. requestMap.put("start", start);
  857. requestMap.put("end", end);
  858. List<JSONObject> list = kwaiXiaoDianReportService.getSaleDetail(requestMap);
  859. List<List<Object>> exportList = new ArrayList<>();
  860. if (!Check.isNull(list)) {
  861. for (int i = 0; i < list.size(); i++) {
  862. JSONObject data = list.get(i);
  863. List<Object> export = new ArrayList();
  864. export.add(data.getString("itemId"));
  865. export.add(data.getString("itemTitle"));
  866. export.add(data.getString("userId"));
  867. export.add(data.getString("userName"));
  868. export.add(data.getString("orderNum"));
  869. export.add(data.getString("totalFee"));
  870. export.add(data.getString("costPrice"));
  871. exportList.add(export);
  872. }
  873. }
  874. String[] headers = {"商品ID", "商品名称", "销售ID", "销售", "订单数", "收入", "成本"};
  875. OutputStream os = response.getOutputStream();
  876. ExportExcelUtils eeu = new ExportExcelUtils();
  877. XSSFWorkbook workbook = new XSSFWorkbook();
  878. eeu.exportExcel(workbook, 0, "销售详情", headers, exportList);
  879. this.setResponseHeader(response, "销售详情.xls");
  880. try {
  881. workbook.write(os);
  882. } catch (IOException e) {
  883. e.printStackTrace();
  884. }
  885. os.flush();
  886. os.close();
  887. }
  888. @GetMapping("/getPurchaserReport")
  889. public TableDataInfo getPurchaserReport(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  890. TableDataInfo rspData = new TableDataInfo();
  891. try {
  892. if (Check.isNull(userId)) {
  893. throw new Exception("请传入用户ID");
  894. }
  895. Map<String, Object> requestMap = new HashMap<>();
  896. String roleId = sysRoleService.getRoleBYUserId(userId);
  897. if ("admin".equals(roleId)) { // 管理员查看所有
  898. if (!Check.isNull(companyId)) {
  899. requestMap.put("companyId", companyId);
  900. }
  901. } else if ("industry_admin".equals(roleId) || "industry_sale_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 供应链管理员查看所属公司
  902. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  903. if (Check.isNull(companyId)) {
  904. throw new Exception("请传入公司ID");
  905. }
  906. requestMap.put("companyId", companyId);
  907. } else if ("industry_sale".equals(roleId) || "industry_purchase".equals(roleId)) {
  908. requestMap.put("userId", userId);
  909. }
  910. Long start = DateUtils.strDateToInt(startDate);
  911. Long end = DateUtils.strDateToInt(endDate);
  912. requestMap.put("start", start);
  913. requestMap.put("end", end);
  914. startPage(pageNum, pageSize);
  915. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
  916. rspData.setCode(HttpStatus.SUCCESS);
  917. rspData.setMsg("查询成功");
  918. rspData.setRows(list);
  919. rspData.setTotal(new PageInfo(list).getTotal());
  920. } catch (Exception e) {
  921. e.printStackTrace();
  922. rspData.setCode(HttpStatus.ERROR);
  923. rspData.setMsg(e.getMessage());
  924. }
  925. return rspData;
  926. }
  927. @GetMapping("/exportPurchaserReport")
  928. 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 {
  929. if (Check.isNull(userId)) {
  930. return;
  931. }
  932. if (Check.isNull(startDate)) {
  933. return;
  934. }
  935. if (Check.isNull(endDate)) {
  936. return;
  937. }
  938. Map<String, Object> requestMap = new HashMap<>();
  939. String roleId = sysRoleService.getRoleBYUserId(userId);
  940. if ("admin".equals(roleId)) { // 管理员查看所有
  941. if (!Check.isNull(companyId)) {
  942. requestMap.put("companyId", companyId);
  943. }
  944. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  945. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  946. if (Check.isNull(companyId)) {
  947. return;
  948. }
  949. requestMap.put("companyId", companyId);
  950. }
  951. Long start = DateUtils.strDateToInt(startDate);
  952. Long end = DateUtils.strDateToInt(endDate);
  953. requestMap.put("start", start);
  954. requestMap.put("end", end);
  955. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaserReport(requestMap);
  956. List<List<Object>> exportList = new ArrayList<>();
  957. if (!Check.isNull(list)) {
  958. for (int i = 0; i < list.size(); i++) {
  959. JSONObject data = list.get(i);
  960. List<Object> export = new ArrayList();
  961. export.add(data.getString("userId"));
  962. export.add(data.getString("userName"));
  963. export.add(data.getString("orderNum"));
  964. export.add(data.getString("totalFee"));
  965. export.add(data.getString("costPrice"));
  966. export.add(data.getString("purchaseCost"));
  967. exportList.add(export);
  968. }
  969. }
  970. String[] headers = {"采购ID", "采购", "订单数", "收入", "成本", "采购金额"};
  971. OutputStream os = response.getOutputStream();
  972. ExportExcelUtils eeu = new ExportExcelUtils();
  973. XSSFWorkbook workbook = new XSSFWorkbook();
  974. eeu.exportExcel(workbook, 0, "采购管理", headers, exportList);
  975. this.setResponseHeader(response, "采购管理.xls");
  976. try {
  977. workbook.write(os);
  978. } catch (IOException e) {
  979. e.printStackTrace();
  980. }
  981. os.flush();
  982. os.close();
  983. }
  984. @GetMapping("/getPurchaseDetail")
  985. public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long loginUserId, Long itemId, String itemTitle) {
  986. TableDataInfo rspData = new TableDataInfo();
  987. try {
  988. Map<String, Object> requestMap = new HashMap<>();
  989. if (!Check.isNull(userId)) {
  990. requestMap.put("userId", userId);
  991. } else {
  992. requestMap.put("userId", null);
  993. String roleId = sysRoleService.getRoleBYUserId(loginUserId);
  994. if ("admin".equals(roleId)) {
  995. requestMap.put("companyId", null);
  996. } else {
  997. Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
  998. requestMap.put("companyId", companyId);
  999. }
  1000. }
  1001. Long start = DateUtils.strDateToInt(startDate);
  1002. Long end = DateUtils.strDateToInt(endDate);
  1003. requestMap.put("start", start);
  1004. requestMap.put("end", end);
  1005. if (!Check.isNull(itemId)) {
  1006. requestMap.put("itemId", itemId);
  1007. }
  1008. if (!Check.isNull(itemTitle)) {
  1009. requestMap.put("itemTitle", itemTitle);
  1010. }
  1011. startPage(pageNum, pageSize);
  1012. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
  1013. rspData.setCode(HttpStatus.SUCCESS);
  1014. rspData.setMsg("查询成功");
  1015. rspData.setRows(list);
  1016. rspData.setTotal(new PageInfo(list).getTotal());
  1017. } catch (Exception e) {
  1018. e.printStackTrace();
  1019. rspData.setCode(HttpStatus.ERROR);
  1020. rspData.setMsg(e.getMessage());
  1021. }
  1022. return rspData;
  1023. }
  1024. @GetMapping("/exportPurchaseDetail")
  1025. public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
  1026. if (Check.isNull(startDate)) {
  1027. return;
  1028. }
  1029. if (Check.isNull(endDate)) {
  1030. return;
  1031. }
  1032. Map<String, Object> requestMap = new HashMap<>();
  1033. if (!Check.isNull(userId)) {
  1034. requestMap.put("userId", userId);
  1035. } else {
  1036. requestMap.put("userId", null);
  1037. String roleId = sysRoleService.getRoleBYUserId(loginUserId);
  1038. if ("admin".equals(roleId)) {
  1039. requestMap.put("companyId", null);
  1040. } else {
  1041. Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
  1042. requestMap.put("companyId", companyId);
  1043. }
  1044. }
  1045. Long start = DateUtils.strDateToInt(startDate);
  1046. Long end = DateUtils.strDateToInt(endDate);
  1047. requestMap.put("start", start);
  1048. requestMap.put("end", end);
  1049. List<JSONObject> list = kwaiXiaoDianReportService.getPurchaseDetail(requestMap);
  1050. List<List<Object>> exportList = new ArrayList<>();
  1051. if (!Check.isNull(list)) {
  1052. for (int i = 0; i < list.size(); i++) {
  1053. JSONObject data = list.get(i);
  1054. List<Object> export = new ArrayList();
  1055. export.add(data.getString("itemId"));
  1056. export.add(data.getString("itemTitle"));
  1057. export.add(data.getString("saleName"));
  1058. export.add(data.getString("userId"));
  1059. export.add(data.getString("purchaseName"));
  1060. export.add(data.getString("orderNum"));
  1061. export.add(data.getString("totalFee"));
  1062. export.add(data.getString("costPrice"));
  1063. exportList.add(export);
  1064. }
  1065. }
  1066. String[] headers = {"商品ID", "商品名称", "销售", "采购ID", "采购", "订单数", "收入", "成本"};
  1067. OutputStream os = response.getOutputStream();
  1068. ExportExcelUtils eeu = new ExportExcelUtils();
  1069. XSSFWorkbook workbook = new XSSFWorkbook();
  1070. eeu.exportExcel(workbook, 0, "采购详情", headers, exportList);
  1071. this.setResponseHeader(response, "采购详情.xls");
  1072. try {
  1073. workbook.write(os);
  1074. } catch (IOException e) {
  1075. e.printStackTrace();
  1076. }
  1077. os.flush();
  1078. os.close();
  1079. }
  1080. public void setResponseHeader(HttpServletResponse response, String fileName) {
  1081. try {
  1082. try {
  1083. fileName = new String(fileName.getBytes(), "ISO8859-1");
  1084. } catch (UnsupportedEncodingException e) {
  1085. e.printStackTrace();
  1086. }
  1087. response.setContentType("application/octet-stream;charset=ISO8859-1");
  1088. response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
  1089. response.addHeader("Pargam", "no-cache");
  1090. response.addHeader("Cache-Control", "no-cache");
  1091. } catch (Exception ex) {
  1092. ex.printStackTrace();
  1093. }
  1094. }
  1095. }