aijinhui
2023-10-07 8c8af4faa4303499fe9e81dd117932e246008eb0
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
package com.ruoyi.statistical.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.alarm.access.mapper.ArdAlarmAccessMapper;
import com.ruoyi.alarm.apponekey.mapper.ArdAlarmApponekeyMapper;
import com.ruoyi.alarm.camera.mapper.ArdAlarmCameraMapper;
import com.ruoyi.alarm.digitization3.mapper.ArdAlarmDigitization3Mapper;
import com.ruoyi.alarm.external.mapper.ArdAlarmExternalMapper;
import com.ruoyi.alarm.radar.mapper.ArdAlarmRadarFireMapper;
import com.ruoyi.alarm.radar.mapper.ArdAlarmRadarMoveMapper;
import com.ruoyi.alarm.steal.mapper.ArdAlarmStealelecMapper;
import com.ruoyi.alarm.tube.mapper.ArdAlarmTubeMapper;
import com.ruoyi.alarm.wall.mapper.ArdAlarmWallMapper;
import com.ruoyi.alarmpoints.well.domain.ArdAlarmpointsWell;
import com.ruoyi.alarmpoints.well.mapper.ArdAlarmpointsWellMapper;
import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.statistical.param.ESParam;
import com.ruoyi.statistical.service.StatisticalService;
import com.ruoyi.statistical.vo.CountVo;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.utils.result.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
 
/**
 * @author Administrator
 */
@Service
public class StatisticalServiceImpl implements StatisticalService {
 
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private ArdAlarmpointsWellMapper wellMapper;
    @Autowired
    private ArdAlarmStealelecMapper stealelecMapper;
    @Autowired
    private ArdAlarmCameraMapper cameraMapper;
    @Autowired
    private ArdAlarmRadarMoveMapper moveMapper;
    @Autowired
    private ArdAlarmRadarFireMapper fireMapper;
    @Autowired
    private ArdAlarmExternalMapper externalMapper;
    @Autowired
    private ArdAlarmAccessMapper accessMapper;
    @Autowired
    private ArdAlarmApponekeyMapper apponekeyMapper;
    @Autowired
    private ArdAlarmWallMapper wallMapper;
    @Autowired
    private ArdAlarmDigitization3Mapper digitization3Mapper;
    @Autowired
    private ArdAlarmTubeMapper tubeMapper;
 
 
    @Override
    public Results factorySave(Map<String, String> map) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            //如果存在修改
            SysConfig sysConfigUpd = sysConfigMapper.checkConfigKeyUnique(entry.getKey());
            if(sysConfigUpd != null){
                sysConfigUpd.setConfigValue(entry.getValue());
                sysConfigUpd.setUpdateBy(SecurityUtils.getUsername());
                sysConfigMapper.updateConfig(sysConfigUpd);
            }else {
                //否则新增
                SysConfig sysConfig = new SysConfig();
                int randomNum = (int) (Math.random() * (1000 - 100 + 1)) + 100;
                sysConfig.setConfigId((long) randomNum);
                sysConfig.setConfigType("Y");
                sysConfig.setCreateBy(SecurityUtils.getUsername());
                sysConfig.setRemark("厂区介绍");
                if ("area".equals(entry.getKey())) {
                    sysConfig.setConfigName("占地面积");
                    sysConfig.setConfigKey(entry.getKey());
                    sysConfig.setConfigValue(entry.getValue());
                    sysConfigMapper.insertConfig(sysConfig);
                } else if ("store".equals(entry.getKey())) {
                    sysConfig.setConfigName("原始地质储量");
                    sysConfig.setConfigKey(entry.getKey());
                    sysConfig.setConfigValue(entry.getValue());
                    sysConfigMapper.insertConfig(sysConfig);
                }else if ("people".equals(entry.getKey())) {
                    sysConfig.setConfigName("员工");
                    sysConfig.setConfigKey(entry.getKey());
                    sysConfig.setConfigValue(entry.getValue());
                    sysConfigMapper.insertConfig(sysConfig);
                }else if ("depot".equals(entry.getKey())) {
                    sysConfig.setConfigName("各类站库");
                    sysConfig.setConfigKey(entry.getKey());
                    sysConfig.setConfigValue(entry.getValue());
                    sysConfigMapper.insertConfig(sysConfig);
                }else if ("unit".equals(entry.getKey())) {
                    sysConfig.setConfigName("下设单位");
                    sysConfig.setConfigKey(entry.getKey());
                    sysConfig.setConfigValue(entry.getValue());
                    sysConfigMapper.insertConfig(sysConfig);
                }
            }
        }
        return Results.succeed("添加成功!");
    }
 
    @Override
    public Results factorySelect() {
        JSONObject jsonObject = new JSONObject();
        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("config_key","area","store","people","well","depot","unit");
        List<SysConfig> list = sysConfigMapper.selectList(queryWrapper);
        for (int i = 0; i < list.size(); i++) {
            SysConfig sysConfig = list.get(i);
            jsonObject.put(sysConfig.getConfigKey(),sysConfig.getConfigValue());
        }
        //记录well表中oil_production为抽油机的数据有多少条
        QueryWrapper<ArdAlarmpointsWell> queryWrapperWell = new QueryWrapper<>();
        queryWrapperWell.eq("oil_production","抽油机");
        int num = wellMapper.selectCount(queryWrapperWell);
        jsonObject.put("well",String.valueOf(num));
        return Results.succeed(jsonObject);
    }
 
    @Override
    public List<CountVo> stealelecYear(ESParam esParam) {
        List<CountVo> list = stealelecMapper.stealelecYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> cameraYear(ESParam esParam) {
        List<CountVo> list = cameraMapper.cameraYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> moveYear(ESParam esParam) {
        List<CountVo> list = moveMapper.moveYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> fireYear(ESParam esParam) {
        List<CountVo> list = fireMapper.fileYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> externalYear(ESParam esParam) {
        List<CountVo> list = externalMapper.externalYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> accessYear(ESParam esParam) {
        List<CountVo> list = accessMapper.accessYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> apponekeyYear(ESParam esParam) {
        List<CountVo> list = apponekeyMapper.apponekeyYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> wallYear(ESParam esParam) {
        List<CountVo> list = wallMapper.wallYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> digitizationYear(ESParam esParam) {
        List<CountVo> list = digitization3Mapper.digitizationYear(esParam);
        return es(list);
    }
 
    @Override
    public List<CountVo> tubeYear(ESParam esParam) {
        List<CountVo> list = tubeMapper.tubeYear(esParam);
        return es(list);
    }
 
    public List<CountVo> es(List<CountVo> list){
        for (int i = 1; i <= 12 ; i++) {
            String month = null;
            if(i<=10){
                month = "0"+i;
            }else {
                month = String.valueOf(i);
            }
            Boolean bo = false;
            for (int j = 0; j < list.size(); j++) {
                CountVo countVo = list.get(j);
                String mon = countVo.getMonth();
                if(mon.equals(month)){
                    bo = true;
                }
            }
            if(!bo){
                CountVo countVo = new CountVo();
                countVo.setMonth(month);
                countVo.setCount(0);
                list.add(countVo);
            }
        }
        return list;
    }
}