From 1ae1dd83f0070888facf91a4aa9e01832c9cef3d Mon Sep 17 00:00:00 2001 From: zjh <15615273395@163.com> Date: Tue, 28 Apr 2026 17:59:45 +0800 Subject: [PATCH] =?UTF-8?q?TC=E6=95=B0=E6=8D=AE=E5=85=A8=E9=83=A8=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E6=95=B0=E6=8D=AE=E5=BA=93=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TcDataQueryServiceImpl.java | 352 ++++-------------- 1 file changed, 76 insertions(+), 276 deletions(-) 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 99c70c5..c5755d0 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 @@ -92,7 +92,6 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID); //查到所有TC表的参数 返回零部件,参数列表 for (String subsystemType : subsystemTypes) { - HashMap> stringListHashMap = new HashMap<>(); if (subsystemType.split("-").length != 2) { throw new CommonException("查询条件异常,需子系统-零部件名称,若零部件为空则传入“/”"); } @@ -113,46 +112,28 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { allPojos.addAll(pojoList); } - //开始查找TC数据 - List lbjmcs = bd.getTCDatabase() - .eq("ztj", dataEntryEngineModelPojo.getProductNumber()) - .eq("lbjmc", partsName) - .doQuery(EnginePartsCollectionPojo.class); - if (ObjectUtils.isEmpty(lbjmcs)) { - log.error("根据零部件未找到状态机图号列表"); - } - List listl = new ArrayList<>(); - for (EnginePartsCollectionPojo lbjmc : lbjmcs) { - //获取图号 - String lbjth = lbjmc.getLbjth(); - if (ObjectUtils.isEmpty(lbjth)) { - continue; - } - listl.addAll(bd.getTCDatabase() - .eq("pitemId", lbjth) - .doQuery(ClassificationAttributePojo.class)); - } - stringListHashMap.put(partsName, listl); - for (Map.Entry> stringListEntry : stringListHashMap.entrySet()) { - String key = stringListEntry.getKey();//零部件 - List list = stringListEntry.getValue();//零部件里的值 - for (ClassificationAttributePojo classificationAttribute : list) { - String idattrtbutehame = classificationAttribute.getIdattrtbutehame(); - String fieldvalue = classificationAttribute.getFieldvalue(); - List pojos = parameters.stream() - .filter(x -> (x.getPartsName() + "&&" + x.getParameterName()).equals(key + "&&" + idattrtbutehame)) - .map(x -> { - EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo(); - engineParamDetailPojo.setEngineModelId(dataEntryEngineModelPojo.getId()); - engineParamDetailPojo.setPartsName(x.getPartsName()); - engineParamDetailPojo.setSubsystemName(x.getSubsystemName()); - engineParamDetailPojo.setParameterName(x.getParameterName()); - engineParamDetailPojo.setParameterValue(fieldvalue); - return engineParamDetailPojo; - }).collect(Collectors.toList()); - if (ObjectUtils.isNotEmpty(pojos)) { - allPojos.addAll(pojos); - } + //使用selectTCFromDB查询TC数据 + List tcSubsystemParts = new ArrayList<>(); + tcSubsystemParts.add(subsystem + "-" + partsName); + List tcPojos = selectTCFromDB(engineModelID, tcSubsystemParts); + + //处理TC数据,转换为EngineParamDetailPojo + for (EngineParamDetailPojo tcPojo : tcPojos) { + String paramName = tcPojo.getParameterName(); + String paramValue = tcPojo.getParameterValue(); + List matchedPojos = parameters.stream() + .filter(x -> (x.getPartsName() + "&&" + x.getParameterName()).equals(partsName + "&&" + paramName)) + .map(x -> { + EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo(); + engineParamDetailPojo.setEngineModelId(dataEntryEngineModelPojo.getId()); + engineParamDetailPojo.setPartsName(x.getPartsName()); + engineParamDetailPojo.setSubsystemName(x.getSubsystemName()); + engineParamDetailPojo.setParameterName(x.getParameterName()); + engineParamDetailPojo.setParameterValue(paramValue); + return engineParamDetailPojo; + }).collect(Collectors.toList()); + if (ObjectUtils.isNotEmpty(matchedPojos)) { + allPojos.addAll(matchedPojos); } } @@ -211,73 +192,25 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { allPojos.addAll(filteredSystemData); - //批量查询所有TC数据 - List uniquePartsNames = subsystemPartsPairs.stream() - .map(Map.Entry::getValue) - .distinct() + //使用selectTCFromDB批量查询TC数据 + List tcDataPojos = selectTCFromDB(engineModelID, subsystemTypes); + + //处理TC数据,转换为EngineParamDetailPojo + List convertedTcPojos = tcDataPojos.stream() + .filter(tcPojo -> parameterMap.containsKey(tcPojo.getPartsName() + "&&" + tcPojo.getParameterName())) + .map(tcPojo -> { + ParameterPojo param = parameterMap.get(tcPojo.getPartsName() + "&&" + tcPojo.getParameterName()).get(0); + EngineParamDetailPojo pojo = new EngineParamDetailPojo(); + pojo.setEngineModelId(dataEntryEngineModelPojo.getId()); + pojo.setPartsName(param.getPartsName()); + pojo.setSubsystemName(param.getSubsystemName()); + pojo.setParameterName(param.getParameterName()); + pojo.setParameterValue(tcPojo.getParameterValue()); + return pojo; + }) .collect(Collectors.toList()); - List allEngineParts = bd.getTCDatabase() - .eq("ztj", dataEntryEngineModelPojo.getProductNumber()) - .in("lbjmc", uniquePartsNames) - .doQuery(EnginePartsCollectionPojo.class); - - // 按零部件名称分组 - Map> partsMap = allEngineParts.stream() - .collect(Collectors.groupingBy(EnginePartsCollectionPojo::getLbjmc)); - - //批量查询所有图号对应的分类属性 - List allLbjths = allEngineParts.stream() - .map(EnginePartsCollectionPojo::getLbjth) - .filter(ObjectUtils::isNotEmpty) - .distinct() - .collect(Collectors.toList()); - - Map> classificationMap = new HashMap<>(); - if (!allLbjths.isEmpty()) { - List allClassifications = bd.getTCDatabase() - .in("pitemId", allLbjths) - .doQuery(ClassificationAttributePojo.class); - - // 按图号分组 - classificationMap = allClassifications.stream() - .collect(Collectors.groupingBy(ClassificationAttributePojo::getPitemId)); - } - - // 处理每个子系统-零部件对 - for (Map.Entry pair : subsystemPartsPairs) { - - String partsName = pair.getValue(); - - // 获取该零部件的所有图号 - List partsCollections = partsMap.getOrDefault(partsName, Collections.emptyList()); - - // 获取所有分类属性 - List allAttributes = new ArrayList<>(); - for (EnginePartsCollectionPojo 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 -> { - ParameterPojo 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); - } + allPojos.addAll(convertedTcPojos); //将allPojos存到Redis,KEY为userID+engineModelID+预操作,过期时间24小时 try { String redisKey = userID + ":" + engineModelID + ":" + "ComparisonExport"; @@ -304,7 +237,7 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) { setupResponse(response, "参数值导入模板" + (new Date())); ArrayList enginePartsCollections = new ArrayList<>(); - List lbjmcs = bd.getTCDatabase() + List lbjmcs = bd.getBusinessDatabase() .doQuery(EnginePartsCollectionPojo.class); for (EnginePartsCollectionPojo parameter : lbjmcs) { EnginePartsCollectionPojo engineParamDetailExcel = new EnginePartsCollectionPojo(); @@ -331,7 +264,7 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { public void excelExportB(HttpServletResponse response) { try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) { ArrayList enginePartsCollections = new ArrayList<>(); - List lbjmcs = bd.getTCDatabase() + List lbjmcs = bd.getBusinessDatabase() .doQuery(ClassificationAttributePojo.class); for (ClassificationAttributePojo parameter : lbjmcs) { ClassificationAttributePojo engineParamDetailExcel = new ClassificationAttributePojo(); @@ -460,77 +393,21 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { //批量查询所有TC数据 Map> parameterMapTc = tcPojos.stream() .collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName())); - List> subsystemPartsPairsTc = analysisRequest.getSubsystemParts().stream() - .map(subsystemType -> { - if (subsystemType.split("-").length != 2) { - throw new CommonException("查询条件异常,需子系统-零部件名称,若零部件为空则传入“/ ”"); - } - String subsystem = subsystemType.split("-")[0]; - String partsName = subsystemType.split("-")[1]; - return new AbstractMap.SimpleEntry<>(subsystem, partsName); + + //使用selectTCFromDB查询TC数据 + List tcDataResults = selectTCFromDB(analysisRequest.getEngineModelID(), analysisRequest.getSubsystemParts()); + + //处理TC数据,更新parameterValue + List convertedTcPojos = tcDataResults.stream() + .filter(tcPojo -> parameterMapTc.containsKey(tcPojo.getPartsName() + "&&" + tcPojo.getParameterName())) + .map(tcPojo -> { + EngineParamDetailPojo param = parameterMapTc.get(tcPojo.getPartsName() + "&&" + tcPojo.getParameterName()).get(0); + param.setParameterValue(tcPojo.getParameterValue()); + return param; }) .collect(Collectors.toList()); - List uniquePartsNames = subsystemPartsPairsTc.stream() - .map(Map.Entry::getValue) - .distinct() - .collect(Collectors.toList()); - List allEngineParts = bd.getTCDatabase() - .eq("ztj", dataEntryEngineModelPojo.getProductNumber()) - .in("lbjmc", uniquePartsNames) - .doQuery(EnginePartsCollectionPojo.class); - - // 按零部件名称分组 - Map> partsMap = allEngineParts.stream() - .collect(Collectors.groupingBy(EnginePartsCollectionPojo::getLbjmc)); - - //批量查询所有图号对应的分类属性 - List allLbjths = allEngineParts.stream() - .map(EnginePartsCollectionPojo::getLbjth) - .filter(ObjectUtils::isNotEmpty) - .distinct() - .collect(Collectors.toList()); - - Map> classificationMap = new HashMap<>(); - if (!allLbjths.isEmpty()) { - List allClassifications = bd.getTCDatabase() - .in("pitemId", allLbjths) - .doQuery(ClassificationAttributePojo.class); - - // 按图号分组 - classificationMap = allClassifications.stream() - .collect(Collectors.groupingBy(ClassificationAttributePojo::getPitemId)); - } - - // 处理每个子系统-零部件对 - for (Map.Entry pair : subsystemPartsPairsTc) { - - String partsName = pair.getValue(); - - // 获取该零部件的所有图号 - List partsCollections = partsMap.getOrDefault(partsName, Collections.emptyList()); - - // 获取所有分类属性 - List allAttributes = new ArrayList<>(); - for (EnginePartsCollectionPojo parts : partsCollections) { - String lbjth = parts.getLbjth(); - if (ObjectUtils.isNotEmpty(lbjth)) { - allAttributes.addAll(classificationMap.getOrDefault(lbjth, Collections.emptyList())); - } - } - - //批量处理分类属性 - List tcDataPojos = allAttributes.stream() - .filter(attr -> parameterMapTc.containsKey(partsName + "&&" + attr.getIdattrtbutehame())) - .map(attr -> { - EngineParamDetailPojo param = parameterMapTc.get(partsName + "&&" + attr.getIdattrtbutehame()).get(0); - param.setParameterValue(attr.getFieldvalue()); - return param; - }) - .collect(Collectors.toList()); - - systemDataList.addAll(tcDataPojos); - } + systemDataList.addAll(convertedTcPojos); // 按权限过滤返回数据 List filerData = engineParamDetailService.selectModelParamByIsUserId(systemDataList, analysisRequest.getUserID()); @@ -557,16 +434,6 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { * @return 引擎参数详情列表 */ public List tcDataSelectAllByproductNumberBatch(List engineModelPojos) { - // 收集所有 productNumber - Set productNumbers = engineModelPojos.stream() - .map(DataEntryEngineModelPojo::getProductNumber) - .filter(ObjectUtils::isNotEmpty) - .collect(Collectors.toSet()); - - if (productNumbers.isEmpty()) { - return Collections.emptyList(); - } - // 一次性查询所有参数模板 TC 参数数据 List parameters = engineParamDetailService.selectAllAndTcByNewVersion(); List collect = parameters.stream() @@ -594,105 +461,38 @@ public class TcDataQueryServiceImpl implements TcDataQueryService { } } - // 一次性查询所有 EnginePartsCollectionPojo - List allPartsCollections = bd.getTCDatabase() - .in("ztj", productNumbers) - .in("lbjmc", partsNames) - .doQuery(EnginePartsCollectionPojo.class); - - // 按 productNumber 和 partsName 分组 - Map>> partsCollectionsMap = allPartsCollections.stream() - .collect(Collectors.groupingBy( - EnginePartsCollectionPojo::getZtj, - Collectors.groupingBy(EnginePartsCollectionPojo::getLbjmc) - )); - - // 收集所有图号 - Set allLbjths = allPartsCollections.stream() - .map(EnginePartsCollectionPojo::getLbjth) - .filter(ObjectUtils::isNotEmpty) - .collect(Collectors.toSet()); - - if (allLbjths.isEmpty()) { - return Collections.emptyList(); - } - - // 一次性查询所有 ClassificationAttributePojo - List allClassifications = bd.getTCDatabase() - .in("pitemId", allLbjths) - .doQuery(ClassificationAttributePojo.class); - - // 按 pitemId 分组 - Map> classificationMap = allClassifications.stream() - .collect(Collectors.groupingBy(ClassificationAttributePojo::getPitemId)); - - Map>> productPartsLbjthMap = new HashMap<>(); - for (Map.Entry>> productEntry : partsCollectionsMap.entrySet()) { - String productNumber = productEntry.getKey(); - Map> partsMap = productEntry.getValue(); - - Map> partsLbjthMap = new HashMap<>(); - for (Map.Entry> partsEntry : partsMap.entrySet()) { - String partsName = partsEntry.getKey(); - List partsCollections = partsEntry.getValue(); - - // 提前过滤并收集图号 - List lbjths = partsCollections.stream() - .map(EnginePartsCollectionPojo::getLbjth) - .filter(ObjectUtils::isNotEmpty) - .filter(classificationMap::containsKey) - .collect(Collectors.toList()); - partsLbjthMap.put(partsName, lbjths); - } - productPartsLbjthMap.put(productNumber, partsLbjthMap); - } - // 构建结果 List result = new ArrayList<>(); for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) { - String productNumber = engineModelPojo.getProductNumber(); - if (ObjectUtils.isEmpty(productNumber)) { - continue; - } - - Map> partsMap = partsCollectionsMap.get(productNumber); - if (partsMap == null) { - continue; - } - - Map> partsLbjthMap = productPartsLbjthMap.get(productNumber); - if (partsLbjthMap == null) { + if (ObjectUtils.isEmpty(engineModelPojo.getId())) { continue; } + // 构建 subsystemParts 列表 + List subsystemPartsList = new ArrayList<>(); for (String partsName : partsNames) { + // 由于没有 subsystem 信息,使用 partsName 作为占位符 + // 实际应用中需要根据业务逻辑获取 subsystem + subsystemPartsList.add("*-" + partsName); + } + + // 使用 selectTCFromDB 查询 + List tcDataResults = selectTCFromDB(engineModelPojo.getId(), subsystemPartsList); + + // 过滤并构建结果 + for (EngineParamDetailPojo tcData : tcDataResults) { + String partsName = tcData.getPartsName(); + String paramName = tcData.getParameterName(); + Set parameterNameSet = partsParamNameMap.get(partsName); - if (parameterNameSet == null || parameterNameSet.isEmpty()) { - continue; - } - - List lbjths = partsLbjthMap.get(partsName); - if (lbjths == null || lbjths.isEmpty()) { - continue; - } - - for (String lbjth : lbjths) { - List classifications = classificationMap.get(lbjth); - if (classifications == null) { - continue; - } - - for (ClassificationAttributePojo classificationAttribute : classifications) { - if (parameterNameSet.contains(classificationAttribute.getIdattrtbutehame())) { - EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo(); - engineParamDetailPojo.setEngineModelId(engineModelPojo.getId()); - engineParamDetailPojo.setPartsName(partsName); - engineParamDetailPojo.setParameterName(classificationAttribute.getIdattrtbutehame()); - engineParamDetailPojo.setParameterValue(classificationAttribute.getFieldvalue()); - result.add(engineParamDetailPojo); - } - } + if (parameterNameSet != null && parameterNameSet.contains(paramName)) { + EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo(); + engineParamDetailPojo.setEngineModelId(engineModelPojo.getId()); + engineParamDetailPojo.setPartsName(partsName); + engineParamDetailPojo.setParameterName(paramName); + engineParamDetailPojo.setParameterValue(tcData.getParameterValue()); + result.add(engineParamDetailPojo); } } }