feat(wms): 增加版本管理功能和操作按钮

在规程主表的操作列中新增“版本与方案”按钮,点击后可跳转至版本管理页面。更新了操作列的宽度以适应新按钮。同时,在后端服务中添加了对规程版本存在性的校验,确保在删除规程时不会影响相关版本数据。
This commit is contained in:
王文昊
2026-04-20 19:14:50 +08:00
parent 62b594026b
commit f501994da6
22 changed files with 1357 additions and 2 deletions

View File

@@ -0,0 +1,107 @@
package com.klp.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.WmsProcessPlan;
import com.klp.domain.WmsProcessSpecVersion;
import com.klp.domain.bo.WmsProcessPlanBo;
import com.klp.domain.vo.WmsProcessPlanVo;
import com.klp.mapper.WmsProcessPlanMapper;
import com.klp.mapper.WmsProcessSpecVersionMapper;
import com.klp.service.IWmsProcessPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
/**
* 方案点位Service实现
*
* @author klp
*/
@RequiredArgsConstructor
@Service
public class WmsProcessPlanServiceImpl implements IWmsProcessPlanService {
private final WmsProcessPlanMapper baseMapper;
private final WmsProcessSpecVersionMapper wmsProcessSpecVersionMapper;
@Override
public WmsProcessPlanVo queryById(Long planId) {
return baseMapper.selectVoById(planId);
}
@Override
public TableDataInfo<WmsProcessPlanVo> queryPageList(WmsProcessPlanBo bo, PageQuery pageQuery) {
LambdaQueryWrapper<WmsProcessPlan> lqw = buildQueryWrapper(bo);
Page<WmsProcessPlanVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
@Override
public List<WmsProcessPlanVo> queryList(WmsProcessPlanBo bo) {
return baseMapper.selectVoList(buildQueryWrapper(bo));
}
private LambdaQueryWrapper<WmsProcessPlan> buildQueryWrapper(WmsProcessPlanBo bo) {
LambdaQueryWrapper<WmsProcessPlan> lqw = Wrappers.lambdaQuery();
lqw.eq(bo.getVersionId() != null, WmsProcessPlan::getVersionId, bo.getVersionId());
lqw.eq(StringUtils.isNotBlank(bo.getSegmentType()), WmsProcessPlan::getSegmentType, bo.getSegmentType());
lqw.like(StringUtils.isNotBlank(bo.getPointName()), WmsProcessPlan::getPointName, bo.getPointName());
lqw.eq(StringUtils.isNotBlank(bo.getPointCode()), WmsProcessPlan::getPointCode, bo.getPointCode());
lqw.orderByAsc(WmsProcessPlan::getSortOrder).orderByAsc(WmsProcessPlan::getPlanId);
return lqw;
}
@Override
public Boolean insertByBo(WmsProcessPlanBo bo) {
WmsProcessSpecVersion ver = wmsProcessSpecVersionMapper.selectById(bo.getVersionId());
if (ver == null) {
throw new ServiceException("规程版本不存在");
}
WmsProcessPlan add = BeanUtil.toBean(bo, WmsProcessPlan.class);
if (add.getSortOrder() == null) {
add.setSortOrder(0);
}
validEntityBeforeSave(add);
boolean flag = baseMapper.insert(add) > 0;
if (flag) {
bo.setPlanId(add.getPlanId());
}
return flag;
}
@Override
public Boolean updateByBo(WmsProcessPlanBo bo) {
WmsProcessPlan update = BeanUtil.toBean(bo, WmsProcessPlan.class);
validEntityBeforeSave(update);
return baseMapper.updateById(update) > 0;
}
private void validEntityBeforeSave(WmsProcessPlan entity) {
LambdaQueryWrapper<WmsProcessPlan> lqw = Wrappers.lambdaQuery();
lqw.eq(WmsProcessPlan::getVersionId, entity.getVersionId());
lqw.eq(WmsProcessPlan::getPointCode, entity.getPointCode());
if (entity.getPlanId() != null) {
lqw.ne(WmsProcessPlan::getPlanId, entity.getPlanId());
}
if (baseMapper.selectCount(lqw) > 0) {
throw new ServiceException("同一版本下点位编码已存在");
}
}
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (Boolean.TRUE.equals(isValid)) {
// 可扩展业务校验
}
return baseMapper.deleteBatchIds(ids) > 0;
}
}

View File

@@ -9,9 +9,11 @@ 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.WmsProcessSpecVersion;
import com.klp.domain.bo.WmsProcessSpecBo;
import com.klp.domain.vo.WmsProcessSpecVo;
import com.klp.mapper.WmsProcessSpecMapper;
import com.klp.mapper.WmsProcessSpecVersionMapper;
import com.klp.service.IWmsProcessSpecService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@@ -29,6 +31,7 @@ import java.util.List;
public class WmsProcessSpecServiceImpl implements IWmsProcessSpecService {
private final WmsProcessSpecMapper baseMapper;
private final WmsProcessSpecVersionMapper wmsProcessSpecVersionMapper;
@Override
public WmsProcessSpecVo queryById(Long specId) {
@@ -94,7 +97,13 @@ public class WmsProcessSpecServiceImpl implements IWmsProcessSpecService {
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (Boolean.TRUE.equals(isValid)) {
// 任务3 可在此校验版本等从表数据
for (Long specId : ids) {
LambdaQueryWrapper<WmsProcessSpecVersion> vq = Wrappers.lambdaQuery();
vq.eq(WmsProcessSpecVersion::getSpecId, specId);
if (wmsProcessSpecVersionMapper.selectCount(vq) > 0) {
throw new ServiceException("规程下存在版本数据,请先删除版本及方案");
}
}
}
return baseMapper.deleteBatchIds(ids) > 0;
}

View File

@@ -0,0 +1,149 @@
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;
import com.klp.domain.WmsProcessSpecVersion;
import com.klp.domain.bo.WmsProcessSpecVersionBo;
import com.klp.domain.vo.WmsProcessSpecVersionVo;
import com.klp.mapper.WmsProcessPlanMapper;
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;
import java.util.Collection;
import java.util.List;
/**
* 规程版本Service实现
*
* @author klp
*/
@RequiredArgsConstructor
@Service
public class WmsProcessSpecVersionServiceImpl implements IWmsProcessSpecVersionService {
private final WmsProcessSpecVersionMapper baseMapper;
private final WmsProcessSpecMapper wmsProcessSpecMapper;
private final WmsProcessPlanMapper wmsProcessPlanMapper;
@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;
}
@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);
wmsProcessPlanMapper.delete(pq);
}
return baseMapper.deleteBatchIds(ids) > 0;
}
}