|
|
@@ -0,0 +1,44 @@ |
|
|
|
package com.hz.pm.api.common.util; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.UUID; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import com.hz.pm.api.projectlib.model.enumeration.status.ProjectStatus; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* ProjectLibApiResponseToExcelUtil |
|
|
|
* </p> |
|
|
|
* |
|
|
|
* @author WendyYang |
|
|
|
* @since 10:14 2024/11/1 |
|
|
|
*/ |
|
|
|
public class ProjectLibApiResponseToExcelUtil { |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String str = ""; |
|
|
|
JSONObject parse = JSONUtil.toBean(str, JSONObject.class); |
|
|
|
List<JSONObject> objects = parse.getJSONObject("data").getBeanList("records", JSONObject.class); |
|
|
|
List<Map<String, String>> projects = objects.stream().map(w -> { |
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
map.put("项目名称", w.getStr("projectName")); |
|
|
|
map.put("建设单位", w.getStr("buildOrg")); |
|
|
|
map.put("申报总投资", w.getStr("declaredAmount")); |
|
|
|
map.put("项目年度", w.getStr("projectYear")); |
|
|
|
map.put("项目状态", ProjectStatus.getDesc(w.getInt("status"))); |
|
|
|
return map; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
ExcelUtil.getWriter() |
|
|
|
.write(projects, true) |
|
|
|
.flush(new File("/Users/wendy/Desktop/" + UUID.randomUUID().toString(true) + ".xlsx")) |
|
|
|
.close(); |
|
|
|
} |
|
|
|
|
|
|
|
} |