diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java index 81edf2b..87fbdd7 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialBatchController.java @@ -47,14 +47,14 @@ public class MaterialBatchController implements BusinessControllerMarker { @PostMapping("/create") @Operation(summary = "创建物料批次") -// @PreAuthorize("@ss.hasPermission('qms:material-batch:create')") + @PreAuthorize("@ss.hasPermission('qms:material-batch:create')") public CommonResult createMaterialBatch(@Validated(AddGroup.class) @RequestBody MaterialBatchSaveReqVO createReqVO) { return success(materialBatchService.createMaterialBatch(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新物料批次") -// @PreAuthorize("@ss.hasPermission('qms:material-batch:update')") + @PreAuthorize("@ss.hasPermission('qms:material-batch:update')") public CommonResult updateMaterialBatch(@Validated(UpdateGroup.class) @RequestBody MaterialBatchSaveReqVO updateReqVO) { materialBatchService.updateMaterialBatch(updateReqVO); return success(true); @@ -63,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 deleteMaterialBatch(@RequestParam("id") Long id) { materialBatchService.deleteMaterialBatch(id); return success(true); @@ -72,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 deleteMaterialBatchList(@RequestBody BatchDeleteReqVO req) { materialBatchService.deleteMaterialBatchListByIds(req.getIds()); return success(true); @@ -110,9 +110,17 @@ public class MaterialBatchController implements BusinessControllerMarker { @PostMapping("/assign-gongduan") @Operation(summary = "批次工段拆分") -// @PreAuthorize("@ss.hasPermission('qms:material-batch:create')") + @PreAuthorize("@ss.hasPermission('qms:material-batch:create')") public CommonResult> assignMaterialBatchGongduan(@Valid @RequestBody List createReqVOs) { return success(materialBatchService.assignMaterialBatchGongduan(createReqVOs)); } + @GetMapping("gongduan-page") + @Operation(summary = "获取工段列表") + @Parameter(name = "id", description = "物料批次 id", required = true, example = "1054") + public CommonResult> getMaterialBatchGongduanList(@RequestParam("id") Long id) { + List list = materialBatchService.getMaterialBatchGongduanList(id); + return success(BeanUtils.toBean(list, MaterialBatchRespVO.class)); + } + } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialProductController.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialProductController.java index 262b324..14f5748 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialProductController.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/admin/MaterialProductController.java @@ -51,7 +51,7 @@ public class MaterialProductController extends AbstractFileUploadController impl @PostMapping("/save-category") @Operation(summary = "保存分类") -// @PreAuthorize("@ss.hasPermission('qms:material-product:create-category')") + @PreAuthorize("@ss.hasPermission('qms:material-product:create-category')") public CommonResult saveMaterialCategory(@Valid @RequestBody MaterialProductSaveReqVO createReqVO) { return success(materialProductService.saveMaterialCategory(createReqVO)); } @@ -72,7 +72,7 @@ public class MaterialProductController extends AbstractFileUploadController impl @PostMapping("/save-material") @Operation(summary = "保存物料大类") -// @PreAuthorize("@ss.hasPermission('qms:material-product:create')") + @PreAuthorize("@ss.hasPermission('qms:material-product:create')") public CommonResult saveMaterialProduct(@Valid @RequestBody MaterialProductSaveReqVO createReqVO) { return success(materialProductService.saveMaterialProduct(createReqVO)); } @@ -97,7 +97,7 @@ public class MaterialProductController extends AbstractFileUploadController impl @DeleteMapping("/delete") @Operation(summary = "删除物料分类或大类") @Parameter(name = "id", description = "编号", required = true) -// @PreAuthorize("@ss.hasPermission('qms:material-product:delete')") + @PreAuthorize("@ss.hasPermission('qms:material-product:delete')") public CommonResult deleteMaterialProduct(@RequestParam("id") Long id) { materialProductService.deleteMaterialProduct(id); return success(true); diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductRespVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductRespVO.java index 4da4890..d609997 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductRespVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductRespVO.java @@ -2,6 +2,7 @@ package com.zt.plat.module.qms.resource.material.controller.vo; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; +import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -21,6 +22,10 @@ public class MaterialProductRespVO { @ExcelProperty("父id") private Long parentId; + @Schema(description = "分类名称") + @ExcelProperty("分类名称") + private String categoryName; + @Schema(description = "id路径") @ExcelProperty("id路径") private String idPath; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductSaveReqVO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductSaveReqVO.java index 0669cb3..e9e9ae3 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductSaveReqVO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/controller/vo/MaterialProductSaveReqVO.java @@ -39,6 +39,9 @@ public class MaterialProductSaveReqVO { @Schema(description = "标签(预留的扩展字段)") private String tag; + @Schema(description = "标签模板") + private String labelTemplateKey; + @Schema(description = "型号") private String modelNo; diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialProductDO.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialProductDO.java index 461f43c..dcf8177 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialProductDO.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/dataobject/MaterialProductDO.java @@ -32,6 +32,11 @@ public class MaterialProductDO extends BusinessBaseDO { */ @TableField("PRN_ID") private Long parentId; + /** + * 分类名称 + */ + @TableField(exist = false) + private String categoryName; /** * id路径 */ diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialProductMapper.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialProductMapper.java index 7e1c791..3135749 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialProductMapper.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/dal/mapper/MaterialProductMapper.java @@ -1,6 +1,6 @@ package com.zt.plat.module.qms.resource.material.dal.mapper; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.collection.CollUtil; 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; @@ -9,6 +9,11 @@ import com.zt.plat.module.qms.resource.material.controller.vo.MaterialProductPag import com.zt.plat.module.qms.resource.material.dal.dataobject.MaterialProductDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + /** * 物料大类 Mapper * @@ -18,7 +23,7 @@ import org.apache.ibatis.annotations.Mapper; public interface MaterialProductMapper extends BaseMapperX { default PageResult selectPage(MaterialProductPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() + PageResult pageResult = selectPage(reqVO, new LambdaQueryWrapperX() .eq(MaterialProductDO::getNodeType, DataTypeConstant.DATA_TYPE_DATA) .eqIfPresent(MaterialProductDO::getParentId, reqVO.getParentId()) .likeIfPresent(MaterialProductDO::getIdPath, reqVO.getIdPath()) @@ -49,6 +54,17 @@ public interface MaterialProductMapper extends BaseMapperX { .orderByAsc(MaterialProductDO::getSortNo) .orderByAsc(MaterialProductDO::getIdPath) .orderByDesc(MaterialProductDO::getId)); + List mtrlDos = pageResult.getList(); + if (CollUtil.isEmpty(mtrlDos)) return pageResult; + Set prnIds = mtrlDos.stream().map(MaterialProductDO::getParentId).collect(Collectors.toSet()); + List prnDos = this.selectByIds(prnIds); + if (CollUtil.isEmpty(prnDos)) return pageResult; + Map prnIdNameMap = prnDos.stream().collect(Collectors.toMap(MaterialProductDO::getId, MaterialProductDO::getName)); + for (MaterialProductDO mtrlDo : mtrlDos) { + mtrlDo.setCategoryName(prnIdNameMap.get(mtrlDo.getParentId())); + } + pageResult.setList(mtrlDos); + return pageResult; } } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java index bd45936..a185ce0 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchService.java @@ -84,4 +84,12 @@ public interface MaterialBatchService { * @return 存在与否 */ boolean checkIsExistsDataByPdts(List ids); + + /** + * 获取工段列表 + * + * @param batId 批次 id + * @return 工段列表 + */ + List getMaterialBatchGongduanList(Long batId); } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java index 4c450e6..e54f4eb 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialBatchServiceImpl.java @@ -174,7 +174,8 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { public boolean checkIsExistsDataByPdt(Long pdtId) { return materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class) - .eq(MaterialBatchDO::getProductId, pdtId)); + .eq(MaterialBatchDO::getProductId, pdtId) + .eq(MaterialBatchDO::getParentId, 0)); } @@ -182,7 +183,17 @@ public class MaterialBatchServiceImpl implements MaterialBatchService { public boolean checkIsExistsDataByPdts(List ids) { return materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class) - .in(MaterialBatchDO::getProductId, ids)); + .in(MaterialBatchDO::getProductId, ids) + .eq(MaterialBatchDO::getParentId, 0)); + } + + + @Override + public List getMaterialBatchGongduanList(Long batId) { + + return materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class) + .eq(MaterialBatchDO::getParentId, batId) + .ne(MaterialBatchDO::getParentId, 0)); } } \ No newline at end of file diff --git a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java index a13b97b..8ce8838 100644 --- a/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java +++ b/zt-module-qms/zt-module-qms-server/src/main/java/com/zt/plat/module/qms/resource/material/service/MaterialProductServiceImpl.java @@ -15,6 +15,7 @@ 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.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -25,6 +26,7 @@ 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.*; +import static org.checkerframework.checker.units.qual.Prefix.one; /** * 物料大类 Service 实现类 @@ -37,9 +39,10 @@ public class MaterialProductServiceImpl implements MaterialProductService { @Resource private MaterialProductMapper materialProductMapper; -// -// @Resource -// private MaterialBatchService materialBatchService; + + @Lazy + @Autowired + private MaterialBatchService materialBatchService; /** * 保存分类 @@ -58,8 +61,8 @@ public class MaterialProductServiceImpl implements MaterialProductService { // 新增 if (reqId == null) { // 检查分类名称是否重复 - MaterialProductDO one = materialProductMapper.selectOne(queryWrapperX); - if (one != null) throw exception(DICTIONARY_BUSINESS_CLASSIFY_DUPLICATE); + boolean exists = materialProductMapper.exists(queryWrapperX); + if (exists) throw exception(DICTIONARY_BUSINESS_CLASSIFY_DUPLICATE); mtrl.setNodeType(DataTypeConstant.DATA_TYPE_CATEGORY); @@ -84,8 +87,8 @@ public class MaterialProductServiceImpl implements MaterialProductService { if (origDO == null) throw exception(MATERIAL_PRODUCT_NOT_EXISTS); // 检查分类名称是否重复 queryWrapperX.ne(MaterialProductDO::getId, reqId); - MaterialProductDO one = materialProductMapper.selectOne(queryWrapperX); - if (one != null) throw exception(DICTIONARY_BUSINESS_CLASSIFY_DUPLICATE); + boolean exists = materialProductMapper.exists(queryWrapperX); + if (exists) throw exception(DICTIONARY_BUSINESS_CLASSIFY_DUPLICATE); Long parentId = mtrl.getParentId(); // 当前节点的父节点不能是当前节点 @@ -184,8 +187,8 @@ public class MaterialProductServiceImpl implements MaterialProductService { .eqIfPresent(MaterialProductDO::getNodeType, DataTypeConstant.DATA_TYPE_DATA); // 新增 if (reqId == null) { - MaterialProductDO one = materialProductMapper.selectOne(queryWrapperX); - if (one != null) throw exception(MATERIAL_PRODUCT_CODE_EXISTED); + boolean exists = materialProductMapper.exists(queryWrapperX); + if (exists) throw exception(MATERIAL_PRODUCT_CODE_EXISTED); // 从直接父分类获取是否危险品、是否标准物质、是否标准溶液 MaterialProductDO prnCtg = materialProductMapper.selectById(mtrl.getParentId()); if (prnCtg != null) { @@ -200,6 +203,10 @@ public class MaterialProductServiceImpl implements MaterialProductService { // 修改 MaterialProductDO origDO = materialProductMapper.selectById(reqId); if (origDO == null) throw exception(MATERIAL_PRODUCT_NOT_EXISTS); + if (mtrl.getCode() != null && !mtrl.getCode().equals(origDO.getCode())) { + boolean exists = materialProductMapper.exists(queryWrapperX); + if (exists) throw exception(MATERIAL_PRODUCT_CODE_EXISTED); + } Long newParentId = createReqVO.getParentId(); if (origDO.getParentId().equals(newParentId)) { materialProductMapper.updateById(mtrl); @@ -240,8 +247,8 @@ public class MaterialProductServiceImpl implements MaterialProductService { else { // 大类下有批次时不可删除 // TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等 -// boolean exists = materialBatchService.checkIsExistsDataByPdt(id); -// if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH); + boolean exists = materialBatchService.checkIsExistsDataByPdt(id); + if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH); } materialProductMapper.deleteById(id); } @@ -258,7 +265,8 @@ public class MaterialProductServiceImpl implements MaterialProductService { if (CollUtil.isNotEmpty(mtCtgList)) throw exception(MATERIAL_PRODUCTS_EXISTS_CATEGORY); // 检查是否可删除 大类下有批次时不可删除 // TODO 以及其他不可删除的情况,如库存记录、物料实例、使用记录等 -// boolean exists = materialBatchService.checkIsExistsDataByPdts(ids); + boolean exists = materialBatchService.checkIsExistsDataByPdts(ids); + if (exists) throw exception(MATERIAL_PRODUCT_EXISTS_BATCH); // 删除 materialProductMapper.deleteByIds(ids); }