Преглед изворни кода

泥人继电器&人脸识别优化同步

linfutong пре 2 година
родитељ
комит
6e0e3fe68b

+ 6 - 0
zd-api/zd-laboratory-api/src/main/java/com/zd/laboratory/api/vo/ClassifyVO.java

@@ -21,6 +21,12 @@ public class ClassifyVO {
     /** 类目类型 1文字 2图片 */
     private Integer classifyType;
 
+    /** 颜色*/
+    private String showColour;
+
+    /** 是否特殊类目 1否 2 是*/
+    private Integer isSpecial;
+
     /**公共类目**/
     private List<ClassifyDetailVO> publicList;
     /***私有类目**/

+ 10 - 12
zd-modules/zd-algorithm/src/main/java/com/zd/alg/face/controller/FaceApi.java

@@ -8,6 +8,7 @@ import com.zd.alg.face.service.FaceService;
 import com.zd.alg.face.utils.FileUtil;
 import com.zd.algorithm.api.face.feign.FaceCompare;
 import com.zd.common.core.utils.DateUtils;
+import com.zd.common.core.utils.SpringUtils;
 import com.zd.common.core.utils.StringUtils;
 import com.zd.common.swagger.config.Knife4jConfiguration;
 import com.zd.laboratory.api.entity.LabStudentsInfo;
@@ -43,21 +44,18 @@ import java.util.stream.Collectors;
 @RequestMapping("/faceApi")
 public class FaceApi {
 
-    private static final int taskSize = 50;
+    private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
 
-    private static ExecutorService pool = Executors.newFixedThreadPool(taskSize);
-
-
-    Logger logger = LoggerFactory.getLogger(FaceApi.class);
+    private Logger logger = LoggerFactory.getLogger(FaceApi.class);
 
     @Autowired
-    FaceService faceService;
+    private FaceService faceService;
 
     @Autowired
-    RemoteStudentsService remoteStudentsService;
+    private RemoteStudentsService remoteStudentsService;
 
     @Autowired
-    RemoteDutyService remoteDutyService;
+    private RemoteDutyService remoteDutyService;
 
 
     @ApiOperation("根据照片文件获取特征码")
@@ -177,15 +175,16 @@ public class FaceApi {
     @PostMapping("/multiCompare")
     public ResultData multiFaceDetection(@RequestBody FaceCompare faceCompare) throws ExecutionException, InterruptedException {
         logger.info("====人脸比较====");
-        long time=System.currentTimeMillis();
         ResultData<List<LabSysUserInfo>> infoList = remoteStudentsService.getFaceBySecuritySubjectId(faceCompare.getLabId());
+        long time=System.currentTimeMillis();
         if(infoList.getCode() == 200 && infoList.getData() != null){
             List<Future> list = Optional.ofNullable(infoList.getData()).orElseGet(Collections::emptyList)
                     .stream()
                     .map(a->{
-                        Future f = pool.submit(new Callable<Object>() {
+                        Future f = scheduledExecutorService.submit(new Callable<Object>() {
                             @Override
                             public Object call() throws Exception {
+                                logger.info("执行线程名称:"+Thread.currentThread().getName());
                                 return getMultiFaceDetection(a,faceCompare);
                             }
                         });
@@ -196,11 +195,10 @@ public class FaceApi {
                 ResultData r=(ResultData)future.get();
                 if(r.getCode()==200){
                     long time2=System.currentTimeMillis();
-                    System.out.println("执行时间:"+(time2-time));
+                    logger.info("多线程人脸对比执行时间:"+(time2-time));
                     return r;
                 }
             }
-            //pool.shutdown();
         }
         return ResultData.fail("未获取实验室安全准入人脸数据!");
     }

+ 44 - 13
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/service/impl/LabSubjectManagerService.java

@@ -17,12 +17,14 @@ import com.zd.laboratory.api.entity.*;
 import com.zd.laboratory.api.vo.*;
 import com.zd.laboratory.config.HardwareFunctionStatusConfig;
 import com.zd.laboratory.config.TimeWaitConfigUtils;
+import com.zd.laboratory.constant.RelayConstants;
 import com.zd.laboratory.domain.*;
 import com.zd.laboratory.domain.dto.LabSubListQuery;
 import com.zd.laboratory.domain.vo.*;
 import com.zd.laboratory.mapper.*;
 import com.zd.laboratory.mqtt.entiy.EquipmentStatus;
 import com.zd.laboratory.mqtt.service.impl.SubMessageSendManager;
+import com.zd.laboratory.netty.NettyPushMsgService;
 import com.zd.laboratory.service.*;
 import com.zd.laboratory.socket.command.Symbol;
 import com.zd.laboratory.socket.service.SocketService;
@@ -48,6 +50,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
@@ -246,21 +249,40 @@ public class LabSubjectManagerService {
             logger.error("未关联继电器位!id:{},名称:{}", id, labHardwareVO.getName());
             return false;
         }
-        if (labHardwareVO.getHardwareType() == 2) {
-            ResultData ResultData = socketService.sendMqttCommand(labHardwareVO.getId(), labHardwareVO.getRelayCode(), command, labHardwareVO.getBit(),labHardwareVO.getSubjectId());
+        if (labHardwareVO.getHardwareType() == 1) {
+            ResultData ResultData = socketService.sendCommand(Symbol.order.control, labHardwareVO.getRelayCode(), command, labHardwareVO.getBit());
             boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
             if (equals) {
                 //添加记录
                 labControlService.manualCreateLabControlAndSave(labHardwareVO, Symbol.order.control, command);
             }
-        } else {
-            ResultData ResultData = socketService.sendCommand(Symbol.order.control, labHardwareVO.getRelayCode(), command, labHardwareVO.getBit());
+            return equals;
+        } else if (labHardwareVO.getHardwareType() == 2) {
+            ResultData ResultData = socketService.sendMqttCommand(labHardwareVO.getId(), labHardwareVO.getRelayCode(), command, labHardwareVO.getBit(), labHardwareVO.getSubjectId());
             boolean equals = ResultData.getCode().equals(HttpStatus.SUCCESS);
             if (equals) {
                 //添加记录
                 labControlService.manualCreateLabControlAndSave(labHardwareVO, Symbol.order.control, command);
             }
-            return equals;
+        } else if (labHardwareVO.getHardwareType() == 3) {
+            try {
+                String relayCode = labHardwareVO.getRelayCode();
+                String type = command.getType();
+                if(RelayConstants.AT_OPEN_STR.equals(type)){
+                    type=RelayConstants.AT_OPEN.toString();
+                }
+                if(RelayConstants.AT_CLOSE_STR.equals(type)){
+                    type=RelayConstants.AT_CLOSE.toString();
+                }
+                String commandStr = RelayConstants.AT_STACH + labHardwareVO.getBit() + "=" + type + RelayConstants.SPACE_WRAP;
+                NettyPushMsgService.push(relayCode, commandStr.getBytes());
+                return true;
+            } catch (IOException e) {
+                logger.error("泥人继电器调用成功" + e.getMessage());
+                return false;
+            }
+        } else {
+            return false;
         }
         return true;
     }
@@ -728,6 +750,8 @@ public class LabSubjectManagerService {
                 classifyVO.setId(xcf.getId());
                 classifyVO.setClassifyName(xcf.getClassifyName());
                 classifyVO.setClassifyType(xcf.getClassifyType());
+                classifyVO.setShowColour(xcf.getShowColour());
+                classifyVO.setIsSpecial(xcf.getIsSpecial());
                 classifyVOList.add(classifyVO);
 
                 //查询公共配置
@@ -1615,7 +1639,15 @@ public class LabSubjectManagerService {
             hardware.setIsPcfire(a.getIsPcfire());
         }
         //初始化开关状态 (开关类型)
-        if (a.getHardwareType() == 2) {
+        if(a.getHardwareType()==1){
+            if (StrUtil.isNotBlank(a.getRelayCode()) && a.getBit() != null) {
+                Map<Integer, ControlEntity.SwitchEnums> switchEnums = socketService.getSwitchEnums(a.getRelayCode());
+                if (switchEnums != null) {
+                    ControlEntity.SwitchEnums switchEnums1 = switchEnums.get(a.getBit());
+                    hardware.setSwitchEnums(switchEnums1);
+                }
+            }
+        } else if (a.getHardwareType() == 2) {
             Integer code=redisService.getCacheObject(CacheConstants.RELAY_STATUS_KEY+a.getId());
             if(null==code){
                 if(null!=a.getOperate() && a.getOperate().getCode()==3){
@@ -1635,13 +1667,12 @@ public class LabSubjectManagerService {
                     hardware.setState(HardwareOperate.CLOSE);
                 }
             }
-        } else {
-            if (StrUtil.isNotBlank(a.getRelayCode()) && a.getBit() != null) {
-                Map<Integer, ControlEntity.SwitchEnums> switchEnums = socketService.getSwitchEnums(a.getRelayCode());
-                if (switchEnums != null) {
-                    ControlEntity.SwitchEnums switchEnums1 = switchEnums.get(a.getBit());
-                    hardware.setSwitchEnums(switchEnums1);
-                }
+        } else if(a.getHardwareType() == 3){
+            if(null!=a.getOperate() && a.getOperate().getCode()==3){
+                hardware.setSwitchEnums(ControlEntity.SwitchEnums.ON);
+            }
+            if(null!=a.getOperate() &&  a.getOperate().getCode()==4){
+                hardware.setSwitchEnums(ControlEntity.SwitchEnums.OFF);
             }
         }