Commit 968ab2d3 authored by 赵啸非's avatar 赵啸非

添加服务追踪

parent 2393d963
package com.mortals.xhx.daemon.task;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.utils.ServletUtils;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.hik.face.model.req.img.ImgReq;
import com.mortals.xhx.module.hik.face.service.IHikFaceService;
import com.mortals.xhx.module.realtime.model.RealtimeDataflowEntity;
import com.mortals.xhx.module.realtime.model.RealtimeDataflowQuery;
import com.mortals.xhx.module.realtime.model.RealtimeDataflowStatEntity;
......@@ -14,10 +21,15 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import static java.util.stream.Collectors.toList;
/**
* 人流统计接口
*/
......@@ -29,6 +41,10 @@ public class RealTimePeopleStatTaskImpl implements ITaskExcuteService {
private RealtimeDataflowService realtimeDataflowService;
@Autowired
private RealtimeDataflowStatService realtimeDataflowStatService;
@Autowired
private IHikFaceService faceService;
@Autowired
private UploadService uploadService;
@Override
......@@ -36,6 +52,8 @@ public class RealTimePeopleStatTaskImpl implements ITaskExcuteService {
statPeople();
donwnloadSnap();
}
private void statPeople() {
......@@ -91,6 +109,37 @@ public class RealTimePeopleStatTaskImpl implements ITaskExcuteService {
}
private void donwnloadSnap() {
//下载最近一天的抓拍数据
RealtimeDataflowQuery realtimeDataflowQuery = new RealtimeDataflowQuery();
realtimeDataflowQuery.setDetectTimeStart(DateUtil.yesterday().toStringDefaultTimeZone());
//realtimeDataflowQuery.setPicture("");
List<RealtimeDataflowEntity> updateList = realtimeDataflowService.find(realtimeDataflowQuery).stream().filter(f -> ObjectUtils.isEmpty(f.getPicture()) && !ObjectUtils.isEmpty(f.getPicUri())).map(item -> {
ImgReq imgReq = new ImgReq();
imgReq.setUrl(item.getPicUri());
Rest<String> rest = faceService.downloadPicture(imgReq);
if (YesNoEnum.YES.getValue() == rest.getCode()) {
byte[] bytes = Base64.decode(rest.getData());
if (bytes.length > 0) {
InputStream inputStream = new ByteArrayInputStream(bytes);
MultipartFile file = ServletUtils.getMultipartFile(inputStream, "snap.jpg");
String filePath = uploadService.saveFileUpload(file, "file/fileupload", null);
item.setPicture(filePath);
item.setUpdateTime(new Date());
item.setUpdateUserId(1L);
item.setUpdateUserName("system");
return item;
}
}
return null;
}).filter(f -> f != null).collect(toList());
if (ObjectUtils.isEmpty(updateList)) {
realtimeDataflowService.update(updateList, null);
}
}
@Override
public void stopTask(ITask task) throws AppException {
......
......@@ -8,4 +8,6 @@ public class ImgReq {
private String svrIndexCode;
private String picUri;
private String url;
}
......@@ -18,6 +18,7 @@ import java.util.List;
/**
* 海康门禁接口对接类
*
* @author:
* @date: 2023/4/12 17:47
*/
......@@ -26,6 +27,7 @@ public interface IHikFaceService {
/**
* 查询人脸
*
* @param faceListReq
* @return
*/
......@@ -34,6 +36,7 @@ public interface IHikFaceService {
/**
* 添加单个人脸
*
* @param faceReq
* @return
*/
......@@ -41,6 +44,7 @@ public interface IHikFaceService {
/**
* 修改单个人脸
*
* @param faceReq
* @return
*/
......@@ -48,6 +52,7 @@ public interface IHikFaceService {
/**
* 删除单个人脸
*
* @param faceReq
* @return
*/
......@@ -55,6 +60,7 @@ public interface IHikFaceService {
/**
* 查询人脸分组
*
* @param faceGroupReq
* @return
*/
......@@ -62,6 +68,7 @@ public interface IHikFaceService {
/**
* 添加人脸分组
*
* @param faceGroupReq
* @return
*/
......@@ -69,6 +76,7 @@ public interface IHikFaceService {
/**
* 删除人脸分组
*
* @param faceGroupReq
* @return
*/
......@@ -77,21 +85,31 @@ public interface IHikFaceService {
/**
* 查询人脸资源
*
* @param recognReq
* @return
*/
Rest<List<ResRecognDataInfo>> findResRecognList(ResRecognReq recognReq);
/**
* 下载抓拍人脸图片
*
* @param imgReq
* @return
*/
Rest<String> downloadPicture(ImgReq imgReq);
/**
* 获取识别资源
*
* @param recognReq
* @return
*/
Rest<List<ResourceDataInfo>> getResourceRecognition(ResourceReq recognReq);
InputStream callPostImgs(ImgReq imgReq) throws Exception;
InputStream callPostImgs(ImgReq imgReq) throws Exception;
}
......@@ -221,6 +221,28 @@ public class HikFaceServiceImpl extends AbstractHikService implements IHikFaceSe
}
}
@Override
public Rest<String> downloadPicture(ImgReq imgReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/frs/v1/application/picture";
path.put(protocol, getCamsApi);
try {
log.info("download img req=>{}", JSON.toJSONString(imgReq));
String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(imgReq), null, null, "application/json");
//log.info("face single add resp=>{}", respJson);
HikApiRest<String> rest = JSON.parseObject(respJson, new TypeReference<HikApiRest<String>>() {
});
if ("0".equals(rest.getCode())) {
return Rest.ok(rest.getMsg(), rest.getData());
} else {
return Rest.fail(rest.getMsg());
}
} catch (Exception e) {
log.error("img download error异常", e);
return Rest.fail(e.getMessage());
}
}
@Override
public Rest<List<ResourceDataInfo>> getResourceRecognition(ResourceReq recognReq) {
ArtemisConfig config = getArtemisConfig();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment