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));
|
}
|
}
|