MonthlyCustomersController.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. try {
  39. calculateDifferentMonth(dateList, startMonth, endMonth);
  40. } catch (ParseException e) {
  41. e.printStackTrace();
  42. }
  43. String merchSn = null;
  44. SysUserEntity sysUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
  45. if(!"1".equals(sysUser.getRoleType())){
  46. merchSn = sysUser.getMerchSn();
  47. }
  48. Map<String,Object> map = monthlyCustomersService.queryMonthlyCustomers(startMonth,endMonth,merchSn);
  49. Map<String, Object> returnMap = new HashMap<>();
  50. returnMap.put("dateList", dateList);
  51. returnMap.putAll(map);
  52. return R.ok(returnMap);
  53. }
  54. }