1697371125@qq.com
2020-12-25 c085e6fa1cb24f0173b500488ecd192dd2ae624f
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
package cn.cetc54.platform.zhyl.api;
 
import cn.cetc54.platform.core.common.utils.ResultUtil;
import cn.cetc54.platform.core.common.vo.Result;
import cn.cetc54.platform.zhyl.entity.SubsidyPersonStatics;
import cn.cetc54.platform.zhyl.service.ISubsidyPersonStaticsService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @author xfei
 * @date 2020/12/12
 */
@Slf4j
@RestController
@Api(description = "服务对象")
@RequestMapping("/api2/fwdx")
@Transactional
@CrossOrigin("*")
public class FwdxController {
    @Autowired
    private ISubsidyPersonStaticsService iSubsidyPersonStaticsService;
    private int b = 18;//倍数
//    @GetMapping("getStaticsData")
//    @ApiOperation(value = "获取统计数据")
    public Result getStaticsData(String areaId,Integer type){
        if (StrUtil.isEmpty(areaId)){
            return ResultUtil.error("缺少参数");
        }
        String month = DateUtil.format(new Date(),"yyyy-MM");
        QueryWrapper<SubsidyPersonStatics> query = new QueryWrapper<>();
        query.lambda().eq(SubsidyPersonStatics::getAreaId,areaId);
        query.lambda().eq(SubsidyPersonStatics::getMonth,month);
        if (type!=null){
            query.lambda().eq(SubsidyPersonStatics::getSubsidyType,type);
        }
        List<SubsidyPersonStatics> list = iSubsidyPersonStaticsService.list(query);
        SubsidyPersonStatics statics = new SubsidyPersonStatics();
        statics.setChild(list);
        list.forEach(e->{
            statics.setMonth(e.getMonth());
            statics.setYearAdd(statics.getYearAdd()+e.getYearAdd());
            statics.setYearOut(statics.getYearOut()+e.getYearOut());
            statics.setYearSum(statics.getYearSum()+e.getYearSum());
            statics.setMonthAdd(statics.getMonthAdd()+e.getMonthAdd());
            statics.setMonthOut(statics.getMonthOut()+e.getMonthOut());
            statics.setMonthSum(statics.getMonthSum()+e.getMonthSum());
            statics.setTotalNum(statics.getTotalNum()+e.getTotalNum());
            statics.setCheckNum(statics.getCheckNum()+e.getCheckNum());
            statics.setPersonNum(statics.getPersonNum()+e.getPersonNum());
        });
        return ResultUtil.data(statics);
    }
//    @GetMapping("getHistoryStaticsData")
//    @ApiOperation(value = "获取历史统计数据")
    public Result getHistoryStaticsData(String areaId,Integer type){
        if (StrUtil.isEmpty(areaId)){
            return ResultUtil.error("缺少参数");
        }
        List<Map<String,Object>> result = iSubsidyPersonStaticsService.getMonthAddOut(areaId,type);
        StatisVO vo = new StatisVO();
        result.forEach(e->{
            String month = (String) e.get("month");
            int mAdd = Integer.parseInt(String.valueOf(e.get("mAdd")));
            int mOut = Integer.parseInt(String.valueOf(e.get("mOut")));
            int checkNum = Integer.parseInt(String.valueOf(e.get("checkNum")));
            int totalNum = Integer.parseInt(String.valueOf(e.get("totalNum")));
            vo.month.add(0,month.split("-")[1]);
            vo.mAdd.add(0,mAdd);
            vo.mOut.add(0,mOut);
            vo.checkNum.add(0,checkNum);
            vo.totalNum.add(0,totalNum);
        });
        return ResultUtil.data(vo);
 
    }
 
    @GetMapping("getStaticsData")
    @ApiOperation(value = "获取统计数据")
    public Result getStaticsDataT(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        boolean all = areaId==null;
 
        List<SubsidyPersonStatics> list = new ArrayList<>();
        for (int i=0;i<(type==null?12:1);i++){
            SubsidyPersonStatics s = new SubsidyPersonStatics();
            int mAdd = NumberUtil.generateBySet(50,100,1)[0];
            int mOut = NumberUtil.generateBySet(1,50,1)[0];
            int mSum = NumberUtil.generateBySet(150,280,1)[0];
            int yAdd = NumberUtil.generateBySet(500,1600,1)[0];
            int yOut = NumberUtil.generateBySet(50,650,1)[0];
            int ySum = NumberUtil.generateBySet(1500,2800,1)[0];
            int totalNum = NumberUtil.generateBySet(200,300,1)[0];
            int checkNum = NumberUtil.generateBySet(100,200,1)[0];
            int personNum = NumberUtil.generateBySet(16000,23000,1)[0];
            s.setMonthAdd(all?mAdd*b:mAdd);
            s.setMonthOut(all?mOut*b:mOut);
            s.setMonthSum(all?mSum*b:mSum);
            s.setYearSum(all?ySum*b:ySum);
            s.setYearAdd(all?yAdd*b:yAdd);
            s.setYearOut(all?yOut*b:yOut);
            s.setTotalNum(all?totalNum*b:totalNum);
            s.setCheckNum(all?checkNum*b:checkNum);
            s.setPersonNum(all?personNum*b:personNum);
            s.setSubsidyType(type==null?i:type);
            list.add(s);
        }
 
 
 
 
 
 
        SubsidyPersonStatics statics = new SubsidyPersonStatics();
        statics.setChild(list);
        list.forEach(e->{
            statics.setMonth(e.getMonth());
            statics.setYearAdd(statics.getYearAdd()+e.getYearAdd());
            statics.setYearOut(statics.getYearOut()+e.getYearOut());
            statics.setYearSum(statics.getYearSum()+e.getYearSum());
            statics.setMonthAdd(statics.getMonthAdd()+e.getMonthAdd());
            statics.setMonthOut(statics.getMonthOut()+e.getMonthOut());
            statics.setMonthSum(statics.getMonthSum()+e.getMonthSum());
            statics.setTotalNum(statics.getTotalNum()+e.getTotalNum());
            statics.setCheckNum(statics.getCheckNum()+e.getCheckNum());
            statics.setPersonNum(statics.getPersonNum()+e.getPersonNum());
        });
        return ResultUtil.data(statics);
    }
    @GetMapping("getHistoryStaticsData")
    @ApiOperation(value = "获取历史统计数据")
    public Result getHistoryStaticsDataT(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        boolean all = areaId==null;
 
        StatisVO vo = new StatisVO();
        for (int i=1;i<13;i++){
            int mAdd = NumberUtil.generateBySet(50,100,1)[0];
            int mOut = NumberUtil.generateBySet(1,50,1)[0];
            int checkNum = NumberUtil.generateBySet(100,200,1)[0];
            int totalNum = NumberUtil.generateBySet(200,300,1)[0];
            vo.month.add(i);
            vo.mAdd.add(all?mAdd*b:mAdd);
            vo.mOut.add(all?mOut*b:mOut);
            vo.checkNum.add(all?checkNum*b:checkNum);
            vo.totalNum.add(all?totalNum*b:totalNum);
        }
        return ResultUtil.data(vo);
    }
 
 
 
    @Data
    class StatisVO{
        //月份
        List month = new ArrayList();
        //月新增
        List mAdd = new ArrayList();
        //月退出
        List mOut = new ArrayList();
        //月复核数
        List checkNum = new ArrayList();
        //月复核数
        List totalNum = new ArrayList();
 
    }
 
}