Helius
2021-01-11 854d9d55a86b7076abc4f526e90001bd806d324c
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.matrix.system.app.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.app.dto.BusinessesDto;
import com.matrix.system.app.dto.VipStatisticsParamDto;
import com.matrix.system.app.vo.BeauticianVo;
import com.matrix.system.app.vo.BusinessesDataShowVo;
import com.matrix.system.app.vo.VipAchieveDataShowVo;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.AchieveNew;
import com.matrix.system.hive.bean.SysBusinessData;
import com.matrix.system.hive.dao.SysBusinessDataDao;
import com.matrix.system.hive.service.imp.DataAnalysisCustomerServiceImpl;
import com.matrix.system.hiveErp.analysUtil.Caculate;
import com.matrix.system.hiveErp.analysUtil.SeriesVo;
import com.matrix.system.hiveErp.analysUtil.StatisticsParamVo;
import com.matrix.system.hiveErp.analysUtil.StatisticsTimeDaoParam;
import com.matrix.system.hiveErp.dao.TjVipSumDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2020-12-28
 **/
@Api(value = "ApiStatisticsAction", tags = "报表接口类")
@RestController
@RequestMapping(value = "/api/statistics")
public class ApiStatisticsAction {
 
    @Autowired
    TjVipSumDao tjVipSumDao;
 
    @Autowired
    private SysBusinessDataDao sysBusinessDataDao;
 
    @Autowired
    private DataAnalysisCustomerServiceImpl dataAnalysisCustomerService;
 
    @ApiOperation(value = "公司经营报表/门店经营报表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = BusinessesDataShowVo.class)
    })
    @PostMapping(value = "/findShopBusinessesData")
    public AjaxResult findShopBusinessesData(@RequestBody BusinessesDto businessesDto) {
        SysBusinessData sysBusinessData = new SysBusinessData();
        // 若shopId为空,则查询门店经营报表
        if (businessesDto.getShopId() == null) {
            sysBusinessData.setShopId(businessesDto.getShopId());
        }
        QueryUtil.setQueryLimitCom(sysBusinessData);
 
        if (BusinessesDto.DAY.equals(businessesDto.getType())) {
            sysBusinessData.setT1("%Y-%m-%d");
        } else {
            sysBusinessData.setT1("%Y-%m");
        }
        PaginationVO pageVo = new PaginationVO();
        pageVo.setOffset((businessesDto.getPageNum() - 1) * businessesDto.getPageSize());
        pageVo.setLimit(businessesDto.getPageSize());
 
        return AjaxResult.buildSuccessInstance(sysBusinessDataDao.selectApiBusinessDataInPage(sysBusinessData, pageVo), sysBusinessDataDao.selectApiBusinessDataTotal(sysBusinessData));
    }
 
    @ApiOperation(value = "专项", notes = "专项")
    @PostMapping(value = "/findBusinessInCome")
    public AjaxResult findBusinessInCome(@RequestBody @Validated StatisticsParamVo statisticsParam) {
        if (statisticsParam.getShopId() != null) {
            AjaxResult ajaxResult = dataAnalysisCustomerService.getAnalysisResult(statisticsParam, new Caculate<BigDecimal>() {
                @Override
                public Map<String, BigDecimal> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId, Long companyId) {
                    switch (statisticsParam.getType()) {
                        case "1" :
                            return tjVipSumDao.selectBusinessInCome(timeSpaceParam, shopId, null);
                        case "2" :
                            return tjVipSumDao.selectCashIncome(timeSpaceParam, shopId, null);
                        case "3" :
                            return tjVipSumDao.selectCardUse(timeSpaceParam, shopId, null);
                        case "4" :
                            return tjVipSumDao.selectHisConsume(timeSpaceParam, shopId, null);
                        case "5" :
                            return tjVipSumDao.selectFreeConsume(timeSpaceParam, shopId, null);
                        case "6" :
                            return tjVipSumDao.selectCashRefund(timeSpaceParam, shopId, null);
                        case "7" :
                            return tjVipSumDao.selectCardRefund(timeSpaceParam, shopId, null);
                        case "8" :
                            return tjVipSumDao.selectArrears(timeSpaceParam, shopId, null);
                        default :
                            return tjVipSumDao.selectBusinessInCome(timeSpaceParam, shopId, null);
                    }
                }
            });
            return setDataList(ajaxResult);
        } else {
            AjaxResult ajaxResult = dataAnalysisCustomerService.getCompanyAnalysisResult(statisticsParam, new Caculate<BigDecimal>() {
                @Override
                public Map<String, BigDecimal> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId, Long companyId) {
                    switch (statisticsParam.getType()) {
                        case "1" :
                            return tjVipSumDao.selectBusinessInCome(timeSpaceParam, null, companyId);
                        case "2" :
                            return tjVipSumDao.selectCashIncome(timeSpaceParam, null, companyId);
                        case "3" :
                            return tjVipSumDao.selectCardUse(timeSpaceParam, null, companyId);
                        case "4" :
                            return tjVipSumDao.selectHisConsume(timeSpaceParam, null, companyId);
                        case "5" :
                            return tjVipSumDao.selectFreeConsume(timeSpaceParam, null, companyId);
                        case "6" :
                            return tjVipSumDao.selectCashRefund(timeSpaceParam, null, companyId);
                        case "7" :
                            return tjVipSumDao.selectCardRefund(timeSpaceParam, null, companyId);
                        case "8" :
                            return tjVipSumDao.selectArrears(timeSpaceParam, null, companyId);
                        default :
                            return tjVipSumDao.selectBusinessInCome(timeSpaceParam, null, companyId);
                    }
                }
            });
            return setDataList(ajaxResult);
        }
    }
 
    private AjaxResult setDataList(AjaxResult ajaxResult) {
        List<SeriesVo> list = (List<SeriesVo>) ajaxResult.getMapInfo().get("series");
        String[] xAxis = (String[]) ajaxResult.getMapInfo().get("xAxis");
        String [] data = list.get(0).getData();
        if (data != null && data.length != 0) {
            List<Map<String, String>> dataList = new ArrayList<>();
            for(int i = data.length - 1; i >= 0; i--) {
                Map<String, String> map = new HashMap<>();
                map.put(xAxis[i], data[i]);
                dataList.add(map);
            }
            ajaxResult.setRows(dataList);
        }
 
        return ajaxResult;
    }
 
 
    @ApiOperation(value = "查询员工业绩报表", notes = "查询员工业绩报表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = VipAchieveDataShowVo.class)
    })
    @PostMapping(value = "/findVipAchieve")
    public AjaxResult findVipAchieve(@RequestBody BusinessesDto businessesDto) {
        AchieveNew achieveNew = new AchieveNew();
        if (BusinessesDto.DAY.equals(businessesDto.getType())) {
            achieveNew.setT1("%Y-%m-%d");
        } else {
            achieveNew.setT1("%Y-%m");
        }
 
        SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        if (businessesDto.getStaffId() == null) {
 
            businessesDto.setStaffId(sysUsers.getSuId());
        }
        achieveNew.setVipId(businessesDto.getStaffId());
 
        PaginationVO pageVo = new PaginationVO();
        pageVo.setLimit(businessesDto.getPageSize());
        pageVo.setOffset((businessesDto.getPageNum() - 1) * businessesDto.getPageSize());
        return AjaxResult.buildSuccessInstance(tjVipSumDao.selectVipAchieveInPage(achieveNew, pageVo));
    }
 
    @ApiOperation(value = "员工专项", notes = "员工专项")
    @PostMapping(value = "/findVipBusinessData")
    public AjaxResult findVipBusinessData(@RequestBody @Validated VipStatisticsParamDto vipStatisticsParamDto) {
        AjaxResult ajaxResult = dataAnalysisCustomerService.getStaffAnalysisResult(vipStatisticsParamDto, new Caculate<BigDecimal>() {
            @Override
            public Map<String, BigDecimal> exec(List<StatisticsTimeDaoParam> timeSpaceParam, Long shopId, Long staffId) {
                switch (vipStatisticsParamDto.getType()) {
                    case "1" :
                        return tjVipSumDao.selectStaffOrderAchieve(timeSpaceParam, staffId);
                    case "2" :
                        return tjVipSumDao.selectStaffCashAchieve(timeSpaceParam, staffId);
                    case "3" :
                        return tjVipSumDao.selectStaffCardAchieve(timeSpaceParam, staffId);
                    case "4" :
                        return tjVipSumDao.selectStaffGoodsAchieve(timeSpaceParam, staffId);
                    case "5" :
                        return tjVipSumDao.selectStaffCardUseAchieve(timeSpaceParam, staffId);
                    case "6" :
                        return tjVipSumDao.selectStaffHisConsumeAchieve(timeSpaceParam, staffId);
                    case "7" :
                        return tjVipSumDao.selectStaffFreeConsumeAchieve(timeSpaceParam, staffId);
                    case "8" :
                        return tjVipSumDao.selectStaffCommissionAchieve(timeSpaceParam, staffId);
                    case "9" :
                        return tjVipSumDao.selectStaffPeopleNum(timeSpaceParam, staffId);
                    case "10" :
                        return tjVipSumDao.selectStaffProjNum(timeSpaceParam, staffId);
                    case "11" :
                        return tjVipSumDao.selectStaffProjTime(timeSpaceParam, staffId);
                    default:
                        return tjVipSumDao.selectStaffOrderAchieve(timeSpaceParam, staffId);
                }
            }
        });
 
        return setDataList(ajaxResult);
    }
 
}