diff --git a/src/main/java/com/xdap/self_development/controller/DataEntryEngineModelController.java b/src/main/java/com/xdap/self_development/controller/DataEntryEngineModelController.java index fa5b8f3..4c8f588 100644 --- a/src/main/java/com/xdap/self_development/controller/DataEntryEngineModelController.java +++ b/src/main/java/com/xdap/self_development/controller/DataEntryEngineModelController.java @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; + /** *

* 发动机型号数据表 前端控制器 @@ -45,6 +47,16 @@ public class DataEntryEngineModelController { } return Response.ok().data("导入成功"); } + //导出模板 + @GetMapping("/excelExport") + public Response excelExport(HttpServletResponse response) { + try { + entryEngineModelService.excelExport(response); + } catch (Exception e) { + return Response.error("导出失败" + e.getMessage()); + } + return Response.ok().data("导出成功"); + } //添加-单条写入 @PostMapping("/insert") 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 f537754..48ae7d9 100644 --- a/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java +++ b/src/main/java/com/xdap/self_development/controller/TcDataQueryController.java @@ -28,6 +28,12 @@ public class TcDataQueryController { Map> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsName(analysisRequest); return Response.ok().data(stringListHashMap); } + //根据机型ID和子系统-零部件查询参数数据 备----未使用 + @PostMapping("/tcDataSelectAllByPartsNameBack") + public Response tcDataSelectAllByPartsNameBack(@RequestBody AnalysisRequest analysisRequest) { + Map> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsNameBack(analysisRequest); + return Response.ok().data(stringListHashMap); + } //下载TC数据ads_prd_f_yfsjglpt_fdjlbjcjb @PostMapping("/syncA") public Response excelExportA(HttpServletResponse response) { diff --git a/src/main/java/com/xdap/self_development/controller/request/DataEntryEngineModelExcel.java b/src/main/java/com/xdap/self_development/controller/request/DataEntryEngineModelExcel.java index 6fc5682..5c03d9f 100644 --- a/src/main/java/com/xdap/self_development/controller/request/DataEntryEngineModelExcel.java +++ b/src/main/java/com/xdap/self_development/controller/request/DataEntryEngineModelExcel.java @@ -17,7 +17,7 @@ import java.util.Date; * @since 2025-11-12 */ @Data -public class DataEntryEngineModelExcel extends MpaasBasePojo { +public class DataEntryEngineModelExcel { /** * 产品型号(全称) diff --git a/src/main/java/com/xdap/self_development/listener/EngineParamDetailListener.java b/src/main/java/com/xdap/self_development/listener/EngineParamDetailListener.java index a804c64..12d192f 100644 --- a/src/main/java/com/xdap/self_development/listener/EngineParamDetailListener.java +++ b/src/main/java/com/xdap/self_development/listener/EngineParamDetailListener.java @@ -116,6 +116,7 @@ public class EngineParamDetailListener implements ReadListener selectAllByNewVersion(); List selectAllAndTcByNewVersion(); +/** + * 根据型号查询最新的引擎参数详情列表 + * + * @param model 型号名称 + * @return 返回指定型号的最新版本引擎参数详情列表 + */ List selectByModelNewVersion(String model); //根据责任人查询最新发版的参数详情 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 814b85c..a80c729 100644 --- a/src/main/java/com/xdap/self_development/service/TcDataQueryService.java +++ b/src/main/java/com/xdap/self_development/service/TcDataQueryService.java @@ -20,6 +20,7 @@ public interface TcDataQueryService { ArrayList tcDataSelectAllByproductNumber(DataEntryEngineModelPojo engineModelPojo); Map> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest); + Map> tcDataSelectAllByPartsNameBack(AnalysisRequest analysisRequest); void excelExportA(HttpServletResponse response); diff --git a/src/main/java/com/xdap/self_development/service/impl/DataEntryEngineModelServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/DataEntryEngineModelServiceImpl.java index f29da96..68f83a1 100644 --- a/src/main/java/com/xdap/self_development/service/impl/DataEntryEngineModelServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/DataEntryEngineModelServiceImpl.java @@ -2,12 +2,15 @@ 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.definesys.mpaas.query.db.PageQueryResult; import com.xdap.api.moudle.user.pojo.XdapUsers; import com.xdap.runtime.service.RuntimeDatasourceService; import com.xdap.self_development.controller.request.DataEntryEngineModelExcel; import com.xdap.self_development.controller.request.DataEntryEngineModelPageRequest; +import com.xdap.self_development.controller.request.EngineParamDetailExcel; import com.xdap.self_development.enums.DistributeStatusEnum; import com.xdap.self_development.enums.ParamValueVersionEnum; import com.xdap.self_development.exception.ExcelImportException; @@ -30,6 +33,9 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.net.URLEncoder; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -61,6 +67,7 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ private int size = 10; private Integer versionNumber = 1; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Override @@ -280,7 +287,7 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ modelPojo.setId(UUID.randomUUID().toString()); sw.buildFromDatasource("xdap_app_223770822127386625").doInsert(modelPojo); - saveDataParamDetail(modelPojo, parameters,versionNumber, xdapUsersPojo); + saveDataParamDetail(modelPojo, parameters, versionNumber, xdapUsersPojo); return 0; } @@ -305,12 +312,12 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ .rowid("id", entryEngineModelPojo.getId()) .doUpdate(DataEntryEngineModelPojo.class); //绑定参数准备重新走分发 - saveDataParamDetail(entryEngineModelPojo, parameters, newVersionNum,null); + saveDataParamDetail(entryEngineModelPojo, parameters, newVersionNum, null); } } //为每个机型绑定参数 - public void saveDataParamDetail(DataEntryEngineModelPojo modelPojo, List parameters,Integer newVersionNum, XdapUsers xdapUsersPojo) { + public void saveDataParamDetail(DataEntryEngineModelPojo modelPojo, List parameters, Integer newVersionNum, XdapUsers xdapUsersPojo) { /** * 遍历机型 * 查找参数 将每个机型都把参数,和参数所属的填写部门关联上 @@ -388,7 +395,20 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ @Override public void excelExport(HttpServletResponse response) { - + try { + setupResponse(response, "机型导入模板" + (formatter.format(LocalDateTime.now()))); + } catch (IOException e) { + } + // 定义Sheet名称集合 + try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) { + List dataEntryEngineModelExcel = new ArrayList<>(); + WriteSheet sheet = EasyExcel.writerSheet() + .head(DataEntryEngineModelExcel.class) // 所有Sheet使用相同的表头 + .build(); + excelWriter.write(dataEntryEngineModelExcel, sheet); // 写入数据,只生成表头 + } catch (Exception e) { + e.printStackTrace(); + } } @Override @@ -404,5 +424,11 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ return null; } + 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"); + } } diff --git a/src/main/java/com/xdap/self_development/service/impl/EngineParamDetailServiceImpl.java b/src/main/java/com/xdap/self_development/service/impl/EngineParamDetailServiceImpl.java index 526fa8c..cc7e986 100644 --- a/src/main/java/com/xdap/self_development/service/impl/EngineParamDetailServiceImpl.java +++ b/src/main/java/com/xdap/self_development/service/impl/EngineParamDetailServiceImpl.java @@ -30,6 +30,8 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -63,6 +65,7 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService { private Integer versionNumber = 0; private String createdBy = "Excel导入"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); /** @@ -203,7 +206,7 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService { @Override public void excelExport(HttpServletResponse response) { try { - setupResponse(response, "参数值导入模板" + (new Date())); + setupResponse(response, "参数值导入模板" + (formatter.format(LocalDateTime.now()))); } catch (IOException e) { } @@ -657,12 +660,15 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService { .eq("engine_model_id", modelId) .doQuery(EngineParamDetailPojo.class); - EngineParamDetailPojo engineParamDetailPojoMaxVersion = engineParamDetailPojos.stream() - .sorted(Comparator.comparing(EngineParamDetailPojo::getMajorVersion) - .reversed()).collect(Collectors.toList()).get(0); + //根据机型ID查找机型 + DataEntryEngineModelPojo dataEntryEngineModelPojo = dataEntryEngineModelService.selectBymodelId(modelId); + + if (ObjectUtils.isEmpty(dataEntryEngineModelPojo)) { + throw new RuntimeException("机型不存在"); + } List paramDetailPojos = engineParamDetailPojos.stream().filter( - x -> x.getMajorVersion() == engineParamDetailPojoMaxVersion.getMajorVersion() + x -> x.getMajorVersion() == dataEntryEngineModelPojo.getVersionNumber() ).collect(Collectors.toList()); return paramDetailPojos; } 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 58947aa..760d05d 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 @@ -6,17 +6,12 @@ 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; import com.xdap.self_development.service.EngineParamDetailService; 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; @@ -93,7 +88,18 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { @Override public Map> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest) { - long a = System.currentTimeMillis(); + return tcDataSelectAllByPartsNameFunctionOptimized(analysisRequest); + + } + + @Override + public Map> tcDataSelectAllByPartsNameBack(AnalysisRequest analysisRequest) { + return tcDataSelectAllByPartsNameFunction(analysisRequest); + + } + + public Map> tcDataSelectAllByPartsNameFunction(AnalysisRequest analysisRequest) { + // long a = System.currentTimeMillis(); String engineModelID = analysisRequest.getEngineModelID(); List subsystemTypes = analysisRequest.getSubsystemParts(); @@ -135,17 +141,18 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { if (ObjectUtils.isEmpty(lbjmcs)) { log.error("根据零部件未找到状态机图号列表"); } + List listl = new ArrayList<>(); for (EnginePartsCollection lbjmc : lbjmcs) { //获取图号 String lbjth = lbjmc.getLbjth(); if (ObjectUtils.isEmpty(lbjth)) { continue; } - List list = bd.getTCDatabase() + listl.addAll(bd.getTCDatabase() .eq("pitemId", lbjth) - .doQuery(ClassificationAttribute.class); - stringListHashMap.put(parts_name, list); + .doQuery(ClassificationAttribute.class)); } + stringListHashMap.put(parts_name, listl); for (Map.Entry> stringListEntry : stringListHashMap.entrySet()) { String key = stringListEntry.getKey();//零部件 List list = stringListEntry.getValue();//零部件里的值 @@ -173,8 +180,131 @@ 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; +// throw new RuntimeException(String.valueOf(b - a)); + return valueBySubSysName; + } + + + public Map> tcDataSelectAllByPartsNameFunctionOptimized(AnalysisRequest analysisRequest) { + String engineModelID = analysisRequest.getEngineModelID(); + List subsystemTypes = analysisRequest.getSubsystemParts(); + + if (ObjectUtils.isEmpty(engineModelID) || ObjectUtils.isEmpty(subsystemTypes)) { + throw new RuntimeException("传入参数为空,请检查"); + } + + List allPojos = new ArrayList<>(); + List parameters = engineParamDetailService.selectAllAndTcByNewVersion(); + DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID); + + // 预加载所有参数信息 + + Map> parameterMap = parameters.stream() + .collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName())); + + //解析所有子系统-零部件对 + List> subsystemPartsPairs = subsystemTypes.stream() + .map(subsystemType -> { + if (subsystemType.split("-").length != 2) { + throw new RuntimeException("查询条件异常,需子系统-零部件名称,若零部件为空则传入“/ ”"); + } + String subsystem = subsystemType.split("-")[0]; + String parts_name = subsystemType.split("-")[1]; + return new AbstractMap.SimpleEntry<>(subsystem, parts_name); + }) + .collect(Collectors.toList()); + + //批量查询所有系统数据 + List systemDataList = new ArrayList<>(); + for (Map.Entry subsystemPartsPair : subsystemPartsPairs) { + List pojoList = sw.buildFromDatasource("xdap_app_223770822127386625") + .eq("engine_model_id", engineModelID) + .eq("subsystem_name", subsystemPartsPair.getKey()) + .eq("parts_name", subsystemPartsPair.getValue()) + .doQuery(EngineParamDetailPojo.class); + if (ObjectUtils.isNotEmpty(pojoList)) { + systemDataList.addAll(pojoList); + } + } + + // 过滤版本号 + List filteredSystemData = systemDataList.stream() + .filter(x -> x.getMajorVersion().equals(dataEntryEngineModelPojo.getVersionNumber())) + .collect(Collectors.toList()); + + allPojos.addAll(filteredSystemData); + + //批量查询所有TC数据 + List uniquePartsNames = subsystemPartsPairs.stream() + .map(Map.Entry::getValue) + .distinct() + .collect(Collectors.toList()); + + List allEngineParts = bd.getTCDatabase() + .eq("ztj", dataEntryEngineModelPojo.getProductNumber()) + .in("lbjmc", uniquePartsNames) + .doQuery(EnginePartsCollection.class); + + // 按零部件名称分组 + Map> partsMap = allEngineParts.stream() + .collect(Collectors.groupingBy(EnginePartsCollection::getLbjmc)); + + //批量查询所有图号对应的分类属性 + List allLbjths = allEngineParts.stream() + .map(EnginePartsCollection::getLbjth) + .filter(ObjectUtils::isNotEmpty) + .distinct() + .collect(Collectors.toList()); + + Map> classificationMap = new HashMap<>(); + if (!allLbjths.isEmpty()) { + List allClassifications = bd.getTCDatabase() + .in("pitemId", allLbjths) + .doQuery(ClassificationAttribute.class); + + // 按图号分组 + classificationMap = allClassifications.stream() + .collect(Collectors.groupingBy(ClassificationAttribute::getPitemId)); + } + + // 处理每个子系统-零部件对 + for (Map.Entry pair : subsystemPartsPairs) { + String subsystem = pair.getKey(); + String partsName = pair.getValue(); + + // 获取该零部件的所有图号 + List partsCollections = partsMap.getOrDefault(partsName, Collections.emptyList()); + + // 获取所有分类属性 + List allAttributes = new ArrayList<>(); + for (EnginePartsCollection parts : partsCollections) { + String lbjth = parts.getLbjth(); + if (ObjectUtils.isNotEmpty(lbjth)) { + allAttributes.addAll(classificationMap.getOrDefault(lbjth, Collections.emptyList())); + } + } + + //批量处理分类属性 + List tcDataPojos = allAttributes.stream() + .filter(attr -> parameterMap.containsKey(partsName + "&&" + attr.getIdattrtbutehame())) + .map(attr -> { + Parameter param = parameterMap.get(partsName + "&&" + attr.getIdattrtbutehame()).get(0); + EngineParamDetailPojo pojo = new EngineParamDetailPojo(); + pojo.setEngineModelId(dataEntryEngineModelPojo.getId()); + pojo.setPartsName(param.getPartsName()); + pojo.setSubsystemName(param.getSubsystemName()); + pojo.setParameterName(param.getParameterName()); + pojo.setParameterValue(attr.getFieldvalue()); + return pojo; + }) + .collect(Collectors.toList()); + + allPojos.addAll(tcDataPojos); + } + + Map> valueBySubSysName = + allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName)); + return valueBySubSysName; } @Override