Bladeren bron

modify:

1. 项目库列表返回值生成Excel工具类;
tags/24110601
WendyYang 2 maanden geleden
bovenliggende
commit
625e5824ba
2 gewijzigde bestanden met toevoegingen van 48 en 1 verwijderingen
  1. +44
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java
  2. +4
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java

+ 44
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/util/ProjectLibApiResponseToExcelUtil.java Bestand weergeven

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

}

+ 4
- 1
hz-pm-api/src/main/java/com/hz/pm/api/open/controller/OpenApiMeetingExpertInfoController.java Bestand weergeven

@@ -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;


Laden…
Annuleren
Opslaan