cl
4 小时以前 52e09a6b7b7054fc51b9d4bf5f1fbec0a57e60f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
    }
}