Commit 76f2e70b authored by tianbo's avatar tianbo

feat(validation): 优化气瓶充装数据校验逻辑并修复字段类型错误

- 添加充装前后数据一致性校验,确保三个数组长度相等 - 实现预校验方法preValidateData验证基础字段完整性 - 重构校验逻辑将原始字符串列表改为JSON对象列表返回详细错误信息 - 修复componentContents字段类型从Double改为String以支持多组分含量 - 修正枚举类中的字段名称映射错误 - 优化错误处理逻辑提供更精确的错误定位信息
parent be956de4
...@@ -45,7 +45,7 @@ public enum CylinderTypeFieldValidation { ...@@ -45,7 +45,7 @@ public enum CylinderTypeFieldValidation {
isNoBulgingOrLeakage2(CylinderType.LIQUEFIED_GAS_LPG, "isNoBulgingOrLeakage", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "瓶体未出现鼓包变形或泄漏等严重缺陷"), isNoBulgingOrLeakage2(CylinderType.LIQUEFIED_GAS_LPG, "isNoBulgingOrLeakage", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "瓶体未出现鼓包变形或泄漏等严重缺陷"),
isTemperatureNormal2(CylinderType.LIQUEFIED_GAS_LPG, "isTemperatureNormal", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "瓶体温度没有异常升高的迹象"), isTemperatureNormal2(CylinderType.LIQUEFIED_GAS_LPG, "isTemperatureNormal", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "瓶体温度没有异常升高的迹象"),
hasWarningAndFillingLabels(CylinderType.LIQUEFIED_GAS_LPG, "hasWarningAndFillingLabels", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "气瓶粘贴警示标签和充装标签)"), hasWarningAndFillingLabels(CylinderType.LIQUEFIED_GAS_LPG, "hasWarningAndFillingLabels", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "气瓶粘贴警示标签和充装标签)"),
reweighedWithinLimit(CylinderType.LIQUEFIED_GAS_LPG, "hasWarningAndFillingLabels", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "充装量复秤未超重"), reweighedWithinLimit(CylinderType.LIQUEFIED_GAS_LPG, "reweighedWithinLimit", true, false, new String[]{CylinderField.FillStage.AFTER.getCode()}, "充装量复秤未超重"),
// 压缩气体气瓶 COMPRESSED_GAS // 压缩气体气瓶 COMPRESSED_GAS
...@@ -106,7 +106,7 @@ public enum CylinderTypeFieldValidation { ...@@ -106,7 +106,7 @@ public enum CylinderTypeFieldValidation {
oxidizingGasCylinderFreeOfOil(CylinderType.MIXED_GAS, "oxidizingGasCylinderFreeOfOil", true, false, new String[]{CylinderField.FillStage.BEFORE.getCode()}, "氧化性混合气体的瓶体、瓶阀未沾染油脂"), oxidizingGasCylinderFreeOfOil(CylinderType.MIXED_GAS, "oxidizingGasCylinderFreeOfOil", true, false, new String[]{CylinderField.FillStage.BEFORE.getCode()}, "氧化性混合气体的瓶体、瓶阀未沾染油脂"),
preTreatedSuccessfully(CylinderType.MIXED_GAS, "preTreatedSuccessfully", true, false, new String[]{CylinderField.FillStage.BEFORE.getCode()}, "气瓶经预处理(抽真空、烘干、置换或组合)合格"), preTreatedSuccessfully(CylinderType.MIXED_GAS, "preTreatedSuccessfully", true, false, new String[]{CylinderField.FillStage.BEFORE.getCode()}, "气瓶经预处理(抽真空、烘干、置换或组合)合格"),
fillingPressure5(CylinderType.MIXED_GAS, "fillingPressureLessThan", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "充装压力"), fillingPressure5(CylinderType.MIXED_GAS, "fillingPressure", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "充装压力"),
fillingAmount5(CylinderType.MIXED_GAS, "fillingAmount", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "充装量"), fillingAmount5(CylinderType.MIXED_GAS, "fillingAmount", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "充装量"),
componentContents(CylinderType.MIXED_GAS, "componentContents", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "各组分含量"), componentContents(CylinderType.MIXED_GAS, "componentContents", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "各组分含量"),
abnormalConditions5(CylinderType.MIXED_GAS, "abnormalConditions", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "异常情况"), abnormalConditions5(CylinderType.MIXED_GAS, "abnormalConditions", true, false, new String[]{CylinderField.FillStage.FILLING.getCode()}, "异常情况"),
......
...@@ -58,7 +58,7 @@ public class TmCylinderFillingRecordModel extends CylinderAbstractBaseModel { ...@@ -58,7 +58,7 @@ public class TmCylinderFillingRecordModel extends CylinderAbstractBaseModel {
private Double acetyleneFillingAmount; private Double acetyleneFillingAmount;
@ApiModelProperty(value = "各组分含量") @ApiModelProperty(value = "各组分含量")
private Double componentContents; private String componentContents;
@ApiModelProperty(value = "标称皮重") @ApiModelProperty(value = "标称皮重")
private Double tareWeightNominal; private Double tareWeightNominal;
......
...@@ -64,7 +64,7 @@ public class TmCylinderFillingRecord extends CylinderAbstractBaseEntity { ...@@ -64,7 +64,7 @@ public class TmCylinderFillingRecord extends CylinderAbstractBaseEntity {
private Double acetyleneFillingAmount; private Double acetyleneFillingAmount;
@ApiModelProperty(value = "各组分含量") @ApiModelProperty(value = "各组分含量")
private Double componentContents; private String componentContents;
@ApiModelProperty(value = "标称皮重") @ApiModelProperty(value = "标称皮重")
private Double tareWeightNominal; private Double tareWeightNominal;
......
...@@ -3,7 +3,10 @@ package com.yeejoin.amos.api.openapi.face.service; ...@@ -3,7 +3,10 @@ package com.yeejoin.amos.api.openapi.face.service;
import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ConcurrentHashSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.yeejoin.amos.api.openapi.enums.*; import com.yeejoin.amos.api.openapi.enums.CylinderField;
import com.yeejoin.amos.api.openapi.enums.CylinderOffloadingFieldEnum;
import com.yeejoin.amos.api.openapi.enums.CylinderType;
import com.yeejoin.amos.api.openapi.enums.CylinderTypeFieldValidation;
import com.yeejoin.amos.api.openapi.face.model.*; import com.yeejoin.amos.api.openapi.face.model.*;
import com.yeejoin.amos.api.openapi.face.orm.dao.MidEquipRegistrationInfoMapper; import com.yeejoin.amos.api.openapi.face.orm.dao.MidEquipRegistrationInfoMapper;
import com.yeejoin.amos.boot.module.cylinder.api.dto.TzBaseEnterpriseInfoDto; import com.yeejoin.amos.boot.module.cylinder.api.dto.TzBaseEnterpriseInfoDto;
...@@ -14,6 +17,7 @@ import net.sf.json.JSONObject; ...@@ -14,6 +17,7 @@ import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.*; import java.util.*;
...@@ -194,6 +198,19 @@ public class CylinderFillingDataValidationService { ...@@ -194,6 +198,19 @@ public class CylinderFillingDataValidationService {
throw new BadRequest("充装后复查数据不能为空!!!"); throw new BadRequest("充装后复查数据不能为空!!!");
} }
JSONArray fillingBefore = jsonobject.getJSONArray("fillingBefore");
JSONArray filling = jsonobject.getJSONArray("filling");
JSONArray fillingAfter = jsonobject.getJSONArray("fillingAfter");
List<JSONObject> errorList = new ArrayList<>();
// 判断3个数组大小是否一致
if (fillingBefore.size() != filling.size() || filling.size() != fillingAfter.size()) {
JSONObject resultJson = new JSONObject();
resultJson.put("result", "充装前检查数据、充装记录数据、充装后复查数据长度不一致,请检查后重新上传数据!");
errorList.add(resultJson);
result.setBeforeErrorData(errorList.stream().map(JSONObject::toString).collect(Collectors.toList()));
return result;
}
Set<String> cylinderCodeSet = new ConcurrentHashSet<>(); Set<String> cylinderCodeSet = new ConcurrentHashSet<>();
Set<String> beforeErrorCylinderSet = new ConcurrentHashSet<>(); Set<String> beforeErrorCylinderSet = new ConcurrentHashSet<>();
Set<String> recordErrorCylinderSet = new ConcurrentHashSet<>(); Set<String> recordErrorCylinderSet = new ConcurrentHashSet<>();
...@@ -201,36 +218,24 @@ public class CylinderFillingDataValidationService { ...@@ -201,36 +218,24 @@ public class CylinderFillingDataValidationService {
CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> beforeFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验充装前数据 // 异步校验充装前数据
JSONArray fillingBefore = jsonobject.getJSONArray("fillingBefore"); List<JSONObject> innerErrorList = new ArrayList<>();
if (!ObjectUtils.isEmpty(fillingBefore)) { if (preValidateData(fillingBefore, innerErrorList, cylinderCodeSet))
for (int i = 0; i < fillingBefore.size(); i++) { return innerErrorList.stream().map(JSONObject::toString).collect(Collectors.toList());
JSONObject row = fillingBefore.getJSONObject(i);
cylinderCodeSet.add(row.getString("sequenceCode"));
}
}
return validateFillingBeforeData(fillingBefore, beforeErrorCylinderSet); return validateFillingBeforeData(fillingBefore, beforeErrorCylinderSet);
}); });
CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> recordFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验检充装时数据 // 异步校验检充装时数据
JSONArray filling = jsonobject.getJSONArray("filling"); List<JSONObject> innerErrorList = new ArrayList<>();
if (!ObjectUtils.isEmpty(filling)) { if (preValidateData(filling, innerErrorList, cylinderCodeSet))
for (int i = 0; i < filling.size(); i++) { return innerErrorList.stream().map(JSONObject::toString).collect(Collectors.toList());
JSONObject row = filling.getJSONObject(i);
cylinderCodeSet.add(row.getString("sequenceCode"));
}
}
return validateFillingRecordData(filling, recordErrorCylinderSet); return validateFillingRecordData(filling, recordErrorCylinderSet);
}); });
CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<String>> afterFuture = CompletableFuture.supplyAsync(() -> {
// 异步校验充装后数据 // 异步校验充装后数据
JSONArray fillingAfter = jsonobject.getJSONArray("fillingAfter"); List<JSONObject> innerErrorList = new ArrayList<>();
if (!ObjectUtils.isEmpty(fillingAfter)) { if (preValidateData(fillingAfter, innerErrorList, cylinderCodeSet))
for (int i = 0; i < fillingAfter.size(); i++) { return innerErrorList.stream().map(JSONObject::toString).collect(Collectors.toList());
JSONObject row = fillingAfter.getJSONObject(i);
cylinderCodeSet.add(row.getString("sequenceCode"));
}
}
return validateFillingAfterData(fillingAfter, afterErrorCylinderSet); return validateFillingAfterData(fillingAfter, afterErrorCylinderSet);
}); });
...@@ -258,6 +263,31 @@ public class CylinderFillingDataValidationService { ...@@ -258,6 +263,31 @@ public class CylinderFillingDataValidationService {
return result; return result;
} }
private boolean preValidateData(JSONArray fillingAfter, List<JSONObject> errorList, Set<String> cylinderCodeSet) {
if (!ObjectUtils.isEmpty(fillingAfter)) {
for (int i = 0; i < fillingAfter.size(); i++) {
JSONObject row = fillingAfter.getJSONObject(i);
if (!ValidationUtil.isEmpty(row)) {
if (!row.containsKey("sequenceCode") || !row.containsKey("cylinderType")) {
JSONObject error = new JSONObject();
error.put("result", "第" + (i + 1) + "个数据有误:sequenceCode或cylinderType为空。请检查后重新上传数据!");
error.put("errorData", row);
errorList.add(error);
return true;
} else {
cylinderCodeSet.add(row.getString("sequenceCode"));
}
} else {
JSONObject error = new JSONObject();
error.put("result", "第" + (i + 1) + "个数据为空,请检查后重新上传数据!");
errorList.add(error);
return true;
}
}
}
return false;
}
/** /**
* 验证检验前数据 * 验证检验前数据
...@@ -308,16 +338,24 @@ public class CylinderFillingDataValidationService { ...@@ -308,16 +338,24 @@ public class CylinderFillingDataValidationService {
* @return 校验结果 通过为 true,不通过为false * @return 校验结果 通过为 true,不通过为false
*/ */
public List<String> validateRequiredByStage(CylinderField.FillStage stage, JSONArray jsonArray, Set<String> errorCylinderSet) { public List<String> validateRequiredByStage(CylinderField.FillStage stage, JSONArray jsonArray, Set<String> errorCylinderSet) {
List<String> errorList = new ArrayList<>(); List<JSONObject> errorList = new ArrayList<>();
JSONObject error = new JSONObject();
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
JSONObject row = jsonArray.getJSONObject(i); JSONObject row = jsonArray.getJSONObject(i);
CylinderType type = CylinderType.getByCode(row.getString("cylinderType")); CylinderType type = CylinderType.getByCode(row.getString("cylinderType"));
List<String> keys = CylinderTypeFieldValidation.getRequiredFieldsForType(type, stage.getCode()); List<String> keys = CylinderTypeFieldValidation.getRequiredFieldsForType(type, stage.getCode());
List<String> missingKeys = Lists.newArrayList();
for (String key : keys) { for (String key : keys) {
if (!row.containsKey(key) || ObjectUtils.isEmpty(row.get(key)) || row.get(key).equals(JSONNull.getInstance())) { if (!row.containsKey(key) || ObjectUtils.isEmpty(row.get(key)) || row.get(key).equals(JSONNull.getInstance())) {
errorList.add(row.toString()); missingKeys.add(key);
} }
} }
if (!ObjectUtils.isEmpty(missingKeys)) {
error.put("missingKeys", missingKeys);
error.put("rawData", row);
error.put("sequenceCode", row.getString("sequenceCode"));
errorList.add(error);
}
} }
if (!ObjectUtils.isEmpty(errorList)) { if (!ObjectUtils.isEmpty(errorList)) {
...@@ -327,10 +365,10 @@ public class CylinderFillingDataValidationService { ...@@ -327,10 +365,10 @@ public class CylinderFillingDataValidationService {
}); });
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("result", "必填字段不能为空"); result.put("result", "必填字段不能为空");
return errorList.stream().map(e -> { result.put("errorData", e); return result.toString(); }).collect(Collectors.toList()); return errorList.stream().map(e -> { result.putAll(e); return result.toString(); }).collect(Collectors.toList());
} }
return errorList; return errorList.stream().map(JSONObject::toString).collect(Collectors.toList());
} }
/** /**
...@@ -342,7 +380,8 @@ public class CylinderFillingDataValidationService { ...@@ -342,7 +380,8 @@ public class CylinderFillingDataValidationService {
*/ */
public List<String> validateUniqueByStage(CylinderField.FillStage stage, JSONArray jsonArray, Set<String> errorCylinderSet) { public List<String> validateUniqueByStage(CylinderField.FillStage stage, JSONArray jsonArray, Set<String> errorCylinderSet) {
Map<String, Set<Object>> valuesMap = new HashMap<>(); Map<String, Set<Object>> valuesMap = new HashMap<>();
List<String> errorList = new ArrayList<>(); List<JSONObject> errorList = new ArrayList<>();
JSONObject error = new JSONObject();
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
JSONObject row = jsonArray.getJSONObject(i); JSONObject row = jsonArray.getJSONObject(i);
CylinderType type = CylinderType.getByCode(row.getString("cylinderType")); CylinderType type = CylinderType.getByCode(row.getString("cylinderType"));
...@@ -352,7 +391,10 @@ public class CylinderFillingDataValidationService { ...@@ -352,7 +391,10 @@ public class CylinderFillingDataValidationService {
valuesMap.put(key, new HashSet<>()); valuesMap.put(key, new HashSet<>());
} }
if (valuesMap.get(key).contains(row.get(key))) { if (valuesMap.get(key).contains(row.get(key))) {
errorList.add(row.toString()); error.put("duplicateKeys", key);
error.put("rawData", row);
error.put("sequenceCode", row.getString("sequenceCode"));
errorList.add(error);
} }
valuesMap.get(key).add(row.get(key)); valuesMap.get(key).add(row.get(key));
} }
...@@ -363,10 +405,12 @@ public class CylinderFillingDataValidationService { ...@@ -363,10 +405,12 @@ public class CylinderFillingDataValidationService {
String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode"); String sequenceCode = JSONObject.fromObject(json).getString("sequenceCode");
errorCylinderSet.add(sequenceCode); errorCylinderSet.add(sequenceCode);
}); });
return errorList.stream().map(e -> "上传数据重复:" + e).collect(Collectors.toList()); JSONObject result = new JSONObject();
result.put("result", "上传数据重复");
return errorList.stream().map(e -> { result.putAll(e); return result.toString(); }).collect(Collectors.toList());
} }
return errorList; return errorList.stream().map(JSONObject::toString).collect(Collectors.toList());
} }
/** /**
......
...@@ -206,8 +206,9 @@ public class CylinderService { ...@@ -206,8 +206,9 @@ public class CylinderService {
cylinderFillingMessageEntity.setCylinderNumber(validateResult.getCylinderNumber()); cylinderFillingMessageEntity.setCylinderNumber(validateResult.getCylinderNumber());
List<String> logMessage = new ArrayList<>(); List<String> logMessage = new ArrayList<>();
int errorNumber = 0; int errorNumber = 0;
JSONObject error = new JSONObject();
if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getBeforeErrorData())) {
JSONObject error = new JSONObject();
errorNumber += validateResult.getBeforeErrorData().size(); errorNumber += validateResult.getBeforeErrorData().size();
error.put("充装前检查错误数据:", validateResult.getBeforeErrorData()); error.put("充装前检查错误数据:", validateResult.getBeforeErrorData());
errorData.add(error); errorData.add(error);
...@@ -216,6 +217,7 @@ public class CylinderService { ...@@ -216,6 +217,7 @@ public class CylinderService {
} }
if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getRecordErrorData())) {
JSONObject error = new JSONObject();
errorNumber += validateResult.getRecordErrorData().size(); errorNumber += validateResult.getRecordErrorData().size();
error.put("充装记录错误数据:", validateResult.getRecordErrorData()); error.put("充装记录错误数据:", validateResult.getRecordErrorData());
errorData.add(error); errorData.add(error);
...@@ -224,6 +226,7 @@ public class CylinderService { ...@@ -224,6 +226,7 @@ public class CylinderService {
} }
if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getAfterErrorData())) {
JSONObject error = new JSONObject();
errorNumber += validateResult.getAfterErrorData().size(); errorNumber += validateResult.getAfterErrorData().size();
error.put("充装后复查错误数据:", validateResult.getAfterErrorData()); error.put("充装后复查错误数据:", validateResult.getAfterErrorData());
errorData.add(error); errorData.add(error);
...@@ -232,6 +235,7 @@ public class CylinderService { ...@@ -232,6 +235,7 @@ public class CylinderService {
} }
if (!ObjectUtils.isEmpty(validateResult.getSeqCodeErrorData())) { if (!ObjectUtils.isEmpty(validateResult.getSeqCodeErrorData())) {
JSONObject error = new JSONObject();
errorNumber += validateResult.getSeqCodeErrorData().size(); errorNumber += validateResult.getSeqCodeErrorData().size();
error.put("气瓶信息不存在:", validateResult.getSeqCodeErrorData()); error.put("气瓶信息不存在:", validateResult.getSeqCodeErrorData());
errorData.add(error); errorData.add(error);
......
...@@ -210,7 +210,7 @@ public class ESCylinderFillingInfoDto { ...@@ -210,7 +210,7 @@ public class ESCylinderFillingInfoDto {
@Field(type = FieldType.Keyword) @Field(type = FieldType.Keyword)
@ApiModelProperty(value = "各组分含量") @ApiModelProperty(value = "各组分含量")
private Double componentContents; private String componentContents;
@Field(type = FieldType.Double) @Field(type = FieldType.Double)
@ApiModelProperty(value = "标称皮重") @ApiModelProperty(value = "标称皮重")
......
...@@ -70,7 +70,7 @@ public class CylinderFillingRecord extends CylinderFillingBaseEntity { ...@@ -70,7 +70,7 @@ public class CylinderFillingRecord extends CylinderFillingBaseEntity {
private Double acetyleneFillingAmount; private Double acetyleneFillingAmount;
@ApiModelProperty(value = "各组分含量") @ApiModelProperty(value = "各组分含量")
private Double componentContents; private String componentContents;
@ApiModelProperty(value = "标称皮重") @ApiModelProperty(value = "标称皮重")
private Double tareWeightNominal; private Double tareWeightNominal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment