4.25日部署服务器

master
coco1986509808 2023-04-25 23:52:46 +08:00
parent ccc03b8cb1
commit 0a4da40b6b
6 changed files with 183 additions and 95 deletions

View File

@ -7,6 +7,7 @@
<groupId>com.dkha</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<artifactId>face-server</artifactId>
@ -78,6 +79,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -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<String,FaceResEntity> faceRes = new HashMap<>();
private List<FaceResEntity> facelist = new ArrayList<>();
private List<CompareFaceList> compareFaceLists = new ArrayList<>();
@ -137,27 +157,45 @@ public class FaceController extends CommonResult {
//System.out.println("发送信息结束");
}
public void sendWebsocket2(List<CompareFaceList> oncompareFacelist){
compareFaceLists.clear();
compareFaceLists = oncompareFacelist;
// compareFaceLists = oncompareFacelist;
for (CompareFaceList com :oncompareFacelist){
if(UtilValidate.isNotEmpty(com.getName())){
//根据人脸名称去找rphoto
QueryWrapper<Portrait> 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<CompareFaceList> 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<CompareFaceList>() {});
// compareFaceLists.add(compareFaceList);
// return successResult(compareFaceLists);
@RequestBody List<CompareFaceList> 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<Portrait> 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<FaceResEntity> getFacelist() {

View File

@ -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<WebSocketContral> webSocketSet=new CopyOnWriteArraySet<WebSocketContral>();
public static Map<String, WebSocketContral> 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<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class);
List<FaceResEntity> onfacelist = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<FaceResEntity>>() {});
FaceController faceController = new FaceController();
faceController.sendWebsocket1(onfacelist);
faceController1.sendWebsocket1(onfacelist);
}
}
else if(returnVO.getMessage().equals("okplus")){
if (UtilValidate.isNotEmpty(returnVO.getData())) {
// List<FaceResEntity> facelist =gson.fromJson(gson.toJson(returnVO.getData()),List<FaceResEntity>.class);
List<CompareFaceList> oncompareFaceLists = JsonUtil.string2Obj(JsonUtil.obj2String(returnVO.getData()), new TypeReference<List<CompareFaceList>>() {});
FaceController faceController = new FaceController();
faceController.sendWebsocket2(oncompareFaceLists);
// FaceController faceController = new FaceController();
faceController1.sendWebsocket2(oncompareFaceLists);
}
}
}
log.info("【websocket消息】收到客户端消息{}",message);
log.info("【websocket消息】收到客户端消息{}","发送完成");
}

View File

@ -58,7 +58,8 @@ public class ControlTaskServiceImpl extends ServiceImpl<ControlTaskMapper, Contr
ControlLibraryMidMapper controlLibraryMidMapper;
@Autowired
ControlLibraryMidServiceImpl controlLibraryMidService;
@Autowired
FaceCameraServiceImpl faceCameraServiceImpl;
@Autowired
private IPortraitService iPortraitService;
@ -144,6 +145,11 @@ public class ControlTaskServiceImpl extends ServiceImpl<ControlTaskMapper, Contr
for (String camerid : listcamera) {
ControlBayonetMid controlBayonetMid = new ControlBayonetMid();
FaceCameraEntity faceCamera = faceCameraService.getById(camerid);
System.out.println(faceCamera.getStatus());
if (faceCamera.getStatus().equals(YNEnums.NO.code)){
faceCameraServiceImpl.status(faceCamera.getIdFaceCamera(),true);
}
System.out.println(faceCamera.getStatus());
if (controlBayonetMidService.selectexistByCarmeID(camerid) == 0) {
//依次判断摄像头是否添加到任务中
controlBayonetMid.setIsValid(YNEnums.YES.code);
@ -183,23 +189,30 @@ public class ControlTaskServiceImpl extends ServiceImpl<ControlTaskMapper, Contr
ctvo.setThreshold(taskvo.getControlThreshold());
ctvo.setCameraId(camerList);
ctvo.setLibraryId(taskvo.getLibIds());
Map<String,Object> resultMap = ( Map<String,Object>) httpUtil.post(link+ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class);
if(resultMap!=null){
if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString()))
{
Map<String,Object> data= (Map<String,Object>) 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<String,Object> resultMap = ( Map<String,Object>) httpUtil.post(link+ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class);
// if(resultMap!=null){
// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString()))
// {
// Map<String,Object> data= (Map<String,Object>) 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<ControlTaskMapper, Contr
return new CommonResult(null, SystemCode.ILLEGAL_ARGUMENT_EXCEPTION.code, "参数异常非法的任务ID");
} else {
try {
boolean isDeleteApi = false;
boolean isDeleteApi = true;
//1. 调用平台API接口
Map<String, Object> resultMap = (Map<String, Object>) 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<String, Object> resultMap = (Map<String, Object>) 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<FaceCameraEntity> 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<ControlTaskMapper, Contr
if (controlOne == null) {
return new CommonResult(null, SystemCode.ILLEGAL_ARGUMENT_EXCEPTION.code, "参数异常非法的任务ID");
} else {
boolean isDeleteApi = false;
boolean isDeleteApi = true;
try{
//1. 调用平台API接口
Map<String, Object> resultMap = (Map<String, Object>) 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<String, Object> resultMap = (Map<String, Object>) 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<FaceCameraEntity> 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<ControlTaskMapper, Contr
if (controlOne == null) {
return new CommonResult(null, SystemCode.ILLEGAL_ARGUMENT_EXCEPTION.code, "参数异常非法的任务ID");
} else {
boolean isDeleteApi = false;
boolean isDeleteApi = true;
try{
//1. 调用平台API接口
Map<String, Object> resultMap = (Map<String, Object>) 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<String, Object> resultMap = (Map<String, Object>) 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<FaceCameraEntity> 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<ControlTaskMapper, Contr
if (UtilValidate.isEmpty(listBayoneMid)) {
return new CommonResult(controlOne.getTaskName(), SystemCode.ILLEGAL_ARGUMENT_EXCEPTION.code, "恢复任务失败,该任务下没有查询到有效摄像头列表!");
}
List<FaceCameraEntity> 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<ControlLibraryMid> listLibMid = controlLibraryMidService.list(queryWrapper);
//获取人像中间库
@ -437,23 +478,24 @@ public class ControlTaskServiceImpl extends ServiceImpl<ControlTaskMapper, Contr
try {
//2. 发送任务到API层
// 调用平台API接口
String strTaskNo = "000000";
Map<String, Object> resultMap = (Map<String, Object>) httpUtil.post(link + ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class);
if (resultMap != null) {
if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){
Map<String, Object> data = (Map<String, Object>) 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<String, Object> resultMap = (Map<String, Object>) httpUtil.post(link + ApiUrlEnum.TASK_POSTURL.getUrl(), ctvo, Map.class);
// if (resultMap != null) {
// if(ErrEnum.OK.getCode().toString().equalsIgnoreCase(resultMap.get("code").toString())){
// Map<String, Object> data = (Map<String, Object>) 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<ControlTaskMapper, Contr
return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, "生成特征库识别!");
}
//2.添加人脸信息特征
Portrait portrait;
try {
portrait = iPortraitService.addPortraitPngs(faceLibrar.getIdFactory().toString(), url);
} catch (Exception e) {
log.error("上传人像异常"+e.getMessage());
return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, e.getMessage());
}
// Portrait portrait;
// try {
// System.out.println(faceLibrar.getIdFactory().toString());
// portrait = iPortraitService.addPortraitPngs(faceLibrar.getIdFactory().toString(), url);
// } catch (Exception e) {
// log.error("上传人像异常"+e.getMessage());
// return new CommonResult(null, SystemCode.INTERNAL_PROGRAM_ERROR.code, e.getMessage());
// }
Map<String,Object> 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,"人像文件上传成功!");
}

View File

@ -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:

View File

@ -19,7 +19,7 @@
<appender name="traceFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/trace.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>/home/cb/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/trace.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!--访问日志最大500M-->
<maxFileSize>500MB</maxFileSize>
<!-- 保留10天 -->
@ -32,9 +32,9 @@
<appender name="errorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/appSystems/logs/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>/home/cb/mnt/appSystems/logs/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- rollover daily -->
<fileNamePattern>/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>/home/cb/mnt/appSystems/logs/${app_name}/%d{yyyy-MM, aux}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!--访问日志最大500M-->
<maxFileSize>500MB</maxFileSize>
<!-- 保留10天 -->