puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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;
    }
 
}