fix:新增物料批次接口及批次拆分及接口。

This commit is contained in:
shusir
2026-01-26 18:05:23 +08:00
parent 2336c370fa
commit 0d164c660e
11 changed files with 251 additions and 72 deletions

View File

@@ -5,6 +5,8 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchRespV
import com.zt.plat.module.qms.resource.material.controller.vo.MaterialBatchSaveReqVO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.service.MaterialBatchService;
import com.zt.plat.module.qms.resource.material.valid.AddGroup;
import com.zt.plat.module.qms.resource.material.valid.UpdateGroup;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@@ -35,7 +37,7 @@ import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 物料批次")
@RestController
@RequestMapping("/qms/material-batch")
@RequestMapping("/qms/resource/material-batch")
@Validated
public class MaterialBatchController implements BusinessControllerMarker {
@@ -45,15 +47,15 @@ public class MaterialBatchController implements BusinessControllerMarker {
@PostMapping("/create")
@Operation(summary = "创建物料批次")
@PreAuthorize("@ss.hasPermission('qms:material-batch:create')")
public CommonResult<MaterialBatchRespVO> createMaterialBatch(@Valid @RequestBody MaterialBatchSaveReqVO createReqVO) {
// @PreAuthorize("@ss.hasPermission('qms:material-batch:create')")
public CommonResult<MaterialBatchRespVO> createMaterialBatch(@Validated(AddGroup.class) @RequestBody MaterialBatchSaveReqVO createReqVO) {
return success(materialBatchService.createMaterialBatch(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新物料批次")
@PreAuthorize("@ss.hasPermission('qms:material-batch:update')")
public CommonResult<Boolean> updateMaterialBatch(@Valid @RequestBody MaterialBatchSaveReqVO updateReqVO) {
// @PreAuthorize("@ss.hasPermission('qms:material-batch:update')")
public CommonResult<Boolean> updateMaterialBatch(@Validated(UpdateGroup.class) @RequestBody MaterialBatchSaveReqVO updateReqVO) {
materialBatchService.updateMaterialBatch(updateReqVO);
return success(true);
}
@@ -61,7 +63,7 @@ public class MaterialBatchController implements BusinessControllerMarker {
@DeleteMapping("/delete")
@Operation(summary = "删除物料批次")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('qms:material-batch:delete')")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:delete')")
public CommonResult<Boolean> deleteMaterialBatch(@RequestParam("id") Long id) {
materialBatchService.deleteMaterialBatch(id);
return success(true);
@@ -70,7 +72,7 @@ public class MaterialBatchController implements BusinessControllerMarker {
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除物料批次")
@PreAuthorize("@ss.hasPermission('qms:material-batch:delete')")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:delete')")
public CommonResult<Boolean> deleteMaterialBatchList(@RequestBody BatchDeleteReqVO req) {
materialBatchService.deleteMaterialBatchListByIds(req.getIds());
return success(true);
@@ -79,7 +81,7 @@ public class MaterialBatchController implements BusinessControllerMarker {
@GetMapping("/get")
@Operation(summary = "获得物料批次")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('qms:material-batch:query')")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:query')")
public CommonResult<MaterialBatchRespVO> getMaterialBatch(@RequestParam("id") Long id) {
MaterialBatchDO materialBatch = materialBatchService.getMaterialBatch(id);
return success(BeanUtils.toBean(materialBatch, MaterialBatchRespVO.class));
@@ -87,7 +89,7 @@ public class MaterialBatchController implements BusinessControllerMarker {
@GetMapping("/page")
@Operation(summary = "获得物料批次分页")
@PreAuthorize("@ss.hasPermission('qms:material-batch:query')")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:query')")
public CommonResult<PageResult<MaterialBatchRespVO>> getMaterialBatchPage(@Valid MaterialBatchPageReqVO pageReqVO) {
PageResult<MaterialBatchDO> pageResult = materialBatchService.getMaterialBatchPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MaterialBatchRespVO.class));
@@ -106,4 +108,11 @@ public class MaterialBatchController implements BusinessControllerMarker {
BeanUtils.toBean(list, MaterialBatchRespVO.class));
}
@PostMapping("/assign-gongduan")
@Operation(summary = "批次工段拆分")
// @PreAuthorize("@ss.hasPermission('qms:material-batch:create')")
public CommonResult<List<MaterialBatchRespVO>> assignMaterialBatchGongduan(@Valid @RequestBody List<MaterialBatchSaveReqVO> createReqVOs) {
return success(materialBatchService.assignMaterialBatchGongduan(createReqVOs));
}
}

View File

@@ -62,6 +62,7 @@ public class MaterialProductController extends AbstractFileUploadController impl
return success(materialProductService.getMaterialCategoryTree());
}
// TODO
@GetMapping("/orig-material/{code}")
@Operation(summary = "根据物料编码获取外部系统原始物料")
public CommonResult<Object> getOriginalMaterial(@PathVariable String code) {
@@ -84,18 +85,18 @@ public class MaterialProductController extends AbstractFileUploadController impl
}
@PutMapping("/update")
@Operation(summary = "更新物料")
@PreAuthorize("@ss.hasPermission('qms:material-product:update')")
public CommonResult<Boolean> updateMaterialProduct(@Valid @RequestBody MaterialProductSaveReqVO updateReqVO) {
materialProductService.updateMaterialProduct(updateReqVO);
return success(true);
}
// @PutMapping("/update")
// @Operation(summary = "更新物料")
// @PreAuthorize("@ss.hasPermission('qms:material-product:update')")
// public CommonResult<Boolean> updateMaterialProduct(@Valid @RequestBody MaterialProductSaveReqVO updateReqVO) {
// materialProductService.updateMaterialProduct(updateReqVO);
// return success(true);
// }
@DeleteMapping("/delete")
@Operation(summary = "删除物料")
@Operation(summary = "删除物料分类或大类")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('qms:material-product:delete')")
// @PreAuthorize("@ss.hasPermission('qms:material-product:delete')")
public CommonResult<Boolean> deleteMaterialProduct(@RequestParam("id") Long id) {
materialProductService.deleteMaterialProduct(id);
return success(true);

View File

@@ -1,10 +1,12 @@
package com.zt.plat.module.qms.resource.material.controller.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import io.swagger.v3.oas.annotations.media.Schema;
import com.zt.plat.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -20,8 +22,8 @@ public class MaterialBatchPageReqVO extends PageParam {
@Schema(description = "批次编号")
private String batchNo;
@Schema(description = "总数量")
private String inboundQuantity;
// @Schema(description = "总数量")
// private BigDecimal inboundQuantity;
@Schema(description = "存放位置描述")
private String location;
@@ -37,6 +39,12 @@ public class MaterialBatchPageReqVO extends PageParam {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDate[] dueDate;
@Schema(description = "分配部门id")
private Long assignDepartmentId;
@Schema(description = "分配部门名称")
private String assignDepartmentName;
@Schema(description = "验收状态", example = "1")
private String acceptanceStatus;
@@ -46,8 +54,8 @@ public class MaterialBatchPageReqVO extends PageParam {
@Schema(description = "检化验状态,NOT_STARTED-未开始IN_PROGRESS-进行中PASSED-通过NOT_PASSED-未通过", example = "2")
private String assayStatus;
@Schema(description = "检化验结果")
private String assayResult;
// @Schema(description = "检化验结果")
// private String assayResult;
@Schema(description = "所属部门")
private String systemDepartmentCode;

View File

@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@@ -17,6 +18,10 @@ public class MaterialBatchRespVO {
@ExcelProperty("主键")
private Long id;
@Schema(description = "父id,为0时是批次不为0时是工段", example = "1035")
@ExcelProperty("父id,为0时是批次不为0时是工段")
private Long parentId;
@Schema(description = "物料大类id", example = "9381")
@ExcelProperty("物料大类id")
private Long productId;
@@ -27,7 +32,7 @@ public class MaterialBatchRespVO {
@Schema(description = "总数量")
@ExcelProperty("总数量")
private String inboundQuantity;
private BigDecimal inboundQuantity;
@Schema(description = "存放位置描述")
@ExcelProperty("存放位置描述")
@@ -45,6 +50,14 @@ public class MaterialBatchRespVO {
@ExcelProperty("到期日期")
private LocalDate dueDate;
@Schema(description = "分配部门id")
@ExcelProperty("分配部门id")
private Long assignDepartmentId;
@Schema(description = "分配部门名称")
@ExcelProperty("分配部门名称")
private String assignDepartmentName;
@Schema(description = "验收状态", example = "1")
@ExcelProperty("验收状态")
private String acceptanceStatus;

View File

@@ -1,26 +1,39 @@
package com.zt.plat.module.qms.resource.material.controller.vo;
import com.zt.plat.module.qms.resource.material.valid.AddGroup;
import com.zt.plat.module.qms.resource.material.valid.UpdateGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import jakarta.validation.constraints.*;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
@Schema(description = "管理后台 - 物料批次新增/修改 Request VO")
@Data
public class MaterialBatchSaveReqVO {
@Null(groups = AddGroup.class, message = "新增数据 ID 必须为空")
@NotNull(groups = UpdateGroup.class, message = "修改数据 ID 不能为空")
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "9716")
private Long id;
@Schema(description = "父id,为0时是批次不为0时是工段", example = "1035")
private Long parentId;
@Schema(description = "物料大类id", example = "9381")
@NotNull(groups = AddGroup.class, message = "物料大类 ID 不能为空")
private Long productId;
@Schema(description = "批次编号")
private String batchNo;
// @Schema(description = "批次编号")
// private String batchNo;
@Schema(description = "总数量")
private String inboundQuantity;
@NotNull(groups = AddGroup.class, message = "总数量不能为空")
@Min(value = 0, message = "总数量不能小于0")
private BigDecimal inboundQuantity;
@Schema(description = "存放位置描述")
private String location;
@@ -29,22 +42,29 @@ public class MaterialBatchSaveReqVO {
private Long supplierId;
@Schema(description = "生产日期")
@NotNull(groups = AddGroup.class, message = "生产日期不能为空")
private LocalDate manufacturerDate;
@Schema(description = "到期日期")
private LocalDate dueDate;
@Schema(description = "验收状态", example = "1")
private String acceptanceStatus;
@Schema(description = "分配部门id")
private Long assignDepartmentId;
@Schema(description = "分配部门名称")
private String assignDepartmentName;
// @Schema(description = "验收状态", example = "1")
// private String acceptanceStatus;
@Schema(description = "是否检化验,1-是0-否")
private Integer assayFlag;
@Schema(description = "检化验状态,NOT_STARTED-未开始IN_PROGRESS-进行中PASSED-通过NOT_PASSED-未通过", example = "2")
private String assayStatus;
// @Schema(description = "检化验状态,NOT_STARTED-未开始IN_PROGRESS-进行中PASSED-通过NOT_PASSED-未通过", example = "IN_PROGRESS")
// private String assayStatus;
@Schema(description = "检化验结果")
private String assayResult;
// @Schema(description = "检化验结果")
// private String assayResult;
@Schema(description = "所属部门")
private String systemDepartmentCode;

View File

@@ -4,6 +4,7 @@ import lombok.*;
import com.baomidou.mybatisplus.annotation.*;
import com.zt.plat.framework.mybatis.core.dataobject.BusinessBaseDO;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
@@ -31,6 +32,11 @@ public class MaterialBatchDO extends BusinessBaseDO {
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 父id,为0时是批次不为0时是工段
*/
@TableField("PRN_ID")
private Long parentId;
/**
* 物料大类id
*/
@@ -45,7 +51,7 @@ public class MaterialBatchDO extends BusinessBaseDO {
* 总数量
*/
@TableField("INB_QTY")
private String inboundQuantity;
private BigDecimal inboundQuantity;
/**
* 存放位置描述
*/
@@ -66,6 +72,16 @@ public class MaterialBatchDO extends BusinessBaseDO {
*/
@TableField("DUE_DT")
private LocalDate dueDate;
/**
* 分配部门id
*/
@TableField("ASN_DEPT_ID")
private Long assignDepartmentId;
/**
* 分配部门名称
*/
@TableField("ASN_DEPT_NAME")
private String assignDepartmentName;
/**
* 验收状态
*/

View File

@@ -18,16 +18,17 @@ public interface MaterialBatchMapper extends BaseMapperX<MaterialBatchDO> {
default PageResult<MaterialBatchDO> selectPage(MaterialBatchPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MaterialBatchDO>()
.eqIfPresent(MaterialBatchDO::getProductId, reqVO.getProductId())
.eqIfPresent(MaterialBatchDO::getBatchNo, reqVO.getBatchNo())
.eqIfPresent(MaterialBatchDO::getInboundQuantity, reqVO.getInboundQuantity())
.eqIfPresent(MaterialBatchDO::getLocation, reqVO.getLocation())
.likeIfPresent(MaterialBatchDO::getBatchNo, reqVO.getBatchNo())
.likeIfPresent(MaterialBatchDO::getLocation, reqVO.getLocation())
.eqIfPresent(MaterialBatchDO::getSupplierId, reqVO.getSupplierId())
.betweenIfPresent(MaterialBatchDO::getManufacturerDate, reqVO.getManufacturerDate())
.betweenIfPresent(MaterialBatchDO::getDueDate, reqVO.getDueDate())
.eqIfPresent(MaterialBatchDO::getAssignDepartmentId, reqVO.getAssignDepartmentId())
.likeIfPresent(MaterialBatchDO::getAssignDepartmentName, reqVO.getAssignDepartmentName())
.eqIfPresent(MaterialBatchDO::getAcceptanceStatus, reqVO.getAcceptanceStatus())
.eqIfPresent(MaterialBatchDO::getAssayFlag, reqVO.getAssayFlag())
.eqIfPresent(MaterialBatchDO::getAssayStatus, reqVO.getAssayStatus())
.eqIfPresent(MaterialBatchDO::getAssayResult, reqVO.getAssayResult())
//.eqIfPresent(MaterialBatchDO::getAssayResult, reqVO.getAssayResult())
.eqIfPresent(MaterialBatchDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
.eqIfPresent(MaterialBatchDO::getRemark, reqVO.getRemark())
.betweenIfPresent(MaterialBatchDO::getCreateTime, reqVO.getCreateTime())

View File

@@ -61,4 +61,11 @@ public interface MaterialBatchService {
*/
PageResult<MaterialBatchDO> getMaterialBatchPage(MaterialBatchPageReqVO pageReqVO);
/**
* 批次工段拆分
*
* @param createReqVOs 创建信息
* @return 工段编号
*/
List<MaterialBatchRespVO> assignMaterialBatchGongduan(@Valid List<MaterialBatchSaveReqVO> createReqVOs);
}

View File

@@ -1,18 +1,31 @@
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.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.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;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialBatchDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialInfomationDO;
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialBatchMapper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.module.qms.enums.ErrorCodeConstants.*;
@@ -28,20 +41,39 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
@Resource
private MaterialBatchMapper materialBatchMapper;
@Autowired
private SequenceUtil sequenceUtil;
@Autowired
private MaterialProductService materialProductService;
private final String sequenceKey = "QMS_MATERIAL_BATCH_NO";
@Override
public MaterialBatchRespVO createMaterialBatch(MaterialBatchSaveReqVO createReqVO) {
// 插入
MaterialBatchDO materialBatch = BeanUtils.toBean(createReqVO, MaterialBatchDO.class);
materialBatchMapper.insert(materialBatch);
MaterialBatchDO mtrlBat = BeanUtils.toBean(createReqVO, MaterialBatchDO.class);
// 批次编号
mtrlBat.setBatchNo(sequenceUtil.genCode(sequenceKey));
mtrlBat.setParentId(0L);
materialBatchMapper.insert(mtrlBat);
// 返回
return BeanUtils.toBean(materialBatch, MaterialBatchRespVO.class);
return BeanUtils.toBean(mtrlBat, MaterialBatchRespVO.class);
}
@Override
public void updateMaterialBatch(MaterialBatchSaveReqVO updateReqVO) {
// 校验存在
validateMaterialBatchExists(updateReqVO.getId());
Long reqId = updateReqVO.getId();
validateMaterialBatchExists(reqId);
// 已经拆分工段的不可编辑
List<MaterialBatchDO> asnDOs = materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
.eq(MaterialBatchDO::getParentId, reqId));
if (CollUtil.isNotEmpty(asnDOs)) throw exception(MATERIAL_BATCH_ASSIGN_END);
// 更新
MaterialBatchDO updateObj = BeanUtils.toBean(updateReqVO, MaterialBatchDO.class);
materialBatchMapper.updateById(updateObj);
@@ -51,6 +83,12 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
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);
// 删除
materialBatchMapper.deleteById(id);
}
@@ -59,6 +97,10 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
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);
// 删除
materialBatchMapper.deleteByIds(ids);
}
@@ -86,4 +128,45 @@ public class MaterialBatchServiceImpl implements MaterialBatchService {
return materialBatchMapper.selectPage(pageReqVO);
}
/**
* 批次工段拆分
*
*/
@Override
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);
// 2. 拆分后的数量要相等
MaterialBatchDO mtrlBat = materialBatchMapper.selectById(batId);
if (mtrlBat == null) throw exception(MATERIAL_BATCH_NOT_EXISTS);
BigDecimal total = BigDecimal.valueOf(0);
for (MaterialBatchSaveReqVO batAsn : createReqVOs) {
total = total.add(batAsn.getInboundQuantity());
}
if (!total.equals(mtrlBat.getInboundQuantity()))
throw exception(GONGDUAN_QUANTITY_MATERIAL_BATCH_NOT_EQUAL);
// 修改工段
if (CollUtil.isNotEmpty(asnDOs)) {
// 删除之前的拆分数据TODO 需要检查是否可以删除
materialBatchMapper.delete(Wrappers.lambdaQuery(MaterialBatchDO.class)
.eq(MaterialBatchDO::getParentId, batId));
}
// 3. 保存工段
List<MaterialBatchDO> gongEts = createReqVOs.stream().map(
batAsn -> BeanUtils.toBean(batAsn, MaterialBatchDO.class)).toList();
materialBatchMapper.insertBatch(gongEts);
return gongEts.stream().map(
gong -> BeanUtils.toBean(gong, MaterialBatchRespVO.class)
).toList();
}
}

View File

@@ -14,6 +14,7 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductSav
import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO;
import com.zt.plat.module.qms.resource.material.dal.mapper.MaterialProductMapper;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -180,19 +181,20 @@ public class MaterialProductServiceImpl implements MaterialProductService {
.setStandardMaterialFlag(prnCtg.getStandardMaterialFlag())
.setStandardSolutionFlag(prnCtg.getStandardSolutionFlag());
}
materialProductMapper.insert(mtrl);
return BeanUtils.toBean(mtrl, MaterialProductRespVO.class);
// 更新 idPath
} else {
// 修改
MaterialProductDO origDO = materialProductMapper.selectById(reqId);
if (origDO == null) throw exception(MATERIAL_PRODUCT_NOT_EXISTS);
Long newParentId = createReqVO.getParentId();
if (origDO.getParentId().equals(newParentId)) {
materialProductMapper.updateById(mtrl);
return BeanUtils.toBean(mtrl, MaterialProductRespVO.class);
}
// 父节点有变更时更新 idPath
}
// 修改
MaterialProductDO origDO = materialProductMapper.selectById(reqId);
if (origDO == null) throw exception(MATERIAL_PRODUCT_NOT_EXISTS);
Long newParentId = createReqVO.getParentId();
if (origDO.getParentId().equals(newParentId)) {
materialProductMapper.updateById(mtrl);
return BeanUtils.toBean(mtrl, MaterialProductRespVO.class);
}
// 父节点有变更时更新 idPath
String newIdPath = getIdPath(mtrl);
mtrl.setIdPath(newIdPath);
materialProductMapper.updateById(mtrl);
@@ -210,9 +212,23 @@ public class MaterialProductServiceImpl implements MaterialProductService {
@Override
public void deleteMaterialProduct(Long id) {
// 校验存在
validateMaterialProductExists(id);
// 删除
MaterialProductDO pdtDo = materialProductMapper.selectById(id);
if (pdtDo == null) throw exception(MATERIAL_PRODUCT_NOT_EXISTS);
// 分类
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);
}
// 大类
else {
// 大类下批次时不可删除 TODO 以及其他不可删除的情况
}
materialProductMapper.deleteById(id);
}