package com.vincent.rsf.server.api.integration.dap;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 鼎捷 DAP 返回结构转云仓上报内部统一格式(供重试任务判断 code==200)
|
*/
|
public final class DapIlcwmsResponseNormalizer {
|
|
private DapIlcwmsResponseNormalizer() {
|
}
|
|
public static Map<String, Object> toNotifyFormat(Map<String, Object> dapBody) {
|
if (dapBody == null) {
|
return resultMap(500, "云仓返回空", null);
|
}
|
Object st = dapBody.get("status");
|
int status = 0;
|
if (st instanceof Number) {
|
status = ((Number) st).intValue();
|
}
|
if (status == 200) {
|
return resultMap(200, "OK", dapBody);
|
}
|
Object err = dapBody.get("errorMessage");
|
String msg = err != null ? String.valueOf(err) : String.valueOf(dapBody.get("statusDescription"));
|
if (msg == null || "null".equals(msg)) {
|
msg = "云仓返回失败";
|
}
|
return resultMap(500, msg, dapBody);
|
}
|
|
/**
|
* 9.2 等仍走旧路径的接口:若返回无顶层 status,则按原 code/msg 透传(兼容旧云仓 JSON)。
|
*/
|
public static Map<String, Object> toNotifyFormatFlexible(Map<String, Object> body) {
|
if (body == null) {
|
return toNotifyFormat(null);
|
}
|
if (body.containsKey("status")) {
|
return toNotifyFormat(body);
|
}
|
if (body.containsKey("code")) {
|
return body;
|
}
|
return toNotifyFormat(body);
|
}
|
|
private static Map<String, Object> resultMap(int code, String msg, Map<String, Object> data) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("code", code);
|
map.put("msg", msg);
|
map.put("data", data);
|
return map;
|
}
|
}
|