|
@@ -4,16 +4,19 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.jeecg.common.constant.AccountReportConstants;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
- * Created by JQ.bi on 2020.06.03
|
|
|
+ * Created by JQ.bi on 2020.06.03
|
|
|
*/
|
|
|
public class JsonResourceUtil {
|
|
|
|
|
@@ -22,6 +25,7 @@ public class JsonResourceUtil {
|
|
|
private JsonResourceUtil() {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
//filename 为文件名字 如 “/json/app_version_info.json”
|
|
|
public static JSONObject getJsonObjFromResource(String filename) {
|
|
|
JSONObject json = null;
|
|
@@ -30,9 +34,9 @@ public class JsonResourceUtil {
|
|
|
}
|
|
|
try {
|
|
|
ClassPathResource classPathResource = new ClassPathResource(filename);
|
|
|
- File file = classPathResource.getFile();
|
|
|
- if (file.exists()) {
|
|
|
- String content = FileUtils.readFileToString(classPathResource.getFile(), "UTF-8");
|
|
|
+ if (classPathResource.exists()) {
|
|
|
+ InputStream inputStream = classPathResource.getInputStream();
|
|
|
+ String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
json = JSON.parseObject(content);
|
|
|
} else {
|
|
|
logger.info("file not exist!");
|
|
@@ -45,51 +49,53 @@ public class JsonResourceUtil {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
- public static Map<String, Map<String,Object>> jsonToMap(Object jsonObj) {
|
|
|
+ public static Map<String, Map<String, Object>> jsonToMap(Object jsonObj) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonObj.toString());
|
|
|
- Map<String,Map<String,Object>> mapMap= new HashMap<>();
|
|
|
- jsonObject.forEach((key,value)->{
|
|
|
- mapMap.put(key,JSONObject.parseObject(value.toString()));
|
|
|
+ Map<String, Map<String, Object>> mapMap = new HashMap<>();
|
|
|
+ jsonObject.forEach((key, value) -> {
|
|
|
+ mapMap.put(key, JSONObject.parseObject(value.toString()));
|
|
|
});
|
|
|
return mapMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 拼接字段
|
|
|
+ * 拼接字段
|
|
|
*/
|
|
|
public static String joinFiled(JSONArray array) {
|
|
|
- StringBuilder sb= new StringBuilder();
|
|
|
- array.forEach(it->{
|
|
|
- if(AccountReportConstants.dicMap.get(it.toString()).isEmpty()){
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ array.forEach(it -> {
|
|
|
+ if (AccountReportConstants.dicMap.get(it.toString()).isEmpty()) {
|
|
|
sb.append(it).append(",");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
sb.append(AccountReportConstants.dicMap.get(it.toString()).get("filed")).append(",");
|
|
|
}
|
|
|
});
|
|
|
- return sb.deleteCharAt(sb.length()-1).toString();
|
|
|
+ return sb.deleteCharAt(sb.length() - 1).toString();
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * 拼接title
|
|
|
+ * 拼接title
|
|
|
*/
|
|
|
public static List<String> joinTitle(JSONArray array) {
|
|
|
- List<String> titles= new ArrayList<>(20);
|
|
|
- array.forEach(it->{
|
|
|
- if(AccountReportConstants.dicMap.get(it.toString()).isEmpty()){
|
|
|
+ List<String> titles = new ArrayList<>(20);
|
|
|
+ array.forEach(it -> {
|
|
|
+ if (AccountReportConstants.dicMap.get(it.toString()).isEmpty()) {
|
|
|
titles.add(it.toString());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
titles.add(AccountReportConstants.dicMap.get(it.toString()).get("comment").toString());
|
|
|
}
|
|
|
});
|
|
|
return titles;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
- * 拼接字段
|
|
|
+ * 拼接字段
|
|
|
*/
|
|
|
public static String joinAllFiled() {
|
|
|
- StringBuilder sb= new StringBuilder();
|
|
|
- AccountReportConstants.dicMap.forEach((k,v)->{
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ AccountReportConstants.dicMap.forEach((k, v) -> {
|
|
|
sb.append(v.get("filed")).append(",");
|
|
|
});
|
|
|
- return sb.deleteCharAt(sb.length()-1).toString();
|
|
|
+ return sb.deleteCharAt(sb.length() - 1).toString();
|
|
|
}
|
|
|
}
|