JiaoYangDingPanController.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. package com.ruixuan.jiaoyang.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ruixuan.common.core.controller.BaseController;
  4. import com.ruixuan.common.core.page.TableDataInfo;
  5. import com.ruixuan.common.utils.Check;
  6. import com.ruixuan.common.utils.DateUtils;
  7. import com.ruixuan.jiaoyang.service.IJiaoYangDingPanService;
  8. import com.ruixuan.system.service.ISysDeptService;
  9. import com.ruixuan.system.service.ISysRoleService;
  10. import io.swagger.annotations.ApiOperation;
  11. import io.swagger.annotations.ApiParam;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import java.util.*;
  20. import static com.ruixuan.common.utils.PageUtils.startPage;
  21. @RestController
  22. @RequestMapping("/jy/dingpan")
  23. public class JiaoYangDingPanController extends BaseController {
  24. @Autowired
  25. private IJiaoYangDingPanService jiaoYangDingPanService;
  26. @Autowired
  27. private ISysRoleService sysRoleService;
  28. @Autowired
  29. private ISysDeptService sysDeptService;
  30. @GetMapping("/getSumInfo")
  31. @ApiOperation(value = "切片盯盘-汇总数据")
  32. public JSONObject getSumInfo(Long userId, String startDate, String endDate) {
  33. Map<String, Object> requestMap = new HashMap<>();
  34. JSONObject returnJson = new JSONObject();
  35. try {
  36. if (Check.isNull(userId)) {
  37. throw new Exception("请传入用户id");
  38. }
  39. if (Check.isNull(startDate)) {
  40. throw new Exception("请传入开始日期");
  41. }
  42. if (Check.isNull(endDate)) {
  43. throw new Exception("请传入结束日期");
  44. }
  45. String roleId = sysRoleService.getRoleBYUserId(userId);
  46. // 剪手经理,渠道经理 查询部门下所有成员数据
  47. List<Long> promoterIds = new ArrayList<>();
  48. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  49. List<Long> userIds = new ArrayList<>();
  50. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  51. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  52. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  53. } else {
  54. userIds.add(userId);
  55. }
  56. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  57. } else if ("jy_expert_business".equals(roleId)) {
  58. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  59. }
  60. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  61. if (Check.isNull(promoterIds)) {
  62. throw new Exception("该用户下未查询到绑定达人");
  63. }
  64. }
  65. if (!Check.isNull(promoterIds)) {
  66. requestMap.put("promoterIds", promoterIds);
  67. }
  68. Long start = DateUtils.strDateToInt(startDate);
  69. Long end = DateUtils.strDateToInt(endDate);
  70. requestMap.put("start", start);
  71. requestMap.put("end", end);
  72. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  73. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  74. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  75. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  76. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  77. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  78. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  79. if (start.equals(nowDate) && end.equals(nowDate)) {
  80. Integer nowHour = DateUtils.getNowHour();
  81. requestMap.put("nowHour", nowHour);
  82. }
  83. JSONObject date = jiaoYangDingPanService.getSumInfo(requestMap);
  84. returnJson.put("code", 200);
  85. returnJson.put("data", date);
  86. returnJson.put("success", true);
  87. } catch (Exception e) {
  88. returnJson.put("code", 500);
  89. returnJson.put("message", e.getMessage());
  90. }
  91. return returnJson;
  92. }
  93. @GetMapping("/getMonthInfo")
  94. @ApiOperation(value = "切片盯盘-当月数据数据")
  95. public JSONObject getMonthInfo(Long userId, String startDate, String endDate) {
  96. Map<String, Object> requestMap = new HashMap<>();
  97. JSONObject returnJson = new JSONObject();
  98. try {
  99. if (Check.isNull(userId)) {
  100. throw new Exception("请传入用户id");
  101. }
  102. if (Check.isNull(startDate)) {
  103. throw new Exception("请传入开始日期");
  104. }
  105. if (Check.isNull(endDate)) {
  106. throw new Exception("请传入结束日期");
  107. }
  108. String monthEndDate = DateUtils.getNowDate("yyyy-MM-dd");
  109. String monthStartDay = DateUtils.getMonthStartDay(monthEndDate);
  110. String roleId = sysRoleService.getRoleBYUserId(userId);
  111. // 剪手经理,渠道经理 查询部门下所有成员数据
  112. List<Long> promoterIds = new ArrayList<>();
  113. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  114. List<Long> userIds = new ArrayList<>();
  115. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  116. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  117. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  118. } else {
  119. userIds.add(userId);
  120. }
  121. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  122. } else if ("jy_expert_business".equals(roleId)) {
  123. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  124. }
  125. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  126. if (Check.isNull(promoterIds)) {
  127. throw new Exception("该用户下未查询到绑定达人");
  128. }
  129. }
  130. if (!Check.isNull(promoterIds)) {
  131. requestMap.put("promoterIds", promoterIds);
  132. }
  133. Long monthStart = DateUtils.strDateToInt(monthStartDay);
  134. Long monthEnd = DateUtils.strDateToInt(monthEndDate);
  135. requestMap.put("monthStart", monthStart);
  136. requestMap.put("monthEnd", monthEnd);
  137. String lastMonthFirstDate = DateUtils.getLastMonthFirstDayByDate(monthEndDate);// 上个月开始时间
  138. String lastMonthEndDate = DateUtils.getLastMonthNowDay(monthEndDate);// 上个月结束时间
  139. requestMap.put("lastMonthStart", DateUtils.strDateToInt(lastMonthFirstDate));
  140. requestMap.put("lastMonthEnd", DateUtils.strDateToInt(lastMonthEndDate));
  141. JSONObject monthDate = jiaoYangDingPanService.getMonthInfo(requestMap);
  142. Long start = DateUtils.strDateToInt(startDate);
  143. Long end = DateUtils.strDateToInt(endDate);
  144. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  145. if (start.equals(nowDate) && end.equals(nowDate)) { // 如果传入时间为当天,取当前月的数据
  146. requestMap.put("echartStart", monthStart);
  147. requestMap.put("echartEnd", monthEnd);
  148. } else {
  149. requestMap.put("echartStart", start);
  150. requestMap.put("echartEnd", end);
  151. }
  152. List<JSONObject> list = jiaoYangDingPanService.getEchartData(requestMap);
  153. monthDate.put("list", list);
  154. returnJson.put("code", 200);
  155. returnJson.put("data", monthDate);
  156. returnJson.put("success", true);
  157. } catch (Exception e) {
  158. returnJson.put("code", 500);
  159. returnJson.put("message", e.getMessage());
  160. }
  161. return returnJson;
  162. }
  163. @GetMapping("/getGmvHours")
  164. @ApiOperation(value = "切片盯盘-当月数据数据")
  165. public JSONObject getGmvHours(Long userId) {
  166. Map<String, Object> requestMap = new HashMap<>();
  167. JSONObject returnJson = new JSONObject();
  168. try {
  169. if (Check.isNull(userId)) {
  170. throw new Exception("请传入用户id");
  171. }
  172. String roleId = sysRoleService.getRoleBYUserId(userId);
  173. // 剪手经理,渠道经理 查询部门下所有成员数据
  174. List<Long> promoterIds = new ArrayList<>();
  175. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  176. List<Long> userIds = new ArrayList<>();
  177. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  178. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  179. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  180. } else {
  181. userIds.add(userId);
  182. }
  183. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  184. } else if ("jy_expert_business".equals(roleId)) {
  185. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  186. }
  187. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  188. if (Check.isNull(promoterIds)) {
  189. throw new Exception("该用户下未查询到绑定达人");
  190. }
  191. }
  192. if (!Check.isNull(promoterIds)) {
  193. requestMap.put("promoterIds", promoterIds);
  194. }
  195. String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
  196. requestMap.put("date", DateUtils.strDateToInt(nowDate));
  197. List<JSONObject> today = jiaoYangDingPanService.getGmvHours(requestMap);
  198. String lastDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1); // 日期 -1
  199. requestMap.put("date", DateUtils.strDateToInt(lastDate));
  200. List<JSONObject> yesterday = jiaoYangDingPanService.getGmvHours(requestMap);
  201. JSONObject data = new JSONObject();
  202. data.put("today", today);
  203. data.put("yesterday", yesterday);
  204. returnJson.put("code", 200);
  205. returnJson.put("data", data);
  206. returnJson.put("success", true);
  207. } catch (Exception e) {
  208. returnJson.put("code", 500);
  209. returnJson.put("message", e.getMessage());
  210. }
  211. return returnJson;
  212. }
  213. /**
  214. * 分团队数据
  215. *
  216. * @param userId
  217. * @param startDate
  218. * @param endDate
  219. * @return
  220. */
  221. @GetMapping("/getTeamList")
  222. @ApiOperation(value = "切片盯盘-分团队数据")
  223. public JSONObject getTeamList(Long userId, String startDate, String endDate) {
  224. Map<String, Object> requestMap = new HashMap<>();
  225. JSONObject returnJson = new JSONObject();
  226. try {
  227. if (Check.isNull(userId)) {
  228. throw new Exception("请传入用户id");
  229. }
  230. if (Check.isNull(startDate)) {
  231. throw new Exception("请传入开始日期");
  232. }
  233. if (Check.isNull(endDate)) {
  234. throw new Exception("请传入结束日期");
  235. }
  236. String roleId = sysRoleService.getRoleBYUserId(userId);
  237. // 剪手经理,渠道经理 查询部门下所有成员数据
  238. List<Long> promoterIds = new ArrayList<>();
  239. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  240. List<Long> userIds = new ArrayList<>();
  241. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  242. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  243. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  244. } else {
  245. userIds.add(userId);
  246. }
  247. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  248. } else if ("jy_expert_business".equals(roleId)) {
  249. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  250. }
  251. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  252. if (Check.isNull(promoterIds)) {
  253. throw new Exception("该用户下未查询到绑定达人");
  254. }
  255. }
  256. if (!Check.isNull(promoterIds)) {
  257. requestMap.put("promoterIds", promoterIds);
  258. }
  259. Long start = DateUtils.strDateToInt(startDate);
  260. Long end = DateUtils.strDateToInt(endDate);
  261. requestMap.put("start", start);
  262. requestMap.put("end", end);
  263. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  264. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  265. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  266. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  267. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  268. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  269. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  270. if (start.equals(nowDate) && end.equals(nowDate)) {
  271. Integer nowHour = DateUtils.getNowHour();
  272. requestMap.put("nowHour", nowHour);
  273. }
  274. List<JSONObject> data = jiaoYangDingPanService.getTeamList(requestMap);
  275. returnJson.put("code", 200);
  276. returnJson.put("data", data);
  277. returnJson.put("success", true);
  278. } catch (Exception e) {
  279. returnJson.put("code", 500);
  280. returnJson.put("message", e.getMessage());
  281. }
  282. return returnJson;
  283. }
  284. /**
  285. * 新增商品
  286. *
  287. * @param deptId
  288. * @param startDate
  289. * @param endDate
  290. * @return
  291. */
  292. @GetMapping("/getAddItemList")
  293. @ApiOperation(value = "切片盯盘-新增商品")
  294. public JSONObject getAddItemList(Long deptId, String startDate, String endDate) {
  295. Map<String, Object> requestMap = new HashMap<>();
  296. JSONObject returnJson = new JSONObject();
  297. try {
  298. if (Check.isNull(deptId)) {
  299. throw new Exception("请传入部门id");
  300. }
  301. if (Check.isNull(startDate)) {
  302. throw new Exception("请传入开始日期");
  303. }
  304. if (Check.isNull(endDate)) {
  305. throw new Exception("请传入结束日期");
  306. }
  307. requestMap.put("deptId", deptId);
  308. Long start = DateUtils.strDateToInt(startDate);
  309. Long end = DateUtils.strDateToInt(endDate);
  310. requestMap.put("start", start);
  311. requestMap.put("end", end);
  312. List<JSONObject> data = jiaoYangDingPanService.getAddItemList(requestMap);
  313. returnJson.put("data", data);
  314. returnJson.put("code", 200);
  315. returnJson.put("success", true);
  316. } catch (Exception e) {
  317. returnJson.put("code", 500);
  318. returnJson.put("success", false);
  319. returnJson.put("message", e.getMessage());
  320. }
  321. return returnJson;
  322. }
  323. /**
  324. * 分成员数据
  325. *
  326. * @param userId
  327. * @param startDate
  328. * @param endDate
  329. * @return
  330. */
  331. @GetMapping("/getPeopleList")
  332. @ApiOperation(value = "切片盯盘-成员数据")
  333. public JSONObject getPeopleList(Long userId, String startDate, String endDate) {
  334. Map<String, Object> requestMap = new HashMap<>();
  335. JSONObject returnJson = new JSONObject();
  336. try {
  337. if (Check.isNull(userId)) {
  338. throw new Exception("请传入用户id");
  339. }
  340. if (Check.isNull(startDate)) {
  341. throw new Exception("请传入开始日期");
  342. }
  343. if (Check.isNull(endDate)) {
  344. throw new Exception("请传入结束日期");
  345. }
  346. String roleId = sysRoleService.getRoleBYUserId(userId);
  347. // 剪手经理,渠道经理 查询部门下所有成员数据
  348. List<Long> promoterIds = new ArrayList<>();
  349. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  350. List<Long> userIds = new ArrayList<>();
  351. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  352. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  353. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  354. } else {
  355. userIds.add(userId);
  356. }
  357. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  358. } else if ("jy_expert_business".equals(roleId)) {
  359. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  360. }
  361. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  362. if (Check.isNull(promoterIds)) {
  363. throw new Exception("该用户下未查询到绑定达人");
  364. }
  365. }
  366. if (!Check.isNull(promoterIds)) {
  367. requestMap.put("promoterIds", promoterIds);
  368. }
  369. Long start = DateUtils.strDateToInt(startDate);
  370. Long end = DateUtils.strDateToInt(endDate);
  371. requestMap.put("start", start);
  372. requestMap.put("end", end);
  373. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  374. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  375. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  376. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  377. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  378. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  379. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  380. if (start.equals(nowDate) && end.equals(nowDate)) {
  381. Integer nowHour = DateUtils.getNowHour();
  382. requestMap.put("nowHour", nowHour);
  383. }
  384. List<JSONObject> data = jiaoYangDingPanService.getPeopleList(requestMap);
  385. returnJson.put("code", 200);
  386. returnJson.put("data", data);
  387. returnJson.put("success", true);
  388. } catch (Exception e) {
  389. returnJson.put("code", 500);
  390. returnJson.put("message", e.getMessage());
  391. }
  392. return returnJson;
  393. }
  394. @GetMapping("/getAddItemListByUserId")
  395. @ApiOperation(value = "切片盯盘-新增商品")
  396. public JSONObject getAddItemListByUserId(Long userId, String startDate, String endDate) {
  397. Map<String, Object> requestMap = new HashMap<>();
  398. JSONObject returnJson = new JSONObject();
  399. try {
  400. if (Check.isNull(userId)) {
  401. throw new Exception("请传入用户id");
  402. }
  403. if (Check.isNull(startDate)) {
  404. throw new Exception("请传入开始日期");
  405. }
  406. if (Check.isNull(endDate)) {
  407. throw new Exception("请传入结束日期");
  408. }
  409. requestMap.put("userId", userId);
  410. Long start = DateUtils.strDateToInt(startDate);
  411. Long end = DateUtils.strDateToInt(endDate);
  412. requestMap.put("start", start);
  413. requestMap.put("end", end);
  414. List<JSONObject> data = jiaoYangDingPanService.getAddItemListByUserId(requestMap);
  415. returnJson.put("data", data);
  416. returnJson.put("code", 200);
  417. returnJson.put("success", true);
  418. } catch (Exception e) {
  419. returnJson.put("code", 500);
  420. returnJson.put("success", false);
  421. returnJson.put("message", e.getMessage());
  422. }
  423. return returnJson;
  424. }
  425. // 分达人数据
  426. @GetMapping("/getPromoterList")
  427. @ApiOperation(value = "切片盯盘-成员数据")
  428. public JSONObject getPromoterList(Long userId, String startDate, String endDate) {
  429. Map<String, Object> requestMap = new HashMap<>();
  430. JSONObject returnJson = new JSONObject();
  431. try {
  432. if (Check.isNull(userId)) {
  433. throw new Exception("请传入用户id");
  434. }
  435. if (Check.isNull(startDate)) {
  436. throw new Exception("请传入开始日期");
  437. }
  438. if (Check.isNull(endDate)) {
  439. throw new Exception("请传入结束日期");
  440. }
  441. String roleId = sysRoleService.getRoleBYUserId(userId);
  442. // 剪手经理,渠道经理 查询部门下所有成员数据
  443. List<Long> promoterIds = new ArrayList<>();
  444. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  445. List<Long> userIds = new ArrayList<>();
  446. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  447. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  448. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  449. } else {
  450. userIds.add(userId);
  451. }
  452. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  453. } else if ("jy_expert_business".equals(roleId)) {
  454. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  455. }
  456. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  457. if (Check.isNull(promoterIds)) {
  458. throw new Exception("该用户下未查询到绑定达人");
  459. }
  460. }
  461. if (!Check.isNull(promoterIds)) {
  462. requestMap.put("promoterIds", promoterIds);
  463. }
  464. Long start = DateUtils.strDateToInt(startDate);
  465. Long end = DateUtils.strDateToInt(endDate);
  466. requestMap.put("start", start);
  467. requestMap.put("end", end);
  468. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  469. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  470. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  471. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  472. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  473. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  474. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  475. if (start.equals(nowDate) && end.equals(nowDate)) {
  476. Integer nowHour = DateUtils.getNowHour();
  477. requestMap.put("nowHour", nowHour);
  478. }
  479. List<JSONObject> data = jiaoYangDingPanService.getPromoterList(requestMap);
  480. returnJson.put("code", 200);
  481. returnJson.put("data", data);
  482. returnJson.put("success", true);
  483. } catch (Exception e) {
  484. returnJson.put("code", 500);
  485. returnJson.put("message", e.getMessage());
  486. }
  487. return returnJson;
  488. }
  489. @GetMapping("/getDingPanItemList")
  490. @ApiOperation(value = "切片盯盘")
  491. public JSONObject getItemList(Long userId, String startDate, String endDate) {
  492. Map<String, Object> requestMap = new HashMap<>();
  493. JSONObject returnJson = new JSONObject();
  494. try {
  495. if (Check.isNull(userId)) {
  496. throw new Exception("请传入用户id");
  497. }
  498. if (Check.isNull(startDate)) {
  499. throw new Exception("请传入开始日期");
  500. }
  501. if (Check.isNull(endDate)) {
  502. throw new Exception("请传入结束日期");
  503. }
  504. String roleId = sysRoleService.getRoleBYUserId(userId);
  505. // 剪手经理,渠道经理 查询部门下所有成员数据
  506. List<Long> promoterIds = new ArrayList<>();
  507. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  508. List<Long> userIds = new ArrayList<>();
  509. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  510. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  511. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  512. } else {
  513. userIds.add(userId);
  514. }
  515. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  516. } else if ("jy_expert_business".equals(roleId)) {
  517. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  518. }
  519. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  520. if (Check.isNull(promoterIds)) {
  521. throw new Exception("该用户下未查询到绑定达人");
  522. }
  523. }
  524. if (!Check.isNull(promoterIds)) {
  525. requestMap.put("promoterIds", promoterIds);
  526. }
  527. Long start = DateUtils.strDateToInt(startDate);
  528. Long end = DateUtils.strDateToInt(endDate);
  529. requestMap.put("start", start);
  530. requestMap.put("end", end);
  531. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  532. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  533. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  534. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  535. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  536. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  537. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  538. if (start.equals(nowDate) && end.equals(nowDate)) {
  539. Integer nowHour = DateUtils.getNowHour();
  540. requestMap.put("nowHour", nowHour);
  541. }
  542. List<JSONObject> data = jiaoYangDingPanService.getItemList(requestMap);
  543. returnJson.put("code", 200);
  544. returnJson.put("data", data);
  545. returnJson.put("success", true);
  546. } catch (Exception e) {
  547. returnJson.put("code", 500);
  548. returnJson.put("message", e.getMessage());
  549. }
  550. return returnJson;
  551. }
  552. @GetMapping("/getDingPanTuiGuangUserList")
  553. @ApiOperation(value = "切片盯盘")
  554. public JSONObject getDingPanTuiGuangUserList(Long userId, String startDate, String endDate) {
  555. Map<String, Object> requestMap = new HashMap<>();
  556. JSONObject returnJson = new JSONObject();
  557. try {
  558. if (Check.isNull(userId)) {
  559. throw new Exception("请传入用户id");
  560. }
  561. if (Check.isNull(startDate)) {
  562. throw new Exception("请传入开始日期");
  563. }
  564. if (Check.isNull(endDate)) {
  565. throw new Exception("请传入结束日期");
  566. }
  567. String roleId = sysRoleService.getRoleBYUserId(userId);
  568. // 剪手经理,渠道经理 查询部门下所有成员数据
  569. List<Long> promoterIds = new ArrayList<>();
  570. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId) || "jy_out_operation_manager".equals(roleId) || "jy_out_operation".equals(roleId)) {
  571. List<Long> userIds = new ArrayList<>();
  572. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_out_operation_manager".equals(roleId)) {
  573. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  574. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  575. } else {
  576. userIds.add(userId);
  577. }
  578. promoterIds = jiaoYangDingPanService.getPromoterIdsByUserIds(userIds);
  579. } else if ("jy_expert_business".equals(roleId)) {
  580. promoterIds = jiaoYangDingPanService.getPromoterIdsByBusinessId(userId);
  581. }
  582. if (!"admin".equals(roleId) && !"jy_admnin".equals(roleId) && !"jy_expert_mentor".equals(roleId)) {
  583. if (Check.isNull(promoterIds)) {
  584. throw new Exception("该用户下未查询到绑定达人");
  585. }
  586. }
  587. if (!Check.isNull(promoterIds)) {
  588. requestMap.put("promoterIds", promoterIds);
  589. }
  590. Long start = DateUtils.strDateToInt(startDate);
  591. Long end = DateUtils.strDateToInt(endDate);
  592. requestMap.put("start", start);
  593. requestMap.put("end", end);
  594. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  595. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  596. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  597. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  598. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  599. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  600. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  601. if (start.equals(nowDate) && end.equals(nowDate)) {
  602. Integer nowHour = DateUtils.getNowHour();
  603. requestMap.put("nowHour", nowHour);
  604. }
  605. List<JSONObject> data = jiaoYangDingPanService.getDingPanTuiGuangUserList(requestMap);
  606. returnJson.put("code", 200);
  607. returnJson.put("data", data);
  608. returnJson.put("success", true);
  609. } catch (Exception e) {
  610. returnJson.put("code", 500);
  611. returnJson.put("message", e.getMessage());
  612. }
  613. return returnJson;
  614. }
  615. @GetMapping("/getDingPanMentorBusinessList")
  616. @ApiOperation(value = "切片盯盘")
  617. public JSONObject getDingPanMentorBusinessList(Long userId, String startDate, String endDate) {
  618. Map<String, Object> requestMap = new HashMap<>();
  619. JSONObject returnJson = new JSONObject();
  620. try {
  621. if (Check.isNull(userId)) {
  622. throw new Exception("请传入用户id");
  623. }
  624. if (Check.isNull(startDate)) {
  625. throw new Exception("请传入开始日期");
  626. }
  627. if (Check.isNull(endDate)) {
  628. throw new Exception("请传入结束日期");
  629. }
  630. String roleId = sysRoleService.getRoleBYUserId(userId);
  631. // 剪手经理,渠道经理 查询部门下所有成员数据
  632. if (!roleId.equals("admin") && !roleId.equals("jy_admin")) {
  633. returnJson.put("code", 200);
  634. returnJson.put("data", null);
  635. return returnJson;
  636. }
  637. Long start = DateUtils.strDateToInt(startDate);
  638. Long end = DateUtils.strDateToInt(endDate);
  639. requestMap.put("start", start);
  640. requestMap.put("end", end);
  641. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  642. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  643. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  644. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  645. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  646. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  647. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  648. if (start.equals(nowDate) && end.equals(nowDate)) {
  649. Integer nowHour = DateUtils.getNowHour();
  650. requestMap.put("nowHour", nowHour);
  651. }
  652. List<JSONObject> data = jiaoYangDingPanService.getDingPanMentorBusinessList(requestMap);
  653. returnJson.put("code", 200);
  654. returnJson.put("data", data);
  655. returnJson.put("success", true);
  656. } catch (Exception e) {
  657. returnJson.put("code", 500);
  658. returnJson.put("message", e.getMessage());
  659. }
  660. return returnJson;
  661. }
  662. @GetMapping("/getTeamDetail")
  663. @ApiOperation(value = "切片盯盘")
  664. public JSONObject getTeamDetail(Long deptId, String startDate, String endDate) {
  665. Map<String, Object> requestMap = new HashMap<>();
  666. JSONObject returnJson = new JSONObject();
  667. try {
  668. if (Check.isNull(deptId)) {
  669. throw new Exception("请传入部门id");
  670. }
  671. if (Check.isNull(startDate)) {
  672. throw new Exception("请传入开始日期");
  673. }
  674. if (Check.isNull(endDate)) {
  675. throw new Exception("请传入结束日期");
  676. }
  677. requestMap.put("deptId", deptId);
  678. Long start = DateUtils.strDateToInt(startDate);
  679. Long end = DateUtils.strDateToInt(endDate);
  680. requestMap.put("start", start);
  681. requestMap.put("end", end);
  682. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  683. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate));
  684. String lastEndStr = DateUtils.getAnotherDay("yyyy-MM-dd", startDate, -1); // 上一时段结束日期
  685. String lastStartStr = DateUtils.getAnotherDay("yyyy-MM-dd", lastEndStr, -differDay); // 上一时段开始日期
  686. requestMap.put("lastEnd", DateUtils.strDateToInt(lastEndStr));
  687. requestMap.put("lastStart", DateUtils.strDateToInt(lastStartStr));
  688. Long nowDate = Long.valueOf(DateUtils.getNowDate("yyyyMMdd"));
  689. if (start.equals(nowDate) && end.equals(nowDate)) {
  690. Integer nowHour = DateUtils.getNowHour();
  691. requestMap.put("nowHour", nowHour);
  692. }
  693. List<JSONObject> data = jiaoYangDingPanService.getDingPanMentorBusinessList(requestMap);
  694. returnJson.put("code", 200);
  695. returnJson.put("data", data);
  696. returnJson.put("success", true);
  697. } catch (Exception e) {
  698. returnJson.put("code", 500);
  699. returnJson.put("message", e.getMessage());
  700. }
  701. return returnJson;
  702. }
  703. }