fix:接口完善
This commit is contained in:
@@ -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<MaterialBatchRespVO> 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<Boolean> 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<Boolean> 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<Boolean> 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<List<MaterialBatchRespVO>> assignMaterialBatchGongduan(@Valid @RequestBody List<MaterialBatchSaveReqVO> createReqVOs) {
|
||||
return success(materialBatchService.assignMaterialBatchGongduan(createReqVOs));
|
||||
}
|
||||
|
||||
@GetMapping("gongduan-page")
|
||||
@Operation(summary = "获取工段列表")
|
||||
@Parameter(name = "id", description = "物料批次 id", required = true, example = "1054")
|
||||
public CommonResult<List<MaterialBatchRespVO>> getMaterialBatchGongduanList(@RequestParam("id") Long id) {
|
||||
List<MaterialBatchDO> list = materialBatchService.getMaterialBatchGongduanList(id);
|
||||
return success(BeanUtils.toBean(list, MaterialBatchRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<MaterialProductRespVO> 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<MaterialProductRespVO> 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<Boolean> deleteMaterialProduct(@RequestParam("id") Long id) {
|
||||
materialProductService.deleteMaterialProduct(id);
|
||||
return success(true);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -39,6 +39,9 @@ public class MaterialProductSaveReqVO {
|
||||
@Schema(description = "标签(预留的扩展字段)")
|
||||
private String tag;
|
||||
|
||||
@Schema(description = "标签模板")
|
||||
private String labelTemplateKey;
|
||||
|
||||
@Schema(description = "型号")
|
||||
private String modelNo;
|
||||
|
||||
|
||||
@@ -32,6 +32,11 @@ public class MaterialProductDO extends BusinessBaseDO {
|
||||
*/
|
||||
@TableField("PRN_ID")
|
||||
private Long parentId;
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String categoryName;
|
||||
/**
|
||||
* id路径
|
||||
*/
|
||||
|
||||
@@ -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<MaterialProductDO> {
|
||||
|
||||
default PageResult<MaterialProductDO> selectPage(MaterialProductPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<MaterialProductDO>()
|
||||
PageResult<MaterialProductDO> pageResult = selectPage(reqVO, new LambdaQueryWrapperX<MaterialProductDO>()
|
||||
.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<MaterialProductDO> {
|
||||
.orderByAsc(MaterialProductDO::getSortNo)
|
||||
.orderByAsc(MaterialProductDO::getIdPath)
|
||||
.orderByDesc(MaterialProductDO::getId));
|
||||
List<MaterialProductDO> mtrlDos = pageResult.getList();
|
||||
if (CollUtil.isEmpty(mtrlDos)) return pageResult;
|
||||
Set<Long> prnIds = mtrlDos.stream().map(MaterialProductDO::getParentId).collect(Collectors.toSet());
|
||||
List<MaterialProductDO> prnDos = this.selectByIds(prnIds);
|
||||
if (CollUtil.isEmpty(prnDos)) return pageResult;
|
||||
Map<Long, String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -84,4 +84,12 @@ public interface MaterialBatchService {
|
||||
* @return 存在与否
|
||||
*/
|
||||
boolean checkIsExistsDataByPdts(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获取工段列表
|
||||
*
|
||||
* @param batId 批次 id
|
||||
* @return 工段列表
|
||||
*/
|
||||
List<MaterialBatchDO> getMaterialBatchGongduanList(Long batId);
|
||||
}
|
||||
@@ -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<Long> ids) {
|
||||
|
||||
return materialBatchMapper.exists(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.in(MaterialBatchDO::getProductId, ids));
|
||||
.in(MaterialBatchDO::getProductId, ids)
|
||||
.eq(MaterialBatchDO::getParentId, 0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<MaterialBatchDO> getMaterialBatchGongduanList(Long batId) {
|
||||
|
||||
return materialBatchMapper.selectList(Wrappers.lambdaQuery(MaterialBatchDO.class)
|
||||
.eq(MaterialBatchDO::getParentId, batId)
|
||||
.ne(MaterialBatchDO::getParentId, 0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user