refactor(qms-inspection): 优化检验标准新增逻辑及异常处理
- 引入IQmsInspectionItemService、IQmsInspectionItemDetailsService、IQmsQcMaterialCategoryService依赖 - 新增add方法中物料存在性校验,确保物料有效 - 根据物料类别及其父类别获取检验项及明细,自动生成检测标准项及内容 - 优化异常抛出,统一使用STATE.BusinessError替代硬编码常量 - 提取getInspectionItemDetails方法,提升代码复用性 - 更新相关service调用,完善检验标准新增及校验流程
This commit is contained in:
parent
59337c4fbb
commit
d0fb34dc71
|
|
@ -2,10 +2,12 @@ package com.nflg.qms.admin.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
|
import cn.hutool.core.lang.Pair;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.nflg.qms.admin.pojo.qo.QmsPdfExtractRegionQO;
|
import com.nflg.qms.admin.pojo.qo.QmsPdfExtractRegionQO;
|
||||||
|
import com.nflg.wms.common.constant.STATE;
|
||||||
import com.nflg.wms.common.exception.NflgException;
|
import com.nflg.wms.common.exception.NflgException;
|
||||||
import com.nflg.wms.common.pojo.PageData;
|
import com.nflg.wms.common.pojo.PageData;
|
||||||
import com.nflg.wms.common.pojo.dto.QmsInspectionStandardDetailDTO;
|
import com.nflg.wms.common.pojo.dto.QmsInspectionStandardDetailDTO;
|
||||||
|
|
@ -72,6 +74,15 @@ public class QmsInspectionStandardControllerService {
|
||||||
@Resource
|
@Resource
|
||||||
private RegionFilterService regionFilterService;
|
private RegionFilterService regionFilterService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IQmsInspectionItemService inspectionItemService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IQmsInspectionItemDetailsService inspectionItemDetailsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IQmsQcMaterialCategoryService materialCategoryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询检验标准
|
* 分页查询检验标准
|
||||||
*/
|
*/
|
||||||
|
|
@ -123,7 +134,7 @@ public class QmsInspectionStandardControllerService {
|
||||||
|
|
||||||
// 2. 已发布的标准不允许删除
|
// 2. 已发布的标准不允许删除
|
||||||
if (standard.getPublishStatus() != null && standard.getPublishStatus() == 1) {
|
if (standard.getPublishStatus() != null && standard.getPublishStatus() == 1) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError,
|
throw new NflgException(STATE.BusinessError,
|
||||||
"已发布的检验标准不允许删除,ID: " + id);
|
"已发布的检验标准不允许删除,ID: " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +173,7 @@ public class QmsInspectionStandardControllerService {
|
||||||
// 1. 查询检验标准基本信息
|
// 1. 查询检验标准基本信息
|
||||||
QmsInspectionStandard standard = inspectionStandardService.getById(id);
|
QmsInspectionStandard standard = inspectionStandardService.getById(id);
|
||||||
if (standard == null) {
|
if (standard == null) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检验标准不存在");
|
throw new NflgException(STATE.BusinessError, "检验标准不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 查询检验标准详情(关联物料等信息)
|
// 2. 查询检验标准详情(关联物料等信息)
|
||||||
|
|
@ -322,6 +333,9 @@ public class QmsInspectionStandardControllerService {
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long add(QmsInspectionStandardAddQO qo) {
|
public Long add(QmsInspectionStandardAddQO qo) {
|
||||||
|
QmsQcMaterial qmsQcMaterial = qmsQcMaterialService.getById(qo.getMaterialId());
|
||||||
|
VUtil.trueThrowBusinessError(Objects.isNull(qmsQcMaterial)).throwMessage("物料不存在");
|
||||||
|
|
||||||
Long userId = UserUtil.getUserId();
|
Long userId = UserUtil.getUserId();
|
||||||
String userName = UserUtil.getUserName();
|
String userName = UserUtil.getUserName();
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
@ -348,6 +362,56 @@ public class QmsInspectionStandardControllerService {
|
||||||
|
|
||||||
inspectionStandardService.save(standard);
|
inspectionStandardService.save(standard);
|
||||||
|
|
||||||
|
String materialCategoryCode = qmsQcMaterial.getMaterialCategoryCode();
|
||||||
|
if (StrUtil.isNotBlank(materialCategoryCode)) {
|
||||||
|
QmsQcMaterialCategory category = materialCategoryService.lambdaQuery()
|
||||||
|
.eq(QmsQcMaterialCategory::getCategoryCode, materialCategoryCode)
|
||||||
|
.one();
|
||||||
|
if (Objects.nonNull(category)) {
|
||||||
|
Pair<QmsInspectionItem, List<QmsInspectionItemDetails>> data = getInspectionItemDetails(category);
|
||||||
|
if (Objects.isNull(data)) {
|
||||||
|
category = materialCategoryService.lambdaQuery()
|
||||||
|
.eq(QmsQcMaterialCategory::getId, category.getParentCategoryRowId())
|
||||||
|
.one();
|
||||||
|
if (Objects.nonNull(category)) {
|
||||||
|
data = getInspectionItemDetails(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Objects.nonNull(data)) {
|
||||||
|
QmsInspectionStandardItem inspectionStandardItem = new QmsInspectionStandardItem();
|
||||||
|
inspectionStandardItem.setInspectionStandardId(standard.getId());
|
||||||
|
inspectionStandardItem.setItemType((short) 0);
|
||||||
|
Long detectionTypeDictItemId = switch (data.getKey().getDetectionType()) {
|
||||||
|
case 0 -> dictionaryItemService.getIdByCode("InspectionStandardDetectionType", "定性");
|
||||||
|
case 1 -> dictionaryItemService.getIdByCode("InspectionStandardDetectionType", "定量");
|
||||||
|
default -> 0L;
|
||||||
|
};
|
||||||
|
VUtil.trueThrowBusinessError(detectionTypeDictItemId == 0).throwMessage("检测类型字典项不存在");
|
||||||
|
inspectionStandardItem.setDetectionTypeDictItemId(detectionTypeDictItemId);
|
||||||
|
inspectionStandardItem.setSortNo(0);
|
||||||
|
inspectionStandardItem.setName(data.getKey().getInspectionItemName());
|
||||||
|
inspectionStandardItemService.save(inspectionStandardItem);
|
||||||
|
inspectionStandardItemContentService.saveBatch(
|
||||||
|
data.getValue()
|
||||||
|
.stream()
|
||||||
|
.map(content -> {
|
||||||
|
QmsInspectionStandardItemContent itemContent = new QmsInspectionStandardItemContent();
|
||||||
|
itemContent.setInspectionStandardItemId(inspectionStandardItem.getId());
|
||||||
|
itemContent.setSortNo(content.getSortNo());
|
||||||
|
itemContent.setTestStandard(content.getTestStandard());
|
||||||
|
itemContent.setLegend(content.getLegend());
|
||||||
|
itemContent.setJudgmentType(content.getDeterminationType());
|
||||||
|
itemContent.setCreateUserId(userId);
|
||||||
|
itemContent.setCreateUserName(userName);
|
||||||
|
itemContent.setCreateTime(now);
|
||||||
|
return itemContent;
|
||||||
|
})
|
||||||
|
.toList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qmsQcMaterialService.lambdaUpdate()
|
qmsQcMaterialService.lambdaUpdate()
|
||||||
.set(QmsQcMaterial::getIsStandardMaintained, true)
|
.set(QmsQcMaterial::getIsStandardMaintained, true)
|
||||||
.eq(QmsQcMaterial::getId, qo.getMaterialId())
|
.eq(QmsQcMaterial::getId, qo.getMaterialId())
|
||||||
|
|
@ -357,6 +421,19 @@ public class QmsInspectionStandardControllerService {
|
||||||
return standard.getId();
|
return standard.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Pair<QmsInspectionItem, List<QmsInspectionItemDetails>> getInspectionItemDetails(QmsQcMaterialCategory category) {
|
||||||
|
QmsInspectionItem inspectionItem = inspectionItemService.lambdaQuery()
|
||||||
|
.eq(QmsInspectionItem::getMaterialTypeId, category.getId())
|
||||||
|
.one();
|
||||||
|
if (Objects.isNull(inspectionItem)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Pair.of(inspectionItem, inspectionItemDetailsService.lambdaQuery()
|
||||||
|
.eq(QmsInspectionItemDetails::getInspectionItemId, inspectionItem.getId())
|
||||||
|
.list()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 生成版本号:查询该物料已发布的最大版本号,如果存在则加1,否则默认为1
|
// * 生成版本号:查询该物料已发布的最大版本号,如果存在则加1,否则默认为1
|
||||||
// * @param materialId 物料ID
|
// * @param materialId 物料ID
|
||||||
|
|
@ -395,12 +472,12 @@ public class QmsInspectionStandardControllerService {
|
||||||
// 1. 校验检验标准是否存在
|
// 1. 校验检验标准是否存在
|
||||||
QmsInspectionStandard standard = inspectionStandardService.getById(qo.getId());
|
QmsInspectionStandard standard = inspectionStandardService.getById(qo.getId());
|
||||||
if (standard == null) {
|
if (standard == null) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检验标准不存在");
|
throw new NflgException(STATE.BusinessError, "检验标准不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 已发布的标准不允许修改
|
// 2. 已发布的标准不允许修改
|
||||||
if (standard.getPublishStatus() != null && standard.getPublishStatus() == 1) {
|
if (standard.getPublishStatus() != null && standard.getPublishStatus() == 1) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "已发布的检验标准不允许修改");
|
throw new NflgException(STATE.BusinessError, "已发布的检验标准不允许修改");
|
||||||
}
|
}
|
||||||
VUtil.trueThrowBusinessError(
|
VUtil.trueThrowBusinessError(
|
||||||
inspectionStandardService.lambdaQuery()
|
inspectionStandardService.lambdaQuery()
|
||||||
|
|
@ -472,7 +549,7 @@ public class QmsInspectionStandardControllerService {
|
||||||
// 更新现有检测项
|
// 更新现有检测项
|
||||||
item = inspectionStandardItemService.getById(itemQO.getId());
|
item = inspectionStandardItemService.getById(itemQO.getId());
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检测项不存在:" + itemQO.getId());
|
throw new NflgException(STATE.BusinessError, "检测项不存在:" + itemQO.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新字段
|
// 更新字段
|
||||||
|
|
@ -517,7 +594,7 @@ public class QmsInspectionStandardControllerService {
|
||||||
// 1. 校验检验标准是否存在
|
// 1. 校验检验标准是否存在
|
||||||
QmsInspectionStandard standard = inspectionStandardService.getById(qo.getInspectionStandardId());
|
QmsInspectionStandard standard = inspectionStandardService.getById(qo.getInspectionStandardId());
|
||||||
if (standard == null) {
|
if (standard == null) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检验标准不存在");
|
throw new NflgException(STATE.BusinessError, "检验标准不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
Long userId = UserUtil.getUserId();
|
Long userId = UserUtil.getUserId();
|
||||||
|
|
@ -712,7 +789,7 @@ public class QmsInspectionStandardControllerService {
|
||||||
// 更新现有内容
|
// 更新现有内容
|
||||||
content = inspectionStandardItemContentService.getById(contentQO.getId());
|
content = inspectionStandardItemContentService.getById(contentQO.getId());
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检测项内容不存在:" + contentQO.getId());
|
throw new NflgException(STATE.BusinessError, "检测项内容不存在:" + contentQO.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateContentFields(content, contentQO, userId, userName, now);
|
updateContentFields(content, contentQO, userId, userName, now);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue