refactor(qmsamplingplan): 优化字码和AQL优先值处理逻辑
- 修改QmsSamplingPlanAddQO,字码和AQL优先值从ID改为内容字段 - 在新增和更新流程中,保存字码和AQL优先值后建立内容到ID的映射 - 使用映射将字码内容和AQL优先值转换为对应ID,保证数据一致性 - 在字码矩阵维护和抽样方案检验中校验字码和优先值是否存在,抛出业务异常 - 添加QmsSamplingPlanApiTest接口测试,覆盖新增抽样方案各类参数校验和正常流程 - 测试用例包含空字段校验、完整参数场景及备注字段验证
This commit is contained in:
parent
2983281b94
commit
72aef97677
|
|
@ -82,7 +82,8 @@ public class QmsSamplingPlanControllerService {
|
|||
samplingPlanService.save(plan);
|
||||
Long planId = plan.getId();
|
||||
|
||||
// 2. 保存AQL优先值预定义
|
||||
// 2. 保存AQL优先值预定义,并建立优先值到ID的映射
|
||||
Map<java.math.BigDecimal, Long> aqlPriorityValueIdMap = new java.util.HashMap<>();
|
||||
if (CollectionUtil.isNotEmpty(request.getAqlPriorityValues())) {
|
||||
List<QmsAqlPriorityValue> aqlPriorityValues = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.AqlPriorityValueQO qo : request.getAqlPriorityValues()) {
|
||||
|
|
@ -92,6 +93,10 @@ public class QmsSamplingPlanControllerService {
|
|||
aqlPriorityValues.add(entity);
|
||||
}
|
||||
aqlPriorityValueService.saveBatch(aqlPriorityValues);
|
||||
// MyBatis-Plus的saveBatch会回填ID,建立映射关系
|
||||
for (QmsAqlPriorityValue entity : aqlPriorityValues) {
|
||||
aqlPriorityValueIdMap.put(entity.getPriorityValue(), entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 保存抽样严格性转移规则
|
||||
|
|
@ -109,7 +114,8 @@ public class QmsSamplingPlanControllerService {
|
|||
strictnessTransferRuleService.saveBatch(rules);
|
||||
}
|
||||
|
||||
// 4. 保存字码
|
||||
// 4. 保存字码,并建立字码到ID的映射
|
||||
Map<String, Long> codeLetterIdMap = new java.util.HashMap<>();
|
||||
if (CollectionUtil.isNotEmpty(request.getCodeLetters())) {
|
||||
List<QmsCodeLetter> codeLetters = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.CodeLetterQO qo : request.getCodeLetters()) {
|
||||
|
|
@ -119,17 +125,28 @@ public class QmsSamplingPlanControllerService {
|
|||
codeLetters.add(entity);
|
||||
}
|
||||
codeLetterService.saveBatch(codeLetters);
|
||||
// MyBatis-Plus的saveBatch会回填ID,建立映射关系
|
||||
for (QmsCodeLetter entity : codeLetters) {
|
||||
codeLetterIdMap.put(entity.getCodeLetter(), entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 保存字码矩阵维护
|
||||
if (CollectionUtil.isNotEmpty(request.getCodeLetterMatrices())) {
|
||||
List<QmsCodeLetterMatrix> matrices = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.CodeLetterMatrixQO qo : request.getCodeLetterMatrices()) {
|
||||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("字码矩阵维护中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
// 通过AQL优先值获取AQL优先值ID
|
||||
Long aqlPriorityValueId = aqlPriorityValueIdMap.get(qo.getAqlPriorityValue());
|
||||
VUtil.trueThrowBusinessError(aqlPriorityValueId == null).throwMessage("字码矩阵维护中的AQL优先值[" + qo.getAqlPriorityValue() + "]在AQL优先值列表中不存在");
|
||||
|
||||
QmsCodeLetterMatrix entity = new QmsCodeLetterMatrix()
|
||||
.setSamplingPlanId(planId)
|
||||
.setInspectionType(qo.getInspectionType())
|
||||
.setCodeLetterId(qo.getCodeLetterId())
|
||||
.setAqlPriorityValueId(qo.getAqlPriorityValueId())
|
||||
.setCodeLetterId(codeLetterId)
|
||||
.setAqlPriorityValueId(aqlPriorityValueId)
|
||||
.setSampleSize(qo.getSampleSize())
|
||||
.setReValue(qo.getReValue())
|
||||
.setAcValue(qo.getAcValue());
|
||||
|
|
@ -142,12 +159,16 @@ public class QmsSamplingPlanControllerService {
|
|||
if (CollectionUtil.isNotEmpty(request.getSamplingPlanInspections())) {
|
||||
List<QmsSamplingPlanInspection> inspections = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.SamplingPlanInspectionQO qo : request.getSamplingPlanInspections()) {
|
||||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("抽样方案检验中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
|
||||
QmsSamplingPlanInspection entity = new QmsSamplingPlanInspection()
|
||||
.setSamplingPlanId(planId)
|
||||
.setRangeStart(qo.getRangeStart())
|
||||
.setRangeEnd(qo.getRangeEnd())
|
||||
.setInspectionDictionaryItemId(qo.getInspectionDictionaryItemId())
|
||||
.setCodeLetterId(qo.getCodeLetterId());
|
||||
.setCodeLetterId(codeLetterId);
|
||||
inspections.add(entity);
|
||||
}
|
||||
samplingPlanInspectionService.saveBatch(inspections);
|
||||
|
|
@ -181,7 +202,8 @@ public class QmsSamplingPlanControllerService {
|
|||
.set(QmsSamplingPlan::getUpdateTime, now)
|
||||
.update();
|
||||
|
||||
// 2. 删除并重新保存AQL优先值预定义
|
||||
// 2. 删除并重新保存AQL优先值预定义,并建立优先值到ID的映射
|
||||
Map<java.math.BigDecimal, Long> aqlPriorityValueIdMap = new java.util.HashMap<>();
|
||||
aqlPriorityValueService.lambdaUpdate()
|
||||
.eq(QmsAqlPriorityValue::getSamplingPlanId, planId)
|
||||
.remove();
|
||||
|
|
@ -194,6 +216,10 @@ public class QmsSamplingPlanControllerService {
|
|||
aqlPriorityValues.add(entity);
|
||||
}
|
||||
aqlPriorityValueService.saveBatch(aqlPriorityValues);
|
||||
// MyBatis-Plus的saveBatch会回填ID,建立映射关系
|
||||
for (QmsAqlPriorityValue entity : aqlPriorityValues) {
|
||||
aqlPriorityValueIdMap.put(entity.getPriorityValue(), entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 删除并重新保存抽样严格性转移规则
|
||||
|
|
@ -214,7 +240,8 @@ public class QmsSamplingPlanControllerService {
|
|||
strictnessTransferRuleService.saveBatch(rules);
|
||||
}
|
||||
|
||||
// 4. 删除并重新保存字码
|
||||
// 4. 删除并重新保存字码,并建立字码到ID的映射
|
||||
Map<String, Long> codeLetterIdMap = new java.util.HashMap<>();
|
||||
codeLetterService.lambdaUpdate()
|
||||
.eq(QmsCodeLetter::getSamplingPlanId, planId)
|
||||
.remove();
|
||||
|
|
@ -227,6 +254,10 @@ public class QmsSamplingPlanControllerService {
|
|||
codeLetters.add(entity);
|
||||
}
|
||||
codeLetterService.saveBatch(codeLetters);
|
||||
// MyBatis-Plus的saveBatch会回填ID,建立映射关系
|
||||
for (QmsCodeLetter entity : codeLetters) {
|
||||
codeLetterIdMap.put(entity.getCodeLetter(), entity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 删除并重新保存字码矩阵维护
|
||||
|
|
@ -236,11 +267,18 @@ public class QmsSamplingPlanControllerService {
|
|||
if (CollectionUtil.isNotEmpty(request.getCodeLetterMatrices())) {
|
||||
List<QmsCodeLetterMatrix> matrices = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.CodeLetterMatrixQO qo : request.getCodeLetterMatrices()) {
|
||||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("字码矩阵维护中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
// 通过AQL优先值获取AQL优先值ID
|
||||
Long aqlPriorityValueId = aqlPriorityValueIdMap.get(qo.getAqlPriorityValue());
|
||||
VUtil.trueThrowBusinessError(aqlPriorityValueId == null).throwMessage("字码矩阵维护中的AQL优先值[" + qo.getAqlPriorityValue() + "]在AQL优先值列表中不存在");
|
||||
|
||||
QmsCodeLetterMatrix entity = new QmsCodeLetterMatrix()
|
||||
.setSamplingPlanId(planId)
|
||||
.setInspectionType(qo.getInspectionType())
|
||||
.setCodeLetterId(qo.getCodeLetterId())
|
||||
.setAqlPriorityValueId(qo.getAqlPriorityValueId())
|
||||
.setCodeLetterId(codeLetterId)
|
||||
.setAqlPriorityValueId(aqlPriorityValueId)
|
||||
.setSampleSize(qo.getSampleSize())
|
||||
.setReValue(qo.getReValue())
|
||||
.setAcValue(qo.getAcValue());
|
||||
|
|
@ -256,12 +294,16 @@ public class QmsSamplingPlanControllerService {
|
|||
if (CollectionUtil.isNotEmpty(request.getSamplingPlanInspections())) {
|
||||
List<QmsSamplingPlanInspection> inspections = new ArrayList<>();
|
||||
for (QmsSamplingPlanAddQO.SamplingPlanInspectionQO qo : request.getSamplingPlanInspections()) {
|
||||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("抽样方案检验中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
|
||||
QmsSamplingPlanInspection entity = new QmsSamplingPlanInspection()
|
||||
.setSamplingPlanId(planId)
|
||||
.setRangeStart(qo.getRangeStart())
|
||||
.setRangeEnd(qo.getRangeEnd())
|
||||
.setInspectionDictionaryItemId(qo.getInspectionDictionaryItemId())
|
||||
.setCodeLetterId(qo.getCodeLetterId());
|
||||
.setCodeLetterId(codeLetterId);
|
||||
inspections.add(entity);
|
||||
}
|
||||
samplingPlanInspectionService.saveBatch(inspections);
|
||||
|
|
|
|||
|
|
@ -236,13 +236,13 @@ public class QmsSamplingPlanApiTest {
|
|||
request.setCodeLetters(codeLetters);
|
||||
|
||||
// 构建字码矩阵维护列表
|
||||
// 注意:codeLetterId 和 aqlPriorityValueId 应该是数据库中已存在的ID
|
||||
// 这里使用占位符ID,测试时需要根据实际数据调整
|
||||
// 使用字码内容和AQL优先值来关联,而不是ID
|
||||
// 字码内容需要在codeLetters列表中存在,AQL优先值需要在aqlPriorityValues列表中存在
|
||||
List<QmsSamplingPlanAddQO.CodeLetterMatrixQO> matrices = new ArrayList<>();
|
||||
QmsSamplingPlanAddQO.CodeLetterMatrixQO matrix = new QmsSamplingPlanAddQO.CodeLetterMatrixQO();
|
||||
matrix.setInspectionType((short) 0); // 正常检查
|
||||
matrix.setCodeLetterId(1L);
|
||||
matrix.setAqlPriorityValueId(1L);
|
||||
matrix.setCodeLetter("A"); // 关联字码列表中的"A"
|
||||
matrix.setAqlPriorityValue(new BigDecimal("0.010")); // 关联AQL优先值列表中的0.010
|
||||
matrix.setSampleSize(125);
|
||||
matrix.setReValue(3);
|
||||
matrix.setAcValue(3);
|
||||
|
|
@ -255,7 +255,7 @@ public class QmsSamplingPlanApiTest {
|
|||
inspection.setRangeStart(1201);
|
||||
inspection.setRangeEnd(3200);
|
||||
inspection.setInspectionDictionaryItemId(1L);
|
||||
inspection.setCodeLetterId(1L);
|
||||
inspection.setCodeLetter("A"); // 关联字码列表中的"A"
|
||||
inspections.add(inspection);
|
||||
request.setSamplingPlanInspections(inspections);
|
||||
|
||||
|
|
|
|||
|
|
@ -126,16 +126,16 @@ public class QmsSamplingPlanAddQO {
|
|||
private Short inspectionType;
|
||||
|
||||
/**
|
||||
* 字码ID
|
||||
* 字码(关联codeLetters中的字码)
|
||||
*/
|
||||
@NotNull(message = "字码ID不能为空")
|
||||
private Long codeLetterId;
|
||||
@NotBlank(message = "字码不能为空")
|
||||
private String codeLetter;
|
||||
|
||||
/**
|
||||
* AQL优先值ID
|
||||
* AQL优先值(关联aqlPriorityValues中的优先值)
|
||||
*/
|
||||
@NotNull(message = "AQL优先值ID不能为空")
|
||||
private Long aqlPriorityValueId;
|
||||
@NotNull(message = "AQL优先值不能为空")
|
||||
private BigDecimal aqlPriorityValue;
|
||||
|
||||
/**
|
||||
* 样本量
|
||||
|
|
@ -180,9 +180,9 @@ public class QmsSamplingPlanAddQO {
|
|||
private Long inspectionDictionaryItemId;
|
||||
|
||||
/**
|
||||
* 字码ID
|
||||
* 字码(关联codeLetters中的字码)
|
||||
*/
|
||||
@NotNull(message = "字码ID不能为空")
|
||||
private Long codeLetterId;
|
||||
@NotBlank(message = "字码不能为空")
|
||||
private String codeLetter;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue