From 625e5824ba21784ec524520d731edcb4ef3b4dbf Mon Sep 17 00:00:00 2001 From: WendyYang Date: Fri, 1 Nov 2024 11:26:25 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E9=A1=B9=E7=9B=AE=E5=BA=93?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=80=BC=E7=94=9F=E6=88=90?= =?UTF-8?q?Excel=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/ProjectLibApiResponseToExcelUtil.java | 44 ++++++++++++++++++++++ .../OpenApiMeetingExpertInfoController.java | 5 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java new file mode 100644 index 0000000..3aa5da7 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java @@ -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; + +/** + *

+ * ProjectLibApiResponseToExcelUtil + *

+ * + * @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 objects = parse.getJSONObject("data").getBeanList("records", JSONObject.class); + List> projects = objects.stream().map(w -> { + Map 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(); + } + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java b/hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java index dce3e8c..f8ac40a 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java @@ -12,7 +12,10 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.util.List;