fix:新增物料批次提交,物料大类删除校验。
This commit is contained in:
@@ -115,7 +115,7 @@ public class DeviceApplyController extends AbstractFileUploadController implemen
|
||||
return success(BeanUtils.toBean(deviceApply, DeviceApplyRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得设备通用流程,验收、降级、停用、报废、还原、启用分页")
|
||||
public CommonResult<PageResult<DeviceApplyRespVO>> getDeviceApplyPage(@Valid DeviceApplyPageReqVO pageReqVO) {
|
||||
PageResult<DeviceApplyDO> pageResult = deviceApplyService.getDeviceApplyPage(pageReqVO);
|
||||
|
||||
@@ -122,8 +122,8 @@ public class MaterialBatchController implements BusinessControllerMarker {
|
||||
@Operation(summary = "提交物料批次")
|
||||
@Parameter(name = "id", required = true)
|
||||
public CommonResult<Boolean> submitMaterialBatch(@RequestParam("id") Long id) {
|
||||
// return success(materialBatchService.submitMaterialBatch(id));
|
||||
return null;
|
||||
|
||||
return success(materialBatchService.submitMaterialBatch(id));
|
||||
}
|
||||
|
||||
@GetMapping("gongduan-page")
|
||||
|
||||
@@ -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.mybatis.core.mapper.BaseMapperX;
|
||||
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.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 org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 物料大类 Mapper
|
||||
*
|
||||
@@ -52,4 +56,17 @@ public interface MaterialProductMapper extends BaseMapperX<MaterialProductDO> {
|
||||
.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);
|
||||
}
|
||||
}
|
||||
@@ -100,4 +100,12 @@ public interface MaterialBatchService {
|
||||
* @return 工段列表
|
||||
*/
|
||||
List<MaterialBatchDO> getMaterialBatchGongduanList(Long batId);
|
||||
|
||||
/**
|
||||
* 提交物料批次
|
||||
*
|
||||
* @param id 批次id
|
||||
* @return 是否
|
||||
*/
|
||||
Boolean submitMaterialBatch(Long id);
|
||||
}
|
||||
@@ -3,11 +3,12 @@ package com.zt.plat.module.qms.resource.material.service;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.ServiceException;
|
||||
import com.zt.plat.framework.common.pojo.PageResult;
|
||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||
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.MaterialBatchRespVO;
|
||||
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO;
|
||||
@@ -83,13 +84,11 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
|
||||
|
||||
@Override
|
||||
public void deleteMaterialBatch(Long id) {
|
||||
// 校验存在
|
||||
validateMaterialBatchExists(id);
|
||||
|
||||
// 已经拆分的批次不可删除
|
||||
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.eq(MaterialBatchDO::getParentId, id));
|
||||
if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END);
|
||||
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, "批次已经提交,不可删除");
|
||||
|
||||
// 删除
|
||||
materialBatchMapper.deleteById(id);
|
||||
@@ -98,11 +97,15 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
|
||||
@Override
|
||||
public void deleteMaterialBatchListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateMaterialBatchExists(ids);
|
||||
// 已经拆分的批次不可删除
|
||||
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.in(MaterialBatchDO::getParentId, ids));
|
||||
if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END);
|
||||
List<MaterialBatchDO> list = materialBatchMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(MATERIAL_BATCH_NOT_EXISTS);
|
||||
}
|
||||
// 存在已经提交的批次时,不可删除
|
||||
for (MaterialBatchDO batch : list) {
|
||||
if (batch.getSubmitStatus() == 1)
|
||||
throw new ServiceException(1_032_160_000, "存在已经提交的批次,不可删除");
|
||||
}
|
||||
// 删除
|
||||
materialBatchMapper.deleteByIds(ids);
|
||||
}
|
||||
@@ -164,8 +167,7 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
|
||||
public List<MaterialBatchRespVO> assignMaterialBatchGongduan(List<MaterialBatchSaveReqVO> createReqVOs) {
|
||||
// 是否已经拆分过
|
||||
Long batId = createReqVOs.get(0).getParentId();
|
||||
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.eq(MaterialBatchDO::getParentId, batId));
|
||||
|
||||
// 1. 所属的批次需要是同一个
|
||||
Set<Long> pIds = createReqVOs.stream().map(MaterialBatchSaveReqVO::getParentId).collect(Collectors.toSet());
|
||||
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)
|
||||
throw exception(GONGDUAN_QUANTITY_MATERIAL_BATCH_NOT_EQUAL);
|
||||
// 修改工段
|
||||
if (CollUtil.isNotEmpty(asnDOs)) {
|
||||
// 删除之前的拆分数据,TODO 需要检查是否可以删除
|
||||
boolean exists = materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.eq(MaterialBatchDO::getParentId, batId));
|
||||
if (exists) {
|
||||
if (mtrlBat.getSubmitStatus() == 1) throw new ServiceException(1_032_160_000, "批次已经提交,禁止修改");
|
||||
// 删除之前的拆分数据
|
||||
materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.eq(MaterialBatchDO::getParentId, batId));
|
||||
}
|
||||
|
||||
// 3. 保存工段
|
||||
List<MaterialBatchDO> gongEts = createReqVOs.stream().map(
|
||||
batAsn -> BeanUtils.toBean(batAsn, MaterialBatchDO.class)).toList();
|
||||
List<MaterialBatchDO> gongEts = createReqVOs.stream().map(batAsn -> {
|
||||
MaterialBatchDO bean = BeanUtils.toBean(batAsn, MaterialBatchDO.class);
|
||||
bean.setProductId(mtrlBat.getProductId());
|
||||
return bean;
|
||||
}).toList();
|
||||
materialBatchMapper.insertBatch(gongEts);
|
||||
|
||||
return gongEts.stream().map(
|
||||
@@ -224,6 +232,19 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
|
||||
.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装物料批次树
|
||||
*
|
||||
|
||||
@@ -238,9 +238,6 @@ public class MaterialProductServiceImpl implements MaterialProductService {
|
||||
// 分类
|
||||
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)
|
||||
.eq(MaterialProductDO::getParentId, id));
|
||||
if (exists) throw exception(MATERIAL_CATEGORY_EXISTS_CHILDREN);
|
||||
@@ -249,8 +246,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
|
||||
else {
|
||||
// 大类下有批次时不可删除
|
||||
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
|
||||
// boolean exists = materialBatchService.checkIsExistsDataByPdt(id);
|
||||
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
|
||||
boolean exists = materialProductMapper.checkIsExistsBatchByPdt(id);
|
||||
if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
|
||||
}
|
||||
materialProductMapper.deleteById(id);
|
||||
}
|
||||
@@ -267,8 +264,8 @@ public class MaterialProductServiceImpl implements MaterialProductService {
|
||||
if (CollUtil.isNotEmpty(mtCtgList)) throw exception(MATERIAL_PRODUCTS_EXISTS_CATEGORY);
|
||||
// 检查是否可删除 大类下有批次时不可删除
|
||||
// TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等
|
||||
// boolean exists = materialBatchService.checkIsExistsDataByPdts(ids);
|
||||
// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
|
||||
boolean exists = materialProductMapper.checkIsExistsDataByPdts(ids);
|
||||
if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH);
|
||||
// 删除
|
||||
materialProductMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user