aijinhui
2023-10-12 87a2fe3e6f1472a7e87e02d3fd956eee17b85352
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package com.ruoyi.statistical.controller;
 
import com.ruoyi.statistical.param.ESParam;
import com.ruoyi.statistical.service.StatisticalService;
import com.ruoyi.statistical.vo.NumVo;
import com.ruoyi.statistical.vo.TenVo;
import com.ruoyi.utils.result.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
 
/**
 * @author Administrator
 */
@RestController
@RequestMapping("statistical")
@Api(tags = "数据统计")
public class StatisticalController {
 
    @Resource
    private StatisticalService statisticalService;
 
    /**
     * 厂区介绍存储
     */
    @ApiOperation("厂区介绍存储")
    @PostMapping("factory/save")
    public Results factorySave(@RequestBody Map<String,String> map){
        return statisticalService.factorySave(map);
    }
 
    /**
     * 厂区介绍查询
     */
    @ApiOperation("厂区介绍查询")
    @GetMapping("factory/select")
    public Results factorySelect(){
        return statisticalService.factorySelect();
    }
 
    /**
     * 报警数量分析年
     */
    @ApiOperation("报警数量分析年")
    @GetMapping("alarm/year")
    public Results alarmYear(String type){
        LocalDate today = LocalDate.now();
        int year = today.getYear();
        ESParam esParam = new ESParam();
        esParam.setStart(year+"-01-01");
        esParam.setEnd(year+"-12-31");
        if("1001".equals(type)){
            //盗电报警
            return Results.succeed(statisticalService.stealelecYear(esParam));
        }else if("1002".equals(type)){
            //通用光电
            return Results.succeed(statisticalService.cameraYear(esParam));
        }else if("1003".equals(type)){
            //雷达报警
            return Results.succeed(statisticalService.moveYear(esParam));
        }else if("1004".equals(type)){
            //防火报警
            return Results.succeed(statisticalService.fireYear(esParam));
        }else if("1005".equals(type)){
            //外联报警
            return Results.succeed(statisticalService.externalYear(esParam));
        }else if("1006".equals(type)){
            //门禁报警
            return Results.succeed(statisticalService.accessYear(esParam));
        }else if("1007".equals(type)){
            //移动终端
            return Results.succeed(statisticalService.apponekeyYear(esParam));
        }else if("1008".equals(type)){
            //雷达停机
            return Results.succeed(statisticalService.pumpYear(esParam));
        }else if("1010".equals(type)){
            //电子围栏
            return Results.succeed(statisticalService.wallYear(esParam));
        }else if("1012".equals(type)){
            //预警告警
            return Results.succeed(statisticalService.digitizationYear(esParam));
        }else if("1014".equals(type)){
            //管线泄漏
            return Results.succeed(statisticalService.tubeYear(esParam));
        }
        return Results.succeed();
    }
 
    /**
     * 报警数量分析月
     */
    @ApiOperation("报警数量分析月")
    @GetMapping("alarm/month")
    public Results alarmMonth(Integer month,String type){
        LocalDate today = LocalDate.now();
        int year = today.getYear();
        int day =  getDaysInMonth(month);
        ESParam esParam = new ESParam();
        esParam.setStart(year+"-"+month+"-01");
        esParam.setEnd(year+"-"+month+"-"+day);
        esParam.setMonth(month);
        if("1001".equals(type)){
            //盗电报警
            return Results.succeed(statisticalService.stealelecMonth(esParam));
        }else if("1002".equals(type)){
            //通用光电
            return Results.succeed(statisticalService.cameraMonth(esParam));
        }else if("1003".equals(type)){
            //雷达报警
            return Results.succeed(statisticalService.moveMonth(esParam));
        }else if("1004".equals(type)){
            //防火报警
            return Results.succeed(statisticalService.fireMonth(esParam));
        }else if("1005".equals(type)){
            //外联报警
            return Results.succeed(statisticalService.externalMonth(esParam));
        }else if("1006".equals(type)){
            //门禁报警
            return Results.succeed(statisticalService.accessMonth(esParam));
        }else if("1007".equals(type)){
            //移动终端
            return Results.succeed(statisticalService.apponekeyMonth(esParam));
        }else if("1008".equals(type)){
            //雷达停机
            return Results.succeed(statisticalService.pumpMonth(esParam));
        }else if("1010".equals(type)){
            //电子围栏
            return Results.succeed(statisticalService.wallMonth(esParam));
        }else if("1012".equals(type)){
            //预警告警
            return Results.succeed(statisticalService.digitizationMonth(esParam));
        }else if("1014".equals(type)){
            //管线泄漏
            return Results.succeed(statisticalService.tubeMonth(esParam));
        }
        return Results.succeed();
    }
 
    //返回每月天数
    public int getDaysInMonth(int month) {
        Calendar calendar = Calendar.getInstance();
        switch (month) {
            case 1: case 3: case 5: case 7: case 8: case 10: case 12:
                return 31;
            case 4: case 6: case 9: case 11:
                return 30;
            case 2:
                if (calendar.get(Calendar.YEAR) % 4 == 0 && (calendar.get(Calendar.YEAR) % 100 != 0 || calendar.get(Calendar.YEAR) % 400 == 0)) {
                    return 29;
                } else {
                    return 28;
                }
            default:
                throw new IllegalArgumentException("Invalid Month");
        }
    }
 
    /**
     * 在线设备数
     */
    @ApiOperation("在线设备数")
    @GetMapping("unit")
    public Results unit(){
        return Results.succeed(statisticalService.unit());
    }
 
    /**
     * 报警数量
     */
    @ApiOperation("报警数量")
    @GetMapping("alarm/num")
    public Results num(){
        List<TenVo> tenVo = new ArrayList<>();
        TenVo stealelec = new TenVo();
        stealelec.setName("盗电报警");
        stealelec.setValue(statisticalService.stealelecNum());
        tenVo.add(stealelec);
        TenVo camera = new TenVo();
        camera.setName("通用光电");
        camera.setValue(statisticalService.cameraNum());
        tenVo.add(camera);
        TenVo move = new TenVo();
        move.setName("雷达移动");
        move.setValue(statisticalService.moveNum());
        tenVo.add(move);
        TenVo fire = new TenVo();
        fire.setName("雷达防火");
        fire.setValue(statisticalService.fireNum());
        tenVo.add(fire);
        TenVo external = new TenVo();
        external.setName("外联报警");
        external.setValue(statisticalService.externalNum());
        tenVo.add(external);
        TenVo access = new TenVo();
        access.setName("门禁报警");
        access.setValue(statisticalService.accessNum());
        tenVo.add(access);
        TenVo apponekey = new TenVo();
        apponekey.setName("移动终端");
        apponekey.setValue(statisticalService.apponekeyNum());
        tenVo.add(apponekey);
        TenVo pump = new TenVo();
        pump.setName("雷达停机");
        pump.setValue(statisticalService.pumpNum());
        tenVo.add(pump);
        TenVo wall = new TenVo();
        wall.setName("电子围栏");
        wall.setValue(statisticalService.wallNum());
        tenVo.add(wall);
        TenVo digitization = new TenVo();
        digitization.setName("预警报警");
        digitization.setValue(statisticalService.digitizationNum());
        tenVo.add(digitization);
        TenVo tube = new TenVo();
        tube.setName("管线泄露");
        tube.setValue(statisticalService.tubeNum());
        tenVo.add(tube);
        return Results.succeed(tenVo);
    }
 
    /**
     * 24小时报警兴趣点前十
     */
    @ApiOperation("24小时报警兴趣点前十")
    @GetMapping("alarm/ten")
    public Results ten(){
        return Results.succeed(statisticalService.ten());
    }
 
    /**
     * 抽油机运行状态
     */
    @ApiOperation("抽油机运行状态")
    @GetMapping("alarm/pump")
    public Results pump(){
        return Results.succeed(statisticalService.pump());
    }
 
    /**
     * 数据处理
     */
    @ApiOperation("数据处理")
    @GetMapping("data")
    public void data(String msg){
        statisticalService.data(msg);
    }
 
}