2026-04-20 19:14:50 +08:00
|
|
|
|
package com.klp.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
|
import com.klp.common.core.domain.PageQuery;
|
|
|
|
|
|
import com.klp.common.core.page.TableDataInfo;
|
|
|
|
|
|
import com.klp.common.exception.ServiceException;
|
|
|
|
|
|
import com.klp.common.utils.StringUtils;
|
|
|
|
|
|
import com.klp.domain.WmsProcessSpec;
|
|
|
|
|
|
import com.klp.domain.WmsProcessPlan;
|
2026-04-20 19:34:01 +08:00
|
|
|
|
import com.klp.domain.WmsProcessPlanParam;
|
2026-04-20 19:14:50 +08:00
|
|
|
|
import com.klp.domain.WmsProcessSpecVersion;
|
|
|
|
|
|
import com.klp.domain.bo.WmsProcessSpecVersionBo;
|
|
|
|
|
|
import com.klp.domain.vo.WmsProcessSpecVersionVo;
|
|
|
|
|
|
import com.klp.mapper.WmsProcessPlanMapper;
|
2026-04-20 19:34:01 +08:00
|
|
|
|
import com.klp.mapper.WmsProcessPlanParamMapper;
|
2026-04-20 19:14:50 +08:00
|
|
|
|
import com.klp.mapper.WmsProcessSpecMapper;
|
|
|
|
|
|
import com.klp.mapper.WmsProcessSpecVersionMapper;
|
|
|
|
|
|
import com.klp.service.IWmsProcessSpecVersionService;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
2026-05-23 19:34:52 +08:00
|
|
|
|
import java.math.BigDecimal;
|
2026-04-20 19:14:50 +08:00
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import java.util.List;
|
2026-05-23 19:34:52 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2026-04-20 19:14:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 规程版本Service实现
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author klp
|
|
|
|
|
|
*/
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class WmsProcessSpecVersionServiceImpl implements IWmsProcessSpecVersionService {
|
|
|
|
|
|
|
|
|
|
|
|
private final WmsProcessSpecVersionMapper baseMapper;
|
|
|
|
|
|
private final WmsProcessSpecMapper wmsProcessSpecMapper;
|
|
|
|
|
|
private final WmsProcessPlanMapper wmsProcessPlanMapper;
|
2026-04-20 19:34:01 +08:00
|
|
|
|
private final WmsProcessPlanParamMapper wmsProcessPlanParamMapper;
|
2026-04-20 19:14:50 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public WmsProcessSpecVersionVo queryById(Long versionId) {
|
|
|
|
|
|
return baseMapper.selectVoById(versionId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public TableDataInfo<WmsProcessSpecVersionVo> queryPageList(WmsProcessSpecVersionBo bo, PageQuery pageQuery) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsProcessSpecVersion> lqw = buildQueryWrapper(bo);
|
|
|
|
|
|
Page<WmsProcessSpecVersionVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
|
|
|
return TableDataInfo.build(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public List<WmsProcessSpecVersionVo> queryList(WmsProcessSpecVersionBo bo) {
|
|
|
|
|
|
return baseMapper.selectVoList(buildQueryWrapper(bo));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<WmsProcessSpecVersion> buildQueryWrapper(WmsProcessSpecVersionBo bo) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsProcessSpecVersion> lqw = Wrappers.lambdaQuery();
|
|
|
|
|
|
lqw.eq(bo.getSpecId() != null, WmsProcessSpecVersion::getSpecId, bo.getSpecId());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getVersionCode()), WmsProcessSpecVersion::getVersionCode, bo.getVersionCode());
|
|
|
|
|
|
lqw.eq(bo.getIsActive() != null, WmsProcessSpecVersion::getIsActive, bo.getIsActive());
|
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), WmsProcessSpecVersion::getStatus, bo.getStatus());
|
|
|
|
|
|
lqw.orderByDesc(WmsProcessSpecVersion::getCreateTime);
|
|
|
|
|
|
return lqw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
public Boolean insertByBo(WmsProcessSpecVersionBo bo) {
|
|
|
|
|
|
WmsProcessSpec spec = wmsProcessSpecMapper.selectById(bo.getSpecId());
|
|
|
|
|
|
if (spec == null) {
|
|
|
|
|
|
throw new ServiceException("规程不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
WmsProcessSpecVersion add = BeanUtil.toBean(bo, WmsProcessSpecVersion.class);
|
|
|
|
|
|
if (add.getIsActive() == null) {
|
|
|
|
|
|
add.setIsActive(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isBlank(add.getStatus())) {
|
|
|
|
|
|
add.setStatus("DRAFT");
|
|
|
|
|
|
}
|
|
|
|
|
|
validEntityBeforeSave(add);
|
|
|
|
|
|
boolean ok = baseMapper.insert(add) > 0;
|
|
|
|
|
|
if (ok) {
|
|
|
|
|
|
bo.setVersionId(add.getVersionId());
|
|
|
|
|
|
if (Integer.valueOf(1).equals(add.getIsActive())) {
|
|
|
|
|
|
activateVersion(add.getVersionId());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return ok;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
public Boolean updateByBo(WmsProcessSpecVersionBo bo) {
|
|
|
|
|
|
WmsProcessSpecVersion exist = baseMapper.selectById(bo.getVersionId());
|
|
|
|
|
|
if (exist == null) {
|
|
|
|
|
|
throw new ServiceException("版本不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
WmsProcessSpecVersion update = BeanUtil.toBean(bo, WmsProcessSpecVersion.class);
|
|
|
|
|
|
validEntityBeforeSave(update);
|
|
|
|
|
|
boolean ok = baseMapper.updateById(update) > 0;
|
|
|
|
|
|
if (ok && Integer.valueOf(1).equals(update.getIsActive())) {
|
|
|
|
|
|
activateVersion(update.getVersionId());
|
|
|
|
|
|
}
|
|
|
|
|
|
return ok;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validEntityBeforeSave(WmsProcessSpecVersion entity) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsProcessSpecVersion> lqw = Wrappers.lambdaQuery();
|
|
|
|
|
|
lqw.eq(WmsProcessSpecVersion::getSpecId, entity.getSpecId());
|
|
|
|
|
|
lqw.eq(WmsProcessSpecVersion::getVersionCode, entity.getVersionCode());
|
|
|
|
|
|
if (entity.getVersionId() != null) {
|
|
|
|
|
|
lqw.ne(WmsProcessSpecVersion::getVersionId, entity.getVersionId());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (baseMapper.selectCount(lqw) > 0) {
|
|
|
|
|
|
throw new ServiceException("同一规程下版本号已存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
public Boolean activateVersion(Long versionId) {
|
|
|
|
|
|
WmsProcessSpecVersion v = baseMapper.selectById(versionId);
|
|
|
|
|
|
if (v == null) {
|
|
|
|
|
|
throw new ServiceException("版本不存在");
|
|
|
|
|
|
}
|
|
|
|
|
|
LambdaUpdateWrapper<WmsProcessSpecVersion> clear = Wrappers.lambdaUpdate();
|
|
|
|
|
|
clear.eq(WmsProcessSpecVersion::getSpecId, v.getSpecId());
|
|
|
|
|
|
clear.set(WmsProcessSpecVersion::getIsActive, 0);
|
|
|
|
|
|
baseMapper.update(null, clear);
|
|
|
|
|
|
|
|
|
|
|
|
WmsProcessSpecVersion one = new WmsProcessSpecVersion();
|
|
|
|
|
|
one.setVersionId(versionId);
|
|
|
|
|
|
one.setIsActive(1);
|
|
|
|
|
|
return baseMapper.updateById(one) > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 19:34:52 +08:00
|
|
|
|
@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());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-20 19:14:50 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
|
|
|
for (Long versionId : ids) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsProcessPlan> pq = Wrappers.lambdaQuery();
|
|
|
|
|
|
pq.eq(WmsProcessPlan::getVersionId, versionId);
|
2026-04-20 19:34:01 +08:00
|
|
|
|
List<WmsProcessPlan> plans = wmsProcessPlanMapper.selectList(pq);
|
|
|
|
|
|
for (WmsProcessPlan plan : plans) {
|
|
|
|
|
|
LambdaQueryWrapper<WmsProcessPlanParam> pr = Wrappers.lambdaQuery();
|
|
|
|
|
|
pr.eq(WmsProcessPlanParam::getPlanId, plan.getPlanId());
|
|
|
|
|
|
wmsProcessPlanParamMapper.delete(pr);
|
|
|
|
|
|
}
|
2026-04-20 19:14:50 +08:00
|
|
|
|
wmsProcessPlanMapper.delete(pq);
|
|
|
|
|
|
}
|
|
|
|
|
|
return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|