数据分析从数据中台实时查询与系统的参数结合待测试

This commit is contained in:
ys.git 2025-12-15 19:30:32 +08:00
parent 81b19e5465
commit 97aba734a8
8 changed files with 305 additions and 39 deletions

View File

@ -0,0 +1,32 @@
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.pojo.ClassificationAttribute;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/custom/tcDataQuery")
public class TcDataQueryController {
@Autowired
private TcDataQueryService tcDataQueryService;
;
//根据机型ID和子系统-零部件查询参数数据
@PostMapping("/tcDataSelectByPartsNames")
public Response tcDataSelectByPartsNames(@RequestBody AnalysisRequest analysisRequest) {
Map<String, List<EngineParamDetailPojo>> stringListHashMap = tcDataQueryService.tcDataSelectAllByPartsName(analysisRequest);
return Response.ok().data(stringListHashMap);
}
}

View File

@ -19,12 +19,10 @@ import java.util.List;
@Data @Data
public class AnalysisRequest{ public class AnalysisRequest{
private String engineModelID;
/** /**
* 机型列表 * 子系统+零部件名称路径
*/ */
private List<String> modelIds; private List<String> subsystemParts;
//常用参数id
private String commonId;
} }

View File

@ -9,7 +9,10 @@ import lombok.EqualsAndHashCode;
@Data @Data
@Table("ads_prd_f_tc_flsxb") @Table("ads_prd_f_tc_flsxb")
public class ClassificationAttribute extends MpaasBasePojo { public class ClassificationAttribute extends MpaasBasePojo {
//图号
private String pitemId; private String pitemId;
//参数名称
private String idattrtbutehame; private String idattrtbutehame;
//参数值
private String fieldvalue; private String fieldvalue;
} }

View File

@ -37,6 +37,7 @@ 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> selectAllAndTcByNewVersion();
List<EngineParamDetailPojo> selectByModelNewVersion(String model); List<EngineParamDetailPojo> selectByModelNewVersion(String model);
//根据责任人查询最新发版的参数详情 //根据责任人查询最新发版的参数详情

View File

@ -0,0 +1,23 @@
package com.xdap.self_development.service;
import com.xdap.self_development.controller.request.AnalysisRequest;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface TcDataQueryService {
//查询TC数据返回格式Map<model,List<parameter>>
HashMap<String, List<ClassificationAttribute>> tcDataSelectByC(String productNumber, String partsName, String parameterName);
ArrayList<EngineParamDetailPojo> tcDataSelectAllByproductNumber(DataEntryEngineModelPojo engineModelPojo);
Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsName(AnalysisRequest analysisRequest);
}

View File

@ -35,44 +35,47 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
@Autowired @Autowired
EngineParamDetailService engineParamDetailService; EngineParamDetailService engineParamDetailService;
@Autowired @Autowired
TcDataQueryService tcDataQueryService;
@Autowired
DataEntryEngineModelService dataEntryEngineModelService; DataEntryEngineModelService dataEntryEngineModelService;
private static final Pattern ALL_NUMBER_PATTERN = Pattern.compile("^[-+]?\\d+(\\.\\d+)?([Ee][-+]?\\d+)?$"); private static final Pattern ALL_NUMBER_PATTERN = Pattern.compile("^[-+]?\\d+(\\.\\d+)?([Ee][-+]?\\d+)?$");
@Override @Override
public ArrayList<AnalysisModelParamterView> selectModelParamByCommon(AnalysisRequest analysisRequest) { public ArrayList<AnalysisModelParamterView> selectModelParamByCommon(AnalysisRequest analysisRequest) {
if (ObjectUtils.isEmpty(analysisRequest.getModelIds()) || ObjectUtils.isEmpty(analysisRequest) || ObjectUtils.isEmpty(analysisRequest.getCommonId())) { // if (ObjectUtils.isEmpty(analysisRequest.getModelIds()) || ObjectUtils.isEmpty(analysisRequest) || ObjectUtils.isEmpty(analysisRequest.getCommonId())) {
log.warn("analysisRequest is empty"); // log.warn("analysisRequest is empty");
return null; // return null;
} // }
List<ModelCommonParameters> commons = businessDatabase.getBusinessDatabase() // List<ModelCommonParameters> commons = businessDatabase.getBusinessDatabase()
.eq("common_id", analysisRequest.getCommonId()) // .eq("common_id", analysisRequest.getCommonId())
.doQuery(ModelCommonParameters.class); // .doQuery(ModelCommonParameters.class);
List<String> paramIds = commons.stream().map(x -> x.getParameterId()).collect(Collectors.toList()); // List<String> paramIds = commons.stream().map(x -> x.getParameterId()).collect(Collectors.toList());
if (ObjectUtils.isEmpty(paramIds)) { // if (ObjectUtils.isEmpty(paramIds)) {
return null; // return null;
} // }
//
ArrayList<AnalysisModelParamterView> analysisModelParamterViews = new ArrayList<>(); // ArrayList<AnalysisModelParamterView> analysisModelParamterViews = new ArrayList<>();
//查找每个机型的参数并且根据常用筛选 // //查找每个机型的参数并且根据常用筛选
for (String modelId : analysisRequest.getModelIds()) { // for (String modelId : analysisRequest.getModelIds()) {
List<EngineParamDetailPojo> pojoListAll = new ArrayList<>(); // List<EngineParamDetailPojo> pojoListAll = new ArrayList<>();
List<EngineParamDetailPojo> pojoList = engineParamDetailService.selectByModelNewVersion(modelId); // List<EngineParamDetailPojo> pojoList = engineParamDetailService.selectByModelNewVersion(modelId);
List<EngineParamDetailPojo> pojos = pojoList.stream() // List<EngineParamDetailPojo> pojos = pojoList.stream()
.filter(x -> paramIds.contains(x.getParameterId())).collect(Collectors.toList()); // .filter(x -> paramIds.contains(x.getParameterId())).collect(Collectors.toList());
if (ObjectUtils.isNotEmpty(pojos)) { // if (ObjectUtils.isNotEmpty(pojos)) {
pojoListAll.addAll(pojos); // pojoListAll.addAll(pojos);
} // }
AnalysisModelParamterView analysisModelParamterView = new AnalysisModelParamterView(); // AnalysisModelParamterView analysisModelParamterView = new AnalysisModelParamterView();
DataEntryEngineModelPojo dataEntryEngineModelPojo = dataEntryEngineModelService.selectBymodelId(modelId); // DataEntryEngineModelPojo dataEntryEngineModelPojo = dataEntryEngineModelService.selectBymodelId(modelId);
analysisModelParamterView.setModelID(modelId); // analysisModelParamterView.setModelID(modelId);
analysisModelParamterView.setModelName(ObjectUtils.isEmpty(dataEntryEngineModelPojo.getModelName()) ? "" : dataEntryEngineModelPojo.getModelName()); // analysisModelParamterView.setModelName(ObjectUtils.isEmpty(dataEntryEngineModelPojo.getModelName()) ? "" : dataEntryEngineModelPojo.getModelName());
analysisModelParamterView.setPojos(pojoListAll); // analysisModelParamterView.setPojos(pojoListAll);
analysisModelParamterViews.add(analysisModelParamterView); // analysisModelParamterViews.add(analysisModelParamterView);
//
} // }
//
return analysisModelParamterViews; // return analysisModelParamterViews;
return null;
} }
@Override @Override
@ -102,13 +105,17 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
return (Double.compare(ec, engineCapacityMin) >= 0 && Double.compare(ec, engineCapacityMax) < 0); return (Double.compare(ec, engineCapacityMin) >= 0 && Double.compare(ec, engineCapacityMax) < 0);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
AnalysisModelParamterViewAndParam andParam = new AnalysisModelParamterViewAndParam(); AnalysisModelParamterViewAndParam andParam = new AnalysisModelParamterViewAndParam();
ArrayList<AnalysisModelParamterView> analysisModelParamterViews = new ArrayList<>(); ArrayList<AnalysisModelParamterView> analysisModelParamterViews = new ArrayList<>();
for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) { for (DataEntryEngineModelPojo engineModelPojo : engineModelPojos) {
AnalysisModelParamterView analysisModelParamterView = new AnalysisModelParamterView(); AnalysisModelParamterView analysisModelParamterView = new AnalysisModelParamterView();
List<EngineParamDetailPojo> pojoList = engineParamDetailService.selectByModelNewVersion(engineModelPojo.getId()); List<EngineParamDetailPojo> pojoList = engineParamDetailService.selectByModelNewVersion(engineModelPojo.getId());
pojoList = pojoList.stream().filter(x->ObjectUtils.isNotEmpty(x.getParameterValue()) && isNumber(x.getParameterValue())).collect(Collectors.toList()); // 编号&&零部件名称-参数
ArrayList<EngineParamDetailPojo> engineParamDetailPojos = tcDataQueryService.tcDataSelectAllByproductNumber(engineModelPojo);
pojoList.addAll(engineParamDetailPojos);
pojoList = pojoList.stream().filter(x -> ObjectUtils.isNotEmpty(x.getParameterValue()) && isNumber(x.getParameterValue())).collect(Collectors.toList());
analysisModelParamterView.setModelID(engineModelPojo.getId()); analysisModelParamterView.setModelID(engineModelPojo.getId());
analysisModelParamterView.setModelName(engineModelPojo.getModelName()); analysisModelParamterView.setModelName(engineModelPojo.getModelName());
BeanUtils.copyProperties(engineModelPojo, analysisModelParamterView); BeanUtils.copyProperties(engineModelPojo, analysisModelParamterView);
@ -117,7 +124,7 @@ public class AnalysisCommonParametersServiceImpl implements AnalysisCommonParame
} }
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (AnalysisModelParamterView analysisModelParamterView : analysisModelParamterViews) { for (AnalysisModelParamterView analysisModelParamterView : analysisModelParamterViews) {
analysisModelParamterView.getPojos().stream().forEach(x->list.add(x.getParameterName())); analysisModelParamterView.getPojos().stream().forEach(x -> list.add(x.getParameterName()));
} }
List<String> strings = list.stream().distinct().collect(Collectors.toList()); List<String> strings = list.stream().distinct().collect(Collectors.toList());
andParam.setParamList(strings); andParam.setParamList(strings);

View File

@ -599,6 +599,43 @@ public class EngineParamDetailServiceImpl implements EngineParamDetailService {
return parameterList; return parameterList;
} }
@Override
public List<Parameter> selectAllAndTcByNewVersion() {
//读取已通过审核的版本 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);
return parameterList;
}
@Override @Override
public List<EngineParamDetailPojo> selectByModelNewVersion(String modelId) { public List<EngineParamDetailPojo> selectByModelNewVersion(String modelId) {

View File

@ -0,0 +1,165 @@
package com.xdap.self_development.service.impl;
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.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.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class TcDataQueryServiceImpl implements TcDataQueryService {
@Autowired
private BusinessDatabase bd;
@Autowired
private EngineParamDetailService engineParamDetailService;
@Autowired
private DataEntryEngineModelService engineModelService;
@Autowired
private MpaasQueryFactory sw;
//产品编号(状态代号) = 状态机
@Override
public HashMap<String, List<ClassificationAttribute>> tcDataSelectByC(String productNumber, String partsName, String parameterName) {
EnginePartsCollection enginePartsCollection = bd.getTCDatabase()
.eq("ztj", productNumber)
.eq("lbjmc", partsName)
.doQueryFirst(EnginePartsCollection.class);
if (enginePartsCollection == null || enginePartsCollection.getLbjth() == null) {
return null;
}
List<ClassificationAttribute> list = bd.getTCDatabase()
.eq("pitemId", enginePartsCollection.getLbjth())
.doQuery(ClassificationAttribute.class);
HashMap<String, List<ClassificationAttribute>> stringListHashMap = new HashMap<>();
stringListHashMap.put(productNumber, list);
return stringListHashMap;
}
//通过状态代号产品编号 返回编号&&零部件名称-参数
@Override
public ArrayList<EngineParamDetailPojo> tcDataSelectAllByproductNumber(DataEntryEngineModelPojo engineModelPojo) {
String productNumber = engineModelPojo.getProductNumber();
HashMap<String, List<ClassificationAttribute>> stringListHashMap = new HashMap<>();
List<EnginePartsCollection> partsCollections = bd.getTCDatabase()
.eq("ztj", productNumber)
.doQuery(EnginePartsCollection.class);
ArrayList<EngineParamDetailPojo> engineParamDetailPojos = new ArrayList<>();
for (EnginePartsCollection partsCollection : partsCollections) {
if (partsCollections == null || partsCollection.getLbjth() == null) {
continue;
}
List<ClassificationAttribute> list = bd.getTCDatabase()
.eq("pitemId", partsCollection.getLbjth())
.doQuery(ClassificationAttribute.class);
for (ClassificationAttribute classificationAttribute : list) {
EngineParamDetailPojo engineParamDetailPojo = new EngineParamDetailPojo();
engineParamDetailPojo.setEngineModelId(engineModelPojo.getId());
engineParamDetailPojo.setPartsName(partsCollection.getLbjmc());
engineParamDetailPojo.setParameterName(classificationAttribute.getIdattrtbutehame());
engineParamDetailPojo.setParameterValue(classificationAttribute.getFieldvalue());
engineParamDetailPojos.add(engineParamDetailPojo);
}
}
return engineParamDetailPojos;
}
@Override
public Map<String, List<EngineParamDetailPojo>> tcDataSelectAllByPartsName(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<EngineParamDetailPojo> SysAllPojos = new ArrayList<>();
List<Parameter> parameters = engineParamDetailService.selectAllAndTcByNewVersion();
DataEntryEngineModelPojo dataEntryEngineModelPojo = engineModelService.selectBymodelId(engineModelID);
//查到所有TC表的参数 返回零部件参数列表
for (String subsystemType : subsystemTypes) {
HashMap<String, List<ClassificationAttribute>> stringListHashMap = new HashMap<>();
if (subsystemType.split("-").length != 2) {
throw new RuntimeException("查询条件异常,需子系统-零部件名称,若零部件为空则传入“/”");
}
String subsystem = subsystemType.split("-")[0];
String parts_name = subsystemType.split("-")[1];
//开始查找系统数据
List<EngineParamDetailPojo> pojoList = sw.buildFromDatasource("xdap_app_223770822127386625")
.eq("engine_model_id", engineModelID)
.eq("subsystem_name", subsystem)
.eq("parts_name", parts_name)
.doQuery(EngineParamDetailPojo.class);
pojoList = pojoList.stream()
.filter(x -> x.getMajorVersion()
.equals(dataEntryEngineModelPojo.getVersionNumber())).collect(Collectors.toList());
if (ObjectUtils.isNotEmpty(pojoList)) {
allPojos.addAll(pojoList);
}
//开始查找TC数据
List<EnginePartsCollection> lbjmcs = bd.getTCDatabase()
.eq("ztj", dataEntryEngineModelPojo.getProductNumber())
.eq("lbjmc", parts_name)
.doQuery(EnginePartsCollection.class);
if (ObjectUtils.isEmpty(lbjmcs)) {
log.error("根据零部件未找到状态机图号列表");
return null;
}
for (EnginePartsCollection lbjmc : lbjmcs) {
//获取图号
String lbjth = lbjmc.getLbjth();
if (ObjectUtils.isEmpty(lbjth)) {
continue;
}
List<ClassificationAttribute> list = bd.getTCDatabase()
.eq("pitemId", lbjth)
.doQuery(ClassificationAttribute.class);
stringListHashMap.put(parts_name, list);
}
for (Map.Entry<String, List<ClassificationAttribute>> stringListEntry : stringListHashMap.entrySet()) {
String key = stringListEntry.getKey();//零部件
List<ClassificationAttribute> list = stringListEntry.getValue();//零部件里的值
for (ClassificationAttribute classificationAttribute : list) {
String idattrtbutehame = classificationAttribute.getIdattrtbutehame();
String fieldvalue = classificationAttribute.getFieldvalue();
List<EngineParamDetailPojo> 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.setParameterName(x.getSubsystemName());
engineParamDetailPojo.setParameterValue(fieldvalue);
return engineParamDetailPojo;
}).collect(Collectors.toList());
if (ObjectUtils.isNotEmpty(pojos)) {
allPojos.addAll(pojos);
}
}
}
}
Map<String, List<EngineParamDetailPojo>> valueBySubSysName =
allPojos.stream().collect(Collectors.groupingBy(EngineParamDetailPojo::getSubsystemName));
return valueBySubSysName;
}
}