feat(mms-mapping): 添加ICD一致性校验功能并重构设备类型管理
- 在MappingController中新增ICD一致性校验接口checkIcdJsonConsistency - 添加IcdConsistencyCheckService服务实现ICD映射JSON一致性校验逻辑 - 添加IcdConsistencyCheckRequest和IcdConsistencyCheckResponse相关数据传输对象 - 在CsIcdPathPO中新增icdContent字段存储ICD内容字节数组 - 在CsIcdPathMapper中新增selectIcdPathList方法支持关键词搜索 - 移除设备类型相关的控制器、服务接口及实现类(MmsDeviceTypeController等) - 更新.gitignore文件排除特定jar包路径 - 在pom.xml中添加device-types模块依赖和JNA库依赖 - 更新README.md文档添加device-types模块说明 - 重命名steady-DataView为steady-dataView模块名统一格式
This commit is contained in:
@@ -0,0 +1,546 @@
|
||||
package com.njcn.gather.icd.mapping.component;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.DataSetGroupItem;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.DoiItem;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.InstItem;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.MappingDocument;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.ReportMapItem;
|
||||
import com.njcn.gather.icd.mapping.pojo.bo.mapping.SdiItem;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdConsistencyCheckRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IcdConsistencyCheckResponse;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IcdConsistencyIssue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* ICD 映射 JSON 一致性校验服务。
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class IcdConsistencyCheckService {
|
||||
|
||||
private static final String PASS_MESSAGE = "符合";
|
||||
private static final String NOT_PASS_MESSAGE = "不符合";
|
||||
private static final String ISSUE_FILE_NAME = "icd-consistency-issues.json";
|
||||
private static final List<String> REQUIRED_REPORT_DESCS = Arrays.asList("统计数据", "波动闪变", "实时数据", "暂态事件");
|
||||
private static final List<String> REQUIRED_LN_CLASSES = Arrays.asList("MMXU", "MSQI", "MHAI", "MFLK");
|
||||
|
||||
private final FileStorageService fileStorageService;
|
||||
private final ObjectMapper objectMapper = buildMapper();
|
||||
|
||||
public IcdConsistencyCheckResponse check(IcdConsistencyCheckRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("ICD 一致性校验请求不能为空");
|
||||
}
|
||||
MappingDocument checked = parseMapping(request.getCheckedJson(), "待校验 JSON");
|
||||
MappingDocument standard = parseMapping(request.getStandardJson(), "标准 JSON");
|
||||
|
||||
List<IcdConsistencyIssue> issues = new ArrayList<IcdConsistencyIssue>();
|
||||
validateSelfFormat(checked, "待校验映射", issues);
|
||||
boolean corrected = applySelfMappingRules(checked, issues);
|
||||
validateConsistency(checked, standard, issues);
|
||||
corrected = applyMappingCorrections(checked, standard, issues) || corrected;
|
||||
|
||||
IcdConsistencyCheckResponse response = new IcdConsistencyCheckResponse();
|
||||
response.setResult(issues.isEmpty() ? 1 : 0);
|
||||
response.setMessage(issues.isEmpty() ? PASS_MESSAGE : NOT_PASS_MESSAGE);
|
||||
response.getIssues().addAll(issues);
|
||||
if (!issues.isEmpty()) {
|
||||
response.setIssuesJson(toJson(issues));
|
||||
if (request.isSaveToDisk()) {
|
||||
fileStorageService.save(ISSUE_FILE_NAME, response.getIssuesJson(), request.getOutputDir());
|
||||
}
|
||||
}
|
||||
if (corrected) {
|
||||
response.setCorrectedJson(toJson(checked));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private MappingDocument parseMapping(String json, String label) {
|
||||
if (isBlank(json)) {
|
||||
throw new IllegalArgumentException(label + "不能为空");
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(json, MappingDocument.class);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException(label + "解析失败:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateSelfFormat(MappingDocument document, String label, List<IcdConsistencyIssue> issues) {
|
||||
if (document == null) {
|
||||
addIssue(issues, "自身格式校验", label, label + "不能为空", null, null, false);
|
||||
return;
|
||||
}
|
||||
requireText(document.getIed(), "IED", issues);
|
||||
requireText(document.getLd(), "LD", issues);
|
||||
requireText(document.getDataType(), "DataType", issues);
|
||||
requireText(document.getUnit(), "unit", issues);
|
||||
|
||||
validateRequiredReportDescs(document, issues);
|
||||
validateRequiredLnClasses(document, issues);
|
||||
validateDoiDuplicateNames(document, issues);
|
||||
validateNestedLists(document, issues);
|
||||
}
|
||||
|
||||
private void requireText(String value, String path, List<IcdConsistencyIssue> issues) {
|
||||
if (isBlank(value)) {
|
||||
addIssue(issues, "自身格式校验", path, path + "不能为空", null, value, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRequiredReportDescs(MappingDocument document, List<IcdConsistencyIssue> issues) {
|
||||
Set<String> actualDescs = new HashSet<String>();
|
||||
if (document.getReportMap() != null) {
|
||||
for (ReportMapItem item : document.getReportMap()) {
|
||||
actualDescs.add(trimToEmpty(item.getDesc()));
|
||||
}
|
||||
}
|
||||
for (String desc : REQUIRED_REPORT_DESCS) {
|
||||
if (!actualDescs.contains(desc)) {
|
||||
addIssue(issues, "自身格式校验", "ReportMap.desc", "ReportMap 最少需要包含一条" + desc, desc, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRequiredLnClasses(MappingDocument document, List<IcdConsistencyIssue> issues) {
|
||||
Set<String> actualLnClasses = new HashSet<String>();
|
||||
if (document.getDataSetList() != null) {
|
||||
for (DataSetGroupItem item : document.getDataSetList()) {
|
||||
actualLnClasses.add(trimToEmpty(item.getLnClass()));
|
||||
}
|
||||
}
|
||||
for (String lnClass : REQUIRED_LN_CLASSES) {
|
||||
if (!actualLnClasses.contains(lnClass)) {
|
||||
addIssue(issues, "自身格式校验", "DataSetList.lnClass", "DataSetList 最少需要包含一组 lnClass=" + lnClass, lnClass, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDoiDuplicateNames(MappingDocument document, List<IcdConsistencyIssue> issues) {
|
||||
if (document.getDataSetList() == null) {
|
||||
return;
|
||||
}
|
||||
for (DataSetGroupItem group : document.getDataSetList()) {
|
||||
if (group.getInstList() == null) {
|
||||
continue;
|
||||
}
|
||||
for (InstItem inst : group.getInstList()) {
|
||||
Set<String> doiKeys = new HashSet<String>();
|
||||
if (inst.getDoiList() == null) {
|
||||
continue;
|
||||
}
|
||||
for (DoiItem doi : inst.getDoiList()) {
|
||||
String key = buildKey(doi.getName(), doi.getDesc());
|
||||
if (!doiKeys.add(key)) {
|
||||
String path = buildInstPath(group, inst) + ".doiList";
|
||||
addIssue(issues, "自身格式校验", path, "同一个 doiList 下不能存在 name+desc 都一样的指标", key, key, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateNestedLists(MappingDocument document, List<IcdConsistencyIssue> issues) {
|
||||
if (document.getDataSetList() == null) {
|
||||
return;
|
||||
}
|
||||
for (DataSetGroupItem group : document.getDataSetList()) {
|
||||
if (isEmpty(group.getInstList())) {
|
||||
addIssue(issues, "自身格式校验", buildGroupPath(group), "instList 不能为空:" + trimToEmpty(group.getDesc()), null, null, false);
|
||||
continue;
|
||||
}
|
||||
for (InstItem inst : group.getInstList()) {
|
||||
String instPath = buildInstPath(group, inst);
|
||||
if (isEmpty(inst.getDoiList())) {
|
||||
addIssue(issues, "自身格式校验", instPath, "doiList 不能为空:" + joinDesc(group.getDesc(), inst.getDesc()), null, null, false);
|
||||
continue;
|
||||
}
|
||||
for (DoiItem doi : inst.getDoiList()) {
|
||||
if (isEmpty(doi.getSdiList())) {
|
||||
addIssue(issues, "自身格式校验", instPath + ".doiList[" + buildKey(doi.getName(), doi.getDesc()) + "]",
|
||||
"sdiList 不能为空:" + joinDesc(group.getDesc(), inst.getDesc(), doi.getDesc()), null, null, false);
|
||||
continue;
|
||||
}
|
||||
for (SdiItem sdi : doi.getSdiList()) {
|
||||
if (isEmpty(sdi.getTypeList())) {
|
||||
addIssue(issues, "自身格式校验", instPath + ".doiList[" + buildKey(doi.getName(), doi.getDesc()) + "].sdiList[" + buildKey(sdi.getName(), sdi.getDesc()) + "]",
|
||||
"typeList 不能为空:" + joinDesc(group.getDesc(), inst.getDesc(), doi.getDesc(), sdi.getDesc()), null, null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConsistency(MappingDocument checked, MappingDocument standard, List<IcdConsistencyIssue> issues) {
|
||||
compareValue(standard.getIed(), checked.getIed(), "基础字段", "IED", issues, false);
|
||||
compareValue(standard.getLd(), checked.getLd(), "基础字段", "LD", issues, false);
|
||||
compareValue(standard.getDataType(), checked.getDataType(), "基础字段", "DataType", issues, false);
|
||||
compareValue(standard.getUnit(), checked.getUnit(), "基础字段", "unit", issues, true);
|
||||
validateReportMapConsistency(checked, standard, issues);
|
||||
validateDataSetConsistency(checked, standard, issues);
|
||||
}
|
||||
|
||||
private boolean applySelfMappingRules(MappingDocument checked, List<IcdConsistencyIssue> issues) {
|
||||
if (checked.getReportMap() == null) {
|
||||
return false;
|
||||
}
|
||||
boolean hasRtFre = false;
|
||||
boolean corrected = false;
|
||||
for (ReportMapItem item : checked.getReportMap()) {
|
||||
if ("实时数据".equals(trimToEmpty(item.getDesc())) && trimToEmpty(item.getRptId()).contains("RtFre")) {
|
||||
hasRtFre = true;
|
||||
if (!"1".equals(trimToEmpty(item.getFlickerFlag()))) {
|
||||
addIssue(issues, "映射规则", "ReportMap[" + buildReportKey(item) + "].FlickerFlag",
|
||||
"实时数据报告 rptID 包含 RtFre,FlickerFlag 已按规则调整为 1", "1", item.getFlickerFlag(), true);
|
||||
item.setFlickerFlag("1");
|
||||
corrected = true;
|
||||
}
|
||||
if (item.getReportCount() != 0) {
|
||||
addIssue(issues, "映射规则", "ReportMap[" + buildReportKey(item) + "].reportCount",
|
||||
"实时数据报告 rptID 包含 RtFre,reportCount 已按规则调整为 0", "0", String.valueOf(item.getReportCount()), true);
|
||||
item.setReportCount(0);
|
||||
corrected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasRtFre) {
|
||||
return false;
|
||||
}
|
||||
for (ReportMapItem item : checked.getReportMap()) {
|
||||
if ("统计数据".equals(trimToEmpty(item.getDesc()))) {
|
||||
int adjustedCount = Math.max(0, item.getReportCount() - 1);
|
||||
if (item.getReportCount() != adjustedCount) {
|
||||
addIssue(issues, "映射规则", "ReportMap[" + buildReportKey(item) + "].reportCount",
|
||||
"存在 RtFre 实时数据报告,统计数据 reportCount 已按规则减 1",
|
||||
String.valueOf(adjustedCount), String.valueOf(item.getReportCount()), true);
|
||||
item.setReportCount(adjustedCount);
|
||||
corrected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private void validateReportMapConsistency(MappingDocument checked, MappingDocument standard, List<IcdConsistencyIssue> issues) {
|
||||
Map<String, ReportMapItem> checkedMap = new HashMap<String, ReportMapItem>();
|
||||
if (checked.getReportMap() != null) {
|
||||
for (ReportMapItem item : checked.getReportMap()) {
|
||||
checkedMap.put(buildReportKey(item), item);
|
||||
}
|
||||
}
|
||||
if (standard.getReportMap() == null) {
|
||||
return;
|
||||
}
|
||||
for (ReportMapItem standardItem : standard.getReportMap()) {
|
||||
String key = buildReportKey(standardItem);
|
||||
ReportMapItem checkedItem = checkedMap.get(key);
|
||||
if (checkedItem == null) {
|
||||
addIssue(issues, "一致性校验", "ReportMap[" + key + "]", "标准映射中的 ReportMap 对象在待校验映射中不存在", key, null, false);
|
||||
continue;
|
||||
}
|
||||
compareValue(String.valueOf(standardItem.getReportCount()), String.valueOf(checkedItem.getReportCount()), "ReportMap", "ReportMap[" + key + "].reportCount", issues, true);
|
||||
compareValue(standardItem.getBuffered(), checkedItem.getBuffered(), "ReportMap", "ReportMap[" + key + "].buffered", issues, true);
|
||||
compareValue(standardItem.getInst(), checkedItem.getInst(), "ReportMap", "ReportMap[" + key + "].inst", issues, true);
|
||||
compareValue(standardItem.getFlickerFlag(), checkedItem.getFlickerFlag(), "ReportMap", "ReportMap[" + key + "].FlickerFlag", issues, true);
|
||||
compareValue(standardItem.getSelect(), checkedItem.getSelect(), "ReportMap", "ReportMap[" + key + "].Select", issues, true);
|
||||
compareValue(standardItem.getTrgOps(), checkedItem.getTrgOps(), "ReportMap", "ReportMap[" + key + "].TrgOps", issues, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDataSetConsistency(MappingDocument checked, MappingDocument standard, List<IcdConsistencyIssue> issues) {
|
||||
Map<String, DataSetGroupItem> checkedGroups = indexGroups(checked);
|
||||
if (standard.getDataSetList() == null) {
|
||||
return;
|
||||
}
|
||||
for (DataSetGroupItem standardGroup : standard.getDataSetList()) {
|
||||
String groupKey = buildKey(standardGroup.getLnClass(), standardGroup.getDesc());
|
||||
DataSetGroupItem checkedGroup = checkedGroups.get(groupKey);
|
||||
if (checkedGroup == null) {
|
||||
addIssue(issues, "一致性校验", "DataSetList[" + groupKey + "]", "标准映射中的 lnClass+desc 在待校验映射中不存在", groupKey, null, false);
|
||||
continue;
|
||||
}
|
||||
validateInstConsistency(checkedGroup, standardGroup, groupKey, issues);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateInstConsistency(DataSetGroupItem checkedGroup, DataSetGroupItem standardGroup, String groupKey, List<IcdConsistencyIssue> issues) {
|
||||
Map<String, InstItem> checkedInstMap = indexInst(checkedGroup);
|
||||
if (standardGroup.getInstList() == null) {
|
||||
return;
|
||||
}
|
||||
for (InstItem standardInst : standardGroup.getInstList()) {
|
||||
String instKey = buildKey(standardInst.getInst(), standardInst.getDesc());
|
||||
InstItem checkedInst = checkedInstMap.get(instKey);
|
||||
if (checkedInst == null) {
|
||||
addIssue(issues, "一致性校验", "DataSetList[" + groupKey + "].instList[" + instKey + "]",
|
||||
"标准映射中的 inst+desc 在待校验映射中不存在", instKey, null, false);
|
||||
continue;
|
||||
}
|
||||
validateDoiConsistency(checkedInst, standardInst, groupKey, instKey, issues);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDoiConsistency(InstItem checkedInst, InstItem standardInst, String groupKey, String instKey, List<IcdConsistencyIssue> issues) {
|
||||
Map<String, DoiItem> checkedDoiMap = indexDoi(checkedInst);
|
||||
if (standardInst.getDoiList() == null) {
|
||||
return;
|
||||
}
|
||||
for (DoiItem standardDoi : standardInst.getDoiList()) {
|
||||
String doiKey = buildKey(standardDoi.getName(), standardDoi.getDesc());
|
||||
DoiItem checkedDoi = checkedDoiMap.get(doiKey);
|
||||
String path = "DataSetList[" + groupKey + "].instList[" + instKey + "].doiList[" + doiKey + "]";
|
||||
if (checkedDoi == null) {
|
||||
addIssue(issues, "一致性校验", path, "标准映射中的 name+desc 在待校验映射中不存在", doiKey, null, false);
|
||||
continue;
|
||||
}
|
||||
compareDoiFields(checkedDoi, standardDoi, path, issues);
|
||||
}
|
||||
}
|
||||
|
||||
private void compareDoiFields(DoiItem checked, DoiItem standard, String path, List<IcdConsistencyIssue> issues) {
|
||||
boolean canCorrectRange = canCorrectDoiRange(checked, standard) && standard.getEnd() <= checked.getIcdcout();
|
||||
compareValue(String.valueOf(standard.getStart()), String.valueOf(checked.getStart()), "doiList", path + ".start", issues, canCorrectRange);
|
||||
compareValue(String.valueOf(standard.getEnd()), String.valueOf(checked.getEnd()), "doiList", path + ".end", issues, canCorrectRange);
|
||||
compareValue(standard.getUnit(), checked.getUnit(), "doiList", path + ".unit", issues, false);
|
||||
compareValue(String.valueOf(standard.getCoefficient()), String.valueOf(checked.getCoefficient()), "doiList", path + ".coefficient", issues, false);
|
||||
compareValue(String.valueOf(standard.getBaseflag()), String.valueOf(checked.getBaseflag()), "doiList", path + ".baseflag", issues, false);
|
||||
compareValue(String.valueOf(standard.getBasecount()), String.valueOf(checked.getBasecount()), "doiList", path + ".basecount", issues, false);
|
||||
compareValue(String.valueOf(standard.getIcdcout()), String.valueOf(checked.getIcdcout()), "doiList", path + ".icdcout", issues, false);
|
||||
}
|
||||
|
||||
private boolean applyMappingCorrections(MappingDocument checked, MappingDocument standard, List<IcdConsistencyIssue> issues) {
|
||||
boolean corrected = false;
|
||||
if (!equalsValue(checked.getUnit(), standard.getUnit())) {
|
||||
checked.setUnit(standard.getUnit());
|
||||
corrected = true;
|
||||
}
|
||||
corrected = correctReportMap(checked, standard) || corrected;
|
||||
corrected = correctDoiRanges(checked, standard, issues) || corrected;
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private boolean correctReportMap(MappingDocument checked, MappingDocument standard) {
|
||||
boolean corrected = false;
|
||||
Map<String, ReportMapItem> checkedMap = new HashMap<String, ReportMapItem>();
|
||||
if (checked.getReportMap() != null) {
|
||||
for (ReportMapItem item : checked.getReportMap()) {
|
||||
checkedMap.put(buildReportKey(item), item);
|
||||
}
|
||||
}
|
||||
if (standard.getReportMap() == null) {
|
||||
return false;
|
||||
}
|
||||
for (ReportMapItem standardItem : standard.getReportMap()) {
|
||||
ReportMapItem checkedItem = checkedMap.get(buildReportKey(standardItem));
|
||||
if (checkedItem != null && !reportOtherFieldsEqual(checkedItem, standardItem)) {
|
||||
checkedItem.setReportCount(standardItem.getReportCount());
|
||||
checkedItem.setBuffered(standardItem.getBuffered());
|
||||
checkedItem.setInst(standardItem.getInst());
|
||||
checkedItem.setFlickerFlag(standardItem.getFlickerFlag());
|
||||
checkedItem.setSelect(standardItem.getSelect());
|
||||
checkedItem.setTrgOps(standardItem.getTrgOps());
|
||||
corrected = true;
|
||||
}
|
||||
}
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private boolean correctDoiRanges(MappingDocument checked, MappingDocument standard, List<IcdConsistencyIssue> issues) {
|
||||
boolean corrected = false;
|
||||
Map<String, DataSetGroupItem> checkedGroups = indexGroups(checked);
|
||||
if (standard.getDataSetList() == null) {
|
||||
return false;
|
||||
}
|
||||
for (DataSetGroupItem standardGroup : standard.getDataSetList()) {
|
||||
DataSetGroupItem checkedGroup = checkedGroups.get(buildKey(standardGroup.getLnClass(), standardGroup.getDesc()));
|
||||
if (checkedGroup == null) {
|
||||
continue;
|
||||
}
|
||||
corrected = correctGroupDoiRanges(checkedGroup, standardGroup, issues) || corrected;
|
||||
}
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private boolean correctGroupDoiRanges(DataSetGroupItem checkedGroup, DataSetGroupItem standardGroup, List<IcdConsistencyIssue> issues) {
|
||||
boolean corrected = false;
|
||||
Map<String, InstItem> checkedInstMap = indexInst(checkedGroup);
|
||||
if (standardGroup.getInstList() == null) {
|
||||
return false;
|
||||
}
|
||||
for (InstItem standardInst : standardGroup.getInstList()) {
|
||||
InstItem checkedInst = checkedInstMap.get(buildKey(standardInst.getInst(), standardInst.getDesc()));
|
||||
if (checkedInst == null) {
|
||||
continue;
|
||||
}
|
||||
corrected = correctInstDoiRanges(checkedGroup, checkedInst, standardInst, issues) || corrected;
|
||||
}
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private boolean correctInstDoiRanges(DataSetGroupItem checkedGroup, InstItem checkedInst, InstItem standardInst, List<IcdConsistencyIssue> issues) {
|
||||
boolean corrected = false;
|
||||
Map<String, DoiItem> checkedDoiMap = indexDoi(checkedInst);
|
||||
if (standardInst.getDoiList() == null) {
|
||||
return false;
|
||||
}
|
||||
for (DoiItem standardDoi : standardInst.getDoiList()) {
|
||||
DoiItem checkedDoi = checkedDoiMap.get(buildKey(standardDoi.getName(), standardDoi.getDesc()));
|
||||
if (checkedDoi == null || !canCorrectDoiRange(checkedDoi, standardDoi)) {
|
||||
continue;
|
||||
}
|
||||
String path = buildInstPath(checkedGroup, checkedInst) + ".doiList[" + buildKey(checkedDoi.getName(), checkedDoi.getDesc()) + "]";
|
||||
if (standardDoi.getEnd() > checkedDoi.getIcdcout()) {
|
||||
addIssue(issues, "映射修改", path, "标准 end 大于待校验 icdcout,不能自动修正 start/end",
|
||||
String.valueOf(standardDoi.getEnd()), String.valueOf(checkedDoi.getIcdcout()), false);
|
||||
continue;
|
||||
}
|
||||
if (checkedDoi.getStart() != standardDoi.getStart() || checkedDoi.getEnd() != standardDoi.getEnd()) {
|
||||
checkedDoi.setStart(standardDoi.getStart());
|
||||
checkedDoi.setEnd(standardDoi.getEnd());
|
||||
corrected = true;
|
||||
}
|
||||
}
|
||||
return corrected;
|
||||
}
|
||||
|
||||
private void compareValue(String standardValue, String checkedValue, String scope, String path,
|
||||
List<IcdConsistencyIssue> issues, boolean corrected) {
|
||||
if (!equalsValue(standardValue, checkedValue)) {
|
||||
addIssue(issues, scope, path, path + " 与标准映射不一致", standardValue, checkedValue, corrected);
|
||||
}
|
||||
}
|
||||
|
||||
private void addIssue(List<IcdConsistencyIssue> issues, String scope, String path, String message,
|
||||
String standardValue, String checkedValue, boolean corrected) {
|
||||
IcdConsistencyIssue issue = new IcdConsistencyIssue();
|
||||
issue.setScope(scope);
|
||||
issue.setPath(path);
|
||||
issue.setMessage(message);
|
||||
issue.setStandardValue(standardValue);
|
||||
issue.setCheckedValue(checkedValue);
|
||||
issue.setCorrected(corrected);
|
||||
issues.add(issue);
|
||||
}
|
||||
|
||||
private Map<String, DataSetGroupItem> indexGroups(MappingDocument document) {
|
||||
Map<String, DataSetGroupItem> result = new HashMap<String, DataSetGroupItem>();
|
||||
if (document.getDataSetList() == null) {
|
||||
return result;
|
||||
}
|
||||
for (DataSetGroupItem item : document.getDataSetList()) {
|
||||
result.put(buildKey(item.getLnClass(), item.getDesc()), item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, InstItem> indexInst(DataSetGroupItem group) {
|
||||
Map<String, InstItem> result = new HashMap<String, InstItem>();
|
||||
if (group.getInstList() == null) {
|
||||
return result;
|
||||
}
|
||||
for (InstItem item : group.getInstList()) {
|
||||
result.put(buildKey(item.getInst(), item.getDesc()), item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, DoiItem> indexDoi(InstItem inst) {
|
||||
Map<String, DoiItem> result = new HashMap<String, DoiItem>();
|
||||
if (inst.getDoiList() == null) {
|
||||
return result;
|
||||
}
|
||||
for (DoiItem item : inst.getDoiList()) {
|
||||
result.put(buildKey(item.getName(), item.getDesc()), item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String buildReportKey(ReportMapItem item) {
|
||||
return buildKey(item.getDesc(), item.getRptId(), item.getName());
|
||||
}
|
||||
|
||||
private String buildGroupPath(DataSetGroupItem group) {
|
||||
return "DataSetList[" + buildKey(group.getLnClass(), group.getDesc()) + "]";
|
||||
}
|
||||
|
||||
private String buildInstPath(DataSetGroupItem group, InstItem inst) {
|
||||
return buildGroupPath(group) + ".instList[" + buildKey(inst.getInst(), inst.getDesc()) + "]";
|
||||
}
|
||||
|
||||
private String buildKey(String... values) {
|
||||
List<String> parts = new ArrayList<String>();
|
||||
for (String value : values) {
|
||||
parts.add(trimToEmpty(value));
|
||||
}
|
||||
return String.join("+", parts);
|
||||
}
|
||||
|
||||
private boolean reportOtherFieldsEqual(ReportMapItem checked, ReportMapItem standard) {
|
||||
return checked.getReportCount() == standard.getReportCount()
|
||||
&& equalsValue(checked.getBuffered(), standard.getBuffered())
|
||||
&& equalsValue(checked.getInst(), standard.getInst())
|
||||
&& equalsValue(checked.getFlickerFlag(), standard.getFlickerFlag())
|
||||
&& equalsValue(checked.getSelect(), standard.getSelect())
|
||||
&& equalsValue(checked.getTrgOps(), standard.getTrgOps());
|
||||
}
|
||||
|
||||
private boolean canCorrectDoiRange(DoiItem checked, DoiItem standard) {
|
||||
return checked.getBaseflag() == standard.getBaseflag()
|
||||
&& (checked.getBaseflag() == 1 || checked.getBaseflag() == 2);
|
||||
}
|
||||
|
||||
private boolean equalsValue(String left, String right) {
|
||||
return trimToEmpty(left).equals(trimToEmpty(right));
|
||||
}
|
||||
|
||||
private boolean isBlank(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private String trimToEmpty(String value) {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private boolean isEmpty(List<?> list) {
|
||||
return list == null || list.isEmpty();
|
||||
}
|
||||
|
||||
private String joinDesc(String... descs) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (String desc : descs) {
|
||||
if (!isBlank(desc)) {
|
||||
values.add(desc.trim());
|
||||
}
|
||||
}
|
||||
return String.join(" / ", values);
|
||||
}
|
||||
|
||||
private String toJson(Object value) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(value);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("ICD 一致性校验结果序列化失败:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static ObjectMapper buildMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.njcn.gather.icd.mapping.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.CsIcdPathParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO;
|
||||
import com.njcn.gather.icd.mapping.service.CsIcdPathService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ICD 存储记录维护入口。
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "ICD存储记录管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/mms-mapping/icd-paths")
|
||||
@RequiredArgsConstructor
|
||||
public class CsIcdPathController extends BaseController {
|
||||
|
||||
private final CsIcdPathService csIcdPathService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("查询ICD存储记录列表")
|
||||
@PostMapping("/list")
|
||||
public HttpResult<List<CsIcdPathVO>> list(@RequestBody(required = false) CsIcdPathParam.ListParam param) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},开始查询ICD存储记录列表", methodDescribe);
|
||||
List<CsIcdPathVO> result = csIcdPathService.listIcdPaths(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("新增ICD存储记录")
|
||||
@PostMapping(value = "/add", consumes = {"application/json"})
|
||||
public HttpResult<Boolean> add(@RequestBody @Validated CsIcdPathParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},开始新增ICD存储记录", methodDescribe);
|
||||
boolean result = csIcdPathService.addIcdPath(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("上传并新增ICD存储记录")
|
||||
@PostMapping(value = "/add", consumes = {"multipart/form-data"})
|
||||
public HttpResult<Boolean> addWithFile(@RequestPart("icdFile") MultipartFile icdFile,
|
||||
@RequestPart("request") @Validated CsIcdPathParam param) {
|
||||
String methodDescribe = getMethodDescribe("addWithFile");
|
||||
LogUtil.njcnDebug(log, "{},开始上传并新增ICD存储记录,fileName={}", methodDescribe, resolveFileName(icdFile));
|
||||
fillIcdFile(param, icdFile);
|
||||
boolean result = csIcdPathService.addIcdPath(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("编辑ICD存储记录")
|
||||
@PostMapping(value = "/update", consumes = {"application/json"})
|
||||
public HttpResult<Boolean> update(@RequestBody @Validated CsIcdPathParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},开始编辑ICD存储记录,icdId={}", methodDescribe, param.getId());
|
||||
boolean result = csIcdPathService.updateIcdPath(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("上传并编辑ICD存储记录")
|
||||
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
|
||||
public HttpResult<Boolean> updateWithFile(@RequestPart("icdFile") MultipartFile icdFile,
|
||||
@RequestPart("request") @Validated CsIcdPathParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("updateWithFile");
|
||||
LogUtil.njcnDebug(log, "{},开始上传并编辑ICD存储记录,icdId={},fileName={}", methodDescribe, param.getId(), resolveFileName(icdFile));
|
||||
fillIcdFile(param, icdFile);
|
||||
boolean result = csIcdPathService.updateIcdPath(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("激活ICD存储记录")
|
||||
@ApiImplicitParam(name = "id", value = "ICD记录ID", required = true)
|
||||
@PostMapping("/{id}/activate")
|
||||
public HttpResult<Boolean> activate(@PathVariable("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("activate");
|
||||
LogUtil.njcnDebug(log, "{},开始激活ICD存储记录,icdId={}", methodDescribe, id);
|
||||
boolean result = csIcdPathService.activateIcdPath(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("删除ICD存储记录")
|
||||
@PostMapping("/delete")
|
||||
public HttpResult<Boolean> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},开始删除ICD存储记录,ids={}", methodDescribe, ids);
|
||||
boolean result = csIcdPathService.deleteIcdPath(ids);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("保存ICD唯一性校验结果")
|
||||
@ApiImplicitParam(name = "id", value = "ICD记录ID", required = true)
|
||||
@PostMapping("/{id}/icd-check-result")
|
||||
public HttpResult<Boolean> saveIcdCheckResult(@PathVariable("id") String id,
|
||||
@RequestBody IcdCheckResultSaveParam param) {
|
||||
String methodDescribe = getMethodDescribe("saveIcdCheckResult");
|
||||
LogUtil.njcnDebug(log, "{},开始保存ICD校验结果,icdId={}", methodDescribe, id);
|
||||
boolean result = csIcdPathService.saveIcdCheckResult(id, param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
private void fillIcdFile(CsIcdPathParam param, MultipartFile icdFile) {
|
||||
if (icdFile == null || icdFile.isEmpty()) {
|
||||
throw new IllegalArgumentException("ICD文件不能为空");
|
||||
}
|
||||
try {
|
||||
param.setIcdContent(icdFile.getBytes());
|
||||
if (param.getPath() == null || param.getPath().trim().isEmpty()) {
|
||||
param.setPath(resolveFileName(icdFile));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalArgumentException("读取ICD文件失败:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveFileName(MultipartFile icdFile) {
|
||||
if (icdFile == null || icdFile.getOriginalFilename() == null) {
|
||||
return null;
|
||||
}
|
||||
String fileName = icdFile.getOriginalFilename().trim();
|
||||
return fileName.isEmpty() ? null : fileName;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.icd.mapping.component.IcdToXmlResponseConverter;
|
||||
import com.njcn.gather.icd.mapping.component.IcdConsistencyCheckService;
|
||||
import com.njcn.gather.icd.mapping.component.IndexSelectionBuildService;
|
||||
import com.njcn.gather.icd.mapping.component.MappingRequestConverter;
|
||||
import com.njcn.gather.icd.mapping.component.MappingResponseConverter;
|
||||
@@ -14,9 +15,11 @@ import com.njcn.gather.icd.mapping.pojo.bo.IcdToXmlGenerateResult;
|
||||
import com.njcn.gather.icd.mapping.pojo.dto.GenerateFromIcdCommand;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.BuildIndexSelectionRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.GenerateMappingFromIcdRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdConsistencyCheckRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IndexCandidateRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.JsonToXmlRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.SubmitIndexSelectionRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IcdConsistencyCheckResponse;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IcdToXmlResponse;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IndexConfirmGroupResponse;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IndexSelectionGroupResponse;
|
||||
@@ -70,6 +73,9 @@ public class MappingController extends BaseController {
|
||||
/** ICD 结构确认弹窗结果组装服务。 */
|
||||
private final IndexSelectionBuildService indexSelectionBuildService;
|
||||
|
||||
/** ICD 映射 JSON 一致性校验服务。 */
|
||||
private final IcdConsistencyCheckService icdConsistencyCheckService;
|
||||
|
||||
/**
|
||||
* 上传 ICD 文件,返回候选结果和可编辑的 ICD 解析结果。
|
||||
*/
|
||||
@@ -181,4 +187,17 @@ public class MappingController extends BaseController {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将待校验 MMS 映射 JSON 与标准 MMS 映射 JSON 做 ICD 一致性校验。
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("ICD 一致性校验")
|
||||
@ApiImplicitParam(name = "request", value = "ICD 一致性校验参数", required = true, dataType = "IcdConsistencyCheckRequest")
|
||||
@PostMapping("/check-icd-json-consistency")
|
||||
public IcdConsistencyCheckResponse checkIcdJsonConsistency(@Validated @RequestBody IcdConsistencyCheckRequest request) {
|
||||
String methodDescribe = getMethodDescribe("checkIcdJsonConsistency");
|
||||
LogUtil.njcnDebug(log, "{},开始执行 ICD 一致性校验", methodDescribe);
|
||||
return icdConsistencyCheckService.check(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.PqdifCheckPlaceholderVO;
|
||||
import com.njcn.gather.icd.mapping.service.MmsDeviceTypeService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备类型校验入口。
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "设备类型ICD校验")
|
||||
@RestController
|
||||
@RequestMapping("/api/mms-mapping/dev-types")
|
||||
@RequiredArgsConstructor
|
||||
public class MmsDeviceTypeController extends BaseController {
|
||||
|
||||
private final MmsDeviceTypeService mmsDeviceTypeService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("查询设备类型校验列表")
|
||||
@GetMapping
|
||||
public HttpResult<List<MmsDeviceTypeVO>> listDeviceTypes() {
|
||||
String methodDescribe = getMethodDescribe("listDeviceTypes");
|
||||
LogUtil.njcnDebug(log, "{},开始查询设备类型校验列表", methodDescribe);
|
||||
List<MmsDeviceTypeVO> result = mmsDeviceTypeService.listDeviceTypes();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("保存设备类型ICD唯一性校验结果")
|
||||
@ApiImplicitParam(name = "id", value = "设备类型ID", required = true)
|
||||
@PostMapping("/{id}/icd-check-result")
|
||||
public HttpResult<Boolean> saveIcdCheckResult(@PathVariable("id") String id,
|
||||
@RequestBody IcdCheckResultSaveParam param) {
|
||||
String methodDescribe = getMethodDescribe("saveIcdCheckResult");
|
||||
LogUtil.njcnDebug(log, "{},开始保存设备类型ICD校验结果,devTypeId={}", methodDescribe, id);
|
||||
boolean result = mmsDeviceTypeService.saveIcdCheckResult(id, param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("设备类型PQDIF校验")
|
||||
@ApiImplicitParam(name = "id", value = "设备类型ID", required = true)
|
||||
@PostMapping("/{id}/pqdif-check")
|
||||
public HttpResult<PqdifCheckPlaceholderVO> pqdifCheck(@PathVariable("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("pqdifCheck");
|
||||
LogUtil.njcnDebug(log, "{},设备类型PQDIF校验预留入口,devTypeId={}", methodDescribe, id);
|
||||
PqdifCheckPlaceholderVO result = mmsDeviceTypeService.pqdifCheck(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsDevTypePO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备类型 Mapper。
|
||||
*/
|
||||
public interface CsDevTypeMapper extends BaseMapper<CsDevTypePO> {
|
||||
|
||||
List<MmsDeviceTypeVO> selectDeviceTypeCheckList();
|
||||
}
|
||||
@@ -2,9 +2,17 @@ package com.njcn.gather.icd.mapping.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsIcdPathPO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ICD 路径 Mapper。
|
||||
*/
|
||||
public interface CsIcdPathMapper extends BaseMapper<CsIcdPathPO> {
|
||||
|
||||
List<CsIcdPathVO> selectIcdPathList(@Param("keyword") String keyword,
|
||||
@Param("type") Integer type,
|
||||
@Param("result") Integer result);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.icd.mapping.mapper.CsDevTypeMapper">
|
||||
|
||||
<select id="selectDeviceTypeCheckList"
|
||||
resultType="com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO">
|
||||
SELECT
|
||||
d.id AS id,
|
||||
d.name AS name,
|
||||
d.icd AS icdId,
|
||||
p.Name AS icdName,
|
||||
p.Path AS icdPath,
|
||||
p.Result AS icdResult,
|
||||
p.Msg AS icdMsg,
|
||||
d.report_name AS reportName,
|
||||
CASE WHEN d.icd IS NOT NULL AND d.icd != '' AND p.ID IS NOT NULL THEN 1 ELSE 0 END AS canCheckIcd,
|
||||
0 AS canCheckPqdif
|
||||
FROM cs_dev_type d
|
||||
LEFT JOIN cs_icd_path p ON d.icd = p.ID
|
||||
WHERE d.State = 1
|
||||
ORDER BY d.Update_Time DESC, d.Create_Time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.icd.mapping.mapper.CsIcdPathMapper">
|
||||
|
||||
<select id="selectIcdPathList"
|
||||
resultType="com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO">
|
||||
SELECT
|
||||
ID AS id,
|
||||
Name AS name,
|
||||
Path AS path,
|
||||
Angle AS angle,
|
||||
Use_Phase_Index AS usePhaseIndex,
|
||||
State AS state,
|
||||
Json_Str AS jsonStr,
|
||||
Xml_Str AS xmlStr,
|
||||
Result AS result,
|
||||
Msg AS msg,
|
||||
Type AS type,
|
||||
Reference_Icd_Id AS referenceIcdId,
|
||||
Create_By AS createBy,
|
||||
Create_Time AS createTime,
|
||||
Update_By AS updateBy,
|
||||
Update_Time AS updateTime
|
||||
FROM cs_icd_path
|
||||
WHERE State = 1
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (Name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR Path LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
<if test="type != null">
|
||||
AND Type = #{type}
|
||||
</if>
|
||||
<if test="result != null">
|
||||
AND Result = #{result}
|
||||
</if>
|
||||
ORDER BY Update_Time DESC, Create_Time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* ICD 存储记录保存参数。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("ICD存储记录保存参数")
|
||||
public class CsIcdPathParam {
|
||||
|
||||
@ApiModelProperty("ICD名称")
|
||||
@NotBlank(message = "ICD名称不能为空")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("ICD存储路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("ICD文件二进制内容")
|
||||
private byte[] icdContent;
|
||||
|
||||
@ApiModelProperty("角度")
|
||||
private Integer angle;
|
||||
|
||||
@ApiModelProperty("是否使用相位索引")
|
||||
private Integer usePhaseIndex;
|
||||
|
||||
@ApiModelProperty("ICD类型,1-标准ICD")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* ICD 存储记录编辑参数。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("ICD存储记录编辑参数")
|
||||
public static class UpdateParam extends CsIcdPathParam {
|
||||
|
||||
@ApiModelProperty("ICD记录ID")
|
||||
@NotBlank(message = "ICD记录ID不能为空")
|
||||
private String id;
|
||||
}
|
||||
|
||||
/**
|
||||
* ICD 存储记录列表查询参数。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("ICD存储记录列表查询参数")
|
||||
public static class ListParam {
|
||||
|
||||
@ApiModelProperty("关键字,匹配ICD名称或路径")
|
||||
private String keyword;
|
||||
|
||||
@ApiModelProperty("ICD类型")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("ICD校验结果,0-否,1-是")
|
||||
private Integer result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ICD 一致性校验请求参数。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("ICD 一致性校验请求参数")
|
||||
public class IcdConsistencyCheckRequest {
|
||||
|
||||
/** 待校验 MMS 映射 JSON。 */
|
||||
@ApiModelProperty(value = "待校验 MMS 映射 JSON", required = true)
|
||||
private String checkedJson;
|
||||
|
||||
/** 标准 MMS 映射 JSON。 */
|
||||
@ApiModelProperty(value = "标准 MMS 映射 JSON", required = true)
|
||||
private String standardJson;
|
||||
|
||||
/** 是否将不符合原因 JSON 保存到磁盘。 */
|
||||
@ApiModelProperty("是否将不符合原因 JSON 保存到磁盘")
|
||||
private boolean saveToDisk;
|
||||
|
||||
/** 输出目录,仅 saveToDisk=true 且存在不符合原因时生效。 */
|
||||
@ApiModelProperty("输出目录,仅 saveToDisk=true 且存在不符合原因时生效")
|
||||
private String outputDir;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 设备类型表。
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_dev_type")
|
||||
public class CsDevTypePO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
private String id;
|
||||
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("icd")
|
||||
private String icd;
|
||||
|
||||
@TableField("power")
|
||||
private String power;
|
||||
|
||||
@TableField("Dev_Volt")
|
||||
private Float devVolt;
|
||||
|
||||
@TableField("Dev_Curr")
|
||||
private Float devCurr;
|
||||
|
||||
@TableField("Dev_Chns")
|
||||
private Integer devChns;
|
||||
|
||||
@TableField("Wave_Cmd")
|
||||
private String waveCmd;
|
||||
|
||||
@TableField("State")
|
||||
private Integer state;
|
||||
|
||||
@TableField("Create_By")
|
||||
private String createBy;
|
||||
|
||||
@TableField("Create_Time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField("Update_By")
|
||||
private String updateBy;
|
||||
|
||||
@TableField("Update_Time")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("report_name")
|
||||
private String reportName;
|
||||
}
|
||||
@@ -26,6 +26,9 @@ public class CsIcdPathPO implements Serializable {
|
||||
@TableField("Path")
|
||||
private String path;
|
||||
|
||||
@TableField("Icd_Content")
|
||||
private byte[] icdContent;
|
||||
|
||||
@TableField("Angle")
|
||||
private Integer angle;
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* ICD 存储记录列表项。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("ICD存储记录列表项")
|
||||
public class CsIcdPathVO {
|
||||
|
||||
@ApiModelProperty("ICD记录ID")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("ICD名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("ICD存储路径")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("角度")
|
||||
private Integer angle;
|
||||
|
||||
@ApiModelProperty("是否使用相位索引")
|
||||
private Integer usePhaseIndex;
|
||||
|
||||
@ApiModelProperty("状态,1-正常,0-删除")
|
||||
private Integer state;
|
||||
|
||||
@ApiModelProperty("MMS映射JSON")
|
||||
private String jsonStr;
|
||||
|
||||
@ApiModelProperty("MMS映射XML")
|
||||
private String xmlStr;
|
||||
|
||||
@ApiModelProperty("校验结论,0-否,1-是")
|
||||
private Integer result;
|
||||
|
||||
@ApiModelProperty("校验结论描述")
|
||||
private String msg;
|
||||
|
||||
@ApiModelProperty("ICD类型,1-标准ICD")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("标准ICD引用ID")
|
||||
private String referenceIcdId;
|
||||
|
||||
@ApiModelProperty("创建人")
|
||||
private String createBy;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty("更新人")
|
||||
private String updateBy;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ICD 一致性校验响应。
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@ApiModel("ICD 一致性校验响应")
|
||||
public class IcdConsistencyCheckResponse {
|
||||
|
||||
/** 校验结论:1-符合,0-不符合。 */
|
||||
@ApiModelProperty("校验结论:1-符合,0-不符合")
|
||||
private Integer result;
|
||||
|
||||
/** 校验结论描述。 */
|
||||
@ApiModelProperty("校验结论描述")
|
||||
private String message;
|
||||
|
||||
/** 不符合原因结构化列表。 */
|
||||
@ApiModelProperty("不符合原因结构化列表")
|
||||
private List<IcdConsistencyIssue> issues = new ArrayList<IcdConsistencyIssue>();
|
||||
|
||||
/** 不符合原因 JSON 字符串。 */
|
||||
@ApiModelProperty("不符合原因 JSON 字符串")
|
||||
private String issuesJson;
|
||||
|
||||
/** 按映射修改规则修正后的 JSON,存在可修正内容时返回。 */
|
||||
@ApiModelProperty("按映射修改规则修正后的 JSON,存在可修正内容时返回")
|
||||
private String correctedJson;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* ICD 一致性校验问题项。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("ICD 一致性校验问题项")
|
||||
public class IcdConsistencyIssue {
|
||||
|
||||
/** 问题所属规则或区域。 */
|
||||
@ApiModelProperty("问题所属规则或区域")
|
||||
private String scope;
|
||||
|
||||
/** JSON 路径或业务定位信息。 */
|
||||
@ApiModelProperty("JSON 路径或业务定位信息")
|
||||
private String path;
|
||||
|
||||
/** 问题描述。 */
|
||||
@ApiModelProperty("问题描述")
|
||||
private String message;
|
||||
|
||||
/** 标准映射中的值。 */
|
||||
@ApiModelProperty("标准映射中的值")
|
||||
private String standardValue;
|
||||
|
||||
/** 待校验映射中的值。 */
|
||||
@ApiModelProperty("待校验映射中的值")
|
||||
private String checkedValue;
|
||||
|
||||
/** 是否已按映射修改规则自动修正。 */
|
||||
@ApiModelProperty("是否已按映射修改规则自动修正")
|
||||
private boolean corrected;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 设备类型校验列表项。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("设备类型校验列表项")
|
||||
public class MmsDeviceTypeVO {
|
||||
|
||||
@ApiModelProperty("设备类型ID")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("设备类型名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("关联ICD ID")
|
||||
private String icdId;
|
||||
|
||||
@ApiModelProperty("ICD名称")
|
||||
private String icdName;
|
||||
|
||||
@ApiModelProperty("ICD路径")
|
||||
private String icdPath;
|
||||
|
||||
@ApiModelProperty("ICD校验结论:0-否,1-是")
|
||||
private Integer icdResult;
|
||||
|
||||
@ApiModelProperty("ICD校验结论描述")
|
||||
private String icdMsg;
|
||||
|
||||
@ApiModelProperty("报告模板名称")
|
||||
private String reportName;
|
||||
|
||||
@ApiModelProperty("是否可执行ICD唯一性校验")
|
||||
private Boolean canCheckIcd;
|
||||
|
||||
@ApiModelProperty("是否可执行PQDIF校验")
|
||||
private Boolean canCheckPqdif;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* PQDIF 校验预留响应。
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("PQDIF校验预留响应")
|
||||
public class PqdifCheckPlaceholderVO {
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty("提示信息")
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.gather.icd.mapping.service;
|
||||
|
||||
import com.njcn.gather.icd.mapping.pojo.param.CsIcdPathParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ICD 存储记录服务。
|
||||
*/
|
||||
public interface CsIcdPathService {
|
||||
|
||||
List<CsIcdPathVO> listIcdPaths(CsIcdPathParam.ListParam param);
|
||||
|
||||
boolean addIcdPath(CsIcdPathParam param);
|
||||
|
||||
boolean updateIcdPath(CsIcdPathParam.UpdateParam param);
|
||||
|
||||
boolean activateIcdPath(String icdId);
|
||||
|
||||
boolean deleteIcdPath(List<String> ids);
|
||||
|
||||
boolean saveIcdCheckResult(String icdId, IcdCheckResultSaveParam param);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.service;
|
||||
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.PqdifCheckPlaceholderVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备类型校验服务。
|
||||
*/
|
||||
public interface MmsDeviceTypeService {
|
||||
|
||||
List<MmsDeviceTypeVO> listDeviceTypes();
|
||||
|
||||
boolean saveIcdCheckResult(String devTypeId, IcdCheckResultSaveParam param);
|
||||
|
||||
PqdifCheckPlaceholderVO pqdifCheck(String devTypeId);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package com.njcn.gather.icd.mapping.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.njcn.gather.icd.mapping.mapper.CsIcdPathMapper;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.CsIcdPathParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsIcdPathPO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.CsIcdPathVO;
|
||||
import com.njcn.gather.icd.mapping.service.CsIcdPathService;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* ICD 存储记录服务实现。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CsIcdPathServiceImpl implements CsIcdPathService {
|
||||
|
||||
private static final int STATE_NORMAL = 1;
|
||||
|
||||
private static final int STATE_DELETED = 0;
|
||||
|
||||
private static final int ICD_TYPE_STANDARD = 1;
|
||||
|
||||
private final CsIcdPathMapper csIcdPathMapper;
|
||||
|
||||
@Override
|
||||
public List<CsIcdPathVO> listIcdPaths(CsIcdPathParam.ListParam param) {
|
||||
CsIcdPathParam.ListParam checkedParam = param == null ? new CsIcdPathParam.ListParam() : param;
|
||||
return csIcdPathMapper.selectIcdPathList(
|
||||
trimToNull(checkedParam.getKeyword()),
|
||||
checkedParam.getType(),
|
||||
checkedParam.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addIcdPath(CsIcdPathParam param) {
|
||||
CsIcdPathParam checkedParam = requireParam(param);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
CsIcdPathPO icdPath = buildIcdPath(checkedParam);
|
||||
icdPath.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
icdPath.setState(STATE_NORMAL);
|
||||
icdPath.setCreateBy(currentUserId());
|
||||
icdPath.setCreateTime(now);
|
||||
icdPath.setUpdateBy(currentUserId());
|
||||
icdPath.setUpdateTime(now);
|
||||
return csIcdPathMapper.insert(icdPath) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateIcdPath(CsIcdPathParam.UpdateParam param) {
|
||||
CsIcdPathParam.UpdateParam checkedParam = requireUpdateParam(param);
|
||||
requireIcdPath(checkedParam.getId());
|
||||
CsIcdPathPO icdPath = buildIcdPath(checkedParam);
|
||||
icdPath.setId(checkedParam.getId());
|
||||
icdPath.setUpdateBy(currentUserId());
|
||||
icdPath.setUpdateTime(LocalDateTime.now());
|
||||
return csIcdPathMapper.updateById(icdPath) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean activateIcdPath(String icdId) {
|
||||
CsIcdPathPO targetIcdPath = requireIcdPath(icdId);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String currentUserId = currentUserId();
|
||||
|
||||
csIcdPathMapper.update(null, new LambdaUpdateWrapper<CsIcdPathPO>()
|
||||
.set(CsIcdPathPO::getType, null)
|
||||
.set(CsIcdPathPO::getUpdateBy, currentUserId)
|
||||
.set(CsIcdPathPO::getUpdateTime, now)
|
||||
.eq(CsIcdPathPO::getState, STATE_NORMAL));
|
||||
|
||||
CsIcdPathPO activeIcdPath = new CsIcdPathPO();
|
||||
activeIcdPath.setType(ICD_TYPE_STANDARD);
|
||||
activeIcdPath.setUpdateBy(currentUserId);
|
||||
activeIcdPath.setUpdateTime(now);
|
||||
return csIcdPathMapper.update(activeIcdPath, new LambdaUpdateWrapper<CsIcdPathPO>()
|
||||
.eq(CsIcdPathPO::getId, targetIcdPath.getId())
|
||||
.eq(CsIcdPathPO::getState, STATE_NORMAL)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteIcdPath(List<String> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
throw new IllegalArgumentException("ICD记录ID不能为空");
|
||||
}
|
||||
CsIcdPathPO icdPath = new CsIcdPathPO();
|
||||
icdPath.setState(STATE_DELETED);
|
||||
icdPath.setUpdateBy(currentUserId());
|
||||
icdPath.setUpdateTime(LocalDateTime.now());
|
||||
return csIcdPathMapper.update(icdPath, new LambdaUpdateWrapper<CsIcdPathPO>()
|
||||
.in(CsIcdPathPO::getId, ids)
|
||||
.eq(CsIcdPathPO::getState, STATE_NORMAL)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean saveIcdCheckResult(String icdId, IcdCheckResultSaveParam param) {
|
||||
if (param == null) {
|
||||
throw new IllegalArgumentException("ICD校验结果不能为空");
|
||||
}
|
||||
CsIcdPathPO icdPath = requireIcdPath(icdId);
|
||||
CsIcdPathPO referenceIcd = requireUniqueReferenceIcd();
|
||||
icdPath.setJsonStr(trimToNull(param.getMappingJson()));
|
||||
icdPath.setXmlStr(trimToNull(param.getXml()));
|
||||
icdPath.setResult(normalizeResult(param.getResult()));
|
||||
icdPath.setMsg(trimToNull(param.getMsg()));
|
||||
icdPath.setReferenceIcdId(referenceIcd.getId());
|
||||
icdPath.setUpdateBy(currentUserId());
|
||||
icdPath.setUpdateTime(LocalDateTime.now());
|
||||
return csIcdPathMapper.updateById(icdPath) > 0;
|
||||
}
|
||||
|
||||
private CsIcdPathPO buildIcdPath(CsIcdPathParam param) {
|
||||
CsIcdPathPO icdPath = new CsIcdPathPO();
|
||||
icdPath.setName(requireText(param.getName(), "ICD名称不能为空"));
|
||||
icdPath.setPath(requireText(param.getPath(), "ICD存储路径不能为空"));
|
||||
icdPath.setIcdContent(param.getIcdContent());
|
||||
icdPath.setAngle(param.getAngle());
|
||||
icdPath.setUsePhaseIndex(param.getUsePhaseIndex());
|
||||
icdPath.setType(param.getType());
|
||||
return icdPath;
|
||||
}
|
||||
|
||||
private CsIcdPathParam requireParam(CsIcdPathParam param) {
|
||||
if (param == null) {
|
||||
throw new IllegalArgumentException("ICD记录参数不能为空");
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
private CsIcdPathParam.UpdateParam requireUpdateParam(CsIcdPathParam.UpdateParam param) {
|
||||
if (param == null) {
|
||||
throw new IllegalArgumentException("ICD记录参数不能为空");
|
||||
}
|
||||
requireText(param.getId(), "ICD记录ID不能为空");
|
||||
return param;
|
||||
}
|
||||
|
||||
private CsIcdPathPO requireIcdPath(String icdId) {
|
||||
String id = requireText(icdId, "ICD记录ID不能为空");
|
||||
CsIcdPathPO icdPath = csIcdPathMapper.selectById(id);
|
||||
if (icdPath == null || !Integer.valueOf(STATE_NORMAL).equals(icdPath.getState())) {
|
||||
throw new IllegalArgumentException("ICD记录不存在或已删除");
|
||||
}
|
||||
return icdPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全系统只允许一个正常状态的标准 ICD 作为唯一参照。
|
||||
*/
|
||||
private CsIcdPathPO requireUniqueReferenceIcd() {
|
||||
List<CsIcdPathPO> referenceIcdList = csIcdPathMapper.selectList(new LambdaQueryWrapper<CsIcdPathPO>()
|
||||
.eq(CsIcdPathPO::getState, STATE_NORMAL)
|
||||
.eq(CsIcdPathPO::getType, ICD_TYPE_STANDARD));
|
||||
if (referenceIcdList == null || referenceIcdList.isEmpty()) {
|
||||
throw new IllegalArgumentException("未配置标准ICD,无法执行唯一性校验");
|
||||
}
|
||||
if (referenceIcdList.size() > 1) {
|
||||
throw new IllegalArgumentException("存在多个标准ICD,无法确定唯一参照");
|
||||
}
|
||||
return referenceIcdList.get(0);
|
||||
}
|
||||
|
||||
private Integer normalizeResult(Integer result) {
|
||||
if (result == null) {
|
||||
throw new IllegalArgumentException("校验结论不能为空");
|
||||
}
|
||||
if (result != 0 && result != 1) {
|
||||
throw new IllegalArgumentException("校验结论只能是0或1");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String requireText(String value, String message) {
|
||||
String text = trimToNull(value);
|
||||
if (text == null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String text = value.trim();
|
||||
return text.isEmpty() ? null : text;
|
||||
}
|
||||
|
||||
private boolean isBlank(String value) {
|
||||
return trimToNull(value) == null;
|
||||
}
|
||||
|
||||
private String currentUserId() {
|
||||
try {
|
||||
String userId = RequestUtil.getUserId();
|
||||
return isBlank(userId) ? "未知用户" : userId;
|
||||
} catch (Exception ex) {
|
||||
return "未知用户";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package com.njcn.gather.icd.mapping.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.gather.icd.mapping.mapper.CsDevTypeMapper;
|
||||
import com.njcn.gather.icd.mapping.mapper.CsIcdPathMapper;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsDevTypePO;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsIcdPathPO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.MmsDeviceTypeVO;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.PqdifCheckPlaceholderVO;
|
||||
import com.njcn.gather.icd.mapping.service.MmsDeviceTypeService;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备类型校验服务实现。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MmsDeviceTypeServiceImpl implements MmsDeviceTypeService {
|
||||
|
||||
private static final int STATE_NORMAL = 1;
|
||||
|
||||
private static final int ICD_TYPE_STANDARD = 1;
|
||||
|
||||
private static final String PQDIF_NOT_SUPPORTED = "NOT_SUPPORTED";
|
||||
|
||||
private final CsDevTypeMapper csDevTypeMapper;
|
||||
|
||||
private final CsIcdPathMapper csIcdPathMapper;
|
||||
|
||||
@Override
|
||||
public List<MmsDeviceTypeVO> listDeviceTypes() {
|
||||
return csDevTypeMapper.selectDeviceTypeCheckList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean saveIcdCheckResult(String devTypeId, IcdCheckResultSaveParam param) {
|
||||
if (param == null) {
|
||||
throw new IllegalArgumentException("ICD校验结果不能为空");
|
||||
}
|
||||
CsDevTypePO devType = requireDevType(devTypeId);
|
||||
if (isBlank(devType.getIcd())) {
|
||||
throw new IllegalArgumentException("设备类型未关联ICD,不能保存校验结果");
|
||||
}
|
||||
|
||||
CsIcdPathPO referenceIcd = requireUniqueReferenceIcd();
|
||||
CsIcdPathPO icdPath = csIcdPathMapper.selectById(devType.getIcd());
|
||||
if (icdPath == null || !Integer.valueOf(STATE_NORMAL).equals(icdPath.getState())) {
|
||||
throw new IllegalArgumentException("设备类型关联的ICD不存在或已删除");
|
||||
}
|
||||
|
||||
icdPath.setJsonStr(trimToNull(param.getMappingJson()));
|
||||
icdPath.setXmlStr(trimToNull(param.getXml()));
|
||||
icdPath.setResult(normalizeResult(param.getResult()));
|
||||
icdPath.setMsg(trimToNull(param.getMsg()));
|
||||
icdPath.setReferenceIcdId(referenceIcd.getId());
|
||||
icdPath.setUpdateBy(currentUserId());
|
||||
icdPath.setUpdateTime(LocalDateTime.now());
|
||||
return csIcdPathMapper.updateById(icdPath) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqdifCheckPlaceholderVO pqdifCheck(String devTypeId) {
|
||||
requireDevType(devTypeId);
|
||||
PqdifCheckPlaceholderVO result = new PqdifCheckPlaceholderVO();
|
||||
result.setStatus(PQDIF_NOT_SUPPORTED);
|
||||
result.setMessage("PQDIF校验功能待实现");
|
||||
return result;
|
||||
}
|
||||
|
||||
private CsDevTypePO requireDevType(String devTypeId) {
|
||||
String id = requireText(devTypeId, "设备类型ID不能为空");
|
||||
CsDevTypePO devType = csDevTypeMapper.selectById(id);
|
||||
if (devType == null || !Integer.valueOf(STATE_NORMAL).equals(devType.getState())) {
|
||||
throw new IllegalArgumentException("设备类型不存在或已删除");
|
||||
}
|
||||
return devType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全系统只允许一个正常状态的标准 ICD 作为唯一参照。
|
||||
*/
|
||||
private CsIcdPathPO requireUniqueReferenceIcd() {
|
||||
List<CsIcdPathPO> referenceIcdList = csIcdPathMapper.selectList(new LambdaQueryWrapper<CsIcdPathPO>()
|
||||
.eq(CsIcdPathPO::getState, STATE_NORMAL)
|
||||
.eq(CsIcdPathPO::getType, ICD_TYPE_STANDARD));
|
||||
if (referenceIcdList == null || referenceIcdList.isEmpty()) {
|
||||
throw new IllegalArgumentException("未配置标准ICD,无法执行唯一性校验");
|
||||
}
|
||||
if (referenceIcdList.size() > 1) {
|
||||
throw new IllegalArgumentException("存在多个标准ICD,无法确定唯一参照");
|
||||
}
|
||||
return referenceIcdList.get(0);
|
||||
}
|
||||
|
||||
private Integer normalizeResult(Integer result) {
|
||||
if (result == null) {
|
||||
throw new IllegalArgumentException("校验结论不能为空");
|
||||
}
|
||||
if (result != 0 && result != 1) {
|
||||
throw new IllegalArgumentException("校验结论只能是0或1");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String requireText(String value, String message) {
|
||||
String text = trimToNull(value);
|
||||
if (text == null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private String trimToNull(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String text = value.trim();
|
||||
return text.isEmpty() ? null : text;
|
||||
}
|
||||
|
||||
private boolean isBlank(String value) {
|
||||
return trimToNull(value) == null;
|
||||
}
|
||||
|
||||
private String currentUserId() {
|
||||
try {
|
||||
String userId = RequestUtil.getUserId();
|
||||
return isBlank(userId) ? "未知用户" : userId;
|
||||
} catch (Exception ex) {
|
||||
return "未知用户";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.njcn.gather.icd.mapping.component;
|
||||
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdConsistencyCheckRequest;
|
||||
import com.njcn.gather.icd.mapping.pojo.vo.IcdConsistencyCheckResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
class IcdConsistencyCheckServiceTest {
|
||||
|
||||
private final FileStorageService fileStorageService = new FileStorageService();
|
||||
private final IcdConsistencyCheckService service = new IcdConsistencyCheckService(fileStorageService);
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void checkShouldReturnMismatchIssuesAndCorrectedJsonWithoutSavedPath() throws Exception {
|
||||
IcdConsistencyCheckRequest request = new IcdConsistencyCheckRequest();
|
||||
request.setStandardJson(buildStandardJson());
|
||||
request.setCheckedJson(buildCheckedJson());
|
||||
request.setSaveToDisk(true);
|
||||
request.setOutputDir(tempDir.toString());
|
||||
|
||||
IcdConsistencyCheckResponse response = service.check(request);
|
||||
|
||||
Assertions.assertEquals(0, response.getResult());
|
||||
Assertions.assertEquals("不符合", response.getMessage());
|
||||
Assertions.assertFalse(response.getIssues().isEmpty());
|
||||
Assertions.assertTrue(response.getIssuesJson().contains("ReportMap"));
|
||||
Assertions.assertTrue(response.getCorrectedJson().contains("\"unit\" : \"s\""));
|
||||
Assertions.assertTrue(response.getCorrectedJson().contains("\"reportCount\" : 2"));
|
||||
Assertions.assertTrue(response.getCorrectedJson().contains("\"start\" : 1"));
|
||||
Assertions.assertTrue(response.getCorrectedJson().contains("\"end\" : 4"));
|
||||
Assertions.assertTrue(Files.list(tempDir).findAny().isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkShouldReturnPassWhenCheckedJsonMatchesStandardJson() {
|
||||
IcdConsistencyCheckRequest request = new IcdConsistencyCheckRequest();
|
||||
request.setStandardJson(buildStandardJson());
|
||||
request.setCheckedJson(buildStandardJson());
|
||||
|
||||
IcdConsistencyCheckResponse response = service.check(request);
|
||||
|
||||
Assertions.assertEquals(1, response.getResult());
|
||||
Assertions.assertEquals("符合", response.getMessage());
|
||||
Assertions.assertTrue(response.getIssues().isEmpty());
|
||||
Assertions.assertNull(response.getCorrectedJson());
|
||||
}
|
||||
|
||||
private String buildStandardJson() {
|
||||
return "{\n" +
|
||||
" \"IED\":\"IED1\",\n" +
|
||||
" \"LD\":\"LD0\",\n" +
|
||||
" \"DataType\":\"1\",\n" +
|
||||
" \"unit\":\"s\",\n" +
|
||||
" \"ReportMap\":[\n" +
|
||||
" {\"desc\":\"统计数据\",\"reportCount\":2,\"rptID\":\"rpt-stat\",\"name\":\"brcbStat\",\"buffered\":\"BR\",\"inst\":\"01\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"波动闪变\",\"reportCount\":1,\"rptID\":\"rpt-flk\",\"name\":\"brcbFlk\",\"buffered\":\"BR\",\"inst\":\"02\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"实时数据\",\"reportCount\":1,\"rptID\":\"rpt-rt\",\"name\":\"brcbRt\",\"buffered\":\"RP\",\"inst\":\"03\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"暂态事件\",\"reportCount\":1,\"rptID\":\"rpt-tran\",\"name\":\"brcbTran\",\"buffered\":\"BR\",\"inst\":\"04\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"}\n" +
|
||||
" ],\n" +
|
||||
" \"DataSetList\":[\n" +
|
||||
buildDataSet("MMXU", "统计数据", "1", "A相", "Hz", "频率", 1, 4, "Hz") + ",\n" +
|
||||
buildDataSet("MSQI", "实时数据", "1", "A相", "A", "电流", 1, 2, "A") + ",\n" +
|
||||
buildDataSet("MHAI", "谐波数据", "1", "A相", "Har", "谐波", 1, 2, "%") + ",\n" +
|
||||
buildDataSet("MFLK", "波动闪变", "1", "A相", "Flk", "闪变", 1, 2, "pu") + "\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
private String buildCheckedJson() {
|
||||
return "{\n" +
|
||||
" \"IED\":\"IED1\",\n" +
|
||||
" \"LD\":\"LD0\",\n" +
|
||||
" \"DataType\":\"1\",\n" +
|
||||
" \"unit\":\"ms\",\n" +
|
||||
" \"ReportMap\":[\n" +
|
||||
" {\"desc\":\"统计数据\",\"reportCount\":1,\"rptID\":\"rpt-stat\",\"name\":\"brcbStat\",\"buffered\":\"BR\",\"inst\":\"01\",\"FlickerFlag\":\"0\",\"Select\":\"part\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"波动闪变\",\"reportCount\":1,\"rptID\":\"rpt-flk\",\"name\":\"brcbFlk\",\"buffered\":\"BR\",\"inst\":\"02\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"实时数据\",\"reportCount\":1,\"rptID\":\"rpt-rt\",\"name\":\"brcbRt\",\"buffered\":\"RP\",\"inst\":\"03\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"},\n" +
|
||||
" {\"desc\":\"暂态事件\",\"reportCount\":1,\"rptID\":\"rpt-tran\",\"name\":\"brcbTran\",\"buffered\":\"BR\",\"inst\":\"04\",\"FlickerFlag\":\"0\",\"Select\":\"all\",\"TrgOps\":\"dchg\"}\n" +
|
||||
" ],\n" +
|
||||
" \"DataSetList\":[\n" +
|
||||
buildDataSet("MMXU", "统计数据", "1", "A相", "Hz", "频率", 3, 6, "Hz") + ",\n" +
|
||||
buildDataSet("MSQI", "实时数据", "1", "A相", "A", "电流", 1, 2, "A") + ",\n" +
|
||||
buildDataSet("MHAI", "谐波数据", "1", "A相", "Har", "谐波", 1, 2, "%") + ",\n" +
|
||||
buildDataSet("MFLK", "波动闪变", "1", "A相", "Flk", "闪变", 1, 2, "pu") + "\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
private String buildDataSet(String lnClass, String groupDesc, String inst, String instDesc,
|
||||
String doiName, String doiDesc, int start, int end, String unit) {
|
||||
return " {\"desc\":\"" + groupDesc + "\",\"lnClass\":\"" + lnClass + "\",\"instList\":[{\"inst\":\"" + inst +
|
||||
"\",\"desc\":\"" + instDesc + "\",\"doiList\":[{\"name\":\"" + doiName + "\",\"desc\":\"" + doiDesc +
|
||||
"\",\"start\":" + start + ",\"end\":" + end + ",\"unit\":\"" + unit +
|
||||
"\",\"coefficient\":1.0,\"baseflag\":1,\"basecount\":1,\"icdcout\":10,\"sdiList\":[{\"name\":\"mag\",\"desc\":\"幅值\",\"typeList\":[{\"name\":\"f\",\"desc\":\"浮点\"}]}]}]}]}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package com.njcn.gather.icd.mapping.service.impl;
|
||||
|
||||
import com.njcn.gather.icd.mapping.mapper.CsIcdPathMapper;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.CsIcdPathParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.param.IcdCheckResultSaveParam;
|
||||
import com.njcn.gather.icd.mapping.pojo.po.CsIcdPathPO;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class CsIcdPathServiceImplTest {
|
||||
|
||||
private final CsIcdPathMapper csIcdPathMapper = mock(CsIcdPathMapper.class);
|
||||
private final CsIcdPathServiceImpl service = new CsIcdPathServiceImpl(csIcdPathMapper);
|
||||
|
||||
@Test
|
||||
void listIcdPathsShouldTrimKeywordBeforeQuery() {
|
||||
CsIcdPathParam.ListParam param = new CsIcdPathParam.ListParam();
|
||||
param.setKeyword(" standard ");
|
||||
|
||||
service.listIcdPaths(param);
|
||||
|
||||
verify(csIcdPathMapper).selectIcdPathList(eq("standard"), eq(null), eq(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void addIcdPathShouldInsertEnabledRecord() {
|
||||
CsIcdPathParam param = buildParam("标准ICD");
|
||||
when(csIcdPathMapper.insert(any(CsIcdPathPO.class))).thenReturn(1);
|
||||
|
||||
boolean result = service.addIcdPath(param);
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper).insert(captor.capture());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertEquals("标准ICD", captor.getValue().getName());
|
||||
Assertions.assertEquals("D:/icd/standard.icd", captor.getValue().getPath());
|
||||
Assertions.assertEquals(1, captor.getValue().getState());
|
||||
Assertions.assertNotNull(captor.getValue().getId());
|
||||
Assertions.assertNotNull(captor.getValue().getCreateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addIcdPathShouldSaveIcdBinaryContent() {
|
||||
CsIcdPathParam param = buildParam("标准ICD");
|
||||
byte[] fileContent = "<SCL></SCL>".getBytes();
|
||||
param.setIcdContent(fileContent);
|
||||
when(csIcdPathMapper.insert(any(CsIcdPathPO.class))).thenReturn(1);
|
||||
|
||||
boolean result = service.addIcdPath(param);
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper).insert(captor.capture());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertArrayEquals(fileContent, captor.getValue().getIcdContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateIcdPathShouldRejectDeletedRecord() {
|
||||
CsIcdPathParam.UpdateParam param = new CsIcdPathParam.UpdateParam();
|
||||
param.setId("icd-001");
|
||||
param.setName("标准ICD");
|
||||
param.setPath("D:/icd/standard.icd");
|
||||
|
||||
CsIcdPathPO deleted = new CsIcdPathPO();
|
||||
deleted.setId("icd-001");
|
||||
deleted.setState(0);
|
||||
when(csIcdPathMapper.selectById(eq("icd-001"))).thenReturn(deleted);
|
||||
|
||||
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class,
|
||||
() -> service.updateIcdPath(param));
|
||||
|
||||
Assertions.assertEquals("ICD记录不存在或已删除", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateIcdPathShouldSaveIcdBinaryContentWhenProvided() {
|
||||
CsIcdPathParam.UpdateParam param = new CsIcdPathParam.UpdateParam();
|
||||
byte[] fileContent = "<SCL version=\"1\"></SCL>".getBytes();
|
||||
param.setId("icd-001");
|
||||
param.setName("标准ICD");
|
||||
param.setPath("standard.icd");
|
||||
param.setIcdContent(fileContent);
|
||||
|
||||
CsIcdPathPO existed = new CsIcdPathPO();
|
||||
existed.setId("icd-001");
|
||||
existed.setState(1);
|
||||
when(csIcdPathMapper.selectById(eq("icd-001"))).thenReturn(existed);
|
||||
when(csIcdPathMapper.updateById(any(CsIcdPathPO.class))).thenReturn(1);
|
||||
|
||||
boolean result = service.updateIcdPath(param);
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper).updateById(captor.capture());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertArrayEquals(fileContent, captor.getValue().getIcdContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteIcdPathShouldMarkRecordDeleted() {
|
||||
when(csIcdPathMapper.update(any(CsIcdPathPO.class), any())).thenReturn(1);
|
||||
|
||||
boolean result = service.deleteIcdPath(Collections.singletonList("icd-001"));
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper).update(captor.capture(), any());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertEquals(0, captor.getValue().getState());
|
||||
Assertions.assertNotNull(captor.getValue().getUpdateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void activateIcdPathShouldOnlyKeepTargetAsStandardIcd() {
|
||||
CsIcdPathPO icdPath = new CsIcdPathPO();
|
||||
icdPath.setId("icd-001");
|
||||
icdPath.setState(1);
|
||||
when(csIcdPathMapper.selectById(eq("icd-001"))).thenReturn(icdPath);
|
||||
when(csIcdPathMapper.update(any(CsIcdPathPO.class), any())).thenReturn(1);
|
||||
|
||||
boolean result = service.activateIcdPath("icd-001");
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper, times(2)).update(captor.capture(), any());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertNull(captor.getAllValues().get(0));
|
||||
Assertions.assertEquals(1, captor.getAllValues().get(1).getType());
|
||||
Assertions.assertNotNull(captor.getAllValues().get(1).getUpdateTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveIcdCheckResultShouldUpdateIcdRecord() {
|
||||
CsIcdPathPO referenceIcd = new CsIcdPathPO();
|
||||
referenceIcd.setId("reference-icd");
|
||||
when(csIcdPathMapper.selectList(any())).thenReturn(Collections.singletonList(referenceIcd));
|
||||
|
||||
CsIcdPathPO icdPath = new CsIcdPathPO();
|
||||
icdPath.setId("icd-001");
|
||||
icdPath.setState(1);
|
||||
when(csIcdPathMapper.selectById(eq("icd-001"))).thenReturn(icdPath);
|
||||
when(csIcdPathMapper.updateById(any(CsIcdPathPO.class))).thenReturn(1);
|
||||
|
||||
IcdCheckResultSaveParam param = new IcdCheckResultSaveParam();
|
||||
param.setMappingJson("{}");
|
||||
param.setXml("<xml/>");
|
||||
param.setResult(1);
|
||||
param.setMsg("通过");
|
||||
|
||||
boolean result = service.saveIcdCheckResult("icd-001", param);
|
||||
|
||||
ArgumentCaptor<CsIcdPathPO> captor = ArgumentCaptor.forClass(CsIcdPathPO.class);
|
||||
verify(csIcdPathMapper).updateById(captor.capture());
|
||||
Assertions.assertTrue(result);
|
||||
Assertions.assertEquals("reference-icd", captor.getValue().getReferenceIcdId());
|
||||
Assertions.assertEquals(1, captor.getValue().getResult());
|
||||
}
|
||||
|
||||
private CsIcdPathParam buildParam(String name) {
|
||||
CsIcdPathParam param = new CsIcdPathParam();
|
||||
param.setName(name);
|
||||
param.setPath("D:/icd/standard.icd");
|
||||
param.setAngle(0);
|
||||
param.setUsePhaseIndex(1);
|
||||
param.setType(1);
|
||||
return param;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user