From 123276fd98a3933605d8c510e7c3b191ddaa9c79 Mon Sep 17 00:00:00 2001 From: "ys.git" <18439391935@163.com> Date: Thu, 18 Dec 2025 09:57:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BATC=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TcDataQueryController.java | 21 ++++++ .../pojo/ClassificationAttribute.java | 4 ++ .../pojo/EnginePartsCollection.java | 4 ++ .../service/TcDataQueryService.java | 4 ++ .../service/impl/TcDataQueryServiceImpl.java | 70 ++++++++++++++++++- 5 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java b/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java index 479f9ee..f537754 100644 --- a/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java +++ b/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java @@ -10,6 +10,7 @@ import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,5 +28,25 @@ public class TcDataQueryController { Map> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsName(analysisRequest); return Response.ok().data(stringListHashMap); } + //下载TC数据ads_prd_f_yfsjglpt_fdjlbjcjb + @PostMapping("/syncA") + public Response excelExportA(HttpServletResponse response) { + try { + tcDataQueryService.excelExportA(response); + } catch (Exception e) { + return Response.error("导出失败" + e.getMessage()); + } + return Response.ok().data("导出成功"); + } + //下载TC数据ads_prd_f_tc_flsxb + @PostMapping("/syncB") + public Response excelExportB(HttpServletResponse response) { + try { + tcDataQueryService.excelExportB(response); + } catch (Exception e) { + return Response.error("导出失败" + e.getMessage()); + } + return Response.ok().data("导出成功"); + } } diff --git a/src/main/java/com/xdap/self_development/pojo/ClassificationAttribute.java b/src/main/java/com/xdap/self_development/pojo/ClassificationAttribute.java index f01f774..7517dd8 100644 --- a/src/main/java/com/xdap/self_development/pojo/ClassificationAttribute.java +++ b/src/main/java/com/xdap/self_development/pojo/ClassificationAttribute.java @@ -1,5 +1,6 @@ package com.xdap.self_development.pojo; +import com.alibaba.excel.annotation.ExcelProperty; import com.definesys.mpaas.query.annotation.Table; import com.definesys.mpaas.query.model.MpaasBasePojo; import lombok.Data; @@ -10,9 +11,12 @@ import lombok.EqualsAndHashCode; @Table("ads_prd_f_tc_flsxb") public class ClassificationAttribute extends MpaasBasePojo { //图号 + @ExcelProperty("PITEM_ID") private String pitemId; //参数名称 + @ExcelProperty("IDATTRTBUTEHAME") private String idattrtbutehame; //参数值 + @ExcelProperty("FIELDVALUE") private String fieldvalue; } diff --git a/src/main/java/com/xdap/self_development/pojo/EnginePartsCollection.java b/src/main/java/com/xdap/self_development/pojo/EnginePartsCollection.java index 98211ac..3a1e94b 100644 --- a/src/main/java/com/xdap/self_development/pojo/EnginePartsCollection.java +++ b/src/main/java/com/xdap/self_development/pojo/EnginePartsCollection.java @@ -1,5 +1,6 @@ package com.xdap.self_development.pojo; +import com.alibaba.excel.annotation.ExcelProperty; import com.definesys.mpaas.query.annotation.Table; import com.definesys.mpaas.query.model.MpaasBasePojo; import lombok.Data; @@ -10,9 +11,12 @@ import lombok.EqualsAndHashCode; @Table("ads_prd_f_yfsjglpt_fdjlbjcjb") public class EnginePartsCollection extends MpaasBasePojo { // 状态机 -> 状态代号 + @ExcelProperty("ztj") private String ztj; // 零部件名称 + @ExcelProperty("lbjmc") private String lbjmc; // 零部件图号 + @ExcelProperty("lbjth") private String lbjth; } diff --git a/src/main/java/com/xdap/self_development/service/TcDataQueryService.java b/src/main/java/com/xdap/self_development/service/TcDataQueryService.java index f66c4dd..814b85c 100644 --- a/src/main/java/com/xdap/self_development/service/TcDataQueryService.java +++ b/src/main/java/com/xdap/self_development/service/TcDataQueryService.java @@ -7,6 +7,7 @@ import com.xdap.self_development.pojo.EngineParamDetailPojo; import com.xdap.self_development.pojo.Parameter; import com.xdap.self_development.pojo.dto.EngineParamDetailDTO; +import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -20,4 +21,7 @@ public interface TcDataQueryService { Map> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest); + void excelExportA(HttpServletResponse response); + + void excelExportB(HttpServletResponse response); } diff --git a/src/main/java/com/xdap/self_development/service/impl/TcDataQueryServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/TcDataQueryServiceImpl.java index 3894e36..58947aa 100644 --- a/src/main/java/com/xdap/self_development/service/impl/TcDataQueryServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/TcDataQueryServiceImpl.java @@ -1,8 +1,13 @@ package com.xdap.self_development.service.impl; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.write.metadata.WriteSheet; import com.definesys.mpaas.query.MpaasQueryFactory; import com.xdap.self_development.config.BusinessDatabase; import com.xdap.self_development.controller.request.AnalysisRequest; +import com.xdap.self_development.controller.request.EngineParamDetailExcel; +import com.xdap.self_development.exception.ExcelImportException; import com.xdap.self_development.pojo.*; import com.xdap.self_development.pojo.dto.EngineParamDetailDTO; import com.xdap.self_development.service.DataEntryEngineModelService; @@ -11,9 +16,13 @@ import com.xdap.self_development.service.TcDataQueryService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.omg.CORBA.PRIVATE_MEMBER; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; import java.util.*; import java.util.stream.Collectors; @@ -84,6 +93,7 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { @Override public Map> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest) { + long a = System.currentTimeMillis(); String engineModelID = analysisRequest.getEngineModelID(); List subsystemTypes = analysisRequest.getSubsystemParts(); @@ -162,7 +172,65 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { } Map> valueBySubSysName = allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName)); + long b = System.currentTimeMillis(); + throw new RuntimeException(String.valueOf(b - a)); +// return valueBySubSysName; + } - return valueBySubSysName; + @Override + public void excelExportA(HttpServletResponse response) { + + try { + setupResponse(response, "参数值导入模板" + (new Date())); + } catch (IOException e) { + + } + try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) { + ArrayList enginePartsCollections = new ArrayList<>(); + List lbjmcs = bd.getTCDatabase() + .doQuery(EnginePartsCollection.class); + for (EnginePartsCollection parameter : lbjmcs) { + EnginePartsCollection engineParamDetailExcel = new EnginePartsCollection(); + engineParamDetailExcel.setZtj(parameter.getZtj()); + engineParamDetailExcel.setLbjth(parameter.getLbjth()); + engineParamDetailExcel.setLbjmc(parameter.getLbjmc()); + enginePartsCollections.add(engineParamDetailExcel); + } + WriteSheet sheet = EasyExcel.writerSheet() + .head(EnginePartsCollection.class) // 所有Sheet使用相同的表头 + .build(); + excelWriter.write(enginePartsCollections, sheet); // 写入数据,只生成表头 + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void excelExportB(HttpServletResponse response) { + try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) { + ArrayList enginePartsCollections = new ArrayList<>(); + List lbjmcs = bd.getTCDatabase() + .doQuery(ClassificationAttribute.class); + for (ClassificationAttribute parameter : lbjmcs) { + ClassificationAttribute engineParamDetailExcel = new ClassificationAttribute(); + engineParamDetailExcel.setFieldvalue(parameter.getFieldvalue()); + engineParamDetailExcel.setIdattrtbutehame(parameter.getIdattrtbutehame()); + engineParamDetailExcel.setPitemId(parameter.getPitemId()); + enginePartsCollections.add(engineParamDetailExcel); + } + WriteSheet sheet = EasyExcel.writerSheet() + .head(ClassificationAttribute.class) // 所有Sheet使用相同的表头 + .build(); + excelWriter.write(enginePartsCollections, sheet); // 写入数据,只生成表头 + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void setupResponse(HttpServletResponse response, String fileName) throws IOException { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + encodedFileName + ".xlsx"); } }