Browse Source

事前标记

zjs 2 weeks ago
parent
commit
0a67c14d62

+ 55 - 0
src/main/java/com/cn/esermis/config/JwtInterceptor.java

@@ -0,0 +1,55 @@
1
+package com.cn.esermis.config;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.cn.esermis.dpld.mapper.DataAcquisitionInstrumentMapper;
5
+import com.cn.esermis.model.BaseUser;
6
+import com.cn.esermis.utils.TokenUtils;
7
+import org.springframework.stereotype.Component;
8
+import org.springframework.web.servlet.HandlerInterceptor;
9
+
10
+import javax.annotation.Resource;
11
+import javax.servlet.http.HttpServletRequest;
12
+import javax.servlet.http.HttpServletResponse;
13
+
14
+@Component
15
+public class JwtInterceptor implements HandlerInterceptor {
16
+
17
+    private static final String AUTH_HEADER = "Authorization";
18
+    private static final String TOKEN_PREFIX = "Bearer ";
19
+
20
+    @Resource
21
+    DataAcquisitionInstrumentMapper dataAcquisitionInstrumentMapper;
22
+
23
+    @Override
24
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
25
+        String token = extractToken(request);
26
+        if (token != null) {
27
+            BaseUser userInfo = TokenUtils.getUserInfo(token);
28
+            if (userInfo != null){
29
+                // 查询数据库是否有 公司和工厂信息
30
+                Boolean verifyCompany = dataAcquisitionInstrumentMapper.verifyCompany(userInfo.getCompanyId());
31
+                Boolean verifydepartmen = dataAcquisitionInstrumentMapper.verifydepartmen(userInfo.getFactoryId());
32
+                if (verifyCompany&&verifydepartmen){
33
+                    // 将用户信息设置到请求属性中,便于后续使用
34
+                    request.setAttribute("userInfo", JSON.toJSONString(userInfo));
35
+                    return true;
36
+                }else {
37
+                    throw new RuntimeException("用户无权限!");
38
+                }
39
+            }else{
40
+                throw new RuntimeException("token解析失败!");
41
+            }
42
+        }else {
43
+            throw new RuntimeException("token为空!");
44
+        }
45
+
46
+    }
47
+
48
+    private String extractToken(HttpServletRequest request) {
49
+        String bearerToken = request.getHeader(AUTH_HEADER);
50
+        if (bearerToken != null && bearerToken.startsWith(TOKEN_PREFIX)) {
51
+            return bearerToken.substring(TOKEN_PREFIX.length());
52
+        }
53
+        return null;
54
+    }
55
+}

+ 18 - 0
src/main/java/com/cn/esermis/config/WebConfig.java

@@ -0,0 +1,18 @@
1
+package com.cn.esermis.config;
2
+import org.springframework.beans.factory.annotation.Autowired;
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
5
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
+
7
+@Configuration
8
+public class WebConfig implements WebMvcConfigurer {
9
+
10
+    @Autowired
11
+    private JwtInterceptor jwtInterceptor;
12
+
13
+    @Override
14
+    public void addInterceptors(InterceptorRegistry registry) {
15
+        registry.addInterceptor(jwtInterceptor)
16
+                .addPathPatterns("/**"); // 拦截所有路径
17
+    }
18
+}

+ 1 - 1
src/main/java/com/cn/esermis/constant/Constant.java

@@ -17,6 +17,6 @@ public class Constant {
17 17
         public static final  String CN = "CN"; //大气环境污染源
18 18
         public static final  String SERVER = "server"; //大气环境污染源
19 19
 
20
-        public static final List<String> COMMAND = new ArrayList<>(Arrays.asList(HOUR, MINUTE, REAL)); // 解析数据编码
20
+        public static final List<String> COMMAND = new ArrayList<>(Arrays.asList(HOUR, MINUTE)); // 解析数据编码
21 21
 
22 22
 }

+ 16 - 2
src/main/java/com/cn/esermis/controller/DataAcquisitionInstrumentController.java

@@ -1,5 +1,6 @@
1 1
 package com.cn.esermis.controller;
2 2
 
3
+import com.alibaba.fastjson2.JSON;
3 4
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 5
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 6
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -10,10 +11,13 @@ import com.cn.esermis.dpld.entity.DetectMonitoringFactor;
10 11
 import com.cn.esermis.dpld.model.AjaxResult;
11 12
 import com.cn.esermis.dpld.model.AnalyticalInstrumentsVo;
12 13
 import com.cn.esermis.dpld.model.DataAcquisitionInstrumentVo;
14
+import com.cn.esermis.dpld.model.OutletAndFactorVo;
13 15
 import com.cn.esermis.dpld.service.IAnalyticalInstrumentsService;
14 16
 import com.cn.esermis.dpld.service.IDataAcquisitionInstrumentService;
15 17
 import com.cn.esermis.dpld.service.IDetectMonitoringFactorService;
16 18
 import org.springframework.beans.BeanUtils;
19
+import org.springframework.beans.factory.annotation.Autowired;
20
+import org.springframework.data.redis.core.RedisTemplate;
17 21
 import org.springframework.transaction.annotation.Transactional;
18 22
 import org.springframework.validation.annotation.Validated;
19 23
 import org.springframework.web.bind.annotation.*;
@@ -33,7 +37,8 @@ public class DataAcquisitionInstrumentController {
33 37
     private IDetectMonitoringFactorService detectMonitoringFactorService;
34 38
     @Resource
35 39
     private IDataAcquisitionInstrumentService dataAcquisitionInstrumentService;
36
-
40
+    @Autowired
41
+    private RedisTemplate<String, Object> redisTemplate;
37 42
     /**
38 43
      * 获取数采仪信息表
39 44
      */
@@ -85,6 +90,8 @@ public class DataAcquisitionInstrumentController {
85 90
             });
86 91
             volits.setRecords(revoList);
87 92
         }
93
+        List<OutletAndFactorVo> selectlist = dataAcquisitionInstrumentService.selectlist();
94
+        redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(selectlist));
88 95
         return success(volits);
89 96
     }
90 97
 
@@ -111,6 +118,8 @@ public class DataAcquisitionInstrumentController {
111 118
             }
112 119
         }
113 120
         dataAcquisitionInstrumentService.remove(new QueryWrapper<DataAcquisitionInstrument>().eq("id", id));
121
+        List<OutletAndFactorVo> selectlist = dataAcquisitionInstrumentService.selectlist();
122
+        redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(selectlist));
114 123
         return success();
115 124
     }
116 125
 
@@ -142,12 +151,14 @@ public class DataAcquisitionInstrumentController {
142 151
                 instrumentVo.setAnalyticalInstruments(analyticalInstrumentList);
143 152
             }
144 153
         }
154
+        List<OutletAndFactorVo> selectlist = dataAcquisitionInstrumentService.selectlist();
155
+        redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(selectlist));
145 156
         return success(instrumentVo);
146 157
     }
147 158
 
148 159
 
149 160
     /**
150
-     * 新增菜单
161
+     * 新增数采仪信息
151 162
      */
152 163
     @PostMapping("/save")
153 164
     @Transactional
@@ -180,6 +191,7 @@ public class DataAcquisitionInstrumentController {
180 191
                     List<DetectMonitoringFactor> detectMonitoringFactors = x.getDetectMonitoringFactors();
181 192
                     detectMonitoringFactors.forEach(y->{
182 193
                         y.setAnalyticalInstrumentId(analyticalInstruments.getId());
194
+
183 195
                         boolean save2 = detectMonitoringFactorService.save(y);
184 196
                         if (!save2){
185 197
                             throw new RuntimeException("添加失败");
@@ -188,6 +200,8 @@ public class DataAcquisitionInstrumentController {
188 200
                }
189 201
             });
190 202
         }
203
+        List<OutletAndFactorVo> selectlist = dataAcquisitionInstrumentService.selectlist();
204
+        redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(selectlist));
191 205
         return success();
192 206
     }
193 207
 

+ 18 - 13
src/main/java/com/cn/esermis/datawarn/common/ExceptionDataDispose.java

@@ -1,5 +1,6 @@
1 1
 package com.cn.esermis.datawarn.common;
2 2
 
3
+import com.baomidou.dynamic.datasource.annotation.DS;
3 4
 import com.cn.esermis.datawarn.mapper.CountAirChargeMapper;
4 5
 import com.cn.esermis.datawarn.mapper.CountWaterChargeMapper;
5 6
 import com.cn.esermis.datawarn.mapper.ExceedDataMapper;
@@ -14,29 +15,30 @@ import java.util.ArrayList;
14 15
  * @ClassName: exceptionDataDispose
15 16
  * @author: Mr.Chen
16 17
  * @date: 2024/9/13 9:51
17
- * 超标A  负值异常B  6小时恒值C  正常数据为Y
18
+ * 正常"0" 异常"1"
18 19
  */
20
+@DS("slave_1")
19 21
 @Component
22
+//@EnableScheduling
20 23
 public class ExceptionDataDispose {
21 24
 
22 25
     @Autowired
23
-    private CountAirChargeMapper countAirChargeMapper;
26
+    CountAirChargeMapper countAirChargeMapper;
24 27
     @Autowired
25
-    private ExceedDataMapper exceedDataMapper;
28
+    ExceedDataMapper exceedDataMapper;
26 29
     @Autowired
27
-    private MonitorFactorMapper monitorFactorMapper;
30
+    MonitorFactorMapper monitorFactorMapper;
28 31
     @Autowired
29
-    private CountWaterChargeMapper countWaterChargeMapper;
32
+    CountWaterChargeMapper countWaterChargeMapper;
30 33
 
31 34
 
32 35
     public String LoseData(Double max, Double min, Double avg) {
33 36
 
34 37
         //判断是否为负值数据
35 38
         if (max < 0 || min < 0 || avg < 0) {
36
-            return "B";
39
+            return "1";
37 40
         }
38
-        return "Y";
39
-
41
+        return "0";
40 42
     }
41 43
 
42 44
     public String SixData(String mn, String factor, Double avg, String dataTime) {
@@ -69,12 +71,15 @@ public class ExceptionDataDispose {
69 71
             }
70 72
         }
71 73
         if (count == 6) {
72
-            return "C";
74
+            return "1";
73 75
         }
74
-        return "Y";
76
+        return "0";
75 77
 
76 78
     }
77
-
79
+//    @Scheduled(cron = "0/10 * * * *  ?")
80
+//    public void test(){
81
+//        System.out.println(SixData("120119ZHSYQ081", "a00000", 18.75, "20241023220000"));
82
+//    }
78 83
 
79 84
     public String ExceedData(String mn, String factor, Double avg) {
80 85
         //获取到小时均值限值
@@ -84,9 +89,9 @@ public class ExceptionDataDispose {
84 89
         int flag = hoursLimit.compareTo(BigDecimal.valueOf(avg));
85 90
         //compareTo会判断两个BigDecimal对象的大小 如果是负值那么avg > HOURSLimit 如果是0那么avg = HOURSLimit 如果是正数那么avg < HOURSLimit
86 91
         if (flag < 0) {
87
-            return "A";
92
+            return "1";
88 93
         }
89
-        return "Y";
94
+        return "0";
90 95
     }
91 96
 
92 97
     public BigDecimal ExceedData(String mn, String factor) {

+ 2 - 1
src/main/java/com/cn/esermis/datawarn/mapper/CountWaterChargeMapper.java

@@ -2,11 +2,12 @@ package com.cn.esermis.datawarn.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.cn.esermis.datawarn.entity.WaterHourRecord;
5
+import org.apache.ibatis.annotations.Mapper;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import org.apache.ibatis.annotations.Select;
7 8
 
8 9
 import java.util.List;
9
-
10
+@Mapper
10 11
 public interface CountWaterChargeMapper extends BaseMapper<WaterHourRecord> {
11 12
     @Select(value = "select avg from water_monitor_hour_record where mn = #{mn} and factor = #{factor} and data_time in (#{time1},#{time2},#{time3},#{time4},#{time5}) ")
12 13
     List<Double> airSixHour(@Param("mn") String mn ,@Param("factor") String factor, @Param("time1") String time1, @Param("time2") String time2, @Param("time3") String time3, @Param("time4") String time4, @Param("time5") String time5);

+ 1 - 6
src/main/java/com/cn/esermis/datawarn/mapper/ExceedDataMapper.java

@@ -5,16 +5,11 @@ import com.cn.esermis.datawarn.entity.MonitoringFactor;
5 5
 import org.apache.ibatis.annotations.Mapper;
6 6
 import org.apache.ibatis.annotations.Param;
7 7
 import org.apache.ibatis.annotations.Select;
8
-import org.apache.ibatis.annotations.SelectProvider;
9 8
 
10 9
 import java.math.BigDecimal;
11 10
 
12 11
 @Mapper
13 12
 public interface ExceedDataMapper extends BaseMapper<MonitoringFactor> {
14
-//    @SelectProvider(type = ExceedDataSQL.class, method = "hoursAvg")
15
-    @Select("select hours_avg from monitoring_factor where analytical_instrument_id in \n" +
16
-            "        (select id from analytical_instruments where data_acquisition_instrument_id in\n" +
17
-            "        (select id from data_acquisition_instrument where mn_code = #{mn})\n" +
18
-            "        ) and factor = #{factor}")
13
+    @Select("select hours_avg from monitoring_factor m left join data_acquisition_instrument d on m.data_acquisition_instrument_id = d.id where d.mn_code = #{mn} and m.factor = #{factor}")
19 14
     BigDecimal hoursAvg(@Param("mn") String mn, @Param("factor") String factor);
20 15
 }

+ 2 - 0
src/main/java/com/cn/esermis/datawarn/mapper/MonitorFactorMapper.java

@@ -2,9 +2,11 @@ package com.cn.esermis.datawarn.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.cn.esermis.datawarn.entity.MonitorFactor;
5
+import org.apache.ibatis.annotations.Mapper;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import org.apache.ibatis.annotations.Select;
7 8
 
9
+@Mapper
8 10
 public interface MonitorFactorMapper extends BaseMapper<MonitorFactor> {
9 11
     @Select(value = "select factor_type from monitor_factor where code = #{factor}")
10 12
     Integer waterOrAir(@Param("factor") String factor);

+ 116 - 98
src/main/java/com/cn/esermis/dpld/business/MonitorBusiness.java

@@ -44,14 +44,13 @@ public class MonitorBusiness {
44 44
     @Autowired
45 45
     private RedisTemplate<String, Object> redisTemplate;
46 46
 
47
-    private List<OutletAndFactorVo>  dataAcquisitionInstruments =  new ArrayList<>();
48 47
 
49 48
 
50 49
     @PostConstruct
51 50
     public void loadData() {
52
-        dataAcquisitionInstruments =
53
-                dataAcquisitionInstrumentService.selectlist();
54
-        System.out.println(dataAcquisitionInstruments);
51
+
52
+        List<OutletAndFactorVo> selectlist = dataAcquisitionInstrumentService.selectlist();
53
+        redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(selectlist));
55 54
         // 处理读取到的数据
56 55
     }
57 56
 
@@ -116,52 +115,54 @@ public class MonitorBusiness {
116 115
                         listData.add(airMonitorMinuteRecord);
117 116
                     });
118 117
                     airMonitorMinuteRecordService.saveBatch(listData);
119
-                } else if (factorModel.getCN().equals(Constant.REAL)) {
120
-                    // 分钟数据入库
121
-                    List<AirMonitorMinuteRecord> listData = new ArrayList<>();
122
-                    cp.forEach(x -> {
123
-                        AirMonitorMinuteRecord airMonitorMinuteRecord = new AirMonitorMinuteRecord();
124
-                        airMonitorMinuteRecord.setQn(factorModel.getQN());
125
-                        airMonitorMinuteRecord.setSt(factorModel.getST());
126
-                        airMonitorMinuteRecord.setCn(factorModel.getCN());
127
-                        airMonitorMinuteRecord.setPw(factorModel.getPW());
128
-                        airMonitorMinuteRecord.setMn(factorModel.getMN());
129
-                        airMonitorMinuteRecord.setFlag(factorModel.getFlag());
130
-                        airMonitorMinuteRecord.setDataTime(factorModel.getDataTime());
131
-                        airMonitorMinuteRecord.setFactor(x.getFactor());
132
-                        airMonitorMinuteRecord.setMin(x.getMin());
133
-                        airMonitorMinuteRecord.setMax(x.getMax());
134
-                        airMonitorMinuteRecord.setAvg(x.getAvg());
135
-                        airMonitorMinuteRecord.setCou(x.getCou());
136
-                        airMonitorMinuteRecord.setFactorFlag(x.getFlag());
137
-                        airMonitorMinuteRecord.setZsAvg(x.getZsAvg());
138
-                        airMonitorMinuteRecord.setZsMax(x.getZsMax());
139
-                        airMonitorMinuteRecord.setZsMin(x.getZsMin());
140
-                        airMonitorMinuteRecord.setRtd(x.getRtd());
141
-                        try {
142
-                            airMonitorMinuteRecord.setWorkCondition(sendMessage(factorModel.getDataTime(),factorModel.getMN()));
143
-                        } catch (ParseException e) {
144
-                            throw new RuntimeException(e);
145
-                        }
146
-                        try {
147
-                            airMonitorMinuteRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
148
-                            airMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
149
-                                    x.getMin()!=null?x.getMin().doubleValue():0,
150
-                                    x.getAvg()!=null?x.getAvg().doubleValue():0));
151
-                            if ((airMonitorMinuteRecord.getIsExceed()!=null && !airMonitorMinuteRecord.getIsExceed().equals("Y") )||
152
-                                    (airMonitorMinuteRecord.getIsLose()!=null && !airMonitorMinuteRecord.getIsLose().equals("Y") )||
153
-                                    (airMonitorMinuteRecord.getIsSix()!=null && !airMonitorMinuteRecord.getIsSix().equals("Y"))){
154
-                                saveExcepLog(x, airMonitorMinuteRecord);
155
-                            }
156
-                        } catch (Exception e) {
157
-                            log.error("调用 ExceptionDataDispose2 方法异常{} 当前参数为:{}",e,airMonitorMinuteRecord);
158
-                        }
159
-                        listData.add(airMonitorMinuteRecord);
160
-                    });
161
-                    if (!listData.isEmpty()) {
162
-                        airMonitorMinuteRecordService.saveBatch(listData);
163
-                    }
164
-                } else if (factorModel.getCN().equals(Constant.HOUR)) {
118
+                }
119
+//                else if (factorModel.getCN().equals(Constant.REAL)) {
120
+//                    // 分钟数据入库
121
+//                    List<AirMonitorMinuteRecord> listData = new ArrayList<>();
122
+//                    cp.forEach(x -> {
123
+//                        AirMonitorMinuteRecord airMonitorMinuteRecord = new AirMonitorMinuteRecord();
124
+//                        airMonitorMinuteRecord.setQn(factorModel.getQN());
125
+//                        airMonitorMinuteRecord.setSt(factorModel.getST());
126
+//                        airMonitorMinuteRecord.setCn(factorModel.getCN());
127
+//                        airMonitorMinuteRecord.setPw(factorModel.getPW());
128
+//                        airMonitorMinuteRecord.setMn(factorModel.getMN());
129
+//                        airMonitorMinuteRecord.setFlag(factorModel.getFlag());
130
+//                        airMonitorMinuteRecord.setDataTime(factorModel.getDataTime());
131
+//                        airMonitorMinuteRecord.setFactor(x.getFactor());
132
+//                        airMonitorMinuteRecord.setMin(x.getMin());
133
+//                        airMonitorMinuteRecord.setMax(x.getMax());
134
+//                        airMonitorMinuteRecord.setAvg(x.getAvg());
135
+//                        airMonitorMinuteRecord.setCou(x.getCou());
136
+//                        airMonitorMinuteRecord.setFactorFlag(x.getFlag());
137
+//                        airMonitorMinuteRecord.setZsAvg(x.getZsAvg());
138
+//                        airMonitorMinuteRecord.setZsMax(x.getZsMax());
139
+//                        airMonitorMinuteRecord.setZsMin(x.getZsMin());
140
+//                        airMonitorMinuteRecord.setRtd(x.getRtd());
141
+//                        try {
142
+//                            airMonitorMinuteRecord.setWorkCondition(sendMessage(factorModel.getDataTime(),factorModel.getMN()));
143
+//                        } catch (ParseException e) {
144
+//                            throw new RuntimeException(e);
145
+//                        }
146
+//                        try {
147
+//                            airMonitorMinuteRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
148
+//                            airMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
149
+//                                    x.getMin()!=null?x.getMin().doubleValue():0,
150
+//                                    x.getAvg()!=null?x.getAvg().doubleValue():0));
151
+//                            if ((airMonitorMinuteRecord.getIsExceed()!=null && !airMonitorMinuteRecord.getIsExceed().equals("Y") )||
152
+//                                    (airMonitorMinuteRecord.getIsLose()!=null && !airMonitorMinuteRecord.getIsLose().equals("Y") )||
153
+//                                    (airMonitorMinuteRecord.getIsSix()!=null && !airMonitorMinuteRecord.getIsSix().equals("Y"))){
154
+//                                saveExcepLog(x, airMonitorMinuteRecord);
155
+//                            }
156
+//                        } catch (Exception e) {
157
+//                            log.error("调用 ExceptionDataDispose2 方法异常{} 当前参数为:{}",e,airMonitorMinuteRecord);
158
+//                        }
159
+//                        listData.add(airMonitorMinuteRecord);
160
+//                    });
161
+//                    if (!listData.isEmpty()) {
162
+//                        airMonitorMinuteRecordService.saveBatch(listData);
163
+//                    }
164
+//                }
165
+                else if (factorModel.getCN().equals(Constant.HOUR)) {
165 166
                     // 小时数据入库
166 167
                     List<AirMonitorHourRecord> listData = new ArrayList<>();
167 168
                     cp.forEach(x -> {
@@ -244,50 +245,52 @@ public class MonitorBusiness {
244 245
                         listData.add(waterMonitorMinuteRecord);
245 246
                     });
246 247
                     waterMonitorMinuteRecordService.saveBatch(listData);
247
-                } else if (factorModel.getCN().equals(Constant.REAL)) {
248
-                    // 分钟数据入库
249
-                    List<WaterMonitorMinuteRecord> listData = new ArrayList<>();
250
-                    cp.forEach(x -> {
251
-                        WaterMonitorMinuteRecord waterMonitorMinuteRecord = new WaterMonitorMinuteRecord();
252
-                        waterMonitorMinuteRecord.setQn(factorModel.getQN());
253
-                        waterMonitorMinuteRecord.setSt(factorModel.getST());
254
-                        waterMonitorMinuteRecord.setCn(factorModel.getCN());
255
-                        waterMonitorMinuteRecord.setPw(factorModel.getPW());
256
-                        waterMonitorMinuteRecord.setMn(factorModel.getMN());
257
-                        waterMonitorMinuteRecord.setFlag(factorModel.getFlag());
258
-                        waterMonitorMinuteRecord.setDataTime(factorModel.getDataTime());
259
-                        waterMonitorMinuteRecord.setFactor(x.getFactor());
260
-                        waterMonitorMinuteRecord.setMin(x.getMin());
261
-                        waterMonitorMinuteRecord.setMax(x.getMax());
262
-                        waterMonitorMinuteRecord.setAvg(x.getAvg());
263
-                        waterMonitorMinuteRecord.setCou(x.getCou());
264
-                        waterMonitorMinuteRecord.setFactorFlag(x.getFlag());
265
-                        waterMonitorMinuteRecord.setRtd(x.getRtd());
266
-                        try {
267
-                            waterMonitorMinuteRecord.setWorkCondition(sendMessage(factorModel.getDataTime(),factorModel.getMN()));
268
-                        } catch (ParseException e) {
269
-                            throw new RuntimeException(e);
270
-                        }
271
-                        try {
272
-                            waterMonitorMinuteRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
273
-                            waterMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
274
-                                    x.getMin()!=null?x.getMin().doubleValue():0,
275
-                                    x.getAvg()!=null?x.getAvg().doubleValue():0));
276
-                            if ((waterMonitorMinuteRecord.getIsExceed()!=null && !waterMonitorMinuteRecord.getIsExceed().equals("Y") )||
277
-                                    (waterMonitorMinuteRecord.getIsLose()!=null && !waterMonitorMinuteRecord.getIsLose().equals("Y") )||
278
-                                    (waterMonitorMinuteRecord.getIsSix()!=null && !waterMonitorMinuteRecord.getIsSix().equals("Y"))){
279
-                                saveExcepLog(x, waterMonitorMinuteRecord);
280
-                            }
281
-                        } catch (Exception e) {
282
-                            log.error("调用 ExceptionDataDispose5 方法异常{} 当前参数为:{}",e,waterMonitorMinuteRecord);
283
-                        }
284
-
285
-                        listData.add(waterMonitorMinuteRecord);
286
-                    });
287
-                    if (!listData.isEmpty()) {
288
-                        waterMonitorMinuteRecordService.saveBatch(listData);
289
-                    }
290
-                } else if
248
+                }
249
+//                else if (factorModel.getCN().equals(Constant.REAL)) {
250
+//                    // 分钟数据入库
251
+//                    List<WaterMonitorMinuteRecord> listData = new ArrayList<>();
252
+//                    cp.forEach(x -> {
253
+//                        WaterMonitorMinuteRecord waterMonitorMinuteRecord = new WaterMonitorMinuteRecord();
254
+//                        waterMonitorMinuteRecord.setQn(factorModel.getQN());
255
+//                        waterMonitorMinuteRecord.setSt(factorModel.getST());
256
+//                        waterMonitorMinuteRecord.setCn(factorModel.getCN());
257
+//                        waterMonitorMinuteRecord.setPw(factorModel.getPW());
258
+//                        waterMonitorMinuteRecord.setMn(factorModel.getMN());
259
+//                        waterMonitorMinuteRecord.setFlag(factorModel.getFlag());
260
+//                        waterMonitorMinuteRecord.setDataTime(factorModel.getDataTime());
261
+//                        waterMonitorMinuteRecord.setFactor(x.getFactor());
262
+//                        waterMonitorMinuteRecord.setMin(x.getMin());
263
+//                        waterMonitorMinuteRecord.setMax(x.getMax());
264
+//                        waterMonitorMinuteRecord.setAvg(x.getAvg());
265
+//                        waterMonitorMinuteRecord.setCou(x.getCou());
266
+//                        waterMonitorMinuteRecord.setFactorFlag(x.getFlag());
267
+//                        waterMonitorMinuteRecord.setRtd(x.getRtd());
268
+//                        try {
269
+//                            waterMonitorMinuteRecord.setWorkCondition(sendMessage(factorModel.getDataTime(),factorModel.getMN()));
270
+//                        } catch (ParseException e) {
271
+//                            throw new RuntimeException(e);
272
+//                        }
273
+//                        try {
274
+//                            waterMonitorMinuteRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
275
+//                            waterMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
276
+//                                    x.getMin()!=null?x.getMin().doubleValue():0,
277
+//                                    x.getAvg()!=null?x.getAvg().doubleValue():0));
278
+//                            if ((waterMonitorMinuteRecord.getIsExceed()!=null && !waterMonitorMinuteRecord.getIsExceed().equals("Y") )||
279
+//                                    (waterMonitorMinuteRecord.getIsLose()!=null && !waterMonitorMinuteRecord.getIsLose().equals("Y") )||
280
+//                                    (waterMonitorMinuteRecord.getIsSix()!=null && !waterMonitorMinuteRecord.getIsSix().equals("Y"))){
281
+//                                saveExcepLog(x, waterMonitorMinuteRecord);
282
+//                            }
283
+//                        } catch (Exception e) {
284
+//                            log.error("调用 ExceptionDataDispose5 方法异常{} 当前参数为:{}",e,waterMonitorMinuteRecord);
285
+//                        }
286
+//
287
+//                        listData.add(waterMonitorMinuteRecord);
288
+//                    });
289
+//                    if (!listData.isEmpty()) {
290
+//                        waterMonitorMinuteRecordService.saveBatch(listData);
291
+//                    }
292
+//                }
293
+                else if
291 294
                 (factorModel.getCN().equals(Constant.HOUR)) {
292 295
                     // 小时数据入库
293 296
                     List<WaterMonitorHourRecord> listData = new ArrayList<>();
@@ -333,7 +336,7 @@ public class MonitorBusiness {
333 336
 
334 337
     private void saveExcepLog(CP x, AirMonitorMinuteRecord record) {
335 338
         ExcepLog excepLog = new ExcepLog();
336
-        Optional<OutletAndFactorVo> first = dataAcquisitionInstruments.stream().filter(d ->d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
339
+        Optional<OutletAndFactorVo> first = getloadData().stream().filter(d ->d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
337 340
         if (first.isPresent()) {
338 341
             excepLog.setOutletName(first.get().getOutletName());
339 342
             excepLog.setOutletCode(first.get().getOutletCode());
@@ -349,7 +352,7 @@ public class MonitorBusiness {
349 352
 
350 353
     private void saveExcepLog(CP x, AirMonitorHourRecord record) {
351 354
         ExcepLog excepLog = new ExcepLog();
352
-        Optional<OutletAndFactorVo> first = dataAcquisitionInstruments.stream().filter(d -> d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
355
+        Optional<OutletAndFactorVo> first = getloadData().stream().filter(d -> d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
353 356
         if (first.isPresent()) {
354 357
             excepLog.setOutletName(first.get().getOutletName());
355 358
             excepLog.setOutletCode(first.get().getOutletCode());
@@ -364,7 +367,7 @@ public class MonitorBusiness {
364 367
 
365 368
     private void saveExcepLog(CP x, WaterMonitorMinuteRecord record) {
366 369
         ExcepLog excepLog = new ExcepLog();
367
-        Optional<OutletAndFactorVo> first = dataAcquisitionInstruments.stream().filter(d ->d.getFactor()!=null &&  d.getFactor().equals(x.getFactor())).findFirst();
370
+        Optional<OutletAndFactorVo> first = getloadData().stream().filter(d ->d.getFactor()!=null &&  d.getFactor().equals(x.getFactor())).findFirst();
368 371
         if (first.isPresent()) {
369 372
             excepLog.setOutletName(first.get().getOutletName());
370 373
             excepLog.setOutletCode(first.get().getOutletCode());
@@ -378,7 +381,7 @@ public class MonitorBusiness {
378 381
     }
379 382
     private void saveExcepLog(CP x, WaterMonitorHourRecord record) {
380 383
         ExcepLog excepLog = new ExcepLog();
381
-        Optional<OutletAndFactorVo> first = dataAcquisitionInstruments.stream().filter(d -> d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
384
+        Optional<OutletAndFactorVo> first = getloadData().stream().filter(d -> d.getFactor()!=null && d.getFactor().equals(x.getFactor())).findFirst();
382 385
         if (first.isPresent()) {
383 386
             excepLog.setOutletName(first.get().getOutletName());
384 387
             excepLog.setOutletCode(first.get().getOutletCode());
@@ -403,4 +406,19 @@ public class MonitorBusiness {
403 406
         }
404 407
         return 1;
405 408
     }
409
+    /**
410
+     * 获取工厂排口信息
411
+     */
412
+    private List<OutletAndFactorVo> getloadData() {
413
+        List<OutletAndFactorVo>  dataAcquisitionInstruments = new ArrayList<>();
414
+        Object o = redisTemplate.opsForValue().get("dataAcquisitionInstruments");
415
+        if (o != null){
416
+            dataAcquisitionInstruments = JSON.parseArray(o.toString(), OutletAndFactorVo.class);
417
+        }else {
418
+            dataAcquisitionInstruments = dataAcquisitionInstrumentService.selectlist();
419
+            redisTemplate.opsForValue().set("dataAcquisitionInstruments", JSON.toJSONString(dataAcquisitionInstruments));
420
+        }
421
+        return dataAcquisitionInstruments;
422
+    }
423
+
406 424
 }

+ 5 - 1
src/main/java/com/cn/esermis/dpld/entity/DetectMonitoringFactor.java

@@ -75,5 +75,9 @@ public class DetectMonitoringFactor {
75 75
      */
76 76
     @TableField(value = "rangeUnit")
77 77
     private String rangeUnit;
78
-
78
+    /**
79
+     * 数据采集仪主键ID
80
+     */
81
+    @TableField(value = "data_acquisition_instrument_id")
82
+    private String dataAcquisitionInstrumentId;
79 83
 }

+ 4 - 0
src/main/java/com/cn/esermis/dpld/mapper/DataAcquisitionInstrumentMapper.java

@@ -26,4 +26,8 @@ public interface DataAcquisitionInstrumentMapper extends BaseMapper<DataAcquisit
26 26
     Map<String, Object> getDepartmentMap();
27 27
 
28 28
     List<DataAcquisitionInstrument> listByCode(DataAcquisitionInstrumentVo vo);
29
+
30
+    Boolean verifydepartmen(String factoryId);
31
+
32
+    Boolean verifyCompany(String companyId);
29 33
 }

+ 6 - 0
src/main/resources/static/mybatis/DataAcquisitionInstrumentMapper.xml

@@ -41,5 +41,11 @@
41 41
             </if>
42 42
         </where>
43 43
     </select>
44
+    <select id="verifydepartmen" resultType="java.lang.Boolean">
45
+        select count(0)>0 from department where departmentid = #{factoryId}
46
+    </select>
47
+    <select id="verifyCompany" resultType="java.lang.Boolean" parameterType="java.lang.String">
48
+        select count(0)>0 from company where companyid =  #{companyId}
49
+    </select>
44 50
 </mapper>
45 51