package com.sinata.shop.modular.mall.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.core.util.DateUtils2;
|
import com.sinata.shop.core.shiro.ShiroKit;
|
import com.sinata.shop.modular.mall.dto.OrderPriceVo;
|
import com.sinata.shop.modular.mall.model.MallGoodsSku;
|
import com.sinata.shop.modular.mall.service.IMallGoodsSkuService;
|
import com.sinata.shop.modular.mall.service.IMallOrderService;
|
import com.sinata.shop.modular.mall.service.ITNoticeService;
|
import com.sinata.shop.modular.system.model.MyDoctor;
|
import com.sinata.shop.modular.system.service.IMyDoctorService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
|
/**
|
* 报表
|
*
|
* @author frankevil
|
* @date 2023/3/30 01:01
|
**/
|
@Slf4j
|
@Controller
|
@RequestMapping("/indexReport")
|
public class IndexReportController extends BaseController {
|
@Resource
|
private IMyDoctorService myDoctorService;
|
@Resource
|
private IMallGoodsSkuService mallGoodsSkuService;
|
|
@Resource
|
private IMallOrderService mallOrderService;
|
|
@Resource
|
private ITNoticeService noticeService;
|
|
|
|
@RequestMapping("/shopNotice")
|
public String shopNotice(Model model){
|
Integer merchantId= ShiroKit.getUserId();
|
List<Map<String,Object>> dataList = noticeService.shopNotice(merchantId);
|
model.addAttribute("dataList", dataList);
|
return "/notice.html";
|
}
|
|
@ResponseBody
|
@RequestMapping("/shopIndex")
|
public Object shopIndex(){
|
Integer merchantId= ShiroKit.getUserId();
|
//商品数量
|
Map<String, Object> result = new HashMap<>(2);
|
result.put("goodsNumber",mallGoodsSkuService.getGoodsListByMerchantId(merchantId).size());
|
|
Wrapper<MyDoctor> wrapper2 = new EntityWrapper<>();
|
wrapper2.where("FIND_IN_SET("+merchantId+", merchant_id)");
|
result.put("doctorNumber", myDoctorService.selectList(wrapper2).size());
|
return result;
|
}
|
|
@ResponseBody
|
@RequestMapping("/orderIndex")
|
public Object orderIndex(){
|
return mallOrderService.orderIndex(ShiroKit.getUserId());
|
}
|
@ResponseBody
|
@RequestMapping("/orderPriceIndex")
|
public Object orderPriceIndex(){
|
Integer merchantId= ShiroKit.getUserId();
|
OrderPriceVo orderPriceIndex = mallOrderService.orderPriceIndex(merchantId);
|
orderPriceIndex.setUseNumber(mallOrderService.orderUse(merchantId));
|
return orderPriceIndex;
|
}
|
|
@ResponseBody
|
@PostMapping("getDataTrend")
|
public Object getDataTrend(Integer dataType,Integer dateType) {
|
Integer merchantId= ShiroKit.getUserId();
|
// 查询上月N天数据
|
Calendar calendar = Calendar.getInstance(Locale.CHINA);
|
calendar.set(Calendar.DAY_OF_MONTH, 1);// 本月第一天
|
calendar.add(Calendar.DAY_OF_MONTH, -1);// 上月月最后一天
|
|
String nowTime = DateUtils2.formatDate(new Date(), "yyyy-MM-dd");
|
|
// 获取日期
|
String beginTime = DateUtils2.getAfterDayDate("-" + dateType, "yyyy-MM-dd") + " 00:00:00";
|
String endTime = nowTime + " 23:59:59";
|
|
Map map = new HashMap();
|
List<String> timeList = new ArrayList<String>();
|
String dateFormat = "%Y-%m-%d";
|
if(dateType.equals(1)){
|
dateFormat = "%H:00:00";
|
for (int i = 0; i <24; i++) {
|
String si = i+":00:00";
|
if(i < 10){
|
si = "0"+si;
|
}
|
timeList.add(si);
|
}
|
} else{
|
for (int i = dateType-1; i >= 0; i--) {
|
timeList.add(DateUtils2.getAfterDayDate("-" + i, "yyyy-MM-dd"));
|
}
|
}
|
List<Object> num0List = new ArrayList<>();
|
// 用户
|
List<Map<String, Object>> agencyNumLit0 = new ArrayList<>();
|
if(dataType.equals(2)){
|
agencyNumLit0 = mallOrderService.getDataTrend2(dataType,merchantId,beginTime,endTime,dateFormat);
|
}else {
|
agencyNumLit0 = mallOrderService.getDataTrend(dataType,merchantId,beginTime,endTime,dateFormat);
|
}
|
|
// 处理封装数据
|
for (String time : timeList) {
|
num0List = getDataList(num0List, time, agencyNumLit0);
|
}
|
map.put("timeList", timeList);
|
map.put("num0List", num0List);
|
return map;
|
}
|
|
/**
|
* 数据封装
|
*/
|
public List<Object> getDataList(List<Object> dataList, String time, List<Map<String, Object>> list) {
|
// 是否匹配到数据
|
boolean flag = false;
|
for (Map<String, Object> map : list) {
|
if (time.equals(map.get("time"))) {
|
dataList.add(map.get("num") == null ? 0 : new Double(map.get("num").toString()));
|
flag = true;
|
}
|
}
|
// 未匹配到数据,设置默认值
|
if (!flag) {
|
dataList.add(0);
|
}
|
return dataList;
|
}
|
|
}
|