fix:新增物料批次提交,物料大类删除校验。

This commit is contained in:
shusir
2026-01-29 17:56:30 +08:00
parent 1c5588a05a
commit 5a03ed1cab
6 changed files with 71 additions and 28 deletions

View File

@@ -115,7 +115,7 @@ public class DeviceApplyController extends AbstractFileUploadController implemen
return success(BeanUtils.toBean(deviceApply, DeviceApplyRespVO.class)); return success(BeanUtils.toBean(deviceApply, DeviceApplyRespVO.class));
} }
@GetMapping("/list") @GetMapping("/page")
@Operation(summary = "获得设备通用流程,验收、降级、停用、报废、还原、启用分页") @Operation(summary = "获得设备通用流程,验收、降级、停用、报废、还原、启用分页")
public CommonResult<PageResult<DeviceApplyRespVO>> getDeviceApplyPage(@Valid DeviceApplyPageReqVO pageReqVO) { public CommonResult<PageResult<DeviceApplyRespVO>> getDeviceApplyPage(@Valid DeviceApplyPageReqVO pageReqVO) {
PageResult<DeviceApplyDO> pageResult = deviceApplyService.getDeviceApplyPage(pageReqVO); PageResult<DeviceApplyDO> pageResult = deviceApplyService.getDeviceApplyPage(pageReqVO);

View File

@@ -122,8 +122,8 @@ public class MaterialBatchController implements BusinessControllerMarker {
@Operation(summary = "提交物料批次") @Operation(summary = "提交物料批次")
@Parameter(name = "id", required = true) @Parameter(name = "id", required = true)
public CommonResult<Boolean> submitMaterialBatch(@RequestParam("id") Long id) { public CommonResult<Boolean> submitMaterialBatch(@RequestParam("id") Long id) {
// return success(materialBatchService.submitMaterialBatch(id));
return null; return success(materialBatchService.submitMaterialBatch(id));
} }
@GetMapping("gongduan-page") @GetMapping("gongduan-page")

View File

@@ -3,11 +3,15 @@ package com.zt.plat.module.qms.resource.material.dal.mapper;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX; import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX; import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.core.constant.DataTypeConstant; import com.zt.plat.module.qms.core.constant.DataTypeConstant;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductPageReqVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO; import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* 物料大类 Mapper * 物料大类 Mapper
* *
@@ -52,4 +56,17 @@ public interface MaterialProductMapper extends BaseMapperX<MaterialProductDO> {
.orderByDesc(MaterialProductDO::getId)); .orderByDesc(MaterialProductDO::getId));
} }
default boolean checkIsExistsBatchByPdt(Long id){
MPJLambdaWrapperX<MaterialProductDO> wrapperX = new MPJLambdaWrapperX<MaterialProductDO>()
.leftJoin(MaterialBatchDO.class, MaterialBatchDO::getProductId, MaterialProductDO::getId)
.eq(MaterialBatchDO::getProductId, id);
return this.exists(wrapperX);
}
default boolean checkIsExistsDataByPdts(List<Long> ids){
MPJLambdaWrapperX<MaterialProductDO> wrapperX = new MPJLambdaWrapperX<MaterialProductDO>()
.leftJoin(MaterialBatchDO.class, MaterialBatchDO::getProductId, MaterialProductDO::getId)
.in(MaterialBatchDO::getProductId, ids);
return this.exists(wrapperX);
}
} }

View File

@@ -100,4 +100,12 @@ public interface MaterialBatchService {
* @return 工段列表 * @return 工段列表
*/ */
List<MaterialBatchDO> getMaterialBatchGongduanList(Long batId); List<MaterialBatchDO> getMaterialBatchGongduanList(Long batId);
/**
* 提交物料批次
*
* @param id 批次id
* @return 是否
*/
Boolean submitMaterialBatch(Long id);
} }

View File

@@ -3,11 +3,12 @@ package com.zt.plat.module.qms.resource.material.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.protobuf.ServiceException;
import com.zt.plat.framework.common.exception.ErrorCode; import com.zt.plat.framework.common.exception.ErrorCode;
import com.zt.plat.framework.common.exception.ServiceException;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.qms.core.code.SequenceUtil; import com.zt.plat.module.qms.core.code.SequenceUtil;
import com.zt.plat.module.qms.enums.ErrorCodeConstants;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchPageReqVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespVO;
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO; import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO;
@@ -83,13 +84,11 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
@Override @Override
public void deleteMaterialBatch(Long id) { public void deleteMaterialBatch(Long id) {
// 校验存在
validateMaterialBatchExists(id);
// 已经拆分的批次不可删除 MaterialBatchDO batchDO = materialBatchMapper.selectById(id);
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class) if (batchDO == null) throw exception(MATERIAL_BATCH_NOT_EXISTS);
.eq(MaterialBatchDO::getParentId, id)); if (batchDO.getSubmitStatus() == 1)
if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END); throw new ServiceException(1_032_160_000, "批次已经提交,不可删除");
// 删除 // 删除
materialBatchMapper.deleteById(id); materialBatchMapper.deleteById(id);
@@ -98,11 +97,15 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
@Override @Override
public void deleteMaterialBatchListByIds(List<Long> ids) { public void deleteMaterialBatchListByIds(List<Long> ids) {
// 校验存在 // 校验存在
validateMaterialBatchExists(ids); List<MaterialBatchDO> list = materialBatchMapper.selectByIds(ids);
// 已经拆分的批次不可删除 if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class) throw exception(MATERIAL_BATCH_NOT_EXISTS);
.in(MaterialBatchDO::getParentId, ids)); }
if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END); // 存在已经提交的批次时,不可删除
for (MaterialBatchDO batch : list) {
if (batch.getSubmitStatus() == 1)
throw new ServiceException(1_032_160_000, "存在已经提交的批次,不可删除");
}
// 删除 // 删除
materialBatchMapper.deleteByIds(ids); materialBatchMapper.deleteByIds(ids);
} }
@@ -164,8 +167,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
public List<MaterialBatchRespVO> assignMaterialBatchGongduan(List<MaterialBatchSaveReqVO> createReqVOs) { public List<MaterialBatchRespVO> assignMaterialBatchGongduan(List<MaterialBatchSaveReqVO> createReqVOs) {
// 是否已经拆分过 // 是否已经拆分过
Long batId = createReqVOs.get(0).getParentId(); Long batId = createReqVOs.get(0).getParentId();
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
.eq(MaterialBatchDO::getParentId, batId));
// 1. 所属的批次需要是同一个 // 1. 所属的批次需要是同一个
Set<Long> pIds = createReqVOs.stream().map(MaterialBatchSaveReqVO::getParentId).collect(Collectors.toSet()); Set<Long> pIds = createReqVOs.stream().map(MaterialBatchSaveReqVO::getParentId).collect(Collectors.toSet());
if (pIds.size() > 1) throw exception(GONGDUAN_BELONG_MATERIAL_BATCH_NOT_EQUAL); if (pIds.size() > 1) throw exception(GONGDUAN_BELONG_MATERIAL_BATCH_NOT_EQUAL);
@@ -181,15 +183,21 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
if (total.compareTo(mtrlBat.getInboundQuantity()) != 0) if (total.compareTo(mtrlBat.getInboundQuantity()) != 0)
throw exception(GONGDUAN_QUANTITY_MATERIAL_BATCH_NOT_EQUAL); throw exception(GONGDUAN_QUANTITY_MATERIAL_BATCH_NOT_EQUAL);
// 修改工段 // 修改工段
if (CollUtil.isNotEmpty(asnDOs)) { boolean exists = materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class)
// 删除之前的拆分数据TODO 需要检查是否可以删除 .eq(MaterialBatchDO::getParentId, batId));
if (exists) {
if (mtrlBat.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,禁止修改");
// 删除之前的拆分数据
materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class) materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class)
.eq(MaterialBatchDO::getParentId, batId)); .eq(MaterialBatchDO::getParentId, batId));
} }
// 3. 保存工段 // 3. 保存工段
List<MaterialBatchDO> gongEts = createReqVOs.stream().map( List<MaterialBatchDO> gongEts = createReqVOs.stream().map(batAsn -> {
batAsn -> BeanUtils.toBean(batAsn, MaterialBatchDO.class)).toList(); MaterialBatchDO bean = BeanUtils.toBean(batAsn, MaterialBatchDO.class);
bean.setProductId(mtrlBat.getProductId());
return bean;
}).toList();
materialBatchMapper.insertBatch(gongEts); materialBatchMapper.insertBatch(gongEts);
return gongEts.stream().map( return gongEts.stream().map(
@@ -224,6 +232,19 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
.ne(MaterialBatchDO::getParentId, 0)); .ne(MaterialBatchDO::getParentId, 0));
} }
@Override
public Boolean submitMaterialBatch(Long id) {
MaterialBatchDO batchDO = materialBatchMapper.selectById(id);
if (batchDO == null) throw exception(MATERIAL_BATCH_NOT_EXISTS);
if (batchDO.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交过");
boolean exists = materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class)
.eq(MaterialBatchDO::getParentId, id));
if (!exists) throw new ServiceException(1_032_160_000, "批次还未拆分,不可提交");
batchDO.setSubmitStatus(1);
materialBatchMapper.updateById(batchDO);
return true;
}
/** /**
* 组装物料批次树 * 组装物料批次树
* *

View File

@@ -238,9 +238,6 @@ public class MaterialProductServiceImpl implements MaterialProductService {
// 分类 // 分类
if (DataTypeConstant.DATA_TYPE_CATEGORY.equals(pdtDo.getNodeType())) { if (DataTypeConstant.DATA_TYPE_CATEGORY.equals(pdtDo.getNodeType())) {
// 分类下有子分类或大类时不可删除 // 分类下有子分类或大类时不可删除
// boolean exists = materialProductMapper.exists(Wrappers.lambdaQuery(MaterialProductDO.class)
// .like(MaterialProductDO::getIdPath, id)
// .ne(MaterialProductDO::getId, id));
boolean exists = materialProductMapper.exists(Wrappers.lambdaQuery(MaterialProductDO.class) boolean exists = materialProductMapper.exists(Wrappers.lambdaQuery(MaterialProductDO.class)
.eq(MaterialProductDO::getParentId, id)); .eq(MaterialProductDO::getParentId, id));
if (exists) throw exception(MATERIAL_CATEGORY_EXISTS_CHILDREN); if (exists) throw exception(MATERIAL_CATEGORY_EXISTS_CHILDREN);
@@ -249,8 +246,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
else { else {
// 大类下有批次时不可删除 // 大类下有批次时不可删除
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等 // TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
// boolean exists = materialBatchService.checkIsExistsDataByPdt(id); boolean exists = materialProductMapper.checkIsExistsBatchByPdt(id);
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH); if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
} }
materialProductMapper.deleteById(id); materialProductMapper.deleteById(id);
} }
@@ -267,8 +264,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
if (CollUtil.isNotEmpty(mtCtgList)) throw exception(MATERIAL_PRODUCTS_EXISTS_CATEGORY); if (CollUtil.isNotEmpty(mtCtgList)) throw exception(MATERIAL_PRODUCTS_EXISTS_CATEGORY);
// 检查是否可删除 大类下有批次时不可删除 // 检查是否可删除 大类下有批次时不可删除
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等 // TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
// boolean exists = materialBatchService.checkIsExistsDataByPdts(ids); boolean exists = materialProductMapper.checkIsExistsDataByPdts(ids);
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH); if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
// 删除 // 删除
materialProductMapper.deleteByIds(ids); materialProductMapper.deleteByIds(ids);
} }