refactor(sis):
- 同步删除华为盒子人像 - 华为盒子人脸比对接口
This commit is contained in:
parent
d70d99fb9a
commit
7db6d2adac
@ -89,4 +89,9 @@ public class SisPersonLibImgVo implements Serializable {
|
||||
@ExcelProperty(value = "出生日期")
|
||||
private String birthDate;
|
||||
|
||||
/**
|
||||
* 远程库图像ID
|
||||
*/
|
||||
@ExcelProperty(value = "远程库图像ID")
|
||||
private Long remoteImgId;
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package org.dromara.sis.sdk.huawei;
|
||||
|
||||
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
|
||||
import org.dromara.sis.sdk.huawei.domain.FinaHWPersonReq;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -19,4 +21,19 @@ public interface HuaWeiBoxApi {
|
||||
*/
|
||||
Long addPerson(List<AddHWPersonReq> req);
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
*
|
||||
* @param ids 入参
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean deletePerson(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据抓拍图片比对,返回人员ID
|
||||
*
|
||||
* @param req 入参
|
||||
* @return Long
|
||||
*/
|
||||
Long findPerson(FinaHWPersonReq req);
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package org.dromara.sis.sdk.huawei.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
* @apiNote FinaHWPersonReq
|
||||
* @since 2025/7/10
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class FinaHWPersonReq {
|
||||
/**
|
||||
* 人员库ID
|
||||
*/
|
||||
private String groupids = "201";
|
||||
/**
|
||||
* 相似度
|
||||
*/
|
||||
private String similarityThreshold = "85";
|
||||
/**
|
||||
* page
|
||||
*/
|
||||
private PageDTO page;
|
||||
/**
|
||||
* picture
|
||||
*/
|
||||
private PictureDTO picture;
|
||||
|
||||
/**
|
||||
* PageDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class PageDTO {
|
||||
|
||||
/**
|
||||
* no
|
||||
*/
|
||||
private String no = "1";
|
||||
|
||||
/**
|
||||
* size
|
||||
*/
|
||||
private String size = "100";
|
||||
|
||||
/**
|
||||
* sort
|
||||
*/
|
||||
private String sort = "desc";
|
||||
|
||||
/**
|
||||
* orderName
|
||||
*/
|
||||
private String orderName = "similarity";
|
||||
}
|
||||
|
||||
/**
|
||||
* PictureDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class PictureDTO {
|
||||
/**
|
||||
* base64
|
||||
*/
|
||||
private String base64;
|
||||
}
|
||||
}
|
@ -7,10 +7,13 @@ import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sis.sdk.huawei.HuaWeiBoxApi;
|
||||
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
|
||||
import org.dromara.sis.sdk.huawei.domain.FinaHWPersonReq;
|
||||
import org.dromara.sis.sdk.huawei.utils.HuaWeiHttp;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
@ -42,7 +45,7 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
|
||||
JSONObject jsonRes = JSONUtil.parseObj(jsonStrRes);
|
||||
|
||||
if (jsonRes.getInt("resultCode") != 0) {
|
||||
log.error("新增图片失败,msg:{}", jsonRes.getStr("resultMsg"));
|
||||
log.error("华为盒子新增图片失败,msg:{}", jsonRes.getStr("resultMsg"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -50,4 +53,57 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
|
||||
JSONObject obj = jsonArr.getJSONObject(0);
|
||||
return Long.parseLong(obj.getStr("peopleId"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
*
|
||||
* @param ids 图片id
|
||||
* @return Boolean
|
||||
*/
|
||||
@Override
|
||||
public Boolean deletePerson(Collection<Long> ids) {
|
||||
String url = "/sdk_service/rest/facerepositories/201/peoples";
|
||||
|
||||
String idStr = ids.stream().map(String::valueOf).collect(Collectors.joining(","));
|
||||
JSONObject json = new JSONObject();
|
||||
json.putOnce("ids", idStr);
|
||||
|
||||
String jsonStrRes = huaWeiHttp.doGetOrDel(url, json.toString(), true);
|
||||
JSONObject jsonRes = JSONUtil.parseObj(jsonStrRes);
|
||||
|
||||
if (jsonRes.getInt("resultCode") != 0) {
|
||||
log.error("华为盒子删除图片失败,msg:{}", jsonRes.getStr("resultMsg"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据抓拍图片比对,返回人员ID
|
||||
*
|
||||
* @param req 入参
|
||||
* @return Long
|
||||
*/
|
||||
@Override
|
||||
public Long findPerson(FinaHWPersonReq req){
|
||||
String url = "/sdk_service/rest/facerepositories/peoples";
|
||||
|
||||
String jsonReq = JSONUtil.toJsonStr(req);
|
||||
String jsonStrRes = huaWeiHttp.doPost(url, jsonReq);
|
||||
JSONObject jsonRes = JSONUtil.parseObj(jsonStrRes);
|
||||
|
||||
if (jsonRes.getInt("resultCode") != 0) {
|
||||
log.error("华为盒子人脸比对败,msg:{}", jsonRes.getStr("resultMsg"));
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONArray jsonArr = jsonRes.getJSONArray("algorithmCode");
|
||||
JSONObject obj = jsonArr.getJSONObject(0);
|
||||
|
||||
JSONArray peopleList = obj.getJSONArray("peopleList");
|
||||
JSONObject people = peopleList.getJSONObject(0);
|
||||
|
||||
return Long.parseLong(people.getStr("peopleId"));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
package org.dromara.sis.sdk.huawei.utils;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.redis.utils.RedisUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
* @apiNote HuaWeiHttp
|
||||
@ -32,10 +37,10 @@ public class HuaWeiHttp {
|
||||
// 发送请求获取响应
|
||||
// 使用 try-with-resources 确保资源释放
|
||||
try (HttpResponse response = HttpRequest.post(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.body(jsonStr)
|
||||
.execute()) {
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.body(jsonStr)
|
||||
.execute()) {
|
||||
if (response.getStatus() == 200 && response.getCookie("JSESSIONID") != null) {
|
||||
RedisUtils.setCacheObject("JSESSIONID", response.getCookie("JSESSIONID").toString());
|
||||
RedisUtils.expire("JSESSIONID", 1800);
|
||||
@ -47,7 +52,14 @@ public class HuaWeiHttp {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String doPost(String url, String json) {
|
||||
/**
|
||||
* 发起Post请求
|
||||
*
|
||||
* @param jsonStr 请求入参
|
||||
* @param url 请求接口
|
||||
* @return 请求结果
|
||||
*/
|
||||
public String doPost(String url, String jsonStr) {
|
||||
if (!RedisUtils.isExistsObject("JSESSIONID")) {
|
||||
if (!this.login()) {
|
||||
RedisUtils.deleteObject("JSESSIONID");
|
||||
@ -58,11 +70,11 @@ public class HuaWeiHttp {
|
||||
String api = BASE_URL + url;
|
||||
|
||||
try (HttpResponse response = HttpRequest.post(api)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.header("Cookie", RedisUtils.getCacheObject("JSESSIONID"))
|
||||
.body(json)
|
||||
.execute()) {
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.header("Cookie", RedisUtils.getCacheObject("JSESSIONID"))
|
||||
.body(jsonStr)
|
||||
.execute()) {
|
||||
if (response.isOk()) {
|
||||
return response.body();
|
||||
} else {
|
||||
@ -71,4 +83,40 @@ public class HuaWeiHttp {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起Get/Delete请求
|
||||
*
|
||||
* @param url 请求接口
|
||||
* @param jsonStr 请求入参
|
||||
* @return 请求结果
|
||||
*/
|
||||
public String doGetOrDel(String url, String jsonStr, Boolean isDelete) {
|
||||
if (!RedisUtils.isExistsObject("JSESSIONID")) {
|
||||
if (!this.login()) {
|
||||
RedisUtils.deleteObject("JSESSIONID");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String api = BASE_URL + url;
|
||||
|
||||
if (isDelete) {
|
||||
// 直接转换为Map
|
||||
Map<String, Object> map = JSONUtil.toBean(jsonStr, new TypeReference<>() {
|
||||
}, false);
|
||||
|
||||
String fullUrl = HttpUtil.urlWithForm(api, map, null, false);
|
||||
|
||||
try (HttpResponse response = HttpRequest.delete(fullUrl)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Cache-Control", "no-cache")
|
||||
.header("Cookie", RedisUtils.getCacheObject("JSESSIONID"))
|
||||
.execute()) {
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
|
||||
Assert.notNull(add, "数据处理失败");
|
||||
boolean flag;
|
||||
try {
|
||||
log.info("准备写入华为盒子,imgName={}", bo.getImgName());
|
||||
AddHWPersonReq req = new AddHWPersonReq();
|
||||
req.setIndex(CodePrefixConstants.PERSON_LIB_IMAGE_CODE_PREFIX + IdUtil.getSnowflakeNextIdStr());
|
||||
req.setName(bo.getImgName());
|
||||
@ -127,6 +128,7 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
|
||||
|
||||
Long pId = huaWeiBoxApi.addPerson(List.of(req));
|
||||
Assert.notNull(pId, "调用华为盒子新增图片失败");
|
||||
log.info("写入华为盒子完成,pId={}", pId);
|
||||
|
||||
add.setRemoteImgId(pId);
|
||||
flag = baseMapper.insert(add) > 0;
|
||||
@ -168,6 +170,17 @@ public class SisPersonLibImgServiceImpl implements ISisPersonLibImgService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
List<SisPersonLibImgVo> list = this.queryListByIds(ids);
|
||||
Collection<Long> remoteIds = list.stream().map(SisPersonLibImgVo::getRemoteImgId).toList();
|
||||
|
||||
if (!remoteIds.isEmpty()) {
|
||||
Boolean flag = huaWeiBoxApi.deletePerson(remoteIds);
|
||||
Assert.isTrue(flag, "调用华为盒子删除图片失败");
|
||||
}
|
||||
|
||||
boolean flag = baseMapper.deleteByIds(ids) > 0;
|
||||
Assert.isTrue(flag, "删除失败");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user