新增:机型和数据的多版本查询
This commit is contained in:
parent
e7f3a1c3fa
commit
4030c1ae5a
@ -72,6 +72,14 @@ public class DataEntryEngineModelController {
|
||||
System.out.println("进入方法");
|
||||
return Response.ok().data(tPageResultDTO);
|
||||
}
|
||||
|
||||
// 多版本机型分页查询
|
||||
@GetMapping("/selectVersionByPage")
|
||||
public Response selectVersionByConditionPage() {
|
||||
PageResultDTO<DataEntryEngineModelDto> tPageResultDTO =
|
||||
entryEngineModelService.selectVersionByConditionPage();
|
||||
return Response.ok().data(tPageResultDTO);
|
||||
}
|
||||
// //模板更新审核通过同步机型参数
|
||||
// @GetMapping("/updateModelForNewVersion")
|
||||
// public Response updateModelForNewVersion() {
|
||||
|
||||
@ -3,16 +3,20 @@ package com.xdap.self_development.controller;
|
||||
|
||||
import com.definesys.mpaas.common.http.Response;
|
||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||
import com.xdap.self_development.controller.request.AnalysisVerRequest;
|
||||
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||
import com.xdap.self_development.pojo.ClassificationAttribute;
|
||||
import com.xdap.self_development.exception.CommonException;
|
||||
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
||||
import com.xdap.self_development.service.TcDataQueryService;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.validation.BindingResult;
|
||||
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.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -23,6 +27,22 @@ public class TcDataQueryController {
|
||||
@Autowired
|
||||
private TcDataQueryService tcDataQueryService;
|
||||
|
||||
// 根据机型ID、版本和子系统-零部件查询参数数据
|
||||
@PostMapping("/tcDataSelectByVersion")
|
||||
public Response tcDataSelectByVersion(
|
||||
@Valid @RequestBody AnalysisVerRequest analysisRequest,
|
||||
BindingResult bindingResult
|
||||
) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
bindingResult.getFieldErrors().forEach(error -> {
|
||||
throw new CommonException(error.getDefaultMessage());
|
||||
});
|
||||
}
|
||||
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService
|
||||
.tcDataSelectByVersion(analysisRequest);
|
||||
return Response.ok().data(stringListHashMap);
|
||||
}
|
||||
|
||||
//根据机型ID和子系统-零部件查询参数数据
|
||||
@PostMapping("/tcDataSelectByPartsNames")
|
||||
public Response tcDataSelectByPartsNames(@RequestBody AnalysisRequest analysisRequest) {
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package com.xdap.self_development.controller.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AnalysisVerRequest {
|
||||
@NotBlank(message = "用户ID不能为空")
|
||||
private String userID;
|
||||
@NotBlank(message = "机型ID不能为空")
|
||||
private String engineModelID;
|
||||
/**
|
||||
* 子系统+零部件名称路径
|
||||
*/
|
||||
@NotEmpty(message = "子系统+零部件名称路径不能为空")
|
||||
private List<String> subsystemParts;
|
||||
@NotBlank(message = "参数版本不能为空")
|
||||
private String parameterVersion;
|
||||
}
|
||||
@ -2,6 +2,8 @@ package com.xdap.self_development.pojo.dto;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.format.DateTimeFormat;
|
||||
import com.definesys.mpaas.query.annotation.SQL;
|
||||
import com.definesys.mpaas.query.annotation.SQLQuery;
|
||||
import com.definesys.mpaas.query.model.MpaasBasePojo;
|
||||
import lombok.Data;
|
||||
|
||||
@ -15,6 +17,10 @@ import java.util.Date;
|
||||
* @author Lys111
|
||||
* @since 2025-11-12
|
||||
*/
|
||||
@SQLQuery(value = {
|
||||
@SQL(view = "selectVersionByConditionPage",
|
||||
sql = "WITH ranked_models AS ( SELECT deem.*, epd.major_version AS parameterVersion, ROW_NUMBER() OVER (PARTITION BY deem.model_name, epd.major_version ORDER BY deem.id) AS rn FROM data_entry_engine_model deem JOIN engine_param_detail epd ON deem.id = epd.engine_model_id ) SELECT * FROM ranked_models WHERE rn = 1 ORDER BY model_name, parameterVersion")
|
||||
})
|
||||
@Data
|
||||
public class DataEntryEngineModelDto extends MpaasBasePojo {
|
||||
|
||||
@ -126,5 +132,9 @@ public class DataEntryEngineModelDto extends MpaasBasePojo {
|
||||
*/
|
||||
private Integer versionNumber;
|
||||
|
||||
/**
|
||||
* 参数版本
|
||||
*/
|
||||
private Integer parameterVersion;
|
||||
|
||||
}
|
||||
|
||||
@ -45,4 +45,5 @@ public interface DataEntryEngineModelService {
|
||||
|
||||
DataEntryEngineModelPojo selectBymodelId(String modelID);
|
||||
|
||||
PageResultDTO<DataEntryEngineModelDto> selectVersionByConditionPage();
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
package com.xdap.self_development.service;
|
||||
|
||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||
import com.xdap.self_development.controller.request.AnalysisVerRequest;
|
||||
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||
import com.xdap.self_development.pojo.ClassificationAttribute;
|
||||
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
||||
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;
|
||||
@ -28,4 +27,6 @@ public interface TcDataQueryService {
|
||||
void excelExportB(HttpServletResponse response);
|
||||
|
||||
void modelComparisonExport(ModelComparisonExportRequest request, HttpServletResponse response);
|
||||
|
||||
Map<String, List<EngineParamDetailPojo>> tcDataSelectByVersion(AnalysisVerRequest analysisRequest);
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ 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;
|
||||
@ -442,6 +441,18 @@ public class DataEntryEngineModelServiceImpl implements DataEntryEngineModelServ
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultDTO<DataEntryEngineModelDto> selectVersionByConditionPage() {
|
||||
List<DataEntryEngineModelDto> list = sw.buildFromDatasource("xdap_app_223770822127386625")
|
||||
.viewQueryMode(true)
|
||||
.view("selectVersionByConditionPage")
|
||||
.doQuery(DataEntryEngineModelDto.class);
|
||||
PageResultDTO<DataEntryEngineModelDto> pageResultDTO = new PageResultDTO<>();
|
||||
pageResultDTO.setList(list);
|
||||
pageResultDTO.setTotalCount(list.size());
|
||||
return pageResultDTO;
|
||||
}
|
||||
|
||||
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
@ -4,19 +4,19 @@ 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.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xdap.self_development.config.BusinessDatabase;
|
||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||
import com.xdap.self_development.controller.request.AnalysisVerRequest;
|
||||
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||
import com.xdap.self_development.pojo.*;
|
||||
import com.xdap.self_development.service.DataEntryEngineModelService;
|
||||
import com.xdap.self_development.service.EngineParamDetailService;
|
||||
import com.xdap.self_development.service.TcDataQueryService;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -540,6 +540,133 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<EngineParamDetailPojo>> tcDataSelectByVersion(AnalysisVerRequest analysisRequest) {
|
||||
// List<EngineParamDetailPojo> allPojos = new ArrayList<>();
|
||||
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
|
||||
DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(analysisRequest.getEngineModelID());
|
||||
|
||||
// 预加载所有参数信息
|
||||
Map<String, List<Parameter>> parameterMap = parameters.stream()
|
||||
.collect(Collectors.groupingBy(p -> p.getPartsName() + "&&" + p.getParameterName()));
|
||||
|
||||
//解析所有子系统-零部件对
|
||||
List<Map.Entry<String, String>> subsystemPartsPairs = analysisRequest.getSubsystemParts().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", analysisRequest.getEngineModelID())
|
||||
.eq("major_version", analysisRequest.getParameterVersion())
|
||||
.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());
|
||||
|
||||
systemDataList.addAll(tcDataPojos);
|
||||
}
|
||||
//将allPojos存到Redis,KEY为userID+engineModelID+预操作,过期时间24小时
|
||||
// try {
|
||||
// String redisKey = analysisRequest.getUserID() + ":" + analysisRequest.getEngineModelID() + ":" + "ComparisonExport";
|
||||
// String jsonValue = objectMapper.writeValueAsString(systemDataList);
|
||||
// redisTemplate.opsForValue().set(redisKey, jsonValue, 24, java.util.concurrent.TimeUnit.HOURS);
|
||||
// log.info("成功将数据存储到Redis,KEY: {}", redisKey);
|
||||
// } catch (Exception e) {
|
||||
// log.error("存储数据到Redis失败: {}", e.getMessage());
|
||||
// }
|
||||
|
||||
Map<String, List<EngineParamDetailPojo>> valueBySubSysName =
|
||||
systemDataList.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName));
|
||||
|
||||
|
||||
return valueBySubSysName;
|
||||
}
|
||||
|
||||
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user