KwaiXiaoDianReportController.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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.isc.service.IKwaiXiaoDianReportService;
  9. import com.ruixuan.isc.service.IKwaixiaodianItemGetService;
  10. import com.ruixuan.system.service.ISysRoleService;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.text.SimpleDateFormat;
  16. import java.util.ArrayList;
  17. import java.util.Collections;
  18. import java.util.Comparator;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import static com.ruixuan.common.utils.PageUtils.startPage;
  23. @RestController
  24. @RequestMapping("/kwaixiaodian/report")
  25. public class KwaiXiaoDianReportController {
  26. @Autowired
  27. private IKwaiXiaoDianReportService kwaiXiaoDianReportService;
  28. @Autowired
  29. private ISysRoleService sysRoleService;
  30. @Autowired
  31. private IKwaixiaodianItemGetService kwaixiaodianItemGetService;
  32. // 供应链盯盘数据
  33. @GetMapping("/getSumInfo")
  34. public JSONObject getSumInfo(Long userId, String startDate, String endDate, Long companyId) {
  35. JSONObject returnJson = new JSONObject();
  36. try {
  37. if (Check.isNull(userId)) {
  38. throw new Exception("请传入用户ID");
  39. }
  40. Map<String, Object> requestMap = new HashMap<>();
  41. String roleId = sysRoleService.getRoleBYUserId(userId);
  42. if ("admin".equals(roleId)) { // 管理员查看所有
  43. if (!Check.isNull(companyId)) {
  44. requestMap.put("companyId", companyId);
  45. }
  46. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  47. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  48. if (Check.isNull(companyId)) {
  49. throw new Exception("此用户未查询到归属公司");
  50. }
  51. requestMap.put("companyId", companyId);
  52. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  53. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  54. if (Check.isNull(userIds)) {
  55. throw new Exception("此用户未查询到部门成员信息");
  56. }
  57. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  58. requestMap.put("itemIds", itemIds);
  59. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  60. List<Long> userIds = new ArrayList<>();
  61. userIds.add(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_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  68. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  69. if (Check.isNull(courtshipPurchaseIds)) {
  70. throw new Exception("此用户未查询到部门成员信息");
  71. }
  72. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  73. requestMap.put("itemIds", itemIds);
  74. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  75. List<Long> courtshipPurchaseIds = new ArrayList<>();
  76. courtshipPurchaseIds.add(userId);
  77. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  78. requestMap.put("itemIds", itemIds);
  79. }
  80. Long start = DateUtils.strDateToInt(startDate);
  81. Long end = DateUtils.strDateToInt(endDate);
  82. requestMap.put("start", start);
  83. requestMap.put("end", end);
  84. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  85. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  86. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  87. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  88. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  89. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  90. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  91. if (start.equals(nowDate) && end.equals(nowDate)) {
  92. Integer nowHour = DateUtils.getNowHour();
  93. requestMap.put("nowHour", nowHour);
  94. }
  95. JSONObject date = kwaiXiaoDianReportService.getSumInfo(requestMap);
  96. returnJson.put("code", 200);
  97. returnJson.put("data", date);
  98. returnJson.put("success", true);
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. returnJson.put("code", 500);
  102. returnJson.put("message", e.getMessage());
  103. }
  104. return returnJson;
  105. }
  106. @GetMapping("/getMonthData")
  107. public JSONObject getMonthData(Long userId, String startDate, String endDate, Long companyId) {
  108. JSONObject returnJson = new JSONObject();
  109. try {
  110. if (Check.isNull(userId)) {
  111. throw new Exception("请传入用户ID");
  112. }
  113. Map<String, Object> requestMap = new HashMap<>();
  114. String roleId = sysRoleService.getRoleBYUserId(userId);
  115. if ("admin".equals(roleId)) { // 管理员查看所有
  116. if (!Check.isNull(companyId)) {
  117. requestMap.put("companyId", companyId);
  118. }
  119. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  120. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  121. if (Check.isNull(companyId)) {
  122. throw new Exception("此用户未查询到归属公司");
  123. }
  124. requestMap.put("companyId", companyId);
  125. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  126. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  127. if (Check.isNull(userIds)) {
  128. throw new Exception("此用户未查询到部门成员信息");
  129. }
  130. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  131. requestMap.put("itemIds", itemIds);
  132. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  133. List<Long> userIds = new ArrayList<>();
  134. userIds.add(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_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  141. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  142. if (Check.isNull(courtshipPurchaseIds)) {
  143. throw new Exception("此用户未查询到部门成员信息");
  144. }
  145. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  146. requestMap.put("itemIds", itemIds);
  147. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  148. List<Long> courtshipPurchaseIds = new ArrayList<>();
  149. courtshipPurchaseIds.add(userId);
  150. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  151. requestMap.put("itemIds", itemIds);
  152. }
  153. String monthEndDate = DateUtils.getNowDate("yyyy-MM-dd");
  154. String monthStartDay = DateUtils.getMonthStartDay(monthEndDate);
  155. Long monthStart = DateUtils.strDateToInt(monthStartDay);
  156. Long monthEnd = DateUtils.strDateToInt(monthEndDate);
  157. requestMap.put("monthStart", monthStart);
  158. requestMap.put("monthEnd", monthEnd);
  159. String lastMonthFirstDate = DateUtils.getLastMonthFirstDayByDate(monthEndDate);// 上个月开始时间
  160. String lastMonthEndDate = DateUtils.getLastMonthNowDay(monthEndDate);// 上个月结束时间
  161. requestMap.put("lastMonthStart", DateUtils.strDateToInt(lastMonthFirstDate));
  162. requestMap.put("lastMonthEnd", DateUtils.strDateToInt(lastMonthEndDate));
  163. JSONObject monthDate = kwaiXiaoDianReportService.getMonthInfo(requestMap);
  164. Long start = DateUtils.strDateToInt(startDate);
  165. Long end = DateUtils.strDateToInt(endDate);
  166. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  167. if (start.equals(nowDate) && end.equals(nowDate)) { // 如果传入时间为当天,取当前月的数据
  168. requestMap.put("echartStart", monthStart);
  169. requestMap.put("echartEnd", monthEnd);
  170. } else {
  171. requestMap.put("echartStart", start);
  172. requestMap.put("echartEnd", end);
  173. }
  174. List<JSONObject> list = kwaiXiaoDianReportService.getEchartData(requestMap);
  175. monthDate.put("list", list);
  176. returnJson.put("code", 200);
  177. returnJson.put("data", monthDate);
  178. returnJson.put("success", true);
  179. } catch (Exception e) {
  180. e.printStackTrace();
  181. returnJson.put("code", 500);
  182. returnJson.put("message", e.getMessage());
  183. }
  184. return returnJson;
  185. }
  186. @GetMapping("/getGmvHours")
  187. public JSONObject getGmvHours(Long userId, Long companyId, Integer hourType) {
  188. JSONObject returnJson = new JSONObject();
  189. try {
  190. if (Check.isNull(userId)) {
  191. throw new Exception("请传入用户ID");
  192. }
  193. Map<String, Object> requestMap = new HashMap<>();
  194. String roleId = sysRoleService.getRoleBYUserId(userId);
  195. if ("admin".equals(roleId)) { // 管理员查看所有
  196. if (!Check.isNull(companyId)) {
  197. requestMap.put("companyId", companyId);
  198. }
  199. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  200. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  201. if (Check.isNull(companyId)) {
  202. throw new Exception("此用户未查询到归属公司");
  203. }
  204. requestMap.put("companyId", companyId);
  205. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  206. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  207. if (Check.isNull(userIds)) {
  208. throw new Exception("此用户未查询到部门成员信息");
  209. }
  210. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  211. requestMap.put("itemIds", itemIds);
  212. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  213. List<Long> userIds = new ArrayList<>();
  214. userIds.add(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_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  221. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  222. if (Check.isNull(courtshipPurchaseIds)) {
  223. throw new Exception("此用户未查询到部门成员信息");
  224. }
  225. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  226. requestMap.put("itemIds", itemIds);
  227. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  228. List<Long> courtshipPurchaseIds = new ArrayList<>();
  229. courtshipPurchaseIds.add(userId);
  230. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  231. requestMap.put("itemIds", itemIds);
  232. }
  233. String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
  234. requestMap.put("date", DateUtils.strDateToInt(nowDate));
  235. List<JSONObject> today = kwaiXiaoDianReportService.getGmvHours(requestMap);
  236. String lastDate = null;
  237. if (hourType == 1) {
  238. lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 日期 -1
  239. } else if (hourType == 2) {
  240. lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -7); // 日期 -7
  241. }
  242. requestMap.put("date", DateUtils.strDateToInt(lastDate));
  243. List<JSONObject> yesterday = kwaiXiaoDianReportService.getGmvHours(requestMap);
  244. JSONObject data = new JSONObject();
  245. completionTime(today, "charge");
  246. completionTime(yesterday, "charge");
  247. data.put("today", today);
  248. data.put("yesterday", yesterday);
  249. returnJson.put("code", 200);
  250. returnJson.put("data", data);
  251. returnJson.put("success", true);
  252. } catch (Exception e) {
  253. e.printStackTrace();
  254. returnJson.put("code", 500);
  255. returnJson.put("message", e.getMessage());
  256. }
  257. return returnJson;
  258. }
  259. /**
  260. * 补全时辰
  261. * 时辰补全
  262. */
  263. private void completionTime(List<JSONObject> dataList, String type) {
  264. List<Integer> newDayList = new ArrayList<>();
  265. for (JSONObject data : dataList) {
  266. newDayList.add(data.getInteger("time"));
  267. }
  268. List<Integer> dayList = new ArrayList<>();
  269. for (int i = 0; i <= 23; i++) {
  270. dayList.add(i);
  271. }
  272. for (Integer hour : dayList) {
  273. if (!newDayList.contains(hour)) {
  274. JSONObject obj = new JSONObject();
  275. obj.put("time", hour);
  276. obj.put(type, 0.00);
  277. dataList.add(obj);
  278. }
  279. }
  280. statHourListSort(dataList);
  281. }
  282. //排序
  283. private static void statHourListSort(List<JSONObject> list) {
  284. Collections.sort(list, new Comparator<JSONObject>() {
  285. @Override
  286. public int compare(JSONObject o1, JSONObject o2) {
  287. try {
  288. Integer dt1 = o1.getInteger("time");
  289. Integer dt2 = o2.getInteger("time");
  290. return dt1.compareTo(dt2);
  291. } catch (Exception e) {
  292. e.printStackTrace();
  293. }
  294. return 0;
  295. }
  296. });
  297. }
  298. @GetMapping("/getShopListData")
  299. public TableDataInfo getShopListData(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  300. TableDataInfo rspData = new TableDataInfo();
  301. try {
  302. if (Check.isNull(userId)) {
  303. throw new Exception("请传入用户ID");
  304. }
  305. Map<String, Object> requestMap = new HashMap<>();
  306. String roleId = sysRoleService.getRoleBYUserId(userId);
  307. if ("admin".equals(roleId)) { // 管理员查看所有
  308. if (!Check.isNull(companyId)) {
  309. requestMap.put("companyId", companyId);
  310. }
  311. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  312. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  313. if (Check.isNull(companyId)) {
  314. throw new Exception("此用户未查询到归属公司");
  315. }
  316. requestMap.put("companyId", companyId);
  317. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  318. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  319. if (Check.isNull(userIds)) {
  320. throw new Exception("此用户未查询到部门成员信息");
  321. }
  322. List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
  323. requestMap.put("itemIds", itemIds);
  324. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  325. List<Long> userIds = new ArrayList<>();
  326. userIds.add(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_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  333. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  334. if (Check.isNull(courtshipPurchaseIds)) {
  335. throw new Exception("此用户未查询到部门成员信息");
  336. }
  337. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  338. requestMap.put("itemIds", itemIds);
  339. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  340. List<Long> courtshipPurchaseIds = new ArrayList<>();
  341. courtshipPurchaseIds.add(userId);
  342. List<Long> itemIds = kwaixiaodianItemGetService.getCourtshipPurchaseItemIdsByUserIds(courtshipPurchaseIds);
  343. requestMap.put("itemIds", itemIds);
  344. }
  345. Long start = DateUtils.strDateToInt(startDate);
  346. Long end = DateUtils.strDateToInt(endDate);
  347. requestMap.put("start", start);
  348. requestMap.put("end", end);
  349. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  350. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  351. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  352. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  353. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  354. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  355. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  356. if (start.equals(nowDate) && end.equals(nowDate)) {
  357. Integer nowHour = DateUtils.getNowHour();
  358. requestMap.put("nowHour", nowHour);
  359. }
  360. startPage(pageNum, pageSize);
  361. List<JSONObject> list = kwaiXiaoDianReportService.getShopListData(requestMap);
  362. rspData.setCode(HttpStatus.SUCCESS);
  363. rspData.setMsg("查询成功");
  364. rspData.setRows(list);
  365. rspData.setTotal(new PageInfo(list).getTotal());
  366. } catch (Exception e) {
  367. e.printStackTrace();
  368. rspData.setCode(HttpStatus.ERROR);
  369. rspData.setMsg(e.getMessage());
  370. }
  371. return rspData;
  372. }
  373. @GetMapping("/getTeamList")
  374. public TableDataInfo getTeamList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize) {
  375. TableDataInfo rspData = new TableDataInfo();
  376. try {
  377. if (Check.isNull(userId)) {
  378. throw new Exception("请传入用户ID");
  379. }
  380. Map<String, Object> requestMap = new HashMap<>();
  381. String roleId = sysRoleService.getRoleBYUserId(userId);
  382. if ("admin".equals(roleId)) { // 管理员查看所有
  383. if (!Check.isNull(companyId)) {
  384. requestMap.put("companyId", companyId);
  385. }
  386. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  387. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  388. if (Check.isNull(companyId)) {
  389. throw new Exception("此用户未查询到归属公司");
  390. }
  391. requestMap.put("companyId", companyId);
  392. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  393. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  394. if (Check.isNull(userIds)) {
  395. throw new Exception("此用户未查询到部门成员信息");
  396. }
  397. requestMap.put("userIds", userIds);
  398. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  399. List<Long> userIds = new ArrayList<>();
  400. userIds.add(userId);
  401. if (Check.isNull(userIds)) {
  402. throw new Exception("此用户未查询到部门成员信息");
  403. }
  404. requestMap.put("userIds", userIds);
  405. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  406. List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  407. if (Check.isNull(courtshipPurchaseIds)) {
  408. throw new Exception("此用户未查询到部门成员信息");
  409. }
  410. requestMap.put("userIds", courtshipPurchaseIds);
  411. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  412. List<Long> courtshipPurchaseIds = new ArrayList<>();
  413. courtshipPurchaseIds.add(userId);
  414. requestMap.put("userIds", courtshipPurchaseIds);
  415. }
  416. Long start = DateUtils.strDateToInt(startDate);
  417. Long end = DateUtils.strDateToInt(endDate);
  418. requestMap.put("start", start);
  419. requestMap.put("end", end);
  420. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  421. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  422. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  423. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  424. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  425. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  426. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  427. if (start.equals(nowDate) && end.equals(nowDate)) {
  428. Integer nowHour = DateUtils.getNowHour();
  429. requestMap.put("nowHour", nowHour);
  430. }
  431. startPage(pageNum, pageSize);
  432. List<JSONObject> list = kwaiXiaoDianReportService.getTeamList(requestMap);
  433. rspData.setCode(HttpStatus.SUCCESS);
  434. rspData.setMsg("查询成功");
  435. rspData.setRows(list);
  436. rspData.setTotal(new PageInfo(list).getTotal());
  437. } catch (Exception e) {
  438. e.printStackTrace();
  439. rspData.setCode(HttpStatus.ERROR);
  440. rspData.setMsg(e.getMessage());
  441. }
  442. return rspData;
  443. }
  444. @GetMapping("/getTeamDetail")
  445. public JSONObject getTeamDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long deptId, String type) {
  446. JSONObject rspData = new JSONObject();
  447. try {
  448. if (Check.isNull(userId)) {
  449. throw new Exception("请传入用户ID");
  450. }
  451. if (Check.isNull(deptId)) {
  452. throw new Exception("请传入部门ID");
  453. }
  454. if (Check.isNull(type)) {
  455. throw new Exception("请传入类型");
  456. }
  457. Map<String, Object> requestMap = new HashMap<>();
  458. requestMap.put("deptId", deptId);
  459. requestMap.put("type", type);
  460. String roleId = sysRoleService.getRoleBYUserId(userId);
  461. if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  462. requestMap.put("userId", userId);
  463. }
  464. if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) {
  465. requestMap.put("courtshipPurchaseId", userId);
  466. }
  467. Long start = DateUtils.strDateToInt(startDate);
  468. Long end = DateUtils.strDateToInt(endDate);
  469. requestMap.put("start", start);
  470. requestMap.put("end", end);
  471. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  472. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  473. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  474. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  475. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  476. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  477. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  478. if (start.equals(nowDate) && end.equals(nowDate)) {
  479. Integer nowHour = DateUtils.getNowHour();
  480. requestMap.put("nowHour", nowHour);
  481. }
  482. List<JSONObject> list = kwaiXiaoDianReportService.getTeamDetail(requestMap);
  483. rspData.put("code", 200);
  484. rspData.put("message", "查询成功");
  485. rspData.put("data", list);
  486. } catch (Exception e) {
  487. e.printStackTrace();
  488. rspData.put("code", 500);
  489. rspData.put("message", "查询失败");
  490. }
  491. return rspData;
  492. }
  493. @GetMapping("/getItemList")
  494. public TableDataInfo getItemList(String startDate, String endDate, Long userId, Long companyId, Integer pageNum, Integer pageSize, Integer itemType) {
  495. TableDataInfo rspData = new TableDataInfo();
  496. try {
  497. if (Check.isNull(userId)) {
  498. throw new Exception("请传入用户ID");
  499. }
  500. Map<String, Object> requestMap = new HashMap<>();
  501. String roleId = sysRoleService.getRoleBYUserId(userId);
  502. if ("admin".equals(roleId)) { // 管理员查看所有
  503. if (!Check.isNull(companyId)) {
  504. requestMap.put("companyId", companyId);
  505. }
  506. } else if ("industry_admin".equals(roleId)) { // 供应链管理员查看所属公司
  507. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  508. if (Check.isNull(companyId)) {
  509. throw new Exception("此用户未查询到归属公司");
  510. }
  511. requestMap.put("companyId", companyId);
  512. } else if ("industry_sale_manager".equals(roleId)) { // 经理角色查看部门下所有成员数据
  513. List<Long> userIds = kwaixiaodianItemGetService.getUserIds(userId);
  514. if (Check.isNull(userIds)) {
  515. throw new Exception("此用户未查询到部门成员信息");
  516. }
  517. requestMap.put("userIds", userIds);
  518. } else if ("industry_sale".equals(roleId)) { // 销售 查看自己的数据
  519. List<Long> userIds = new ArrayList<>();
  520. userIds.add(userId);
  521. if (Check.isNull(userIds)) {
  522. throw new Exception("此用户未查询到部门成员信息");
  523. }
  524. requestMap.put("userIds", userIds);
  525. } else if ("industry_courtship_manager".equals(roleId) || "industry_purchase_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
  526. // List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
  527. // if (Check.isNull(courtshipPurchaseIds)) {
  528. // throw new Exception("此用户未查询到部门成员信息");
  529. // }
  530. // requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
  531. companyId = kwaixiaodianItemGetService.getCompanyId(userId);
  532. if (Check.isNull(companyId)) {
  533. throw new Exception("此用户未查询到归属公司");
  534. }
  535. requestMap.put("companyId", companyId);
  536. } else if ("industry_purchase".equals(roleId) || "industry_courtship".equals(roleId)) { // 采购 招商 查看自己的数据
  537. List<Long> courtshipPurchaseIds = new ArrayList<>();
  538. courtshipPurchaseIds.add(userId);
  539. requestMap.put("courtshipPurchaseIds", courtshipPurchaseIds);
  540. }
  541. if (!Check.isNull(itemType)) {
  542. if (itemType != 0) {
  543. requestMap.put("itemType", itemType);
  544. }
  545. }
  546. Long start = DateUtils.strDateToInt(startDate);
  547. Long end = DateUtils.strDateToInt(endDate);
  548. requestMap.put("start", start);
  549. requestMap.put("end", end);
  550. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  551. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  552. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  553. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  554. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  555. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  556. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  557. if (start.equals(nowDate) && end.equals(nowDate)) {
  558. Integer nowHour = DateUtils.getNowHour();
  559. requestMap.put("nowHour", nowHour);
  560. }
  561. startPage(pageNum, pageSize);
  562. List<JSONObject> list = kwaiXiaoDianReportService.getItemList(requestMap);
  563. rspData.setCode(HttpStatus.SUCCESS);
  564. rspData.setMsg("查询成功");
  565. rspData.setRows(list);
  566. rspData.setTotal(new PageInfo(list).getTotal());
  567. } catch (Exception e) {
  568. e.printStackTrace();
  569. rspData.setCode(HttpStatus.ERROR);
  570. rspData.setMsg(e.getMessage());
  571. }
  572. return rspData;
  573. }
  574. }