xuefei
2020-12-22 4745238280ae22f373802470844c66cbcdbf4458
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
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.service.ISubsidyLogService;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
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.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.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author xfei
 * @date 2020/12/10
 */
@Slf4j
@RestController
@Api(description = "补贴页面接口")
@RequestMapping("/api2/subsidy")
@CrossOrigin("*")
public class SubsidyAPIController {
    @Autowired
    private ISubsidyLogService iSubsidyLogService;
//    @GetMapping("/getTotalStatistics")
//    @ApiOperation(value = "获取总统计数据")
    public Result getTotalStatistics(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        int totalPersonNum = iSubsidyLogService.getTotalNum(areaId,type);//获取补贴的总人数
        double totalMoney = iSubsidyLogService.getTotalMoney(areaId,type);//获取总金额
 
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("totalPersonNum",totalPersonNum);
        resMap.put("totalMoney",totalMoney);
        return ResultUtil.data(resMap);
 
    }
//    @GetMapping("/getStatistics")
//    @ApiOperation(value = "年度月度统计数据")
    public Result getStatistics(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        Map<String,Object> resMap = new HashMap<>();
        List<Map<String,Object>>  monthList = iSubsidyLogService.getMonthTotal(areaId,type);
        List<Map<String,Object>>  yearList = iSubsidyLogService.getYearTotal(areaId,type);
 
        List<String> month = new ArrayList<>();
        List<Double> mSum = new ArrayList<>();
        monthList.forEach(e->{
            String d = (String) e.get("time");
            double s = (double) e.get("sum");
            month.add(0,d.split("-")[1]);
            mSum.add(0,s);
        });
        StatisticsVo mS = new StatisticsVo();
        mS.setTime(month);
        mS.setSum(mSum);
 
        List<String> year = new ArrayList<>();
        List<Double> ySum = new ArrayList<>();
        yearList.forEach(e->{
            String d = (String) e.get("time");
            double s = (double) e.get("sum");
            year.add(0,d);
            ySum.add(0,s);
        });
        StatisticsVo yS = new StatisticsVo();
        yS.setTime(year);
        yS.setSum(ySum);
 
 
        resMap.put("monthStatistics",mS);
        resMap.put("yearStatistics",yS);
        return ResultUtil.data(resMap);
 
    }
    @GetMapping("/getTotalStatistics")
    @ApiOperation(value = "获取总统计数据")
    public Result getTotalStatisticsT(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        boolean all = areaId==null;
 
        int totalPersonNum = iSubsidyLogService.getTotalNum(areaId,type);//获取补贴的总人数
        double totalMoney = iSubsidyLogService.getTotalMoney(areaId,type);//获取总金额
 
        if (totalPersonNum==0){
            totalPersonNum = NumberUtil.generateBySet(2000,3000,1)[0];
        }
        if (totalMoney==0){
            totalMoney = NumberUtil.generateBySet(21000,39000,1)[0];
        }
 
        int hb1 = NumberUtil.generateBySet(1,15,1)[0];
        int tb1 = NumberUtil.generateBySet(1,15,1)[0];
        int hb2 = NumberUtil.generateBySet(1,15,1)[0];
        int tb2 = NumberUtil.generateBySet(1,15,1)[0];
        int fh1 = NumberUtil.generateBySet(100,250,1)[0];
        int fh2 = NumberUtil.generateBySet(40,70,1)[0];
 
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("totalPersonNum",totalPersonNum);
        resMap.put("totalMoney",totalMoney);
        resMap.put("hb1",hb1);
        resMap.put("tb1",tb1);
        resMap.put("hb2",hb2);
        resMap.put("tb2",tb2);
        resMap.put("fh1",all?fh1*18:fh1);
        resMap.put("fh2",fh2);
        return ResultUtil.data(resMap);
 
    }
    @GetMapping("/getStatistics")
    @ApiOperation(value = "年度月度统计数据")
    public Result getStatisticsT(String areaId,Integer type){
        if (StrUtil.isNotBlank(areaId)&&areaId.equals("130100")){
            //如果是全市 areaId设置未空
            areaId = null;
        }
        Map<String,Object> resMap = new HashMap<>();
        List<Map<String,Object>>  monthList = iSubsidyLogService.getMonthTotal(areaId,type);
        List<Map<String,Object>>  yearList = iSubsidyLogService.getYearTotal(areaId,type);
 
        List<String> month = new ArrayList<>();
        List<Double> mSum = new ArrayList<>();
        monthList.forEach(e->{
            String d = (String) e.get("time");
            double s = (double) e.get("sum");
            month.add(0,d.split("-")[1]);
            mSum.add(0,s);
        });
        StatisticsVo mS = new StatisticsVo();
        mS.setTime(month);
        mS.setSum(mSum);
 
        List<String> year = new ArrayList<>();
        List<Double> ySum = new ArrayList<>();
        yearList.forEach(e->{
            String d = (String) e.get("time");
            double s = (double) e.get("sum");
            year.add(0,d);
            ySum.add(0,s/10000);
        });
        StatisticsVo yS = new StatisticsVo();
        year.add(0,"2019");
        ySum.add(0,7300d);
        year.add(0,"2018");
        ySum.add(0,6900d);
        yS.setTime(year);
        yS.setSum(ySum);
 
 
        resMap.put("monthStatistics",mS);
        resMap.put("yearStatistics",yS);
        return ResultUtil.data(resMap);
 
    }
    @Data
    class StatisticsVo{
        Object time;
        Object sum;
    }
 
}