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<>(); Map returnMap = new HashMap<>(); try { calculateDifferentMonth(dateList, startMonth, endMonth); } catch (ParseException e) { e.printStackTrace(); } try { String merchSn = null; SysUserEntity sysUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); if(!"1".equals(sysUser.getRoleType())){ merchSn = sysUser.getMerchSn(); } Map map = monthlyCustomersService.queryMonthlyCustomers(startMonth,endMonth,merchSn); returnMap.put("dateList", dateList); returnMap.putAll(map); } catch (Exception e) { e.printStackTrace(); return R.error(e.getMessage()); } return R.ok(returnMap); } @RequestMapping("/top10ForProduct") public R top10ForProduct(@RequestParam("month") String month, @RequestParam("week") String week){ Map map = monthlyCustomersService.top10ForProduct(month,week); return R.ok(map); } @RequestMapping("/top10ByBrandAndSupplier") public R top10ByBrandAndSupplier(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate){ Map map = monthlyCustomersService.top10ByBrandAndSupplier(startDate,endDate); return R.ok(map); } }