MonthlyCustomersController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.kmall.admin.controller.statistics;
  2. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  3. import com.kmall.admin.service.statistics.MonthlyCustomersService;
  4. import com.kmall.common.utils.R;
  5. import org.apache.shiro.SecurityUtils;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import java.text.ParseException;
  11. import java.text.SimpleDateFormat;
  12. import java.util.*;
  13. /**
  14. * @author zhangchuangbiao
  15. * @version 1.0
  16. * 2020-09-01 14:35
  17. */
  18. @RestController
  19. @RequestMapping("/monthly")
  20. public class MonthlyCustomersController {
  21. @Autowired
  22. private MonthlyCustomersService monthlyCustomersService;
  23. private void calculateDifferentMonth(List<String> monthList, String startMonth, String endMonth) throws ParseException {
  24. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
  25. Calendar bef = Calendar.getInstance();
  26. Calendar aft = Calendar.getInstance();
  27. bef.setTime(sdf.parse(startMonth));
  28. aft.setTime(sdf.parse(endMonth));
  29. do {
  30. monthList.add(sdf.format(bef.getTime()));
  31. bef.add(Calendar.MONTH, 1);
  32. }
  33. while (bef.compareTo(aft) <= 0);
  34. }
  35. @RequestMapping("/customersQuery")
  36. public R queryMonthlyCustomers(@RequestParam("startMonth") String startMonth, @RequestParam("endMonth") String endMonth) {
  37. List<String> dateList = new ArrayList<>();
  38. Map<String, Object> returnMap = new HashMap<>();
  39. try {
  40. calculateDifferentMonth(dateList, startMonth, endMonth);
  41. } catch (ParseException e) {
  42. e.printStackTrace();
  43. }
  44. try {
  45. String merchSn = null;
  46. SysUserEntity sysUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
  47. if(!"1".equals(sysUser.getRoleType())){
  48. merchSn = sysUser.getMerchSn();
  49. }
  50. Map<String,Object> map = monthlyCustomersService.queryMonthlyCustomers(startMonth,endMonth,merchSn);
  51. returnMap.put("dateList", dateList);
  52. returnMap.putAll(map);
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. return R.error(e.getMessage());
  56. }
  57. return R.ok(returnMap);
  58. }
  59. @RequestMapping("/top10ForProduct")
  60. public R top10ForProduct(@RequestParam("month") String month, @RequestParam("week") String week){
  61. Map<String,Object> map = monthlyCustomersService.top10ForProduct(month,week);
  62. return R.ok(map);
  63. }
  64. @RequestMapping("/top10ByBrandAndSupplier")
  65. public R top10ByBrandAndSupplier(@RequestParam("startDate") String startDate,
  66. @RequestParam("endDate") String endDate){
  67. Map<String,Object> map = monthlyCustomersService.top10ByBrandAndSupplier(startDate,endDate);
  68. return R.ok(map);
  69. }
  70. }