zrj
2024-08-17 5577a7280cd97315fbf9d1ef1b52aa0f569c0081
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
package com.dji.sample.wayline.util;
 
import cn.hutool.core.io.resource.ResourceUtil;
import com.alibaba.fastjson.JSONObject;
 
 
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
 
public class ErrorCodeUtil {
    private static Map DistrictCode = new HashMap();
    static {
        try {
            String result = ResourceUtil.readUtf8Str("classpath:errorCode.json");
            DistrictCode = JSONObject.parseObject(result, Map.class);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    public static boolean isChinese(String str) {
        return str.matches("[\\u4E00-\\u9FFF]+");
    }
    public static String codeToReason(Integer name1) {
        if (Objects.equals(name1, 0)){
            return null;
        }
        String name= String.valueOf(name1);
        boolean bs = isChinese(name);
        if (!bs) {
            return codeToName(name);
        }
        Map<String, Object> jsonObject = new HashMap<>(DistrictCode);
        for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
            if (entry.getValue().equals(name)) {
                return entry.getKey();
            }
        }
        return null;
    }
    public static String codeToName(String code) {
        if (!DistrictCode.containsKey(code)) {
            return null;
        }
        return DistrictCode.get(code).toString();
    }
 
    public static void main(String[] args) {
        System.out.println(codeToReason(321517));
    }
}