wzy
2020-12-14 d151ab96d31e8c581f71e9185d895d1a589e829c
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
154
155
156
157
package com.matrix.system.hiveErp.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.tools.DataAuthUtil;
import com.matrix.system.hive.bean.SysShopInfo;
import com.matrix.system.hive.dao.SysShopInfoDao;
import com.matrix.system.hiveErp.analysUtil.*;
import com.matrix.system.hiveErp.dao.TjVipSumDao;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.*;
 
/**
 * 会员数据分析
 * @author jyy
 */
@Controller
@RequestMapping(value = "admin/analysis")
public class DataAnalysisCustomer {
 
    @Autowired
    TjVipSumDao tjVipSumDao;
 
    @Autowired
    SysShopInfoDao shopInfoDao;
 
 
 
    /**
     * 会员人头数统计
     * 业务说明:
     * 人头指门店所有进店客户的总人数,同一个人在一段时间内无论进店几次都视为一次进店
     * 比如:张三1个月来了3次做护理,李四来2次做护理,杨欢来2次做护理,但是只统计客户名字,那人头就是3个
     * @param statisticsParam
     * @return
     */
    @RequestMapping(value = "/customerHeadCompare")
    public @ResponseBody  AjaxResult customerHeadCompare(StatisticsParamVo statisticsParam) {
        return getAnalysisResult(statisticsParam, new Caculate() {
            @Override
            public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId) {
                //从员工业绩统计表中,按时间段,门店的维度统计人头数
                return tjVipSumDao.customerHeadCompare(timeSpaceParam,shopId);
            }
        });
    }
 
    /**
     * 会员人次统计
     * 业务说明:
     * 一个会员在一天进店一次或者多次即为一个人次
     * @param statisticsParam
     * @return
     */
    @RequestMapping(value = "/customerEnterCountCompare")
    public @ResponseBody  AjaxResult customerEnterCountCompare(StatisticsParamVo statisticsParam) {
        return getAnalysisResult(statisticsParam, new Caculate() {
            @Override
            public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId) {
                //从员工业绩统计表中,按时间段,门店的维度统计人次
                return tjVipSumDao.customerEnterCountCompare(timeSpaceParam,shopId);
            }
        });
    }
 
 
    /**
     * 到店率
     * 业务说明:
     * 门店所有客户人次数除以人头数
     * @param statisticsParam
     * @return
     */
    @RequestMapping(value = "/customerEnterRateCompare")
    public @ResponseBody  AjaxResult customerEnterRateCompare(StatisticsParamVo statisticsParam) {
        return getAnalysisResult(statisticsParam, new Caculate() {
            @Override
            public Map<String, Integer> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId) {
                //从员工业绩统计表中,按时间段,门店的维度统计人次
                return tjVipSumDao.customerEnterRateCompare(timeSpaceParam,shopId);
            }
        });
    }
 
 
 
 
 
 
 
    /**
     *  按店铺查询数据通用格式执行方法,支持时、日、月、年维度
     *  如:              A店铺    B店铺
     *     2020-01-01     12     13
     *     2020-02-02     10     11
     * @param statisticsParam 时间条件
     * @param caculate  循环调用caculate计算该店的数据
     *                  查询的数据需满足  只有一个门店只有一行 列名称为 t0,t1,t2
     * @return
     */
    private AjaxResult getAnalysisResult(StatisticsParamVo statisticsParam, Caculate caculate) {
        AjaxResult result = new AjaxResult();
 
        //根据计算横坐标
        List<Date> xAxis = StatisticsTimeUtil.getTimeSpace(statisticsParam.getBeginTime(), statisticsParam.getEndTime(), statisticsParam.getStatisticsUnit());
 
        //获取所有门店
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        List<SysShopInfo> shops=null;
        if(DataAuthUtil.hasAllShopAuth()){
            shops= shopInfoDao.selectShopInfo(user.getCompanyId());
        }else{
            shops=Arrays.asList(shopInfoDao.selectById(user.getShopId()));
        }
        //定义数据项内容
        List<SeriesVo> series=new ArrayList<>();
 
        //定义数据主体
        String[]  legendData=new String[shops.size()];
 
        int i=0;
 
        //按门店统计数据
        List<StatisticsTimeDaoParam> timeSpaceParam = StatisticsTimeUtil.buidParam(xAxis);
        for(SysShopInfo shop: shops){
 
            legendData[i++]=shop.getShopName();
            //数据项内容
            SeriesVo storeInfoSeries=new SeriesVo();
            storeInfoSeries.setName(shop.getShopName());
            //调用计算器获取数据库统计的结果
            Map<String, Integer> yAxisMap = caculate.exec(timeSpaceParam,shop.getId());
            //把统计结果转成数组格式
            storeInfoSeries.setData(StatisticsTimeUtil.getSeries(yAxisMap));
            series.add(storeInfoSeries);
 
        }
        //构造返回对象
        Map<Object,Object> data=new HashMap<>();
        data.put("legendData",legendData);
        data.put("series",series);
        data.put("xAxis", StatisticsTimeUtil.getFormartDateList(xAxis,statisticsParam));
        result.setMapInfo(data);
        result.setStatus(AjaxResult.STATUS_SUCCESS);
        return result;
    }
 
 
 
}