package com.kmall.admin.controller.statistics; import com.kmall.admin.fromcomm.entity.SysUserEntity; import com.kmall.admin.service.statistics.MonthlyCustomersService; import com.kmall.common.utils.R; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** * @author zhangchuangbiao * @version 1.0 * 2020-09-01 14:35 */ @RestController @RequestMapping("/monthly") public class MonthlyCustomersController { @Autowired private MonthlyCustomersService monthlyCustomersService; private void calculateDifferentMonth(List monthList, String startMonth, String endMonth) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Calendar bef = Calendar.getInstance(); Calendar aft = Calendar.getInstance(); bef.setTime(sdf.parse(startMonth)); aft.setTime(sdf.parse(endMonth)); do { monthList.add(sdf.format(bef.getTime())); bef.add(Calendar.MONTH, 1); } while (bef.compareTo(aft) <= 0); } @RequestMapping("/customersQuery") public R queryMonthlyCustomers(@RequestParam("startMonth") String startMonth, @RequestParam("endMonth") String endMonth) { List dateList = new ArrayList<>(); try { calculateDifferentMonth(dateList, startMonth, endMonth); } catch (ParseException e) { e.printStackTrace(); } String merchSn = null; SysUserEntity sysUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); if(!"1".equals(sysUser.getRoleType())){ merchSn = sysUser.getMerchSn(); } Map map = monthlyCustomersService.queryMonthlyCustomers(startMonth,endMonth,merchSn); Map returnMap = new HashMap<>(); returnMap.put("dateList", dateList); returnMap.putAll(map); return R.ok(returnMap); } }