pdi导入逻辑修改

pdi部件绑定修改
This commit is contained in:
yf001217 2026-06-13 18:29:26 +08:00
parent 5eff7ea7b9
commit 7e5de36bd0
4 changed files with 136 additions and 24 deletions

View File

@ -84,7 +84,11 @@ public class QmsPdiComponentBindingControllerService {
continue;
}
for (QmsPdiComponentBindingSaveQO.ComponentBindingQO component : item.getComponents()) {
List<QmsPdiComponentAnagement> matchedComponents = componentMap.get(component.getComponentName());
String componentName = appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName());
List<QmsPdiComponentAnagement> matchedComponents = componentMap.get(componentName);
if (CollectionUtil.isEmpty(matchedComponents)) {
matchedComponents = componentMap.get(component.getComponentName());
}
if (CollectionUtil.isEmpty(matchedComponents)) {
throw new NflgException(STATE.BusinessError, "部件名称不存在:" + component.getComponentName());
}
@ -190,7 +194,7 @@ public class QmsPdiComponentBindingControllerService {
Map<String, Integer> sortMap = new LinkedHashMap<>();
for (QmsPdiComponentAnagement component : components) {
String componentName = component.getComponentName();
String componentName = appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName());
Integer currentSort = sortMap.get(componentName);
if (!sortMap.containsKey(componentName)
|| currentSort == null
@ -260,13 +264,26 @@ public class QmsPdiComponentBindingControllerService {
if (CollectionUtil.isEmpty(componentIds)) {
return Collections.emptyMap();
}
return componentService.lambdaQuery()
Set<String> queryNames = componentNames.stream()
.filter(StrUtil::isNotBlank)
.flatMap(componentName -> List.of(
componentName,
appendNewlineIfMixedChineseEnglishEndsWithEnglish(componentName)
).stream())
.collect(Collectors.toSet());
Map<String, List<QmsPdiComponentAnagement>> componentMap = new LinkedHashMap<>();
componentService.lambdaQuery()
.eq(QmsPdiComponentAnagement::getDetectionRulesId, detectionRulesId)
.in(QmsPdiComponentAnagement::getId, componentIds)
.in(QmsPdiComponentAnagement::getComponentName, componentNames)
.in(QmsPdiComponentAnagement::getComponentName, queryNames)
.list()
.stream()
.collect(Collectors.groupingBy(QmsPdiComponentAnagement::getComponentName, LinkedHashMap::new, Collectors.toList()));
.forEach(component -> {
addComponentAlias(componentMap, component.getComponentName(), component);
addComponentAlias(componentMap,
appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName()),
component);
});
return componentMap;
}
private List<Long> getUsedComponentIds(Long detectionRulesId) {
@ -337,7 +354,8 @@ public class QmsPdiComponentBindingControllerService {
List<QmsPdiComponentBindingSearchVO.InspectionItemVO> inspectionItems) {
QmsPdiComponentBindingSearchVO.ComponentBindingVO componentVO = new QmsPdiComponentBindingSearchVO.ComponentBindingVO();
componentVO.setPdiComponentId(componentId);
componentVO.setPdiComponentName(component == null ? null : component.getComponentName());
componentVO.setPdiComponentName(component == null ? null
: appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName()));
componentVO.setStatus(status);
componentVO.setInspectionItems(inspectionItems == null ? new ArrayList<>() : new ArrayList<>(inspectionItems));
return componentVO;
@ -385,6 +403,44 @@ public class QmsPdiComponentBindingControllerService {
return new ComponentStatus(Long.valueOf(parts[0]), Short.valueOf(parts[1]));
}
private void addComponentAlias(Map<String, List<QmsPdiComponentAnagement>> componentMap,
String componentName,
QmsPdiComponentAnagement component) {
if (StrUtil.isBlank(componentName)) {
return;
}
componentMap.computeIfAbsent(componentName, ignored -> new ArrayList<>()).add(component);
}
private String appendNewlineIfMixedChineseEnglishEndsWithEnglish(String text) {
if (StrUtil.isBlank(text)) {
return text;
}
String value = text.replaceAll("\\s+$", "");
boolean hasChinese = false;
boolean hasEnglish = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (isChinese(c)) {
hasChinese = true;
} else if (isEnglishLetter(c)) {
hasEnglish = true;
}
}
if (hasChinese && hasEnglish && isEnglishLetter(value.charAt(value.length() - 1))) {
return value + "\n";
}
return value;
}
private boolean isChinese(char c) {
return c >= '\u4e00' && c <= '\u9fff';
}
private boolean isEnglishLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
private static class ComponentStatus {
private final Long componentId;
private final Short status;

View File

@ -50,7 +50,7 @@ public class QmsPdiComponentControllerService {
@Transactional
public void add(QmsPdiComponentAddQO request) {
QmsPdiComponentAnagement entity = new QmsPdiComponentAnagement()
.setComponentName(request.getComponentName())
.setComponentName(appendNewlineIfMixedChineseEnglishEndsWithEnglish(request.getComponentName()))
.setDetectionRulesId(request.getDetectionRulesId())
.setCreateBy(UserUtil.getUserName())
.setCreateTime(LocalDateTime.now());
@ -71,7 +71,8 @@ public class QmsPdiComponentControllerService {
var updateChain = componentService.lambdaUpdate()
.eq(QmsPdiComponentAnagement::getId, request.getId());
if (StrUtil.isNotBlank(request.getComponentName())) {
updateChain.set(QmsPdiComponentAnagement::getComponentName, request.getComponentName());
updateChain.set(QmsPdiComponentAnagement::getComponentName,
appendNewlineIfMixedChineseEnglishEndsWithEnglish(request.getComponentName()));
}
updateChain.update();
}
@ -97,7 +98,39 @@ public class QmsPdiComponentControllerService {
*/
public IPage<QmsPdiComponentAnagement> search(QmsPdiComponentSearchQO request) {
Page<QmsPdiComponentAnagement> page = new Page<>(request.getPage(), request.getPageSize());
return componentMapper.search(request, page);
IPage<QmsPdiComponentAnagement> result = componentMapper.search(request, page);
result.getRecords().forEach(component ->
component.setComponentName(appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName())));
return result;
}
private String appendNewlineIfMixedChineseEnglishEndsWithEnglish(String text) {
if (StrUtil.isBlank(text)) {
return text;
}
String value = text.replaceAll("\\s+$", "");
boolean hasChinese = false;
boolean hasEnglish = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (isChinese(c)) {
hasChinese = true;
} else if (isEnglishLetter(c)) {
hasEnglish = true;
}
}
if (hasChinese && hasEnglish && isEnglishLetter(value.charAt(value.length() - 1))) {
return value + "\n";
}
return value;
}
private boolean isChinese(char c) {
return c >= '\u4e00' && c <= '\u9fff';
}
private boolean isEnglishLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
// ========================= 查询部件检测项 =========================

View File

@ -80,8 +80,9 @@ public class QmsPdiStatusItemControllerService {
// 处理部件部件状态复用检测项的status
if (!isSpecialStatus(request.getStatus()) && StrUtil.isNotBlank(request.getComponentsDes())) {
// 检查部件是否已存在按检测规则ID + 名称 + 状态查询
String componentName = appendNewlineIfMixedChineseEnglishEndsWithEnglish(request.getComponentsDes());
QmsPdiComponentAnagement existingComponent = componentAnagementService.lambdaQuery()
.eq(QmsPdiComponentAnagement::getComponentName, request.getComponentsDes())
.in(QmsPdiComponentAnagement::getComponentName, request.getComponentsDes(), componentName)
.eq(QmsPdiComponentAnagement::getDetectionRulesId, request.getDetectionRulesId())
.eq(QmsPdiComponentAnagement::getStatus, request.getStatus())
.one();
@ -93,7 +94,7 @@ public class QmsPdiStatusItemControllerService {
QmsPdiComponentAnagement component = createComponent(
request.getDetectionRulesId(),
request.getStatus(),
request.getComponentsDes(),
componentName,
operator,
now
);
@ -360,20 +361,21 @@ public class QmsPdiStatusItemControllerService {
// 处理部件
if (!isSpecialStatus(status) && StrUtil.isNotBlank(dto.getComponentsDes())) {
if (componentNameToIdMap.containsKey(dto.getComponentsDes())) {
String componentName = appendNewlineIfMixedChineseEnglishEndsWithEnglish(dto.getComponentsDes());
if (componentNameToIdMap.containsKey(componentName)) {
// 部件已存在直接使用
componentsId = componentNameToIdMap.get(dto.getComponentsDes());
componentsId = componentNameToIdMap.get(componentName);
} else {
QmsPdiComponentAnagement component = componentAnagementService.lambdaQuery()
.eq(QmsPdiComponentAnagement::getDetectionRulesId, detectionRulesId)
.eq(QmsPdiComponentAnagement::getStatus, status)
.eq(QmsPdiComponentAnagement::getComponentName, dto.getComponentsDes())
.in(QmsPdiComponentAnagement::getComponentName, dto.getComponentsDes(), componentName)
.one();
if (component == null) {
component = createComponent(detectionRulesId, status, dto.getComponentsDes(), operator, now);
component = createComponent(detectionRulesId, status, componentName, operator, now);
}
componentsId = component.getId();
componentNameToIdMap.put(dto.getComponentsDes(), componentsId);
componentNameToIdMap.put(componentName, componentsId);
componentItemCountMap.put(componentsId, getMaxItemSort(detectionRulesId, status, componentsId));
}
} else {
@ -381,7 +383,7 @@ public class QmsPdiStatusItemControllerService {
}
// 处理检查核实内容如果以英文字母结束追加换行符
dto.setInspectionContent(appendNewlineIfEndsWithEnglish(dto.getInspectionContent()));
dto.setInspectionContent(appendNewlineIfMixedChineseEnglishEndsWithEnglish(dto.getInspectionContent()));
// 插入检测项
int itemSort = componentItemCountMap.getOrDefault(componentsId, 0) + 1;
@ -405,15 +407,33 @@ public class QmsPdiStatusItemControllerService {
/**
* 如果文本以英文字母结尾则追加换行符
*/
private String appendNewlineIfEndsWithEnglish(String text) {
private String appendNewlineIfMixedChineseEnglishEndsWithEnglish(String text) {
if (StrUtil.isBlank(text)) {
return text;
}
char lastChar = text.charAt(text.length() - 1);
if ((lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z')) {
return text + "\n";
String value = text.replaceAll("\\s+$", "");
boolean hasChinese = false;
boolean hasEnglish = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if (isChinese(c)) {
hasChinese = true;
} else if (isEnglishLetter(c)) {
hasEnglish = true;
}
}
return text;
if (hasChinese && hasEnglish && isEnglishLetter(value.charAt(value.length() - 1))) {
return value + "\n";
}
return value;
}
private boolean isChinese(char c) {
return c >= '\u4e00' && c <= '\u9fff';
}
private boolean isEnglishLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
// ========================= 分页查询 =========================
@ -472,7 +492,7 @@ public class QmsPdiStatusItemControllerService {
QmsPdiStatusItemGroupVO groupVO = new QmsPdiStatusItemGroupVO();
groupVO.setDetectionRulesId(request.getDetectionRulesId());
groupVO.setComponentsId(component.getId());
groupVO.setComponentName(component.getComponentName());
groupVO.setComponentName(appendNewlineIfMixedChineseEnglishEndsWithEnglish(component.getComponentName()));
groupVO.setSort(component.getSort());
// 获取该部件下的检测项

View File

@ -1,6 +1,7 @@
package com.nflg.wms.common.pojo.qo;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
@ -57,6 +58,7 @@ public class QmsPdiComponentBindingSaveQO {
* x轴坐标
*/
@NotBlank(message = "x轴坐标不能为空")
@JsonProperty("xCoordinatePoint")
@JsonAlias({"x_coordinate_point", "XCoordinatePoint"})
private String xCoordinatePoint;
@ -64,6 +66,7 @@ public class QmsPdiComponentBindingSaveQO {
* y轴坐标
*/
@NotBlank(message = "y轴坐标不能为空")
@JsonProperty("yCoordinatePoint")
@JsonAlias({"y_coordinate_point", "YCoordinatePoint"})
private String yCoordinatePoint;
}