修改:查询分析优化
This commit is contained in:
parent
2f58e702e5
commit
fecf4c60fb
@ -3,12 +3,14 @@ package com.xdap.self_development.controller;
|
|||||||
import com.definesys.mpaas.common.http.Response;
|
import com.definesys.mpaas.common.http.Response;
|
||||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||||
import com.xdap.self_development.controller.request.ReportRequest;
|
import com.xdap.self_development.controller.request.ReportRequest;
|
||||||
|
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
||||||
import com.xdap.self_development.service.AnalysisCommonParametersService;
|
import com.xdap.self_development.service.AnalysisCommonParametersService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -28,11 +30,20 @@ public class AnalysisCommonController {
|
|||||||
|
|
||||||
//统计分析图表
|
//统计分析图表
|
||||||
@PostMapping("/showReport")
|
@PostMapping("/showReport")
|
||||||
public Response showReport(@RequestBody ReportRequest request) {
|
public Response showReport(@NotEmpty @RequestBody List<String> models) {
|
||||||
AnalysisModelParamterViewAndParam andParam = analysisCommonParametersService.showReport(request);
|
AnalysisModelParamterViewAndParam andParam = analysisCommonParametersService.showReport(models);
|
||||||
return Response.ok().data(andParam);
|
return Response.ok().data(andParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 模糊查询机型
|
||||||
|
@PostMapping("/selectModelByLike")
|
||||||
|
public Response selectModelByLike(
|
||||||
|
@RequestBody ReportRequest request
|
||||||
|
) {
|
||||||
|
List<DataEntryEngineModelPojo> lists = analysisCommonParametersService.selectModelByLike(request);
|
||||||
|
return Response.ok().data(lists);
|
||||||
|
}
|
||||||
|
|
||||||
// //模糊查询下拉列表
|
// //模糊查询下拉列表
|
||||||
// @GetMapping("/analysisShowList")
|
// @GetMapping("/analysisShowList")
|
||||||
// public Response analysisShowList(@RequestParam("attribute") String attribute) {
|
// public Response analysisShowList(@RequestParam("attribute") String attribute) {
|
||||||
|
|||||||
@ -10,10 +10,14 @@ import com.xdap.self_development.common.UserPermissionGetter;
|
|||||||
import com.xdap.self_development.config.BusinessDatabase;
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||||
import com.xdap.self_development.feign.ApaasMyTokenFeign;
|
import com.xdap.self_development.feign.ApaasMyTokenFeign;
|
||||||
|
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
||||||
|
import com.xdap.self_development.pojo.EngineParamDetailPojo;
|
||||||
import com.xdap.self_development.pojo.ModelDepUserRolePojo;
|
import com.xdap.self_development.pojo.ModelDepUserRolePojo;
|
||||||
import com.xdap.self_development.pojo.view.MenuParamView;
|
import com.xdap.self_development.pojo.view.MenuParamView;
|
||||||
|
import com.xdap.self_development.pojo.view.TcQueryView;
|
||||||
import com.xdap.self_development.schedule.ParameterValueCalculationTimer;
|
import com.xdap.self_development.schedule.ParameterValueCalculationTimer;
|
||||||
import com.xdap.self_development.service.ModelRoleService;
|
import com.xdap.self_development.service.ModelRoleService;
|
||||||
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -24,9 +28,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@ -35,6 +42,55 @@ public class DeleteController {
|
|||||||
@Resource
|
@Resource
|
||||||
private BusinessDatabase yourDataService;
|
private BusinessDatabase yourDataService;
|
||||||
|
|
||||||
|
@PostMapping("queryTc")
|
||||||
|
public Response queryTc(
|
||||||
|
@RequestBody List<String> models
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
Map<String, DataEntryEngineModelPojo> engineModelPojoMap = yourDataService.getBusinessDatabase()
|
||||||
|
.in("id", models)
|
||||||
|
.doQuery(DataEntryEngineModelPojo.class).stream()
|
||||||
|
.collect(Collectors.toMap(DataEntryEngineModelPojo::getId, model -> model));
|
||||||
|
List<EngineParamDetailPojo> allEngineParamDetails = yourDataService.getBusinessDatabase()
|
||||||
|
.in("engine_model_id", models)
|
||||||
|
.doQuery(EngineParamDetailPojo.class);
|
||||||
|
Map<String, List<EngineParamDetailPojo>> engineParamDetailMap = allEngineParamDetails.stream()
|
||||||
|
.collect(Collectors.groupingBy(EngineParamDetailPojo::getEngineModelId));
|
||||||
|
List<QueryModel> queryModels = new ArrayList<>();
|
||||||
|
engineParamDetailMap.forEach((key, value) -> {
|
||||||
|
value.forEach(param -> {
|
||||||
|
QueryModel queryModel = new QueryModel();
|
||||||
|
queryModel.setZtj(engineModelPojoMap.get(key).getProductNumber());
|
||||||
|
queryModel.setIdattrtbutehame(param.getParameterName());
|
||||||
|
queryModel.setLbjmc(param.getPartsName());
|
||||||
|
queryModels.add(queryModel);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
List<TcQueryView> queryTc = yourDataService.getBusinessDatabase()
|
||||||
|
.viewQueryMode(true)
|
||||||
|
.view("queryTc")
|
||||||
|
.setVar("queryModels", queryModels)
|
||||||
|
.doQuery(TcQueryView.class);
|
||||||
|
|
||||||
|
return Response.ok().data(queryTc);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("查询TC失败", e);
|
||||||
|
return Response.error("查询TC失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
static class QueryModel implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
// 状态机
|
||||||
|
private String ztj;
|
||||||
|
// 零件名
|
||||||
|
private String lbjmc;
|
||||||
|
// 参数名
|
||||||
|
private String idattrtbutehame;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/excel/import")
|
@PostMapping("/excel/import")
|
||||||
public String importExcel(@RequestParam("file") MultipartFile file) {
|
public String importExcel(@RequestParam("file") MultipartFile file) {
|
||||||
// 校验文件
|
// 校验文件
|
||||||
|
|||||||
@ -9,6 +9,8 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@SQLQuery(value = {
|
@SQLQuery(value = {
|
||||||
|
@SQL(view = "selectTcParameter",
|
||||||
|
sql = "SELECT p.* FROM yfsjglpt_model_template t LEFT JOIN yfsjglpt_model_parameter_and_template pat ON t.id = pat.template_id LEFT JOIN yfsjglpt_model_parameter p ON pat.parameter_id = p.id WHERE t.status = 'COMPLETE' AND p.parameter_source = '数据平台手工录入'"),
|
||||||
@SQL(view = "selectParametersByTIdAndCreateBy",
|
@SQL(view = "selectParametersByTIdAndCreateBy",
|
||||||
sql = "select p.* from yfsjglpt_model_parameter p left join yfsjglpt_model_parameter_and_template tap on p.id = tap.parameter_id where tap.template_id = #templateId and p.created_by = #createdBy order by p.parameter_number"),
|
sql = "select p.* from yfsjglpt_model_parameter p left join yfsjglpt_model_parameter_and_template tap on p.id = tap.parameter_id where tap.template_id = #templateId and p.created_by = #createdBy order by p.parameter_number"),
|
||||||
@SQL(view = "selectParametersByTId",
|
@SQL(view = "selectParametersByTId",
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.xdap.self_development.pojo.view;
|
||||||
|
|
||||||
|
import com.definesys.mpaas.query.annotation.SQL;
|
||||||
|
import com.definesys.mpaas.query.annotation.SQLQuery;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@SQLQuery(value = {
|
||||||
|
@SQL(view = "queryTc",
|
||||||
|
sql = "SELECT sap.ztj as productNumber, sap.lbjmc as partsName, tc.idattrtbutehame as parameterName, tc.fieldvalue as parameterValue FROM ads_prd_f_yfsjglpt_fdjlbjcjb sap JOIN ads_prd_f_tc_flsxb tc ON sap.lbjth = tc.pitem_id WHERE (sap.ztj, sap.lbjmc, tc.idattrtbutehame) IN (#queryModels)")
|
||||||
|
})
|
||||||
|
@Data
|
||||||
|
public class TcQueryView {
|
||||||
|
// 状态机
|
||||||
|
private String productNumber;
|
||||||
|
// 参数名
|
||||||
|
private String parameterName;
|
||||||
|
// 参数值
|
||||||
|
private String parameterValue;
|
||||||
|
// 零件名
|
||||||
|
private String partsName;
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ package com.xdap.self_development.service;
|
|||||||
import com.xdap.self_development.controller.request.AnalysisRequest;
|
import com.xdap.self_development.controller.request.AnalysisRequest;
|
||||||
|
|
||||||
import com.xdap.self_development.controller.request.ReportRequest;
|
import com.xdap.self_development.controller.request.ReportRequest;
|
||||||
|
import com.xdap.self_development.pojo.DataEntryEngineModelPojo;
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
||||||
|
|
||||||
@ -14,7 +15,8 @@ public interface AnalysisCommonParametersService {
|
|||||||
//查询常用参数返回机型数据
|
//查询常用参数返回机型数据
|
||||||
ArrayList<AnalysisModelParamterView> selectModelParamByCommon(AnalysisRequest analysisRequest);
|
ArrayList<AnalysisModelParamterView> selectModelParamByCommon(AnalysisRequest analysisRequest);
|
||||||
|
|
||||||
AnalysisModelParamterViewAndParam showReport(ReportRequest analysisRequest);
|
AnalysisModelParamterViewAndParam showReport(List<String> models);
|
||||||
AnalysisModelParamterViewAndParam showReportParamList(ReportRequest analysisRequest);
|
AnalysisModelParamterViewAndParam showReportParamList(ReportRequest analysisRequest);
|
||||||
|
|
||||||
|
List<DataEntryEngineModelPojo> selectModelByLike(ReportRequest request);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,6 @@ public interface EngineParamDetailService {
|
|||||||
void updateToInsertFiledBy(List<EngineParamDetailPojo> engineParamDetailPojos, String userID);
|
void updateToInsertFiledBy(List<EngineParamDetailPojo> engineParamDetailPojos, String userID);
|
||||||
|
|
||||||
List<Parameter> selectAllByNewVersion();
|
List<Parameter> selectAllByNewVersion();
|
||||||
List<Parameter> selectNeedFillByNewVersion();
|
|
||||||
|
|
||||||
List<Parameter> selectAllAndTcByNewVersion();
|
List<Parameter> selectAllAndTcByNewVersion();
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,36 +1,36 @@
|
|||||||
package com.xdap.self_development.service.impl;
|
package com.xdap.self_development.service.impl;
|
||||||
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.xdap.self_development.config.BusinessDatabase;
|
import com.xdap.self_development.config.BusinessDatabase;
|
||||||
import com.xdap.self_development.controller.request.*;
|
import com.xdap.self_development.controller.request.*;
|
||||||
import com.xdap.self_development.enums.ParamPermissionEnum;
|
|
||||||
import com.xdap.self_development.exception.CommonException;
|
import com.xdap.self_development.exception.CommonException;
|
||||||
import com.xdap.self_development.pojo.*;
|
import com.xdap.self_development.pojo.*;
|
||||||
import com.xdap.self_development.pojo.dto.PageResultDTO;
|
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterView;
|
||||||
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
import com.xdap.self_development.pojo.view.AnalysisModelParamterViewAndParam;
|
||||||
import com.xdap.self_development.pojo.view.MenuParamView;
|
|
||||||
import com.xdap.self_development.service.*;
|
import com.xdap.self_development.service.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParametersService {
|
public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParametersService {
|
||||||
|
|
||||||
|
// 机型处理批次大小
|
||||||
|
@Value("${tc.query.model.batch.size:20}")
|
||||||
|
private Integer modelBatchSize;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
BusinessDatabase businessDatabase;
|
BusinessDatabase businessDatabase;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -80,9 +80,9 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnalysisModelParamterViewAndParam showReport(ReportRequest request) {
|
public AnalysisModelParamterViewAndParam showReport(List<String> models) {
|
||||||
|
|
||||||
return showReport2(request);
|
return showReport3(models);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,28 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnalysisModelParamterViewAndParam showReport1(ReportRequest request) {
|
@Override
|
||||||
|
public List<DataEntryEngineModelPojo> selectModelByLike(ReportRequest request) {
|
||||||
|
if (request.getEngineCapacityMax() < request.getEngineCapacityMin()) {
|
||||||
|
throw new CommonException("排量范围设置错误");
|
||||||
|
}
|
||||||
|
return new ArrayList<>(businessDatabase.getBusinessDatabase()
|
||||||
|
.like("model_name", request.getModelName())
|
||||||
|
.like("plate", request.getPlate())
|
||||||
|
.like("platform", request.getPlatform())
|
||||||
|
.like("series", request.getSeries())
|
||||||
|
.like("project_name", request.getProjectName())
|
||||||
|
.like("project_number", request.getProjectNumber())
|
||||||
|
.like("emission", request.getEmission())
|
||||||
|
.like("burn_type", request.getBurnType())
|
||||||
|
.conjuctionOr()
|
||||||
|
.lteq("engine_capacity", request.getEngineCapacityMax())
|
||||||
|
.and()
|
||||||
|
.gteq("engine_capacity", request.getEngineCapacityMin())
|
||||||
|
.doQuery(DataEntryEngineModelPojo.class));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public AnalysisModelParamterViewAndParam showReport1(List<String> modelIds) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
List<DataEntryEngineModelPojo> queryResult = businessDatabase.getBusinessDatabase()
|
List<DataEntryEngineModelPojo> queryResult = businessDatabase.getBusinessDatabase()
|
||||||
// .eq("yc_or_oth", request.getYcOrOth())
|
// .eq("yc_or_oth", request.getYcOrOth())
|
||||||
@ -155,45 +176,21 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
|
|||||||
// throw new RuntimeException(String.valueOf(endTime-startTime));
|
// throw new RuntimeException(String.valueOf(endTime-startTime));
|
||||||
return andParam;
|
return andParam;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public AnalysisModelParamterViewAndParam showReport2(@RequestBody ReportRequest request) {
|
public AnalysisModelParamterViewAndParam showReport2(ReportRequest request) {
|
||||||
|
|
||||||
// 查询所有符合条件的机型
|
// 查询所有符合条件的机型
|
||||||
List<DataEntryEngineModelPojo> queryResult = businessDatabase.getBusinessDatabase()
|
List<DataEntryEngineModelPojo> engineModelPojos = selectModelByLike(request);
|
||||||
.like("model_name", request.getModelName())
|
|
||||||
.like("plate", request.getPlate())
|
|
||||||
.like("platform", request.getPlatform())
|
|
||||||
.like("series", request.getSeries())
|
|
||||||
.like("project_name", request.getProjectName())
|
|
||||||
.like("project_number", request.getProjectNumber())
|
|
||||||
.like("emission", request.getEmission())
|
|
||||||
.like("burn_type", request.getBurnType())
|
|
||||||
.doQuery(DataEntryEngineModelPojo.class);
|
|
||||||
|
|
||||||
// 过滤发动机排量
|
|
||||||
Double engineCapacityMin = request.getEngineCapacityMin();
|
|
||||||
Double engineCapacityMax = request.getEngineCapacityMax();
|
|
||||||
List<DataEntryEngineModelPojo> engineModelPojos = queryResult;
|
|
||||||
if (ObjectUtils.isNotEmpty(engineCapacityMin) && ObjectUtils.isNotEmpty(engineCapacityMax)) {
|
|
||||||
engineModelPojos = queryResult.stream().filter(dataEntryEngineModelPojo -> {
|
|
||||||
String engineCapacity = dataEntryEngineModelPojo.getEngineCapacity();
|
|
||||||
Double ec = extractDisplacement(engineCapacity);
|
|
||||||
if (ec == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (Double.compare(ec, engineCapacityMin) >= 0 && Double.compare(ec, engineCapacityMax) < 0);
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engineModelPojos.isEmpty()) {
|
if (engineModelPojos.isEmpty()) {
|
||||||
return new AnalysisModelParamterViewAndParam();
|
throw new CommonException("没有找到符合条件的机型");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量查询 EngineParamDetailPojo
|
// 获取机型id列表
|
||||||
Set<String> modelIds = engineModelPojos.stream()
|
Set<String> modelIds = engineModelPojos.stream()
|
||||||
.map(DataEntryEngineModelPojo::getId)
|
.map(DataEntryEngineModelPojo::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 获取数据平台机型的参数
|
||||||
List<EngineParamDetailPojo> allEngineParamDetails = businessDatabase.getBusinessDatabase()
|
List<EngineParamDetailPojo> allEngineParamDetails = businessDatabase.getBusinessDatabase()
|
||||||
.in("engine_model_id", modelIds)
|
.in("engine_model_id", modelIds)
|
||||||
.doQuery(EngineParamDetailPojo.class);
|
.doQuery(EngineParamDetailPojo.class);
|
||||||
@ -226,7 +223,7 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
|
|||||||
// 过滤版本号
|
// 过滤版本号
|
||||||
Integer versionNumber = engineModelPojo.getVersionNumber();
|
Integer versionNumber = engineModelPojo.getVersionNumber();
|
||||||
pojoList = pojoList.stream()
|
pojoList = pojoList.stream()
|
||||||
.filter(x -> x.getMajorVersion() == versionNumber)
|
.filter(x -> Objects.equals(x.getMajorVersion(), versionNumber))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 添加 TC 数据
|
// 添加 TC 数据
|
||||||
@ -262,32 +259,99 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
|
|||||||
return ALL_NUMBER_PATTERN.matcher(str.trim()).matches();
|
return ALL_NUMBER_PATTERN.matcher(str.trim()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> selectParamOnlyNum(ArrayList<AnalysisModelParamterView> analysisModelParamterViews) {
|
public AnalysisModelParamterViewAndParam showReport3(List<String> models) {
|
||||||
List<String> list = new ArrayList<>();
|
// 查询所有符合条件的机型
|
||||||
for (AnalysisModelParamterView analysisModelParamterView : analysisModelParamterViews) {
|
List<DataEntryEngineModelPojo> engineModelPojos = businessDatabase.getBusinessDatabase()
|
||||||
for (EngineParamDetailPojo pojo : analysisModelParamterView.getPojos()) {
|
.in("id", models)
|
||||||
String parameterValue = pojo.getParameterValue();
|
.doQuery(DataEntryEngineModelPojo.class);
|
||||||
if (ObjectUtils.isEmpty(parameterValue) && isNumber(parameterValue)) {
|
|
||||||
list.add(pojo.getParameterName());
|
if (CollectionUtils.isEmpty(engineModelPojos)) {
|
||||||
}
|
throw new CommonException("没有找到符合条件的机型");
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Double extractDisplacement(String displacementStr) {
|
List<List<DataEntryEngineModelPojo>> modelBatches = splitModelBatch(engineModelPojos, modelBatchSize);
|
||||||
if (displacementStr == null || displacementStr.isEmpty()) {
|
|
||||||
return null;
|
// 最终结果容器
|
||||||
|
List<AnalysisModelParamterView> allAnalysisViews = new ArrayList<>();
|
||||||
|
Set<String> allParamNames = new HashSet<>();
|
||||||
|
|
||||||
|
for (List<DataEntryEngineModelPojo> batch : modelBatches) {
|
||||||
|
// 获取当前批次机型id列表
|
||||||
|
Set<String> batchModelIds = batch.stream()
|
||||||
|
.map(DataEntryEngineModelPojo::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// 获取数据平台机型的参数
|
||||||
|
List<EngineParamDetailPojo> batchEngineParamDetails = businessDatabase.getBusinessDatabase()
|
||||||
|
.in("engine_model_id", batchModelIds)
|
||||||
|
.doQuery(EngineParamDetailPojo.class);
|
||||||
|
|
||||||
|
// 按 modelId 分组
|
||||||
|
Map<String, List<EngineParamDetailPojo>> engineParamDetailMap = batchEngineParamDetails.stream()
|
||||||
|
.collect(Collectors.groupingBy(EngineParamDetailPojo::getEngineModelId));
|
||||||
|
|
||||||
|
// 批量查询 TC 数据(当前批次)
|
||||||
|
List<EngineParamDetailPojo> batchTcData = tcDataQueryService.tcDataSelectAllByproductNumberBatch(batch);
|
||||||
|
|
||||||
|
// 按 modelId 分组
|
||||||
|
Map<String, List<EngineParamDetailPojo>> tcDataMap = batchTcData.stream()
|
||||||
|
.collect(Collectors.groupingBy(EngineParamDetailPojo::getEngineModelId));
|
||||||
|
|
||||||
|
// 处理当前批次机型
|
||||||
|
for (DataEntryEngineModelPojo engineModelPojo : batch) {
|
||||||
|
AnalysisModelParamterView analysisModelParamterView = new AnalysisModelParamterView();
|
||||||
|
analysisModelParamterView.setModelID(engineModelPojo.getId());
|
||||||
|
analysisModelParamterView.setModelName(engineModelPojo.getModelName());
|
||||||
|
BeanUtils.copyProperties(engineModelPojo, analysisModelParamterView);
|
||||||
|
|
||||||
|
// 获取 EngineParamDetailPojo 列表
|
||||||
|
List<EngineParamDetailPojo> pojoList = engineParamDetailMap.getOrDefault(engineModelPojo.getId(), Collections.emptyList());
|
||||||
|
|
||||||
|
Integer versionNumber = engineModelPojo.getVersionNumber();
|
||||||
|
List<EngineParamDetailPojo> tcData = tcDataMap.getOrDefault(engineModelPojo.getId(), Collections.emptyList());
|
||||||
|
|
||||||
|
pojoList = Stream.concat(pojoList.stream(), tcData.stream())
|
||||||
|
.filter(x -> Objects.equals(x.getMajorVersion(), versionNumber)) // 过滤版本号
|
||||||
|
.filter(x -> Objects.nonNull(x.getParameterValue()) && isNumber(x.getParameterValue())) // 过滤非数字
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
analysisModelParamterView.setPojos(pojoList);
|
||||||
|
allAnalysisViews.add(analysisModelParamterView);
|
||||||
|
|
||||||
|
// 收集所有参数名
|
||||||
|
pojoList.stream()
|
||||||
|
.map(EngineParamDetailPojo::getParameterName)
|
||||||
|
.forEach(allParamNames::add);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 正则匹配:数字(包含小数)
|
batchEngineParamDetails.clear();
|
||||||
Pattern pattern = java.util.regex.Pattern.compile("(\\d+\\.?\\d*)");
|
batchTcData.clear();
|
||||||
Matcher matcher = pattern.matcher(displacementStr);
|
|
||||||
|
|
||||||
if (matcher.find()) {
|
|
||||||
return Double.parseDouble(matcher.group(1));
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
AnalysisModelParamterViewAndParam andParam = new AnalysisModelParamterViewAndParam();
|
||||||
|
andParam.setParamList(new ArrayList<>(allParamNames));
|
||||||
|
andParam.setPojos(allAnalysisViews);
|
||||||
|
return andParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分批处理机型
|
||||||
|
private List<List<DataEntryEngineModelPojo>> splitModelBatch(
|
||||||
|
List<DataEntryEngineModelPojo> source,
|
||||||
|
int batchSize
|
||||||
|
) {
|
||||||
|
List<List<DataEntryEngineModelPojo>> batches = new ArrayList<>();
|
||||||
|
List<DataEntryEngineModelPojo> currentBatch = new ArrayList<>(batchSize);
|
||||||
|
for (DataEntryEngineModelPojo pojo : source) {
|
||||||
|
currentBatch.add(pojo);
|
||||||
|
if (currentBatch.size() >= batchSize) {
|
||||||
|
batches.add(new ArrayList<>(currentBatch));
|
||||||
|
currentBatch.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currentBatch.isEmpty()) {
|
||||||
|
batches.add(currentBatch);
|
||||||
|
}
|
||||||
|
return batches;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -736,57 +736,6 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Parameter> selectNeedFillByNewVersion() {
|
|
||||||
//读取已通过审核的版本 DRAFT(草稿)、APPROVING(审批中)、COMPLETE(已完成)、RETURNED(已撤回)、REJECTED(已拒绝)
|
|
||||||
List<Template> templates =
|
|
||||||
sw.buildFromDatasource("xdap_app_223770822127386625")
|
|
||||||
.eq("status", "COMPLETE")
|
|
||||||
.doQuery(Template.class);
|
|
||||||
if (ObjectUtils.isEmpty(templates)) {
|
|
||||||
throw new RuntimeException("未找到未找到已发布的参数模板");
|
|
||||||
}
|
|
||||||
//查找每个模板最新版本
|
|
||||||
Map<String, Template> latestTemplateMap = templates.stream()
|
|
||||||
// 按模板ID分组
|
|
||||||
.collect(Collectors.groupingBy(
|
|
||||||
Template::getTemplateName,
|
|
||||||
// 每组内按版本号降序,取第一个(最新版本)
|
|
||||||
Collectors.collectingAndThen(
|
|
||||||
Collectors.maxBy(Comparator.comparingInt(Template::getVersion)),
|
|
||||||
Optional::get
|
|
||||||
)
|
|
||||||
));
|
|
||||||
ArrayList<Template> templatesMax = new ArrayList<>(latestTemplateMap.values());
|
|
||||||
List<String> strings = templatesMax.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
||||||
//查找最新模板关联的参数
|
|
||||||
List<TemplateAndParameter> templateAndParameters =
|
|
||||||
sw.buildFromDatasource("xdap_app_223770822127386625")
|
|
||||||
.in("template_id", strings)
|
|
||||||
.doQuery(TemplateAndParameter.class);
|
|
||||||
List<String> pIds = templateAndParameters.stream().map(x -> x.getParameterId()).collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<Parameter> parameterList = sw.buildFromDatasource("xdap_app_223770822127386625")
|
|
||||||
.in("id", pIds)
|
|
||||||
.doQuery(Parameter.class);
|
|
||||||
//不需要TC数据来源的参数
|
|
||||||
parameterList = parameterList.stream().filter(x -> {
|
|
||||||
if (ObjectUtils.isEmpty(x.getParameterSource())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if ("TC分类表".equals(x.getParameterSource())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// TODO:还需排除公式计算的
|
|
||||||
else return !Objects.equals(x.getParameterSource(), "公式计算");
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
if (ObjectUtils.isEmpty(parameterList)) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
return parameterList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Parameter> selectAllAndTcByNewVersion() {
|
public List<Parameter> selectAllAndTcByNewVersion() {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package com.xdap.self_development.service.impl;
|
|||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.alibaba.excel.ExcelWriter;
|
import com.alibaba.excel.ExcelWriter;
|
||||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||||
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.definesys.mpaas.query.MpaasQueryFactory;
|
import com.definesys.mpaas.query.MpaasQueryFactory;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.xdap.motor.utils.StringUtils;
|
import com.xdap.motor.utils.StringUtils;
|
||||||
@ -11,7 +12,6 @@ import com.xdap.self_development.controller.request.AnalysisRequest;
|
|||||||
import com.xdap.self_development.controller.request.AnalysisVerRequest;
|
import com.xdap.self_development.controller.request.AnalysisVerRequest;
|
||||||
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
import com.xdap.self_development.controller.request.ModelComparisonExportRequest;
|
||||||
import com.xdap.self_development.controller.request.ModelItem;
|
import com.xdap.self_development.controller.request.ModelItem;
|
||||||
import com.xdap.self_development.exception.CommonException;
|
|
||||||
import com.xdap.self_development.pojo.*;
|
import com.xdap.self_development.pojo.*;
|
||||||
import com.xdap.self_development.service.DataEntryEngineModelService;
|
import com.xdap.self_development.service.DataEntryEngineModelService;
|
||||||
import com.xdap.self_development.service.EngineParamDetailService;
|
import com.xdap.self_development.service.EngineParamDetailService;
|
||||||
@ -19,6 +19,7 @@ import com.xdap.self_development.service.TcDataQueryService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -30,11 +31,16 @@ import java.net.URLEncoder;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TcDataQueryServiceImpl implements TcDataQueryService {
|
public class TcDataQueryServiceImpl implements TcDataQueryService {
|
||||||
|
// TC参数in查询的批次大小
|
||||||
|
@Value("${tc.query.lbjth.batch.size:1000}")
|
||||||
|
private Integer lbjthBatchSize;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BusinessDatabase bd;
|
private BusinessDatabase bd;
|
||||||
@ -754,39 +760,175 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
return valueBySubSysName;
|
return valueBySubSysName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
|
// public List<EngineParamDetailPojo> tcDataSelectAllByproductNumberBatch(List<DataEntryEngineModelPojo> engineModelPojos) {
|
||||||
|
// // 收集所有 productNumber
|
||||||
|
// Set<String> productNumbers = engineModelPojos.stream()
|
||||||
|
// .map(DataEntryEngineModelPojo::getProductNumber)
|
||||||
|
// .filter(ObjectUtils::isNotEmpty)
|
||||||
|
// .collect(Collectors.toSet());
|
||||||
|
//
|
||||||
|
// if (productNumbers.isEmpty()) {
|
||||||
|
// return Collections.emptyList();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 一次性查询所有参数模板 TC 参数数据
|
||||||
|
// List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
|
||||||
|
// List<Parameter> collect = parameters.stream()
|
||||||
|
// .filter(x -> "TC分类表".equals(x.getParameterSource()))
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// if (collect.isEmpty()) {
|
||||||
|
// return Collections.emptyList();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 按 partsName 分组
|
||||||
|
// Map<String, List<Parameter>> stringListMap = collect.stream()
|
||||||
|
// .collect(Collectors.groupingBy(Parameter::getPartsName));
|
||||||
|
//
|
||||||
|
// Set<String> partsNames = stringListMap.keySet();
|
||||||
|
//
|
||||||
|
// // 一次性查询所有 EnginePartsCollection
|
||||||
|
// List<EnginePartsCollection> allPartsCollections = bd.getTCDatabase()
|
||||||
|
// .in("ztj", productNumbers)
|
||||||
|
// .in("lbjmc", partsNames)
|
||||||
|
// .doQuery(EnginePartsCollection.class);
|
||||||
|
//
|
||||||
|
// // 按 productNumber 和 partsName 分组
|
||||||
|
// Map<String, Map<String, List<EnginePartsCollection>>> partsCollectionsMap = allPartsCollections.stream()
|
||||||
|
// .collect(Collectors.groupingBy(
|
||||||
|
// EnginePartsCollection::getZtj,
|
||||||
|
// Collectors.groupingBy(EnginePartsCollection::getLbjmc)
|
||||||
|
// ));
|
||||||
|
//
|
||||||
|
// // 收集所有图号
|
||||||
|
// Set<String> allLbjths = allPartsCollections.stream()
|
||||||
|
// .map(EnginePartsCollection::getLbjth)
|
||||||
|
// .filter(ObjectUtils::isNotEmpty)
|
||||||
|
// .collect(Collectors.toSet());
|
||||||
|
//
|
||||||
|
// if (allLbjths.isEmpty()) {
|
||||||
|
// return Collections.emptyList();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // 一次性查询所有 ClassificationAttribute
|
||||||
|
// List<ClassificationAttribute> allClassifications = bd.getTCDatabase()
|
||||||
|
// .in("pitemId", allLbjths)
|
||||||
|
// .doQuery(ClassificationAttribute.class);
|
||||||
|
//
|
||||||
|
// // 按 pitemId 分组
|
||||||
|
// Map<String, List<ClassificationAttribute>> classificationMap = allClassifications.stream()
|
||||||
|
// .collect(Collectors.groupingBy(ClassificationAttribute::getPitemId));
|
||||||
|
//
|
||||||
|
// // 构建结果
|
||||||
|
// List<EngineParamDetailPojo> result = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) {
|
||||||
|
// String productNumber = engineModelPojo.getProductNumber();
|
||||||
|
// if (ObjectUtils.isEmpty(productNumber)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Map<String, List<EnginePartsCollection>> partsMap = partsCollectionsMap.get(productNumber);
|
||||||
|
// if (partsMap == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (String partsName : partsNames) {
|
||||||
|
// List<Parameter> parameterList = stringListMap.get(partsName);
|
||||||
|
// if (parameterList == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Set<String> parameterNameSet = parameterList.stream()
|
||||||
|
// .map(Parameter::getParameterName).collect(Collectors.toSet());
|
||||||
|
//
|
||||||
|
// List<EnginePartsCollection> partsCollections = partsMap.get(partsName);
|
||||||
|
// if (partsCollections == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// List<String> lbjths = partsCollections.stream()
|
||||||
|
// .map(EnginePartsCollection::getLbjth)
|
||||||
|
// .filter(ObjectUtils::isNotEmpty)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
//
|
||||||
|
// for (String lbjth : lbjths) {
|
||||||
|
// List<ClassificationAttribute> classifications = classificationMap.get(lbjth);
|
||||||
|
// if (classifications == null) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for (ClassificationAttribute 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
public List<EngineParamDetailPojo> tcDataSelectAllByproductNumberBatch(List<DataEntryEngineModelPojo> engineModelPojos) {
|
public List<EngineParamDetailPojo> tcDataSelectAllByproductNumberBatch(List<DataEntryEngineModelPojo> engineModelPojos) {
|
||||||
|
if (CollectionUtils.isEmpty(engineModelPojos)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
// 收集所有 productNumber
|
// 收集所有 productNumber
|
||||||
Set<String> productNumbers = engineModelPojos.stream()
|
Set<String> productNumbers = engineModelPojos.stream()
|
||||||
.map(DataEntryEngineModelPojo::getProductNumber)
|
.map(DataEntryEngineModelPojo::getProductNumber)
|
||||||
.filter(ObjectUtils::isNotEmpty)
|
.filter(Objects::nonNull)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
if (productNumbers.isEmpty()) {
|
if (productNumbers.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一次性查询所有参数模板 TC 参数数据
|
List<Parameter> tcParameters = bd.getBusinessDatabase()
|
||||||
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
|
.viewQueryMode(true)
|
||||||
List<Parameter> collect = parameters.stream()
|
.view("selectTcParameter")
|
||||||
.filter(x -> "TC分类表".equals(x.getParameterSource()))
|
.doQuery(Parameter.class);
|
||||||
.collect(Collectors.toList());
|
if (CollectionUtils.isEmpty(tcParameters)) {
|
||||||
|
|
||||||
if (collect.isEmpty()) {
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按 partsName 分组
|
Set<String> allValidParamNames = tcParameters.stream()
|
||||||
Map<String, List<Parameter>> stringListMap = collect.stream()
|
.map(Parameter::getParameterName)
|
||||||
.collect(Collectors.groupingBy(Parameter::getPartsName));
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
Set<String> partsNames = stringListMap.keySet();
|
Map<String, Set<String>> partsName2ParamNameSet = tcParameters.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
Parameter::getPartsName,
|
||||||
|
Collectors.mapping(Parameter::getParameterName, Collectors.toSet())
|
||||||
|
));
|
||||||
|
|
||||||
// 一次性查询所有 EnginePartsCollection
|
Set<String> partsNames = partsName2ParamNameSet.keySet();
|
||||||
List<EnginePartsCollection> allPartsCollections = bd.getTCDatabase()
|
|
||||||
|
CompletableFuture<List<EnginePartsCollection>> partsCollectionFuture =
|
||||||
|
CompletableFuture.supplyAsync(() -> bd.getTCDatabase()
|
||||||
.in("ztj", productNumbers)
|
.in("ztj", productNumbers)
|
||||||
.in("lbjmc", partsNames)
|
.in("lbjmc", partsNames)
|
||||||
.doQuery(EnginePartsCollection.class);
|
.doQuery(EnginePartsCollection.class));
|
||||||
|
|
||||||
|
List<EnginePartsCollection> allPartsCollections;
|
||||||
|
try {
|
||||||
|
allPartsCollections = partsCollectionFuture.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
// 补充异常处理,避免线程中断导致请求失败
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(allPartsCollections)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
// 按 productNumber 和 partsName 分组
|
// 按 productNumber 和 partsName 分组
|
||||||
Map<String, Map<String, List<EnginePartsCollection>>> partsCollectionsMap = allPartsCollections.stream()
|
Map<String, Map<String, List<EnginePartsCollection>>> partsCollectionsMap = allPartsCollections.stream()
|
||||||
@ -798,20 +940,26 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
// 收集所有图号
|
// 收集所有图号
|
||||||
Set<String> allLbjths = allPartsCollections.stream()
|
Set<String> allLbjths = allPartsCollections.stream()
|
||||||
.map(EnginePartsCollection::getLbjth)
|
.map(EnginePartsCollection::getLbjth)
|
||||||
.filter(ObjectUtils::isNotEmpty)
|
.filter(Objects::nonNull)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
if (allLbjths.isEmpty()) {
|
if (allLbjths.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一次性查询所有 ClassificationAttribute
|
List<List<String>> lbjthBatches = splitBatch(allLbjths, lbjthBatchSize);
|
||||||
List<ClassificationAttribute> allClassifications = bd.getTCDatabase()
|
List<ClassificationAttribute> allClassifications = new ArrayList<>();
|
||||||
.in("pitemId", allLbjths)
|
for (List<String> batch : lbjthBatches) {
|
||||||
.doQuery(ClassificationAttribute.class);
|
allClassifications.addAll(
|
||||||
|
bd.getTCDatabase()
|
||||||
|
.in("pitemId", batch)
|
||||||
|
.doQuery(ClassificationAttribute.class)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 按 pitemId 分组
|
|
||||||
Map<String, List<ClassificationAttribute>> classificationMap = allClassifications.stream()
|
Map<String, List<ClassificationAttribute>> classificationMap = allClassifications.stream()
|
||||||
|
.filter(attr -> allValidParamNames.contains(attr.getIdattrtbutehame()))
|
||||||
.collect(Collectors.groupingBy(ClassificationAttribute::getPitemId));
|
.collect(Collectors.groupingBy(ClassificationAttribute::getPitemId));
|
||||||
|
|
||||||
// 构建结果
|
// 构建结果
|
||||||
@ -819,43 +967,42 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
|
|
||||||
for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) {
|
for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) {
|
||||||
String productNumber = engineModelPojo.getProductNumber();
|
String productNumber = engineModelPojo.getProductNumber();
|
||||||
if (ObjectUtils.isEmpty(productNumber)) {
|
if (Objects.isNull(productNumber) || productNumber.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<EnginePartsCollection>> partsMap = partsCollectionsMap.get(productNumber);
|
Map<String, List<EnginePartsCollection>> partsMap = partsCollectionsMap.get(productNumber);
|
||||||
if (partsMap == null) {
|
if (CollectionUtils.isEmpty((Collection) partsMap)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String partsName : partsNames) {
|
for (String partsName : partsMap.keySet()) {
|
||||||
List<Parameter> parameterList = stringListMap.get(partsName);
|
Set<String> parameterNameSet = partsName2ParamNameSet.get(partsName);
|
||||||
if (parameterList == null) {
|
if (CollectionUtils.isEmpty(parameterNameSet)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> parametersOnPartsName = parameterList.stream()
|
|
||||||
.map(Parameter::getParameterName)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<EnginePartsCollection> partsCollections = partsMap.get(partsName);
|
List<EnginePartsCollection> partsCollections = partsMap.get(partsName);
|
||||||
if (partsCollections == null) {
|
if (CollectionUtils.isEmpty(partsCollections)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 合并Stream操作,减少中间对象创建
|
||||||
List<String> lbjths = partsCollections.stream()
|
List<String> lbjths = partsCollections.stream()
|
||||||
.map(EnginePartsCollection::getLbjth)
|
.map(EnginePartsCollection::getLbjth)
|
||||||
.filter(ObjectUtils::isNotEmpty)
|
.filter(Objects::nonNull)
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (String lbjth : lbjths) {
|
for (String lbjth : lbjths) {
|
||||||
List<ClassificationAttribute> classifications = classificationMap.get(lbjth);
|
List<ClassificationAttribute> classifications = classificationMap.get(lbjth);
|
||||||
if (classifications == null) {
|
if (CollectionUtils.isEmpty(classifications)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 内层循环:利用HashSet的O(1) contains
|
||||||
for (ClassificationAttribute classificationAttribute : classifications) {
|
for (ClassificationAttribute classificationAttribute : classifications) {
|
||||||
if (parametersOnPartsName.contains(classificationAttribute.getIdattrtbutehame())) {
|
if (parameterNameSet.contains(classificationAttribute.getIdattrtbutehame())) {
|
||||||
EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo();
|
EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo();
|
||||||
engineParamDetailPojo.setEngineModelId(engineModelPojo.getId());
|
engineParamDetailPojo.setEngineModelId(engineModelPojo.getId());
|
||||||
engineParamDetailPojo.setPartsName(partsName);
|
engineParamDetailPojo.setPartsName(partsName);
|
||||||
@ -871,6 +1018,23 @@ public class TcDataQueryServiceImpl implements TcDataQueryService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 拆分in参数批次
|
||||||
|
private List<List<String>> splitBatch(Set<String> source, int batchSize) {
|
||||||
|
List<List<String>> batches = new ArrayList<>();
|
||||||
|
List<String> currentBatch = new ArrayList<>(batchSize);
|
||||||
|
for (String s : source) {
|
||||||
|
currentBatch.add(s);
|
||||||
|
if (currentBatch.size() >= batchSize) {
|
||||||
|
batches.add(new ArrayList<>(currentBatch));
|
||||||
|
currentBatch.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currentBatch.isEmpty()) {
|
||||||
|
batches.add(currentBatch);
|
||||||
|
}
|
||||||
|
return batches;
|
||||||
|
}
|
||||||
|
|
||||||
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
private void setupResponse(HttpServletResponse response, String fileName) throws IOException {
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
tc.query.model.batch.size=10
|
||||||
|
tc.query.lbjth.batch.size=500
|
||||||
|
|
||||||
# ====================== APAAS ???? ======================
|
# ====================== APAAS ???? ======================
|
||||||
apaas.token.url=http://apaas-meim.app.yuchai.com/apaas/backend/a5e8e08/ycgf-yf-rddata
|
apaas.token.url=http://apaas-meim.app.yuchai.com/apaas/backend/a5e8e08/ycgf-yf-rddata
|
||||||
apaas.token.clientId=2b5b3de8-e7fd-406a-a59a-d5568457b1f4
|
apaas.token.clientId=2b5b3de8-e7fd-406a-a59a-d5568457b1f4
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user