JiaoYangReportController.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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.IJiaoYangReportService;
  8. import com.ruixuan.system.service.ISysDeptService;
  9. import com.ruixuan.system.service.ISysRoleService;
  10. import com.ruixuan.system.service.ISysUserService;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import lombok.SneakyThrows;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;
  21. @RestController
  22. @RequestMapping("/jy/report")
  23. public class JiaoYangReportController extends BaseController {
  24. @Autowired
  25. private IJiaoYangReportService jiaoYangReportService;
  26. @Autowired
  27. private ISysRoleService sysRoleService;
  28. @Autowired
  29. private ISysDeptService sysDeptService;
  30. @Autowired
  31. private ISysUserService sysUserService;
  32. /**
  33. * 商品数据
  34. *
  35. * @param itemId
  36. * @param itemTitle
  37. * @param orderStartDate
  38. * @param orderEndDate
  39. * @param fieId
  40. * @param sort
  41. * @return
  42. */
  43. @GetMapping("/item")
  44. @ApiOperation(value = "商品列表")
  45. public TableDataInfo item(
  46. @ApiParam("商品Id") @RequestParam(value = "itemId", required = false) String itemId,
  47. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  48. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  49. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  50. @ApiParam("排序字段") @RequestParam(value = "fieId", required = false) String fieId,
  51. @ApiParam("排序方式") @RequestParam(value = "sort", required = false) String sort) {
  52. Map<String, Object> requestMap = new HashMap<>();
  53. if (!Check.isNull(orderStartDate)) {
  54. Long start = DateUtils.strDateToInt(orderStartDate);
  55. requestMap.put("start", start);
  56. }
  57. if (!Check.isNull(orderEndDate)) {
  58. Long end = DateUtils.strDateToInt(orderEndDate);
  59. requestMap.put("end", end);
  60. }
  61. if (!Check.isNull(itemId)) {
  62. requestMap.put("itemId", itemId);
  63. }
  64. if (!Check.isNull(itemTitle)) {
  65. requestMap.put("itemTitle", itemTitle);
  66. }
  67. requestMap.put("fieId", fieId);
  68. requestMap.put("sort", sort);
  69. TableDataInfo dataInfo = new TableDataInfo();
  70. if (Check.isNullMap(requestMap)) {
  71. dataInfo.setCode(-1);
  72. dataInfo.setMsg("入参不能为空");
  73. return dataInfo;
  74. }
  75. startPage();
  76. List<JSONObject> list = jiaoYangReportService.item(requestMap);
  77. return getDataTable(list);
  78. }
  79. /**
  80. * 商品详情
  81. *
  82. * @param itemId
  83. * @param orderStartDate
  84. * @param orderEndDate
  85. * @param promoterId
  86. * @param promoterNickName
  87. * @return
  88. */
  89. @GetMapping("/itemDetail")
  90. @ApiOperation(value = "商品详情")
  91. public TableDataInfo itemDetail(
  92. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) String itemId,
  93. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  94. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  95. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  96. @ApiParam("达人名称") @RequestParam(value = "promoterNickName", required = false) String promoterNickName) {
  97. Map<String, Object> requestMap = new HashMap<>();
  98. if (!Check.isNull(orderStartDate)) {
  99. Long start = DateUtils.strDateToInt(orderStartDate);
  100. requestMap.put("start", start);
  101. }
  102. if (!Check.isNull(orderEndDate)) {
  103. Long end = DateUtils.strDateToInt(orderEndDate);
  104. requestMap.put("end", end);
  105. }
  106. if (!Check.isNull(promoterId)) {
  107. requestMap.put("promoterId", promoterId);
  108. }
  109. if (!Check.isNull(itemId)) {
  110. requestMap.put("itemId", itemId);
  111. }
  112. if (!Check.isNull(promoterNickName)) {
  113. requestMap.put("itemTitle", promoterNickName);
  114. }
  115. TableDataInfo dataInfo = new TableDataInfo();
  116. if (Check.isNullMap(requestMap)) {
  117. dataInfo.setCode(-1);
  118. dataInfo.setMsg("入参不能为空");
  119. return dataInfo;
  120. }
  121. startPage();
  122. List<JSONObject> list = jiaoYangReportService.itemDetail(requestMap);
  123. return getDataTable(list);
  124. }
  125. /**
  126. * 达人数据
  127. *
  128. * @param orderStartDate
  129. * @param orderEndDate
  130. * @param promoterNickName
  131. * @param promoterId
  132. * @return
  133. */
  134. @GetMapping("/promoter")
  135. @ApiOperation(value = "达人订单")
  136. public TableDataInfo promoter(@ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  137. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  138. @ApiParam("达人名称") @RequestParam(value = "promoterNickName", required = false) String promoterNickName,
  139. @ApiParam("达人ID") @RequestParam(value = "promoterId", required = false) Long promoterId,
  140. @ApiParam("类型") @RequestParam(value = "type", required = false) Long type,
  141. Long userId) {
  142. Map<String, Object> requestMap = new HashMap<>();
  143. String roleId = sysRoleService.getRoleBYUserId(userId);
  144. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  145. List<Long> userIds = new ArrayList<>();
  146. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  147. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  148. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  149. } else {
  150. userIds.add(userId);
  151. }
  152. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  153. if (Check.isNull(promoterIds)) {
  154. return getDataTable(new ArrayList<JSONObject>());
  155. }
  156. requestMap.put("promoterIds", promoterIds);
  157. }
  158. if (!Check.isNull(orderStartDate)) {
  159. Long start = DateUtils.strDateToInt(orderStartDate);
  160. requestMap.put("start", start);
  161. }
  162. if (!Check.isNull(orderEndDate)) {
  163. Long end = DateUtils.strDateToInt(orderEndDate);
  164. requestMap.put("end", end);
  165. }
  166. if (!Check.isNull(promoterNickName)) {
  167. requestMap.put("promoterNickName", promoterNickName);
  168. }
  169. if (!Check.isNull(promoterId)) {
  170. requestMap.put("promoterId", promoterId);
  171. }
  172. if (!Check.isNull(type)) {
  173. requestMap.put("type", type);
  174. }
  175. TableDataInfo dataInfo = new TableDataInfo();
  176. if (Check.isNullMap(requestMap)) {
  177. dataInfo.setCode(-1);
  178. dataInfo.setMsg("入参不能为空");
  179. return dataInfo;
  180. }
  181. startPage();
  182. List<JSONObject> list = jiaoYangReportService.promoter(requestMap);
  183. return getDataTable(list);
  184. }
  185. /**
  186. * 达人带货详情
  187. *
  188. * @param promoterId
  189. * @param orderStartDate
  190. * @param orderEndDate
  191. * @param itemTitle
  192. * @param itemId
  193. * @return
  194. */
  195. @GetMapping("/promoterDetail")
  196. @ApiOperation(value = "达人带货详情")
  197. public TableDataInfo promoterDetail(
  198. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  199. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  200. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  201. @ApiParam("商品名称") @RequestParam(value = "itemTitle", required = false) String itemTitle,
  202. @ApiParam("商品ID") @RequestParam(value = "itemId", required = false) String itemId, Long userId) {
  203. Map<String, Object> requestMap = new HashMap<>();
  204. String roleId = sysRoleService.getRoleBYUserId(userId);
  205. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  206. List<Long> userIds = new ArrayList<>();
  207. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  208. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  209. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  210. } else {
  211. userIds.add(userId);
  212. }
  213. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  214. if (Check.isNull(promoterIds)) {
  215. return getDataTable(new ArrayList<>());
  216. }
  217. requestMap.put("promoterIds", promoterIds);
  218. }
  219. if (!Check.isNull(orderStartDate)) {
  220. Long start = DateUtils.strDateToInt(orderStartDate);
  221. requestMap.put("start", start);
  222. }
  223. if (!Check.isNull(orderEndDate)) {
  224. Long end = DateUtils.strDateToInt(orderEndDate);
  225. requestMap.put("end", end);
  226. }
  227. if (!Check.isNull(promoterId)) {
  228. requestMap.put("promoterId", promoterId);
  229. }
  230. if (!Check.isNull(itemId)) {
  231. requestMap.put("itemId", itemId);
  232. }
  233. if (!Check.isNull(itemTitle)) {
  234. requestMap.put("itemTitle", itemTitle);
  235. }
  236. TableDataInfo dataInfo = new TableDataInfo();
  237. if (Check.isNullMap(requestMap)) {
  238. dataInfo.setCode(-1);
  239. dataInfo.setMsg("入参不能为空");
  240. return dataInfo;
  241. }
  242. startPage();
  243. List<JSONObject> list = jiaoYangReportService.anchorOrderDetail(requestMap);
  244. return getDataTable(list);
  245. }
  246. @GetMapping("/promoterStatistics")
  247. @ApiOperation(value = "订单统计")
  248. public JSONObject promoterStatistics(
  249. @ApiParam("达人Id") @RequestParam(value = "promoterId", required = false) String promoterId,
  250. @ApiParam("订单开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  251. @ApiParam("订单结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,Long userId) {
  252. Map<String, Object> requestMap = new HashMap<>();
  253. String roleId = sysRoleService.getRoleBYUserId(userId);
  254. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  255. List<Long> userIds = new ArrayList<>();
  256. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  257. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  258. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  259. } else {
  260. userIds.add(userId);
  261. }
  262. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  263. if (Check.isNull(promoterIds)) {
  264. return new JSONObject();
  265. }
  266. requestMap.put("promoterIds", promoterIds);
  267. }
  268. if (!Check.isNull(orderStartDate)) {
  269. Long start = DateUtils.strDateToInt(orderStartDate);
  270. requestMap.put("start", start);
  271. }
  272. if (!Check.isNull(orderEndDate)) {
  273. Long end = DateUtils.strDateToInt(orderEndDate);
  274. requestMap.put("end", end);
  275. }
  276. if (!Check.isNull(promoterId)) {
  277. requestMap.put("promoterId", promoterId);
  278. }
  279. JSONObject returnJson = new JSONObject();
  280. if (Check.isNullMap(requestMap)) {
  281. returnJson.put("code", -1);
  282. returnJson.put("message", "入参不能为空");
  283. return returnJson;
  284. }
  285. List<JSONObject> list = jiaoYangReportService.promoterStatistics(requestMap);
  286. returnJson.put("code", 0);
  287. returnJson.put("data", list);
  288. return returnJson;
  289. }
  290. @GetMapping("/getClipCooperation")
  291. public TableDataInfo list(String statDate, Long promoterId, String promoterName) {
  292. Long date = Long.valueOf(statDate.replace("-", ""));
  293. startPage();
  294. List<JSONObject> list = jiaoYangReportService.getClipCooperation(date, promoterId, promoterName);
  295. return getDataTable(list);
  296. }
  297. @GetMapping("/indexOrderInfo")
  298. @ApiOperation(value = "首页-订单数据")
  299. public JSONObject orderTotal(
  300. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  301. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  302. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  303. @ApiParam("结束时间") @RequestParam(value = "userId", required = false) Long userId
  304. ) {
  305. Map<String, Object> requestMap = new HashMap<>();
  306. JSONObject returnJson = new JSONObject();
  307. String roleId = sysRoleService.getRoleBYUserId(userId);
  308. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  309. List<Long> userIds = new ArrayList<>();
  310. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  311. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  312. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  313. } else {
  314. userIds.add(userId);
  315. }
  316. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  317. if (Check.isNull(promoterIds)) {
  318. return returnJson;
  319. }
  320. requestMap.put("promoterIds", promoterIds);
  321. }
  322. if (dateType == 0) {
  323. if (!Check.isNull(orderStartDate)) {
  324. Long start = DateUtils.strDateToInt(orderStartDate); //当天开始时间
  325. requestMap.put("start", start);
  326. }
  327. if (!Check.isNull(orderEndDate)) {
  328. Long end = DateUtils.strDateToInt(orderEndDate); // 当天结束时间
  329. requestMap.put("end", end);
  330. }
  331. JSONObject orderTotal = jiaoYangReportService.getOrderTotal(requestMap);
  332. returnJson.put("orderTotal", orderTotal);
  333. Integer hour = DateUtils.getNowHour() - 1; // 当前小时
  334. if (hour >= 0) {
  335. JSONObject ratioJson = new JSONObject();
  336. Long nowDate = DateUtils.strDateToInt(orderStartDate);
  337. Long yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1)); // 昨日日期
  338. Map<String, Object> ratioMap = new HashMap<>();
  339. ratioMap.put("nowDate", nowDate);
  340. ratioMap.put("yesDate", yesDate);
  341. ratioMap.put("hour", hour);
  342. Double ringRatio = jiaoYangReportService.getOrderTotalRatio(ratioMap); //环比
  343. ratioJson.put("ringRatio", ringRatio);
  344. yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -6)); // 昨日日期
  345. ratioMap.put("yesDate", yesDate);
  346. Double yearRatio = jiaoYangReportService.getOrderTotalRatio(ratioMap); //同比
  347. ratioJson.put("yearRatio", yearRatio);
  348. returnJson.put("ratio", ratioJson);
  349. }
  350. } else {
  351. if (!Check.isNull(orderStartDate)) {
  352. Long start = DateUtils.strDateToInt(orderStartDate); //昨日开始时间
  353. requestMap.put("start", start);
  354. }
  355. if (!Check.isNull(orderEndDate)) {
  356. Long end = DateUtils.strDateToInt(orderEndDate); // 前日开始时间
  357. requestMap.put("end", end);
  358. }
  359. JSONObject orderTotal = jiaoYangReportService.getOrderTotal(requestMap);
  360. returnJson.put("orderTotal", orderTotal);
  361. }
  362. return returnJson;
  363. }
  364. /**
  365. * 首页-服务费数据
  366. *
  367. * @param dateType
  368. * @param orderStartDate
  369. * @param orderEndDate
  370. * @return
  371. */
  372. @GetMapping("/indexServiceAmountInfo")
  373. @ApiOperation(value = "首页-服务费数据")
  374. public JSONObject indexServiceAmountInfo(
  375. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  376. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  377. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  378. Long userId
  379. ) {
  380. Map<String, Object> requestMap = new HashMap<>();
  381. JSONObject returnJson = new JSONObject();
  382. String roleId = sysRoleService.getRoleBYUserId(userId);
  383. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  384. List<Long> userIds = new ArrayList<>();
  385. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  386. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  387. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  388. } else {
  389. userIds.add(userId);
  390. }
  391. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  392. if (Check.isNull(promoterIds)) {
  393. return returnJson;
  394. }
  395. requestMap.put("promoterIds", promoterIds);
  396. }
  397. if (!Check.isNull(orderStartDate)) {
  398. Long start = DateUtils.strDateToInt(orderStartDate);
  399. requestMap.put("start", start);
  400. }
  401. if (!Check.isNull(orderEndDate)) {
  402. Long end = DateUtils.strDateToInt(orderEndDate);
  403. requestMap.put("end", end);
  404. }
  405. JSONObject serviceAmountTotal = jiaoYangReportService.getServiceAmountTotal(requestMap);
  406. returnJson.put("serviceAmountTotal", serviceAmountTotal);
  407. return returnJson;
  408. }
  409. /**
  410. * 首页-金额数据
  411. *
  412. * @param dateType
  413. * @param orderStartDate
  414. * @param orderEndDate
  415. * @return
  416. */
  417. @GetMapping("/indexAmountInfo")
  418. @ApiOperation(value = "首页-金额数据")
  419. public JSONObject indexAmountInfo(
  420. @ApiParam("时间类型") @RequestParam(value = "dateType", required = false) Integer dateType,
  421. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  422. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  423. Long userId) {
  424. Map<String, Object> requestMap = new HashMap<>();
  425. JSONObject returnJson = new JSONObject();
  426. String roleId = sysRoleService.getRoleBYUserId(userId);
  427. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  428. List<Long> userIds = new ArrayList<>();
  429. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  430. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  431. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  432. } else {
  433. userIds.add(userId);
  434. }
  435. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  436. if (Check.isNull(promoterIds)) {
  437. return returnJson;
  438. }
  439. requestMap.put("promoterIds", promoterIds);
  440. }
  441. if (dateType == 0) {
  442. if (!Check.isNull(orderStartDate)) {
  443. Long start = DateUtils.strDateToInt(orderStartDate); //当天开始时间
  444. requestMap.put("start", start);
  445. }
  446. if (!Check.isNull(orderEndDate)) {
  447. Long end = DateUtils.strDateToInt(orderEndDate); // 当天结束时间
  448. requestMap.put("end", end);
  449. }
  450. JSONObject amountTotal = jiaoYangReportService.getAmountTotal(requestMap);
  451. returnJson.put("amountTotal", amountTotal);
  452. Integer hour = DateUtils.getNowHour() - 1; // 当前小时
  453. if (hour >= 0) {
  454. JSONObject amountRatioJson = new JSONObject();
  455. Long nowDate = DateUtils.strDateToInt(orderStartDate);
  456. Long yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1)); // 昨日日期
  457. Map<String, Object> ratioMap = new HashMap<>();
  458. ratioMap.put("nowDate", nowDate);
  459. ratioMap.put("yesDate", yesDate);
  460. ratioMap.put("hour", hour);
  461. Double amountRingRatio = jiaoYangReportService.getAmountTotalRatio(ratioMap); //环比
  462. amountRatioJson.put("amountRingRatio", amountRingRatio);
  463. yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -6)); // 昨日日期
  464. ratioMap.put("yesDate", yesDate);
  465. Double amountYearRatio = jiaoYangReportService.getAmountTotalRatio(ratioMap); //同比
  466. amountRatioJson.put("amountYearRatio", amountYearRatio);
  467. returnJson.put("amountRatio", amountRatioJson);
  468. }
  469. } else {
  470. if (!Check.isNull(orderStartDate)) {
  471. Long start = DateUtils.strDateToInt(orderStartDate); //昨日开始时间
  472. requestMap.put("start", start);
  473. }
  474. if (!Check.isNull(orderEndDate)) {
  475. Long end = DateUtils.strDateToInt(orderEndDate); // 前日开始时间
  476. requestMap.put("end", end);
  477. }
  478. JSONObject amountTotal = jiaoYangReportService.getAmountTotal(requestMap);
  479. returnJson.put("amountTotal", amountTotal);
  480. }
  481. return returnJson;
  482. }
  483. @GetMapping("/indexPromoterRank")
  484. @ApiOperation(value = "首页-达人排行")
  485. public TableDataInfo indexPromoterRank(
  486. @ApiParam("时间类型") @RequestParam(value = "dateType", required = true) Integer dateType,
  487. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = true) String orderStartDate,
  488. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = true) String orderEndDate,
  489. @ApiParam("userId") @RequestParam(value = "userId", required = false) Long userId
  490. ) {
  491. Map<String, Object> requestMap = new HashMap<>();
  492. /*String roleId = sysRoleService.getRoleBYUserId(userId);
  493. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  494. List<Long> userIds = new ArrayList<>();
  495. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  496. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  497. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  498. } else {
  499. userIds.add(userId);
  500. }
  501. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  502. if (Check.isNull(promoterIds)) {
  503. return getDataTable(
  504. new ArrayList<>()
  505. );
  506. }
  507. requestMap.put("promoterIds", promoterIds);
  508. }*/
  509. if (dateType == 0) {
  510. if (!Check.isNull(orderStartDate)) {
  511. Long start = DateUtils.strDateToInt(orderStartDate); //当天开始时间
  512. requestMap.put("start", start);
  513. }
  514. if (!Check.isNull(orderEndDate)) {
  515. Long end = DateUtils.strDateToInt(orderEndDate); // 当天结束时间
  516. requestMap.put("end", end);
  517. }
  518. Integer hour = DateUtils.getNowHour(); // 当前小时
  519. Long nowDate = DateUtils.strDateToInt(orderStartDate); // 当天开始时间戳
  520. Long yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1)); // 昨日日期
  521. requestMap.put("nowDate", nowDate);
  522. requestMap.put("hour", hour);
  523. requestMap.put("yesDate", yesDate);
  524. startPage();
  525. List<JSONObject> promoterRankRatioList = jiaoYangReportService.getPromoterRankRatioList(requestMap);
  526. return getDataTable(promoterRankRatioList);
  527. } else {
  528. if (!Check.isNull(orderStartDate)) {
  529. Long start = DateUtils.strDateToInt(orderStartDate);
  530. requestMap.put("start", start);
  531. }
  532. if (!Check.isNull(orderEndDate)) {
  533. Long end = DateUtils.strDateToInt(orderEndDate);
  534. requestMap.put("end", end);
  535. }
  536. startPage();
  537. List<JSONObject> orderRatioList = jiaoYangReportService.getPromoterRatioList(requestMap);
  538. return getDataTable(orderRatioList);
  539. }
  540. }
  541. /**
  542. * 首页-商品排行
  543. *
  544. * @param dateType
  545. * @param orderStartDate
  546. * @param orderEndDate
  547. * @return
  548. */
  549. @GetMapping("/indexOrderRank")
  550. @ApiOperation(value = "首页-商品排行")
  551. public TableDataInfo indexOrderRank(
  552. @ApiParam("时间类型") @RequestParam(value = "dateType", required = true) Integer dateType,
  553. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = true) String orderStartDate,
  554. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = true) String orderEndDate) {
  555. Map<String, Object> requestMap = new HashMap<>();
  556. if (dateType == 0) {
  557. Integer hour = DateUtils.getNowHour(); // 当前小时
  558. Long nowDate = DateUtils.strDateToInt(orderStartDate); // 当天开始时间戳
  559. Long yesDate = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1)); // 昨日日期
  560. requestMap.put("nowDate", nowDate);
  561. requestMap.put("yesDate", yesDate);
  562. requestMap.put("hour", hour);
  563. startPage();
  564. List<JSONObject> orderRankRatioList = jiaoYangReportService.getOrderRankRatioList(requestMap);
  565. return getDataTable(orderRankRatioList);
  566. } else {
  567. if (!Check.isNull(orderStartDate)) {
  568. Long start = DateUtils.strDateToInt(orderStartDate);
  569. requestMap.put("start", start);
  570. }
  571. if (!Check.isNull(orderEndDate)) {
  572. Long end = DateUtils.strDateToInt(orderEndDate);
  573. requestMap.put("end", end);
  574. }
  575. startPage();
  576. List<JSONObject> orderRankRatioList = jiaoYangReportService.getOrderRankList(requestMap);
  577. return getDataTable(orderRankRatioList);
  578. }
  579. }
  580. /**
  581. * 首页-统计图
  582. *
  583. * @param orderStartDate
  584. * @param orderEndDate
  585. * @param type
  586. * @return
  587. */
  588. @GetMapping("/indexStatistics")
  589. @ApiOperation(value = "首页-统计图")
  590. public List<JSONObject> indexStatistics(
  591. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  592. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  593. @ApiParam("类型") @RequestParam(value = "type", required = false) String type,
  594. Long userId) {
  595. Map<String, Object> requestMap = new HashMap<>();
  596. String roleId = sysRoleService.getRoleBYUserId(userId);
  597. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  598. List<Long> userIds = new ArrayList<>();
  599. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  600. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  601. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  602. } else {
  603. userIds.add(userId);
  604. }
  605. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  606. if (Check.isNull(promoterIds)) {
  607. return new ArrayList<>();
  608. }
  609. requestMap.put("promoterIds", promoterIds);
  610. }
  611. String nowDate = DateUtils.getNowDateStr();
  612. Long start = null;
  613. Long end = null;
  614. if (nowDate.equals(orderStartDate) && nowDate.equals(orderEndDate)) {
  615. String endStr = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
  616. end = DateUtils.strDateToInt(endStr);
  617. start = DateUtils.strDateToInt(DateUtils.getAnotherDay("yyyy-MM-dd", endStr, -6));
  618. } else {
  619. start = DateUtils.strDateToInt(orderStartDate);
  620. end = DateUtils.strDateToInt(orderEndDate);
  621. }
  622. if (!Check.isNull(start)) {
  623. requestMap.put("start", start);
  624. }
  625. if (!Check.isNull(end)) {
  626. requestMap.put("end", end);
  627. }
  628. if (!Check.isNull(type)) {
  629. requestMap.put("type", type);
  630. }
  631. List<JSONObject> list = jiaoYangReportService.indexStatistics(requestMap);
  632. return list;
  633. }
  634. /**
  635. * 首页-时段对比
  636. *
  637. * @param orderStartDate
  638. * @param orderEndDate
  639. * @return
  640. */
  641. @SneakyThrows
  642. @GetMapping("/indexTimeIntervalRatio")
  643. @ApiOperation(value = "首页-时段对比")
  644. public JSONObject indexTimeIntervalRatio(
  645. @ApiParam("开始时间") @RequestParam(value = "orderStartDate", required = false) String orderStartDate,
  646. @ApiParam("结束时间") @RequestParam(value = "orderEndDate", required = false) String orderEndDate,
  647. Long userId
  648. ) {
  649. Map<String, Object> requestMap = new HashMap<>();
  650. String roleId = sysRoleService.getRoleBYUserId(userId);
  651. if ("jy_bd".equals(roleId) || "jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId) || "jy_scissors".equals(roleId)) {
  652. List<Long> userIds = new ArrayList<>();
  653. if ("jy_bd_manage".equals(roleId) || "jy_scissors_manage".equals(roleId)) {
  654. Long deptId = sysDeptService.getDeptIdByUserId(userId);
  655. userIds = sysDeptService.getDeptUserListByDeptId(deptId);
  656. } else {
  657. userIds.add(userId);
  658. }
  659. List<Long> promoterIds = jiaoYangReportService.getPromoterIdsByUserIds(userIds);
  660. if (Check.isNull(promoterIds)) {
  661. return new JSONObject();
  662. }
  663. requestMap.put("promoterIds", promoterIds);
  664. }
  665. String nowDate = DateUtils.getNowDateStr();
  666. String thisCycleEnd = null; // 当前时段结束日期
  667. String thisCycleStart = null; // 当前时段开始日期
  668. String lastCycleEnd = null; // 上一时段结束日期
  669. String lastCycleStart = null; // 上一时段开始日期
  670. if (nowDate.equals(orderStartDate) && nowDate.equals(orderEndDate)) {
  671. thisCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
  672. thisCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", thisCycleEnd, -6);
  673. lastCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", thisCycleStart, -1);
  674. lastCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", lastCycleEnd, -6);
  675. } else {
  676. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  677. int differDay = DateUtils.differentDaysByMillisecond(simpleDateFormat.parse(orderStartDate), simpleDateFormat.parse(orderEndDate));
  678. thisCycleEnd = orderEndDate;
  679. thisCycleStart = orderStartDate;
  680. lastCycleEnd = DateUtils.getAnotherDay("yyyy-MM-dd", orderStartDate, -1);
  681. lastCycleStart = DateUtils.getAnotherDay("yyyy-MM-dd", lastCycleEnd, -differDay);
  682. }
  683. if (!Check.isNull(thisCycleStart)) {
  684. Long thisCycleStartTemp = DateUtils.strDateToInt(thisCycleStart);
  685. requestMap.put("thisCycleStartTemp", thisCycleStartTemp);
  686. }
  687. if (!Check.isNull(thisCycleEnd)) {
  688. Long thisCycleEndTemp = DateUtils.strDateToInt(thisCycleEnd);
  689. requestMap.put("thisCycleEndTemp", thisCycleEndTemp);
  690. }
  691. if (!Check.isNull(lastCycleStart)) {
  692. Long lastCycleStartTemp = DateUtils.strDateToInt(lastCycleStart);
  693. requestMap.put("lastCycleStartTemp", lastCycleStartTemp);
  694. }
  695. if (!Check.isNull(lastCycleEnd)) {
  696. Long lastCycleEndTemp = DateUtils.strDateToInt(lastCycleEnd);
  697. requestMap.put("lastCycleEndTemp", lastCycleEndTemp);
  698. }
  699. JSONObject timeIntervalRatioJson = jiaoYangReportService.getTimeIntervalRatio(requestMap);
  700. return timeIntervalRatioJson;
  701. }
  702. }