机型模板导出机型TC参数查询优化

This commit is contained in:
ys.git 2025-12-18 16:51:46 +08:00
parent b04db8080f
commit 3ac62258fb
9 changed files with 209 additions and 21 deletions

View File

@ -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;
/**
* <p>
* 发动机型号数据表 前端控制器
@ -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")

View File

@ -28,6 +28,12 @@ public class TcDataQueryController {
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsName(analysisRequest);
return Response.ok().data(stringListHashMap);
}
//根据机型ID和子系统-零部件查询参数数据 ----未使用
@PostMapping("/tcDataSelectAllByPartsNameBack")
public Response tcDataSelectAllByPartsNameBack(@RequestBody AnalysisRequest analysisRequest) {
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsNameBack(analysisRequest);
return Response.ok().data(stringListHashMap);
}
//下载TC数据ads_prd_f_yfsjglpt_fdjlbjcjb
@PostMapping("/syncA")
public Response excelExportA(HttpServletResponse response) {

View File

@ -17,7 +17,7 @@ import java.util.Date;
* @since 2025-11-12
*/
@Data
public class DataEntryEngineModelExcel extends MpaasBasePojo {
public class DataEntryEngineModelExcel {
/**
* 产品型号全称

View File

@ -116,6 +116,7 @@ public class EngineParamDetailListener implements ReadListener<EngineParamDetail
sw.buildFromDatasource("xdap_app_223770822127386625")
.eq("parameter_id",paramDetailExcel.getId())
.eq("engine_model_id",modelPojo.getId())
.eq("major_version",modelPojo.getVersionNumber())
.doQuery(EngineParamDetailPojo.class);
//如果这个ID有数据则更新小版本为草稿
if (ObjectUtils.isNotEmpty(detailPojos)) {

View File

@ -38,6 +38,12 @@ public interface EngineParamDetailService {
List<Parameter> selectAllByNewVersion();
List<Parameter> selectAllAndTcByNewVersion();
/**
* 根据型号查询最新的引擎参数详情列表
*
* @param model 型号名称
* @return 返回指定型号的最新版本引擎参数详情列表
*/
List<EngineParamDetailPojo> selectByModelNewVersion(String model);
//根据责任人查询最新发版的参数详情

View File

@ -20,6 +20,7 @@ public interface TcDataQueryService {
ArrayList<EngineParamDetailPojo> tcDataSelectAllByproductNumber(DataEntryEngineModelPojo engineModelPojo);
Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest);
Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameBack(AnalysisRequest analysisRequest);
void excelExportA(HttpServletResponse response);

View File

@ -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<Parameter> parameters,Integer newVersionNum, XdapUsers xdapUsersPojo) {
public void saveDataParamDetail(DataEntryEngineModelPojo modelPojo, List<Parameter> 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> 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");
}
}

View File

@ -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<EngineParamDetailPojo> paramDetailPojos = engineParamDetailPojos.stream().filter(
x -> x.getMajorVersion() == engineParamDetailPojoMaxVersion.getMajorVersion()
x -> x.getMajorVersion() == dataEntryEngineModelPojo.getVersionNumber()
).collect(Collectors.toList());
return paramDetailPojos;
}

View File

@ -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<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest) {
long a = System.currentTimeMillis();
return tcDataSelectAllByPartsNameFunctionOptimized(analysisRequest);
}
@Override
public Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameBack(AnalysisRequest analysisRequest) {
return tcDataSelectAllByPartsNameFunction(analysisRequest);
}
public Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameFunction(AnalysisRequest analysisRequest) {
// long a = System.currentTimeMillis();
String engineModelID = analysisRequest.getEngineModelID();
List<String> subsystemTypes = analysisRequest.getSubsystemParts();
@ -135,17 +141,18 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
if (ObjectUtils.isEmpty(lbjmcs)) {
log.error("根据零部件未找到状态机图号列表");
}
List<ClassificationAttribute> listl = new ArrayList<>();
for (EnginePartsCollection lbjmc : lbjmcs) {
//获取图号
String lbjth = lbjmc.getLbjth();
if (ObjectUtils.isEmpty(lbjth)) {
continue;
}
List<ClassificationAttribute> 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<String, List<ClassificationAttribute>> stringListEntry : stringListHashMap.entrySet()) {
String key = stringListEntry.getKey();//零部件
List<ClassificationAttribute> list = stringListEntry.getValue();//零部件里的值
@ -173,8 +180,131 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
Map<String, List<EngineParamDetailPojo>> 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<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsNameFunctionOptimized(AnalysisRequest analysisRequest) {
String engineModelID = analysisRequest.getEngineModelID();
List<String> subsystemTypes = analysisRequest.getSubsystemParts();
if (ObjectUtils.isEmpty(engineModelID) || ObjectUtils.isEmpty(subsystemTypes)) {
throw new RuntimeException("传入参数为空,请检查");
}
List<EngineParamDetailPojo> allPojos = new ArrayList<>();
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID);
// 预加载所有参数信息
Map<String, List<Parameter>> parameterMap = parameters.stream()
.collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName()));
//解析所有子系统-零部件对
List<Map.Entry<String, String>> 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<EngineParamDetailPojo> systemDataList = new ArrayList<>();
for (Map.Entry<String, String> subsystemPartsPair : subsystemPartsPairs) {
List<EngineParamDetailPojo> 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<EngineParamDetailPojo> filteredSystemData = systemDataList.stream()
.filter(x -> x.getMajorVersion().equals(dataEntryEngineModelPojo.getVersionNumber()))
.collect(Collectors.toList());
allPojos.addAll(filteredSystemData);
//批量查询所有TC数据
List<String> uniquePartsNames = subsystemPartsPairs.stream()
.map(Map.Entry::getValue)
.distinct()
.collect(Collectors.toList());
List<EnginePartsCollection> allEngineParts = bd.getTCDatabase()
.eq("ztj", dataEntryEngineModelPojo.getProductNumber())
.in("lbjmc", uniquePartsNames)
.doQuery(EnginePartsCollection.class);
// 按零部件名称分组
Map<String, List<EnginePartsCollection>> partsMap = allEngineParts.stream()
.collect(Collectors.groupingBy(EnginePartsCollection::getLbjmc));
//批量查询所有图号对应的分类属性
List<String> allLbjths = allEngineParts.stream()
.map(EnginePartsCollection::getLbjth)
.filter(ObjectUtils::isNotEmpty)
.distinct()
.collect(Collectors.toList());
Map<String, List<ClassificationAttribute>> classificationMap = new HashMap<>();
if (!allLbjths.isEmpty()) {
List<ClassificationAttribute> allClassifications = bd.getTCDatabase()
.in("pitemId", allLbjths)
.doQuery(ClassificationAttribute.class);
// 按图号分组
classificationMap = allClassifications.stream()
.collect(Collectors.groupingBy(ClassificationAttribute::getPitemId));
}
// 处理每个子系统-零部件对
for (Map.Entry<String, String> pair : subsystemPartsPairs) {
String subsystem = pair.getKey();
String partsName = pair.getValue();
// 获取该零部件的所有图号
List<EnginePartsCollection> partsCollections = partsMap.getOrDefault(partsName, Collections.emptyList());
// 获取所有分类属性
List<ClassificationAttribute> allAttributes = new ArrayList<>();
for (EnginePartsCollection parts : partsCollections) {
String lbjth = parts.getLbjth();
if (ObjectUtils.isNotEmpty(lbjth)) {
allAttributes.addAll(classificationMap.getOrDefault(lbjth, Collections.emptyList()));
}
}
//批量处理分类属性
List<EngineParamDetailPojo> 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<String, List<EngineParamDetailPojo>> valueBySubSysName =
allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName));
return valueBySubSysName;
}
@Override