同步规程同步代码和录入监测代码

This commit is contained in:
2026-05-23 19:34:52 +08:00
parent 6b58f37616
commit 35ad50a79d
29 changed files with 2357 additions and 329 deletions

View File

@@ -24,8 +24,12 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 规程版本Service实现
@@ -139,6 +143,135 @@ public class WmsProcessSpecVersionServiceImpl implements IWmsProcessSpecVersionS
return baseMapper.updateById(one) > 0;
}
@Override
public WmsProcessSpecVersionVo matchBestVersion(BigDecimal entryThick, BigDecimal exitThick,
BigDecimal entryWidth, BigDecimal exitWidth,
String grade, Long lineId) {
LambdaQueryWrapper<WmsProcessSpecVersion> lqw = Wrappers.lambdaQuery();
lqw.eq(WmsProcessSpecVersion::getIsActive, 1);
List<WmsProcessSpecVersionVo> versions = baseMapper.selectVoList(lqw);
if (versions.isEmpty()) {
return null;
}
// 按产线ID过滤只匹配属于指定产线的规程版本
if (lineId != null) {
List<Long> specIds = versions.stream()
.map(WmsProcessSpecVersionVo::getSpecId).distinct().collect(Collectors.toList());
LambdaQueryWrapper<WmsProcessSpec> slqw = Wrappers.lambdaQuery();
slqw.in(WmsProcessSpec::getSpecId, specIds);
slqw.eq(WmsProcessSpec::getLineId, lineId);
Set<Long> validSpecIds = wmsProcessSpecMapper.selectList(slqw)
.stream().map(WmsProcessSpec::getSpecId).collect(Collectors.toSet());
versions = versions.stream()
.filter(v -> validSpecIds.contains(v.getSpecId())).collect(Collectors.toList());
if (versions.isEmpty()) {
return null;
}
}
WmsProcessSpecVersionVo best = null;
int bestScore = -1;
for (WmsProcessSpecVersionVo v : versions) {
int score = 0;
if (entryThick != null && v.getMatchEntryThickMin() != null && v.getMatchEntryThickMax() != null
&& entryThick.compareTo(v.getMatchEntryThickMin()) >= 0
&& entryThick.compareTo(v.getMatchEntryThickMax()) <= 0) {
score++;
}
if (exitThick != null && v.getMatchExitThickMin() != null && v.getMatchExitThickMax() != null
&& exitThick.compareTo(v.getMatchExitThickMin()) >= 0
&& exitThick.compareTo(v.getMatchExitThickMax()) <= 0) {
score++;
}
if (entryWidth != null && v.getMatchEntryWidthMin() != null && v.getMatchEntryWidthMax() != null
&& entryWidth.compareTo(v.getMatchEntryWidthMin()) >= 0
&& entryWidth.compareTo(v.getMatchEntryWidthMax()) <= 0) {
score++;
}
if (exitWidth != null && v.getMatchExitWidthMin() != null && v.getMatchExitWidthMax() != null
&& exitWidth.compareTo(v.getMatchExitWidthMin()) >= 0
&& exitWidth.compareTo(v.getMatchExitWidthMax()) <= 0) {
score++;
}
if (StringUtils.isNotBlank(grade) && StringUtils.isNotBlank(v.getMatchSteelGrade())
&& grade.toLowerCase().contains(v.getMatchSteelGrade().toLowerCase())) {
score++;
}
if (score > bestScore) {
bestScore = score;
best = v;
}
}
if (best == null || bestScore == 0) {
return null;
}
WmsProcessSpec spec = wmsProcessSpecMapper.selectById(best.getSpecId());
if (spec != null) {
best.setSpecCode(spec.getSpecCode());
best.setSpecName(spec.getSpecName());
}
return best;
}
@Override
public List<WmsProcessSpecVersionVo> queryActiveVersionsEnriched(Long lineId) {
LambdaQueryWrapper<WmsProcessSpecVersion> lqw = Wrappers.lambdaQuery();
lqw.eq(WmsProcessSpecVersion::getIsActive, 1);
List<WmsProcessSpecVersionVo> versions = baseMapper.selectVoList(lqw);
if (versions.isEmpty()) {
return versions;
}
if (lineId != null) {
List<Long> specIds = versions.stream()
.map(WmsProcessSpecVersionVo::getSpecId).distinct().collect(Collectors.toList());
LambdaQueryWrapper<WmsProcessSpec> slqw = Wrappers.lambdaQuery();
slqw.in(WmsProcessSpec::getSpecId, specIds);
slqw.eq(WmsProcessSpec::getLineId, lineId);
Set<Long> validSpecIds = wmsProcessSpecMapper.selectList(slqw)
.stream().map(WmsProcessSpec::getSpecId).collect(Collectors.toSet());
versions = versions.stream()
.filter(v -> validSpecIds.contains(v.getSpecId())).collect(Collectors.toList());
if (versions.isEmpty()) {
return versions;
}
}
enrichVersionsWithSpec(versions);
return versions;
}
@Override
public List<WmsProcessSpecVersionVo> queryAllVersionsEnriched() {
// 不过滤 isActive获取全部版本含历史版本用于展示已绑定规程名称
List<WmsProcessSpecVersionVo> versions = baseMapper.selectVoList(Wrappers.lambdaQuery());
if (versions.isEmpty()) return versions;
enrichVersionsWithSpec(versions);
return versions;
}
/** 批量填充 specCode / specName / lineId公共逻辑 */
private void enrichVersionsWithSpec(List<WmsProcessSpecVersionVo> versions) {
List<Long> specIds = versions.stream()
.map(WmsProcessSpecVersionVo::getSpecId).distinct().collect(Collectors.toList());
LambdaQueryWrapper<WmsProcessSpec> sq = Wrappers.lambdaQuery();
sq.in(WmsProcessSpec::getSpecId, specIds);
Map<Long, WmsProcessSpec> specMap = wmsProcessSpecMapper.selectList(sq).stream()
.collect(Collectors.toMap(WmsProcessSpec::getSpecId, s -> s, (a, b) -> a));
for (WmsProcessSpecVersionVo v : versions) {
WmsProcessSpec spec = specMap.get(v.getSpecId());
if (spec != null) {
v.setSpecCode(spec.getSpecCode());
v.setSpecName(spec.getSpecName());
v.setLineId(spec.getLineId());
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {