refactor(huawei): 封装返回结果
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
5d81537bdb
commit
2a36ddf688
@ -1,6 +1,7 @@
|
||||
package org.dromara.sis.sdk.huawei;
|
||||
|
||||
import org.dromara.sis.sdk.huawei.domain.AddHWPersonReq;
|
||||
import org.dromara.sis.sdk.huawei.domain.HWResult;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -35,5 +36,5 @@ public interface HuaWeiBoxApi {
|
||||
* @param base64Img 入参
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> findPerson(String base64Img);
|
||||
HWResult findPerson(String base64Img);
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package org.dromara.sis.sdk.huawei.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author lsm
|
||||
* @apiNote HWResult
|
||||
* @since 2025/8/5
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class HWResult {
|
||||
|
||||
public Integer code;
|
||||
|
||||
public String message;
|
||||
}
|
@ -8,6 +8,7 @@ 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.domain.HWResult;
|
||||
import org.dromara.sis.sdk.huawei.utils.HuaWeiHttp;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -88,7 +89,7 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
|
||||
* @return Long
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findPerson(String base64Img) {
|
||||
public HWResult findPerson(String base64Img) {
|
||||
String url = "/sdk_service/rest/facerepositories/peoples";
|
||||
|
||||
FinaHWPersonReq req = new FinaHWPersonReq();
|
||||
@ -99,42 +100,26 @@ public class HuaWeiBoxApiService implements HuaWeiBoxApi {
|
||||
String jsonReq = JSONUtil.toJsonStr(req);
|
||||
String jsonStrRes = huaWeiHttp.doPost(url, jsonReq);
|
||||
JSONObject jsonRes = JSONUtil.parseObj(jsonStrRes);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (jsonRes.getInt("resultCode") != 0) {
|
||||
switch (jsonRes.getInt("resultCode")) {
|
||||
case 912322041:
|
||||
result.put("code", 912322041);
|
||||
result.put("msg", "特征值提取失败");
|
||||
break;
|
||||
case 912322022:
|
||||
result.put("code", 912333003);
|
||||
result.put("msg", "base64参数非法");
|
||||
break;
|
||||
default:
|
||||
result.put("code", jsonRes.getInt("resultCode"));
|
||||
result.put("msg", jsonRes.getStr("resultMsg"));
|
||||
break;
|
||||
}
|
||||
log.info("调用华为盒子人脸比对接口失败,code:{},msg:{}", jsonRes.getInt("resultCode"), jsonRes.getStr("resultMsg"));
|
||||
return result;
|
||||
return switch (jsonRes.getInt("resultCode")) {
|
||||
case 912322041 -> new HWResult(912322041, "特征值提取失败");
|
||||
case 912333003 -> new HWResult(912333003, "base64参数非法");
|
||||
default -> new HWResult(jsonRes.getInt("resultCode"), jsonRes.getStr("resultMsg"));
|
||||
};
|
||||
}
|
||||
|
||||
JSONArray jsonArr = jsonRes.getJSONArray("algorithmResults");
|
||||
JSONObject obj = jsonArr.getJSONObject(0);
|
||||
|
||||
if (Integer.parseInt(obj.getStr("number")) == 0) {
|
||||
result.put("code", 201);
|
||||
result.put("msg", "无匹配数据");
|
||||
log.info("无人脸比对数据");
|
||||
return null;
|
||||
return new HWResult(201, "无匹配数据");
|
||||
}
|
||||
|
||||
JSONArray peopleList = obj.getJSONArray("peopleList");
|
||||
JSONObject people = peopleList.getJSONObject(0);
|
||||
|
||||
result.put("code", 200);
|
||||
result.put("msg", Long.parseLong(people.getStr("peopleId")));
|
||||
return result;
|
||||
return new HWResult(200, people.getStr("peopleId"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user