【优化】暂存检验标准添加非空校验
This commit is contained in:
parent
50853294f0
commit
44576d5b2b
|
|
@ -1,7 +1,9 @@
|
|||
package com.nflg.qms.admin.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nflg.wms.common.constant.Constant;
|
||||
import com.nflg.wms.common.exception.NflgException;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.QmsInspectionStandardAddQO;
|
||||
|
|
@ -14,15 +16,9 @@ import com.nflg.wms.common.pojo.vo.QmsInspectionStandardItemVO;
|
|||
import com.nflg.wms.common.pojo.vo.QmsInspectionStandardVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.QmsInspectionStandard;
|
||||
import com.nflg.wms.repository.entity.QmsInspectionStandardItem;
|
||||
import com.nflg.wms.repository.entity.QmsInspectionStandardItemContent;
|
||||
import com.nflg.wms.repository.entity.QmsQcMaterial;
|
||||
import com.nflg.wms.repository.entity.*;
|
||||
import com.nflg.wms.repository.mapper.QmsInspectionStandardMapper;
|
||||
import com.nflg.wms.repository.service.IQmsInspectionStandardItemContentService;
|
||||
import com.nflg.wms.repository.service.IQmsInspectionStandardItemService;
|
||||
import com.nflg.wms.repository.service.IQmsInspectionStandardService;
|
||||
import com.nflg.wms.repository.service.IQmsQcMaterialService;
|
||||
import com.nflg.wms.repository.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -31,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -55,6 +52,9 @@ public class QmsInspectionStandardControllerService {
|
|||
@Resource
|
||||
private IQmsQcMaterialService qmsQcMaterialService;
|
||||
|
||||
@Resource
|
||||
private IDictionaryItemService dictionaryItemService;
|
||||
|
||||
/**
|
||||
* 分页查询检验标准
|
||||
*/
|
||||
|
|
@ -80,7 +80,7 @@ public class QmsInspectionStandardControllerService {
|
|||
|
||||
/**
|
||||
* 启用/禁用检验标准(单条)
|
||||
* @param id 检验标准ID
|
||||
* @param id 检验标准ID
|
||||
* @param enable 是否启用
|
||||
*/
|
||||
public void enable(Long id, Boolean enable) {
|
||||
|
|
@ -106,8 +106,8 @@ public class QmsInspectionStandardControllerService {
|
|||
|
||||
// 2. 已发布的标准不允许删除
|
||||
if (standard.getPublishStatus() != null && standard.getPublishStatus() == 1) {
|
||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError,
|
||||
"已发布的检验标准不允许删除,ID: " + id);
|
||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError,
|
||||
"已发布的检验标准不允许删除,ID: " + id);
|
||||
}
|
||||
|
||||
// 3. 查询该检验标准下所有检测项
|
||||
|
|
@ -153,7 +153,7 @@ public class QmsInspectionStandardControllerService {
|
|||
if (detail == null) {
|
||||
detail = new QmsInspectionStandardDetailVO();
|
||||
}
|
||||
|
||||
|
||||
// 填充基础字段
|
||||
detail.setId(standard.getId());
|
||||
detail.setMaterialId(standard.getMaterialId());
|
||||
|
|
@ -183,21 +183,21 @@ public class QmsInspectionStandardControllerService {
|
|||
List<QmsInspectionStandardItemVO> itemVOs = new ArrayList<>();
|
||||
for (QmsInspectionStandardItem item : items) {
|
||||
QmsInspectionStandardItemVO itemVO = convertToItemVO(item);
|
||||
|
||||
|
||||
// 查询检测项内容列表
|
||||
List<QmsInspectionStandardItemContent> contents = inspectionStandardItemContentService.lambdaQuery()
|
||||
.eq(QmsInspectionStandardItemContent::getInspectionStandardItemId, item.getId())
|
||||
.orderByAsc(QmsInspectionStandardItemContent::getSortNo)
|
||||
.list();
|
||||
|
||||
|
||||
List<QmsInspectionStandardItemContentVO> contentVOs = contents.stream()
|
||||
.map(this::convertToContentVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
itemVO.setContents(contentVOs);
|
||||
itemVOs.add(itemVO);
|
||||
}
|
||||
|
||||
|
||||
detail.setItems(itemVOs);
|
||||
return detail;
|
||||
}
|
||||
|
|
@ -361,18 +361,19 @@ public class QmsInspectionStandardControllerService {
|
|||
/**
|
||||
* 处理检测项列表(新增、更新、删除)
|
||||
* @param inspectionStandardId 检验标准ID
|
||||
* @param items 检测项列表
|
||||
* @param userId 用户ID
|
||||
* @param userName 用户名
|
||||
* @param now 当前时间
|
||||
* @param items 检测项列表
|
||||
* @param userId 用户ID
|
||||
* @param userName 用户名
|
||||
* @param now 当前时间
|
||||
*/
|
||||
private void processItems(Long inspectionStandardId,
|
||||
private void processItems(List<DictionaryItem> dictionaryItems,
|
||||
Long inspectionStandardId,
|
||||
List<QmsInspectionStandardSaveQO.InspectionStandardItemQO> items,
|
||||
Long userId, String userName, LocalDateTime now) {
|
||||
if (items == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 获取该检验标准下所有现有的检测项ID
|
||||
List<Long> existingItemIds = inspectionStandardItemService.lambdaQuery()
|
||||
.eq(QmsInspectionStandardItem::getInspectionStandardId, inspectionStandardId)
|
||||
|
|
@ -384,15 +385,30 @@ public class QmsInspectionStandardControllerService {
|
|||
// 处理传入的检测项
|
||||
List<Long> newItemIds = new ArrayList<>();
|
||||
for (QmsInspectionStandardSaveQO.InspectionStandardItemQO itemQO : items) {
|
||||
DictionaryItem dictionaryItem = dictionaryItems.stream()
|
||||
.filter(item -> item.getId().equals(itemQO.getSamplingMethodDictItemId()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(dictionaryItem)).throwMessage("检测项【" + itemQO.getName() + "】设置的抽样方式不存在");
|
||||
if (StrUtil.equals(dictionaryItem.getCode(), "抽样")) {
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(itemQO.getSamplingPlanId()))
|
||||
.throwMessage("检测项【" + itemQO.getName() + "】设置的抽样方式为【抽样】时,抽样方案不能为空");
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(itemQO.getInspectionLevelDictItemId()))
|
||||
.throwMessage("检测项【" + itemQO.getName() + "】设置的抽样方式为【抽样】时,检验水平不能为空");
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(itemQO.getAqlPriorityValueId()))
|
||||
.throwMessage("检测项【" + itemQO.getName() + "】设置的抽样方式为【抽样】时,AQL值不能为空");
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(itemQO.getAqlTypeDictItemId()))
|
||||
.throwMessage("检测项【" + itemQO.getName() + "】设置的抽样方式为【抽样】时,AQL类型不能为空");
|
||||
}
|
||||
QmsInspectionStandardItem item;
|
||||
|
||||
|
||||
if (itemQO.getId() != null) {
|
||||
// 更新现有检测项
|
||||
item = inspectionStandardItemService.getById(itemQO.getId());
|
||||
if (item == null) {
|
||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检测项不存在:" + itemQO.getId());
|
||||
}
|
||||
|
||||
|
||||
// 更新字段
|
||||
updateItemFields(item, itemQO, userId, userName, now);
|
||||
inspectionStandardItemService.updateById(item);
|
||||
|
|
@ -403,7 +419,7 @@ public class QmsInspectionStandardControllerService {
|
|||
updateItemFields(item, itemQO, userId, userName, now);
|
||||
inspectionStandardItemService.save(item);
|
||||
}
|
||||
|
||||
|
||||
newItemIds.add(item.getId());
|
||||
|
||||
// 处理检测项内容
|
||||
|
|
@ -414,13 +430,13 @@ public class QmsInspectionStandardControllerService {
|
|||
List<Long> itemsToDelete = existingItemIds.stream()
|
||||
.filter(id -> !newItemIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
if (!itemsToDelete.isEmpty()) {
|
||||
// 先删除检测项内容
|
||||
inspectionStandardItemContentService.lambdaUpdate()
|
||||
.in(QmsInspectionStandardItemContent::getInspectionStandardItemId, itemsToDelete)
|
||||
.remove();
|
||||
|
||||
|
||||
// 再删除检测项
|
||||
inspectionStandardItemService.removeByIds(itemsToDelete);
|
||||
}
|
||||
|
|
@ -448,13 +464,14 @@ public class QmsInspectionStandardControllerService {
|
|||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 2. 处理检测项列表
|
||||
processItems(qo.getInspectionStandardId(), qo.getItems(), userId, userName, now);
|
||||
processItems(dictionaryItemService.getListByDictionaryCode(Constant.DICTIONARY_INSPECTION_STANDARD_SAMPLING_METHOD),
|
||||
qo.getInspectionStandardId(), qo.getItems(), userId, userName, now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新检测项字段
|
||||
*/
|
||||
private void updateItemFields(QmsInspectionStandardItem item,
|
||||
private void updateItemFields(QmsInspectionStandardItem item,
|
||||
QmsInspectionStandardSaveQO.InspectionStandardItemQO qo,
|
||||
Long userId, String userName, LocalDateTime now) {
|
||||
if (qo.getName() != null) {
|
||||
|
|
@ -487,11 +504,11 @@ public class QmsInspectionStandardControllerService {
|
|||
if (qo.getPdfDrawing() != null) {
|
||||
item.setPdfDrawing(qo.getPdfDrawing());
|
||||
}
|
||||
|
||||
|
||||
item.setUpdateUserId(userId);
|
||||
item.setUpdateUserName(userName);
|
||||
item.setUpdateTime(now);
|
||||
|
||||
|
||||
// 新增时设置创建信息
|
||||
if (item.getCreateUserId() == null) {
|
||||
item.setCreateUserId(userId);
|
||||
|
|
@ -503,7 +520,7 @@ public class QmsInspectionStandardControllerService {
|
|||
/**
|
||||
* 处理检测项内容(新增、更新、删除)
|
||||
*/
|
||||
private void processItemContents(Long itemId,
|
||||
private void processItemContents(Long itemId,
|
||||
List<QmsInspectionStandardSaveQO.InspectionStandardItemContentQO> contents,
|
||||
Long userId, String userName, LocalDateTime now) {
|
||||
// 获取现有的内容ID列表
|
||||
|
|
@ -515,18 +532,18 @@ public class QmsInspectionStandardControllerService {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
List<Long> newContentIds = new ArrayList<>();
|
||||
|
||||
|
||||
if (contents != null && !contents.isEmpty()) {
|
||||
for (QmsInspectionStandardSaveQO.InspectionStandardItemContentQO contentQO : contents) {
|
||||
QmsInspectionStandardItemContent content;
|
||||
|
||||
|
||||
if (contentQO.getId() != null) {
|
||||
// 更新现有内容
|
||||
content = inspectionStandardItemContentService.getById(contentQO.getId());
|
||||
if (content == null) {
|
||||
throw new NflgException(com.nflg.wms.common.constant.STATE.BusinessError, "检测项内容不存在:" + contentQO.getId());
|
||||
}
|
||||
|
||||
|
||||
updateContentFields(content, contentQO, userId, userName, now);
|
||||
inspectionStandardItemContentService.updateById(content);
|
||||
} else {
|
||||
|
|
@ -536,7 +553,7 @@ public class QmsInspectionStandardControllerService {
|
|||
updateContentFields(content, contentQO, userId, userName, now);
|
||||
inspectionStandardItemContentService.save(content);
|
||||
}
|
||||
|
||||
|
||||
newContentIds.add(content.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -545,7 +562,7 @@ public class QmsInspectionStandardControllerService {
|
|||
List<Long> contentsToDelete = existingContentIds.stream()
|
||||
.filter(id -> !newContentIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
if (!contentsToDelete.isEmpty()) {
|
||||
inspectionStandardItemContentService.removeByIds(contentsToDelete);
|
||||
}
|
||||
|
|
@ -575,11 +592,11 @@ public class QmsInspectionStandardControllerService {
|
|||
if (qo.getJudgmentTypeDictItemId() != null) {
|
||||
content.setJudgmentTypeDictItemId(qo.getJudgmentTypeDictItemId());
|
||||
}
|
||||
|
||||
|
||||
content.setUpdateUserId(userId);
|
||||
content.setUpdateUserName(userName);
|
||||
content.setUpdateTime(now);
|
||||
|
||||
|
||||
// 新增时设置创建信息
|
||||
if (content.getCreateUserId() == null) {
|
||||
content.setCreateUserId(userId);
|
||||
|
|
|
|||
|
|
@ -39,4 +39,6 @@ public class Constant {
|
|||
public static final String DICTIONARY_AD_TYPE ="AdvertisementType";
|
||||
|
||||
public static final String DICTIONARY_AD_POSITION ="AdvertisementPosition";
|
||||
|
||||
public static final String DICTIONARY_INSPECTION_STANDARD_SAMPLING_METHOD ="InspectionStandardSamplingMethod";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -38,21 +39,24 @@ public class QmsInspectionStandardSaveQO {
|
|||
/**
|
||||
* 检测项名称
|
||||
*/
|
||||
@NotBlank(message = "检测项名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortNo;
|
||||
private Integer sortNo = 0;
|
||||
|
||||
/**
|
||||
* 检测方式,关联字典项id
|
||||
*/
|
||||
@NotNull(message = "检测方式不能为空")
|
||||
private Long testingMethodDictItemId;
|
||||
|
||||
/**
|
||||
* 抽样方式,关联字典项id
|
||||
*/
|
||||
@NotNull(message = "抽样方式不能为空")
|
||||
private Long samplingMethodDictItemId;
|
||||
|
||||
/**
|
||||
|
|
@ -78,6 +82,7 @@ public class QmsInspectionStandardSaveQO {
|
|||
/**
|
||||
* 检验标准项类型:0-标准检测项,1-尺寸检测项
|
||||
*/
|
||||
@NotNull(message = "检验标准项类型不能为空")
|
||||
private Short itemType;
|
||||
|
||||
/**
|
||||
|
|
@ -106,16 +111,18 @@ public class QmsInspectionStandardSaveQO {
|
|||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortNo;
|
||||
private Integer sortNo=0;
|
||||
|
||||
/**
|
||||
* 检测项名称
|
||||
*/
|
||||
@NotBlank(message = "检测项内容不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 检测标准
|
||||
*/
|
||||
@NotBlank(message = "检测标准不能为空")
|
||||
private String testStandard;
|
||||
|
||||
/**
|
||||
|
|
@ -131,6 +138,7 @@ public class QmsInspectionStandardSaveQO {
|
|||
/**
|
||||
* 判定类型,关联字典项id
|
||||
*/
|
||||
@NotNull(message = "判定类型不能为空")
|
||||
private Long judgmentTypeDictItemId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue