Kaynağa Gözat

预警有无人优化,多实验室排序优化

hanzhiwei 2 yıl önce
ebeveyn
işleme
da3de8f2ea

+ 3 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/WarningDetail.java

@@ -49,6 +49,9 @@ public class WarningDetail extends Model<WarningDetail> {
     @ApiModelProperty("回调图片路径")
     private String callbackPhotoUrl;
 
+    @ApiModelProperty("是否有人(0否 1是)")
+    private Boolean person;
+
     @ApiModelProperty("识别结果(是否异常)")
     private Boolean result;
 

+ 8 - 2
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/event/RedisExpiredPhotographListener.java

@@ -151,6 +151,7 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
                 if(algorithmWarningVo.getIsAlert()){
                     warningDetail.setCallbackPhotoUrl(algorithmWarningVo.getResultImage());
                 }
+                warningDetail.setPerson(algorithmWarningVo.getState());
                 warningDetail.setResult(algorithmWarningVo.getIsAlert());
                 warningDetail.setCreateTime(LocalDateTime.now());
                 warningDetailService.save(warningDetail);
@@ -167,8 +168,13 @@ public class RedisExpiredPhotographListener extends KeyExpirationEventMessageLis
                     //如果没有这个key了 则统计异常率
                     List<WarningDetail> list = warningDetailService.list(new LambdaQueryWrapper<WarningDetail>().eq(WarningDetail::getLogId, warningNoticeLog.getId()));
                     if (list.size() > 0) {
-                        List<WarningDetail> collect = list.stream().filter(i -> i.getResult() == true).collect(Collectors.toList());
-                        double rate = NumberUtil.div(collect.size(), warningConfig.getAnomalyCount().intValue());
+                        List<WarningDetail> collect = list.stream().filter(i -> i.getResult() && i.getPerson()).collect(Collectors.toList());
+                        List<WarningDetail> collect2 = list.stream().filter(i -> i.getPerson()).collect(Collectors.toList());
+                        if(collect2.size() == 0){
+                            log.info("当前算法识别到人、异常数据数量={},当前识别到人数据数量={}",collect.size(),collect2.size());
+                            return;
+                        }
+                        double rate = NumberUtil.div(collect.size(), collect2.size());
                         double rate2 = NumberUtil.div(warningConfig.getAnomalyRate(), new Double(100));
                         log.info("当前识别率={},目标识别率={}",rate,rate2);
                         log.info("比较大小={}",NumberUtil.sub(rate, rate2));

+ 24 - 23
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/WarningNoticeLogServiceImpl.java

@@ -26,10 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -44,6 +41,11 @@ import java.util.concurrent.TimeUnit;
 @Slf4j
 public class WarningNoticeLogServiceImpl extends ServiceImpl<WarningNoticeLogMapper, WarningNoticeLog> implements WarningNoticeLogService {
 
+    /**
+     * 异常识别频率(30秒识别一次)
+     */
+    private final long frequency = 30L;
+
     @Autowired
     private LabHardwareStateMapper hardwareStateMapper;
     @Autowired
@@ -87,32 +89,31 @@ public class WarningNoticeLogServiceImpl extends ServiceImpl<WarningNoticeLogMap
 
     /**
      * 实验室有人时定时拍摄识别实验服
-     * 每小时执行一次
      */
-//    @Scheduled(cron = "0 0/2 * * * ? ")
     public void labCoatTask() {
         log.info("执行实验服识别定时任务!");
         //查询实验室是否有人
         List<LabOnlineSubVO> labSubjects = hardwareStateMapper.onlineByBigView(new LabSubjectVO());
         //查询配置
         WarningConfig warningConfig = warningConfigService.getOne(new LambdaQueryWrapper<WarningConfig>().eq(WarningConfig::getWarningType, 1));
-        Optional.ofNullable(labSubjects).orElseGet(Collections::emptyList).stream().forEach(LabOnlineSubVO -> {
-            //异常识别频率
-            Long frequency = 30L;
-            //异常再识别数
-            Integer anomalyCount = warningConfig.getAnomalyCount();
-            WarningNoticeLog warningNoticeLog = new WarningNoticeLog();
-            warningNoticeLog.setWarningType(1);
-            warningNoticeLog.setSubId(LabOnlineSubVO.getId());
-            warningNoticeLog.setSubName(LabOnlineSubVO.getName());
-            warningNoticeLog.setCreateTime(LocalDateTime.now());
-            warningNoticeLog.setIsDeleted(Boolean.TRUE);
-            baseMapper.insert(warningNoticeLog);
-            for (int i = 0; i < anomalyCount; i++) {
-                JSONObject jsonObject = new JSONObject();
-                jsonObject.put(BaseConstants.PHOTOGRAPH_QUEUE,warningNoticeLog);
-                redisService.setCacheObject(BaseConstants.PHOTOGRAPH_QUEUE+"~"+ jsonObject +"~"+ i,jsonObject, (i + 1) * frequency, TimeUnit.SECONDS);
+        if(Objects.nonNull(labSubjects) && labSubjects.size() > 0){
+            int j = 0;
+            for (LabOnlineSubVO labSubject : labSubjects) {
+                //异常再识别数
+                Integer anomalyCount = warningConfig.getAnomalyCount();
+                WarningNoticeLog warningNoticeLog = new WarningNoticeLog();
+                warningNoticeLog.setWarningType(1);
+                warningNoticeLog.setSubId(labSubject.getId());
+                warningNoticeLog.setSubName(labSubject.getName());
+                warningNoticeLog.setCreateTime(LocalDateTime.now());
+                warningNoticeLog.setIsDeleted(Boolean.TRUE);
+                baseMapper.insert(warningNoticeLog);
+                for (int i = 0; i < anomalyCount; i++, j++) {
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put(BaseConstants.PHOTOGRAPH_QUEUE,warningNoticeLog);
+                    redisService.setCacheObject(BaseConstants.PHOTOGRAPH_QUEUE+"~"+ jsonObject +"~"+ i,jsonObject, (j + 1) * frequency, TimeUnit.SECONDS);
+                }
             }
-        });
+        }
     }
 }

+ 2 - 1
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/WarningDetailMapper.xml

@@ -11,6 +11,7 @@
         <result column="type" property="type" />
         <result column="photo_url" property="photoUrl" />
         <result column="callback_photo_url" property="callbackPhotoUrl" />
+        <result column="person" property="person"/>
         <result column="result" property="result" />
         <result column="create_name" property="createName" />
         <result column="create_by" property="createBy" />
@@ -23,7 +24,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, log_id, sub_id, photo_num, type, photo_url, callback_photo_url, result, create_name, create_by, create_time, update_name, update_by, update_time, is_deleted
+        id, log_id, sub_id, photo_num, type, photo_url, callback_photo_url, person, result, create_name, create_by, create_time, update_name, update_by, update_time, is_deleted
     </sql>
 
 </mapper>