获取新增人员id
parent
3cbc28e17f
commit
1d8809bbdf
|
|
@ -35,7 +35,7 @@ public class DaHuaController {
|
|||
|
||||
@ApiOperation("同步人员到大华平台-新增")
|
||||
@PostMapping("/person/sync")
|
||||
public SingleResponse<Boolean> syncPerson(@Validated @RequestBody DaHuaPersonSyncCmd cmd) {
|
||||
public SingleResponse<Object> syncPerson(@Validated @RequestBody DaHuaPersonSyncCmd cmd) {
|
||||
|
||||
if (daHuaService == null) {
|
||||
throw new RuntimeException("大华服务未配置");
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class DaHuaServiceImpl implements DaHuaServiceI {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SingleResponse<Boolean> syncPerson(DaHuaPersonSyncCmd cmd) {
|
||||
public SingleResponse<Object> syncPerson(DaHuaPersonSyncCmd cmd) {
|
||||
Long personId = daHuaGateway.generatePersonId();
|
||||
System.out.println("大华自动生成人员ID: " + personId);
|
||||
cmd.setId(personId);
|
||||
|
|
@ -37,12 +37,13 @@ public class DaHuaServiceImpl implements DaHuaServiceI {
|
|||
Boolean dhSuccess = (Boolean) syncResult.get("success");
|
||||
String dhCode = (String) syncResult.get("code");
|
||||
String dhErrMsg = (String) syncResult.get("errMsg");
|
||||
SingleResponse<Boolean> resp = new SingleResponse<>();
|
||||
Object dhData = syncResult.get("dhData");
|
||||
SingleResponse<Object> resp = new SingleResponse<>();
|
||||
resp.setSuccess(dhSuccess != null ? dhSuccess : passed);
|
||||
resp.setErrCode(dhCode);
|
||||
resp.setErrMessage(dhErrMsg);
|
||||
resp.setData(passed);
|
||||
System.out.println("大华同步人员最终返回 - success:" + resp.isSuccess() + ", errCode:" + resp.getErrCode() + ", errMessage:" + resp.getErrMessage() + ", data:" + resp.getData());
|
||||
resp.setData(dhData);
|
||||
System.out.println("大华同步人员最终返回 - success:" + resp.isSuccess() + ", errCode:" + resp.getErrCode() + ", errMessage:" + resp.getErrMessage() + ", data(dhData):" + dhData);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public interface DaHuaServiceI {
|
|||
|
||||
SingleResponse<Long> generatePersonId();
|
||||
|
||||
SingleResponse<Boolean> syncPerson(DaHuaPersonSyncCmd cmd);
|
||||
SingleResponse<Object> syncPerson(DaHuaPersonSyncCmd cmd);
|
||||
|
||||
SingleResponse<Boolean> updatePerson(DaHuaPersonSyncCmd cmd);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,19 +91,44 @@ public class DaHuaGatewayImpl implements DaHuaGateway {
|
|||
resultMap.put("success", false);
|
||||
resultMap.put("code", "SYSTEM_ERROR");
|
||||
resultMap.put("errMsg", "response为null");
|
||||
resultMap.put("dhData", null);
|
||||
return resultMap;
|
||||
}
|
||||
JSONObject jsonObject = JSONUtil.parseObj(responseJson);
|
||||
Boolean dhSuccess = jsonObject.getBool("success", false);
|
||||
String dhCode = jsonObject.getStr("code", response.getCode());
|
||||
String dhErrMsg = jsonObject.getStr("errMsg", "");
|
||||
String dhResult = jsonObject.getStr("result", "");
|
||||
Object dhResultObj = jsonObject.get("result");
|
||||
Object dhData = jsonObject.get("data");
|
||||
if (dhResultObj != null) {
|
||||
try {
|
||||
JSONObject bizObj;
|
||||
if (dhResultObj instanceof String) {
|
||||
bizObj = JSONUtil.parseObj((String) dhResultObj);
|
||||
} else if (dhResultObj instanceof JSONObject) {
|
||||
bizObj = (JSONObject) dhResultObj;
|
||||
} else {
|
||||
bizObj = JSONUtil.parseObj(JSONUtil.toJsonStr(dhResultObj));
|
||||
}
|
||||
dhSuccess = bizObj.getBool("success", dhSuccess);
|
||||
dhCode = bizObj.getStr("code", dhCode);
|
||||
dhErrMsg = bizObj.getStr("errMsg", dhErrMsg);
|
||||
Object tmpData = bizObj.get("data");
|
||||
if (tmpData != null) {
|
||||
dhData = tmpData;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("大华同步人员解析result字段失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
boolean passed = "0".equals(dhCode);
|
||||
resultMap.put("passed", passed);
|
||||
resultMap.put("success", dhSuccess);
|
||||
resultMap.put("code", dhCode);
|
||||
resultMap.put("errMsg", dhErrMsg);
|
||||
resultMap.put("result", dhResult);
|
||||
resultMap.put("result", dhResultObj);
|
||||
resultMap.put("dhData", dhData);
|
||||
System.out.println("大华同步人员返回dhData: " + dhData);
|
||||
if (!passed) {
|
||||
log.error("大华同步人员失败: code={}, errMsg={}, response={}", dhCode, dhErrMsg, responseJson);
|
||||
System.out.println("大华同步人员失败: code=" + dhCode + ", errMsg=" + dhErrMsg);
|
||||
|
|
@ -115,6 +140,7 @@ public class DaHuaGatewayImpl implements DaHuaGateway {
|
|||
resultMap.put("success", false);
|
||||
resultMap.put("code", "CLIENT_EXCEPTION");
|
||||
resultMap.put("errMsg", e.getMessage());
|
||||
resultMap.put("dhData", null);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue