diff --git a/face-server/pom.xml b/face-server/pom.xml index 350248a..01d3a42 100644 --- a/face-server/pom.xml +++ b/face-server/pom.xml @@ -7,6 +7,7 @@ com.dkha 1.0-SNAPSHOT + jar 4.0.0 face-server @@ -78,6 +79,7 @@ mysql mysql-connector-java + 5.1.38 org.projectlombok diff --git a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java index 45c28d1..de520fc 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/FaceController.java +++ b/face-server/src/main/java/com/dkha/server/controllers/FaceController.java @@ -1,12 +1,26 @@ package com.dkha.server.controllers; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.dkha.common.fileupload.MinioUtil; import com.dkha.common.http.HttpUtil; +import com.dkha.common.modules.vo.face.ApiSearchFaceRectVO; import com.dkha.common.modules.vo.face.FaceResEntity; import com.dkha.common.modules.vo.CompareFaceList; +import com.dkha.common.modules.vo.search.SearchPortraitVo; +import com.dkha.common.modules.vo.search.SearchRequestVo; +import com.dkha.common.modules.vo.search.SearchResultVo; +import com.dkha.common.page.PageParam; import com.dkha.common.result.CommonResult; import com.dkha.common.modules.vo.ReturnVO; import com.dkha.common.util.JsonUtil; +import com.dkha.common.util.UtilValidate; +import com.dkha.server.mappers.PortraitMapper; +import com.dkha.server.modules.entities.Portrait; +import com.dkha.server.services.IPortraitService; import com.fasterxml.jackson.core.type.TypeReference; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; @@ -14,11 +28,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.*; +import java.util.function.Function; @RestController @@ -33,12 +50,15 @@ public class FaceController extends CommonResult { @Autowired private HttpUtil httpUtil; - private Gson gson =new Gson(); + @Autowired + private IPortraitService iPortraitService; + @Autowired + private PortraitMapper portraitMapper; + @Autowired + private Gson gson; private int count ; - private Map faceRes = new HashMap<>(); - private List facelist = new ArrayList<>(); private List compareFaceLists = new ArrayList<>(); @@ -137,27 +157,45 @@ public class FaceController extends CommonResult { //System.out.println("发送信息结束"); } - - public void sendWebsocket2(List oncompareFacelist){ compareFaceLists.clear(); - compareFaceLists = oncompareFacelist; +// compareFaceLists = oncompareFacelist; + for (CompareFaceList com :oncompareFacelist){ + if(UtilValidate.isNotEmpty(com.getName())){ + //根据人脸名称去找rphoto + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("name",com.getName()); + Portrait rphoto = iPortraitService.getBaseMapper().selectOne(queryWrapper); + System.out.println("rphoto"+rphoto); + com.setRphoto(rphoto.getUrl()); + } + if(com.getXsd()>70) { + System.out.println("相似度为:" + com.getXsd() + "%,小于70"); + compareFaceLists.add(com); + } + } + System.out.println(compareFaceLists); WebSocketContral webSocketContral =new WebSocketContral(); - webSocketContral.sendMessage(gson.toJson(oncompareFacelist)); + webSocketContral.sendMessage(gson.toJson(compareFaceLists)); } @PostMapping("/compareList") public void compareList( - @RequestBody List compareFaceLists ){ -// String compareURL = apiServerPrefix + ApiUrlEnum.ALARMS_POSTURL.getUrl(); -// ReturnVO returnVO = (ReturnVO) httpUtil.post(compareURL, list, ApiVO.class); -// CompareFaceList compareFaceList = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference() {}); -// compareFaceLists.add(compareFaceList); -// return successResult(compareFaceLists); + @RequestBody List faceLists ){ compareFaceLists.clear(); - for(CompareFaceList com: compareFaceLists ){ - compareFaceLists.add(com); + System.out.println("facelist"+faceLists); + for (CompareFaceList com :faceLists){ + if(UtilValidate.isNotEmpty(com.getName())){ + //人脸数量 + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.select("url").eq("name",com.getName()); + Portrait rphoto = portraitMapper.selectOne(queryWrapper); + System.out.println("rphoto:"+rphoto); +// com.setName(rphoto.getUrl()); + } +// compareFaceLists.add(com); } + System.out.println(compareFaceLists); } public List getFacelist() { diff --git a/face-server/src/main/java/com/dkha/server/controllers/WebSocketContral.java b/face-server/src/main/java/com/dkha/server/controllers/WebSocketContral.java index 34e7794..4874746 100644 --- a/face-server/src/main/java/com/dkha/server/controllers/WebSocketContral.java +++ b/face-server/src/main/java/com/dkha/server/controllers/WebSocketContral.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import javax.websocket.OnClose; import javax.websocket.OnMessage; @@ -52,7 +53,10 @@ public class WebSocketContral { private Session session; - private Gson gson=new Gson(); + + private FaceController faceController1; + + private Gson gson =new Gson(); private static CopyOnWriteArraySet webSocketSet=new CopyOnWriteArraySet(); public static Map myMap=new ConcurrentHashMap(); @@ -125,27 +129,28 @@ public class WebSocketContral { //System.out.println(message); if(UtilValidate.isNotEmpty(message)) { + log.info("【websocket消息】收到客户端消息:{}",message); ReturnVO returnVO=gson.fromJson(message,ReturnVO.class); //System.out.println(message); + faceController1 =applicationContext.getBean(FaceController.class); if(returnVO.getMessage().equals("okpro")) { if (UtilValidate.isNotEmpty(returnVO.getData())) { // List facelist =gson.fromJson(gson.toJson(returnVO.getData()),List.class); List onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference>() {}); - FaceController faceController = new FaceController(); - faceController.sendWebsocket1(onfacelist); + faceController1.sendWebsocket1(onfacelist); } } else if(returnVO.getMessage().equals("okplus")){ if (UtilValidate.isNotEmpty(returnVO.getData())) { // List facelist =gson.fromJson(gson.toJson(returnVO.getData()),List.class); List oncompareFaceLists = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference>() {}); - FaceController faceController = new FaceController(); - faceController.sendWebsocket2(oncompareFaceLists); +// FaceController faceController = new FaceController(); + faceController1.sendWebsocket2(oncompareFaceLists); } } } - log.info("【websocket消息】收到客户端消息:{}",message); + log.info("【websocket消息】收到客户端消息:{}","发送完成"); } diff --git a/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java b/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java index 4254dbf..30e16fb 100644 --- a/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java +++ b/face-server/src/main/java/com/dkha/server/services/impl/ControlTaskServiceImpl.java @@ -58,7 +58,8 @@ public class ControlTaskServiceImpl extends ServiceImpl resultMap = ( Map) httpUtil.post(link+ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class); - if(resultMap!=null){ - if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())) - { - Map data= (Map) resultMap.get("data"); - if(data!=null&&data.get("taskId")!=null){ - strTaskNo=data.get("taskId").toString(); - }else - { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!没有获取到任务编号"); - } - }else { - return new CommonResult(resultMap, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); - } - }else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); - } +// System.out.println("设置编码为:9249924"); +// Map resultMap = ( Map) httpUtil.post(link+ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class); +// if(resultMap!=null){ +// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())) +// { +// Map data= (Map) resultMap.get("data"); +// if(data!=null&&data.get("taskId")!=null){ +// strTaskNo=data.get("taskId").toString(); +// }else +// { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!没有获取到任务编号"); +// } +// }else { +// return new CommonResult(resultMap, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); +// } +// }else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); +// } +// strTaskNo="9249924"; + //后端处理taskID + Long testNo = System.currentTimeMillis(); + String testNostring = testNo.toString(); + System.out.println("设置编码为"+testNostring); + strTaskNo = testNostring; ControlTask controlTask = new ControlTask(); controlTask.setTaskNo(strTaskNo); @@ -262,17 +275,24 @@ public class ControlTaskServiceImpl extends ServiceImpl resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); - if (resultMap != null) { - if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ - isDeleteApi=true; - } - } else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); - } +// Map resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); +// if (resultMap != null) { +// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ +// isDeleteApi=true; +// } +// } else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); +// } if (isDeleteApi) { + List listfaceCamera = controlTaskMapper.getCameraByTaskID(taskID); + for (FaceCameraEntity faceCameraEntity : listfaceCamera){ + Long deleteID = faceCameraEntity.getIdFaceCamera(); + if (faceCameraEntity.getStatus().equals(YNEnums.YES.code)){ + faceCameraServiceImpl.status(deleteID,false); + } + } // 删除任务摄像头中间管理库 controlBayonetMidService.deletetaskandcarmerbytaskid(taskID); // 删除任务特征库中间管理库 @@ -321,18 +341,25 @@ public class ControlTaskServiceImpl extends ServiceImpl resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); - if (resultMap != null) { - if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())) { - isDeleteApi=true; - } - } else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); - } +// Map resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); +// if (resultMap != null) { +// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())) { +// isDeleteApi=true; +// } +// } else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); +// } if (isDeleteApi) { + List listfaceCamera = controlTaskMapper.getCameraByTaskID(taskID); + for (FaceCameraEntity faceCameraEntity : listfaceCamera){ + Long deleteID = faceCameraEntity.getIdFaceCamera(); + if (faceCameraEntity.getStatus().equals(YNEnums.YES.code)){ + faceCameraServiceImpl.status(deleteID,false); + } + } // 更新本地数据库的状态为N controlOne.setIsValid(TaskStatusEnum.STOP.code); this.updateById(controlOne); @@ -362,18 +389,25 @@ public class ControlTaskServiceImpl extends ServiceImpl resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); - if (resultMap != null) { - if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ - isDeleteApi=true; - } - } else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); - } +// Map resultMap = (Map) httpUtil.delete(link + ApiUrlEnum.TASK_POSTURL.getUrl() + "/" + controlOne.getTaskNo(), Map.class); +// if (resultMap != null) { +// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ +// isDeleteApi=true; +// } +// } else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API删除任务信息失败!"); +// } if (isDeleteApi) { + List listfaceCamera = controlTaskMapper.getCameraByTaskID(taskID); + for (FaceCameraEntity faceCameraEntity : listfaceCamera){ + Long deleteID = faceCameraEntity.getIdFaceCamera(); + if (faceCameraEntity.getStatus().equals(YNEnums.YES.code)){ + faceCameraServiceImpl.status(deleteID,false); + } + } // 更新本地数据库的状态为暂停 controlOne.setIsValid(TaskStatusEnum.SUSPEND.code); this.updateById(controlOne); @@ -409,6 +443,13 @@ public class ControlTaskServiceImpl extends ServiceImpl listfaceCamera = controlTaskMapper.getCameraByTaskID(taskID); + for (FaceCameraEntity faceCameraEntity : listfaceCamera){ + Long deleteID = faceCameraEntity.getIdFaceCamera(); + if (faceCameraEntity.getStatus().equals(YNEnums.NO.code)){ + faceCameraServiceImpl.status(deleteID,true); + } + } //根据任务ID获取人像中间库 List listLibMid = controlLibraryMidService.list(queryWrapper); //获取人像中间库 @@ -437,23 +478,24 @@ public class ControlTaskServiceImpl extends ServiceImpl resultMap = (Map) httpUtil.post(link + ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class); - if (resultMap != null) { - if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ - Map data = (Map) resultMap.get("data"); - if (data != null && data.get("taskId") != null) { - strTaskNo = data.get("taskId").toString(); - } else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); - } - } else { - return new CommonResult(resultMap, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); - } - } else { - return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); - } +// String strTaskNo = "000000"; +// Map resultMap = (Map) httpUtil.post(link + ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class); +// if (resultMap != null) { +// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){ +// Map data = (Map) resultMap.get("data"); +// if (data != null && data.get("taskId") != null) { +// strTaskNo = data.get("taskId").toString(); +// } else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); +// } +// } else { +// return new CommonResult(resultMap, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); +// } +// } else { +// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "远程API保存任务信息失败!"); +// } //3. 更新本地库任务的状态为RUN状态 + String strTaskNo = controlOne.getTaskNo(); controlOne.setTaskNo(strTaskNo); controlOne.setIsValid(TaskStatusEnum.RUN.code); this.updateById(controlOne); @@ -518,16 +560,17 @@ public class ControlTaskServiceImpl extends ServiceImpl result=new HashMap<>(); result.put("libid",faceLibrar.getIdFactory().toString()); - result.put("url",portrait.getBackgroundUrl()); + result.put("url",url); return new CommonResult(result,SystemCode.HANDLER_SUCCESS.code,"人像文件上传成功!"); } diff --git a/face-server/src/main/resources/application-dev.yml b/face-server/src/main/resources/application-dev.yml index 9951bbf..6a36375 100644 --- a/face-server/src/main/resources/application-dev.yml +++ b/face-server/src/main/resources/application-dev.yml @@ -25,7 +25,7 @@ spring: druid: #MySQL driver-class-name: com.mysql.jdbc.Driver - url: jdbc:mysql://192.168.1.127:3306/face_application_23_3?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + url: jdbc:mysql://192.168.1.127:3306/face_application_23_3?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: root password: Dkha123 initial-size: 10 @@ -92,7 +92,7 @@ mybatis-plus: cache-enabled: false call-setters-on-nulls: true jdbc-type-for-null: 'null' - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 用于控制swagger是否显示 swagger: diff --git a/face-server/src/main/resources/logback-spring.xml b/face-server/src/main/resources/logback-spring.xml index 7239257..121ca79 100644 --- a/face-server/src/main/resources/logback-spring.xml +++ b/face-server/src/main/resources/logback-spring.xml @@ -19,7 +19,7 @@ - /mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/trace.%d{yyyy-MM-dd}.%i.log + /home/cb/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/trace.%d{yyyy-MM-dd}.%i.log 500MB @@ -32,9 +32,9 @@ - /appSystems/logs/error.%d{yyyy-MM-dd}.%i.log + /home/cb/mnt/appSystems/logs/error.%d{yyyy-MM-dd}.%i.log - /mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log + /home/cb/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log 500MB