xuefei
2020-12-13 59380c11771d47459b8db5425bc21293823ada74
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
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.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);
 
    }
    @Data
    class StatisticsVo{
        Object time;
        Object sum;
    }
 
}