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,75 @@
package com.klp.controller;
import com.klp.common.annotation.Log;
import com.klp.common.annotation.RepeatSubmit;
import com.klp.common.core.controller.BaseController;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.domain.R;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import com.klp.common.enums.BusinessType;
import com.klp.common.utils.poi.ExcelUtil;
import com.klp.domain.bo.WmsProcessPlanBo;
import com.klp.domain.vo.WmsProcessPlanVo;
import com.klp.service.IWmsProcessPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
/**
* 方案点位
*
* @author klp
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/processPlan")
public class WmsProcessPlanController extends BaseController {
private final IWmsProcessPlanService wmsProcessPlanService;
@GetMapping("/list")
public TableDataInfo<WmsProcessPlanVo> list(WmsProcessPlanBo bo, PageQuery pageQuery) {
return wmsProcessPlanService.queryPageList(bo, pageQuery);
}
@Log(title = "方案点位", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(WmsProcessPlanBo bo, HttpServletResponse response) {
List<WmsProcessPlanVo> list = wmsProcessPlanService.queryList(bo);
ExcelUtil.exportExcel(list, "方案点位", WmsProcessPlanVo.class, response);
}
@GetMapping("/{planId}")
public R<WmsProcessPlanVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long planId) {
return R.ok(wmsProcessPlanService.queryById(planId));
}
@Log(title = "方案点位", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsProcessPlanBo bo) {
return toAjax(wmsProcessPlanService.insertByBo(bo));
}
@Log(title = "方案点位", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsProcessPlanBo bo) {
return toAjax(wmsProcessPlanService.updateByBo(bo));
}
@Log(title = "方案点位", businessType = BusinessType.DELETE)
@DeleteMapping("/{planIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] planIds) {
return toAjax(wmsProcessPlanService.deleteWithValidByIds(Arrays.asList(planIds), true));
}
}

View File

@@ -0,0 +1,85 @@
package com.klp.controller;
import com.klp.common.annotation.Log;
import com.klp.common.annotation.RepeatSubmit;
import com.klp.common.core.controller.BaseController;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.domain.R;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import com.klp.common.enums.BusinessType;
import com.klp.common.utils.poi.ExcelUtil;
import com.klp.domain.bo.WmsProcessSpecVersionBo;
import com.klp.domain.vo.WmsProcessSpecVersionVo;
import com.klp.service.IWmsProcessSpecVersionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
/**
* 规程版本
*
* @author klp
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/processSpecVersion")
public class WmsProcessSpecVersionController extends BaseController {
private final IWmsProcessSpecVersionService wmsProcessSpecVersionService;
@GetMapping("/list")
public TableDataInfo<WmsProcessSpecVersionVo> list(WmsProcessSpecVersionBo bo, PageQuery pageQuery) {
return wmsProcessSpecVersionService.queryPageList(bo, pageQuery);
}
@Log(title = "规程版本", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(WmsProcessSpecVersionBo bo, HttpServletResponse response) {
List<WmsProcessSpecVersionVo> list = wmsProcessSpecVersionService.queryList(bo);
ExcelUtil.exportExcel(list, "规程版本", WmsProcessSpecVersionVo.class, response);
}
@GetMapping("/{versionId}")
public R<WmsProcessSpecVersionVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long versionId) {
return R.ok(wmsProcessSpecVersionService.queryById(versionId));
}
@Log(title = "规程版本", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsProcessSpecVersionBo bo) {
return toAjax(wmsProcessSpecVersionService.insertByBo(bo));
}
@Log(title = "规程版本", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsProcessSpecVersionBo bo) {
return toAjax(wmsProcessSpecVersionService.updateByBo(bo));
}
/**
* 设为当前生效版本(同规程下仅一条生效)
*/
@Log(title = "规程版本生效", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping("/activate/{versionId}")
public R<Void> activate(@NotNull(message = "主键不能为空") @PathVariable Long versionId) {
return toAjax(wmsProcessSpecVersionService.activateVersion(versionId));
}
@Log(title = "规程版本", businessType = BusinessType.DELETE)
@DeleteMapping("/{versionIds}")
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] versionIds) {
return toAjax(wmsProcessSpecVersionService.deleteWithValidByIds(Arrays.asList(versionIds), true));
}
}

View File

@@ -0,0 +1,59 @@
package com.klp.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.klp.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 方案点位对象 wms_process_plan
*
* @author klp
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("wms_process_plan")
public class WmsProcessPlan extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableId(value = "plan_id")
private Long planId;
/**
* 规程版本ID
*/
private Long versionId;
/**
* 段类型INLET/PROCESS/OUTLET
*/
private String segmentType;
/**
* 段名称
*/
private String segmentName;
/**
* 点位名称
*/
private String pointName;
/**
* 点位编码
*/
private String pointCode;
/**
* 排序
*/
private Integer sortOrder;
@TableLogic
private Integer delFlag;
private String remark;
}

View File

@@ -0,0 +1,49 @@
package com.klp.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.klp.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 规程版本对象 wms_process_spec_version
*
* @author klp
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("wms_process_spec_version")
public class WmsProcessSpecVersion extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableId(value = "version_id")
private Long versionId;
/**
* 规程主表ID
*/
private Long specId;
/**
* 版本号
*/
private String versionCode;
/**
* 是否当前生效0=否1=是)
*/
private Integer isActive;
/**
* 状态
*/
private String status;
@TableLogic
private Integer delFlag;
private String remark;
}

View File

@@ -0,0 +1,42 @@
package com.klp.domain.bo;
import com.klp.common.core.domain.BaseEntity;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 方案点位业务对象 wms_process_plan
*
* @author klp
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WmsProcessPlanBo extends BaseEntity {
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
private Long planId;
@NotNull(message = "版本不能为空", groups = {AddGroup.class, EditGroup.class})
private Long versionId;
@NotBlank(message = "段类型不能为空", groups = {AddGroup.class, EditGroup.class})
private String segmentType;
private String segmentName;
@NotBlank(message = "点位名称不能为空", groups = {AddGroup.class, EditGroup.class})
private String pointName;
@NotBlank(message = "点位编码不能为空", groups = {AddGroup.class, EditGroup.class})
private String pointCode;
@NotNull(message = "排序不能为空", groups = {AddGroup.class, EditGroup.class})
private Integer sortOrder;
private String remark;
}

View File

@@ -0,0 +1,41 @@
package com.klp.domain.bo;
import com.klp.common.core.domain.BaseEntity;
import com.klp.common.core.validate.AddGroup;
import com.klp.common.core.validate.EditGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 规程版本业务对象 wms_process_spec_version
*
* @author klp
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WmsProcessSpecVersionBo extends BaseEntity {
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
private Long versionId;
@NotNull(message = "规程不能为空", groups = {AddGroup.class, EditGroup.class})
private Long specId;
@NotBlank(message = "版本号不能为空", groups = {AddGroup.class, EditGroup.class})
private String versionCode;
/**
* 是否当前生效0=否1=是)
*/
private Integer isActive;
/**
* 状态
*/
private String status;
private String remark;
}

View File

@@ -0,0 +1,50 @@
package com.klp.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 方案点位视图对象 wms_process_plan
*
* @author klp
*/
@Data
@ExcelIgnoreUnannotated
public class WmsProcessPlanVo {
@ExcelProperty(value = "方案点位ID")
private Long planId;
@ExcelProperty(value = "版本ID")
private Long versionId;
@ExcelProperty(value = "段类型")
private String segmentType;
@ExcelProperty(value = "段名称")
private String segmentName;
@ExcelProperty(value = "点位名称")
private String pointName;
@ExcelProperty(value = "点位编码")
private String pointCode;
@ExcelProperty(value = "排序")
private Integer sortOrder;
@ExcelProperty(value = "备注")
private String remark;
@ExcelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ExcelProperty(value = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@@ -0,0 +1,44 @@
package com.klp.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 规程版本视图对象 wms_process_spec_version
*
* @author klp
*/
@Data
@ExcelIgnoreUnannotated
public class WmsProcessSpecVersionVo {
@ExcelProperty(value = "版本ID")
private Long versionId;
@ExcelProperty(value = "规程ID")
private Long specId;
@ExcelProperty(value = "版本号")
private String versionCode;
@ExcelProperty(value = "是否生效")
private Integer isActive;
@ExcelProperty(value = "状态")
private String status;
@ExcelProperty(value = "备注")
private String remark;
@ExcelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ExcelProperty(value = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@@ -0,0 +1,14 @@
package com.klp.mapper;
import com.klp.common.core.mapper.BaseMapperPlus;
import com.klp.domain.WmsProcessPlan;
import com.klp.domain.vo.WmsProcessPlanVo;
/**
* 方案点位Mapper
*
* @author klp
*/
public interface WmsProcessPlanMapper extends BaseMapperPlus<WmsProcessPlanMapper, WmsProcessPlan, WmsProcessPlanVo> {
}

View File

@@ -0,0 +1,14 @@
package com.klp.mapper;
import com.klp.common.core.mapper.BaseMapperPlus;
import com.klp.domain.WmsProcessSpecVersion;
import com.klp.domain.vo.WmsProcessSpecVersionVo;
/**
* 规程版本Mapper
*
* @author klp
*/
public interface WmsProcessSpecVersionMapper extends BaseMapperPlus<WmsProcessSpecVersionMapper, WmsProcessSpecVersion, WmsProcessSpecVersionVo> {
}

View File

@@ -0,0 +1,29 @@
package com.klp.service;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.page.TableDataInfo;
import com.klp.domain.bo.WmsProcessPlanBo;
import com.klp.domain.vo.WmsProcessPlanVo;
import java.util.Collection;
import java.util.List;
/**
* 方案点位Service
*
* @author klp
*/
public interface IWmsProcessPlanService {
WmsProcessPlanVo queryById(Long planId);
TableDataInfo<WmsProcessPlanVo> queryPageList(WmsProcessPlanBo bo, PageQuery pageQuery);
List<WmsProcessPlanVo> queryList(WmsProcessPlanBo bo);
Boolean insertByBo(WmsProcessPlanBo bo);
Boolean updateByBo(WmsProcessPlanBo bo);
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
}

View File

@@ -0,0 +1,34 @@
package com.klp.service;
import com.klp.common.core.domain.PageQuery;
import com.klp.common.core.page.TableDataInfo;
import com.klp.domain.bo.WmsProcessSpecVersionBo;
import com.klp.domain.vo.WmsProcessSpecVersionVo;
import java.util.Collection;
import java.util.List;
/**
* 规程版本Service
*
* @author klp
*/
public interface IWmsProcessSpecVersionService {
WmsProcessSpecVersionVo queryById(Long versionId);
TableDataInfo<WmsProcessSpecVersionVo> queryPageList(WmsProcessSpecVersionBo bo, PageQuery pageQuery);
List<WmsProcessSpecVersionVo> queryList(WmsProcessSpecVersionBo bo);
Boolean insertByBo(WmsProcessSpecVersionBo bo);
Boolean updateByBo(WmsProcessSpecVersionBo bo);
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 将指定版本设为当前规程下唯一生效版本
*/
Boolean activateVersion(Long versionId);
}

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;
}
}