Commit e172ebd9 authored by yangyang's avatar yangyang

feat(data-dock): 添加数据对接模板版本校验功能

- 新增 DataDockTemplateVersion 类用于管理模板版本信息 - 在 EquipInfoExcelDto 中添加模板 Key 和版本号字段 - 在 DataDockServiceImpl 中实现模板版本校验逻辑- 通过版本信息隐藏 sheet维护模板版本,上传时进行版本对比
parent 02fa5621
package com.yeejoin.amos.boot.module.jg.api.common;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.HashMap;
import java.util.Map;
/**
* 批量版本控制
* <p>
* 每个下载模板新建名为“版本信息”的隐藏sheet, sheet内维护模板的版本信息, 每次上传前与模板的版本进行对比,不一致则返回错误信息
* <p>
* ProjectName: amos-boot-biz
* PackageName: com.yeejoin.amos.boot.module.jg.api.common
*
* @author yangyang
* @version v1.0
* @date 2025/7/4 13:44
*/
public class DataDockTemplateVersion {
/**
* 错误提示
*/
public static final String ERROR_MESSAGE = "数据上传模板有更新了,请您下载最新的梳理数据上传!";
public static final Map<String, String> VERSION_MAP = new HashMap<>();
static {
VERSION_MAP.put("工业管道设备", "V1.0.0");
VERSION_MAP.put("公用管道设备", "V1.0.0");
VERSION_MAP.put("历史无证_压力容器设备_氧舱", "V1.0.0");
VERSION_MAP.put("历史无证设备_场内机动车辆", "V1.0.0");
VERSION_MAP.put("历史无证设备_电梯设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_管道设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_锅炉设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_起重机械设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_索道设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_压力容器设备_固定式", "V1.0.0");
VERSION_MAP.put("历史无证设备_压力容器设备", "V1.0.0");
VERSION_MAP.put("历史无证设备_游乐设施设备", "V1.0.0");
VERSION_MAP.put("历史有证_场内机动车辆", "V1.0.0");
VERSION_MAP.put("历史有证_电梯设备", "V1.0.0");
VERSION_MAP.put("历史有证_管道设备", "V1.0.0");
VERSION_MAP.put("历史有证_锅炉设备", "V1.0.0");
VERSION_MAP.put("历史有证_起重机械设备", "V1.0.0");
VERSION_MAP.put("历史有证_索道设备", "V1.0.0");
VERSION_MAP.put("历史有证_压力容器设备_固定式", "V1.0.0");
VERSION_MAP.put("历史有证_压力容器设备_氧舱", "V1.0.0");
VERSION_MAP.put("历史有证_压力容器设备", "V1.0.0");
VERSION_MAP.put("历史有证_游乐设施设备", "V1.0.0");
VERSION_MAP.put("新设备_场内机动车辆", "V1.0.0");
VERSION_MAP.put("新设备_电梯设备", "V1.0.0");
VERSION_MAP.put("新设备_管道设备", "V1.0.0");
VERSION_MAP.put("新设备_锅炉设备", "V1.0.0");
VERSION_MAP.put("新设备_起重机械设备", "V1.0.0");
VERSION_MAP.put("新设备_索道设备", "V1.0.0");
VERSION_MAP.put("新设备_压力容器设备_固定式", "V1.0.0");
VERSION_MAP.put("新设备_压力容器设备_氧舱", "V1.0.0");
VERSION_MAP.put("新设备_游乐设施设备", "V1.0.0");
VERSION_MAP.put("压力容器设备", "V1.0.0");
VERSION_MAP.put("长输管道设备", "V1.0.0");
}
/**
* 比较版本号是否一致
*
* @param key key
* @param version version
* @return {@link boolean}
* @author yangyang
* @date 2025/7/4 15:17
*/
public static boolean isSameVersion(String key, String version) {
if (ValidationUtil.isEmpty(key) || ValidationUtil.isEmpty(version)) {
return false;
}
if (!VERSION_MAP.containsKey(key)) {
return false;
}
return version.equals(VERSION_MAP.get(key));
}
}
...@@ -1124,4 +1124,13 @@ public class EquipInfoExcelDto extends BaseDto { ...@@ -1124,4 +1124,13 @@ public class EquipInfoExcelDto extends BaseDto {
@ApiModelProperty(value = "管道级别") @ApiModelProperty(value = "管道级别")
@ExcelIgnore @ExcelIgnore
private String deviceLevel_GD; private String deviceLevel_GD;
//--------------------------------------------------------------版本信息
@ExcelProperty(value = "模板Key")
@ApiModelProperty(value = "模板Key")
private String templateKey;
@ExcelProperty(value = "版本号")
@ApiModelProperty(value = "版本号")
private String templateVersion;
} }
\ No newline at end of file
...@@ -26,6 +26,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory; ...@@ -26,6 +26,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dao.ExcelImportErrorLogDao; import com.yeejoin.amos.boot.module.common.api.dao.ExcelImportErrorLogDao;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto; import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.api.dto.ExcelImportErrorLogDto; import com.yeejoin.amos.boot.module.common.api.dto.ExcelImportErrorLogDto;
import com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersion;
import com.yeejoin.amos.boot.module.jg.api.converter.DictParamsConverter; import com.yeejoin.amos.boot.module.jg.api.converter.DictParamsConverter;
import com.yeejoin.amos.boot.module.jg.api.converter.EquCategoryConverter; import com.yeejoin.amos.boot.module.jg.api.converter.EquCategoryConverter;
import com.yeejoin.amos.boot.module.jg.api.converter.EquDefineConverter; import com.yeejoin.amos.boot.module.jg.api.converter.EquDefineConverter;
...@@ -75,6 +76,7 @@ import org.typroject.tyboot.core.foundation.utils.ValidationUtil; ...@@ -75,6 +76,7 @@ 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 org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.sql.Timestamp; import java.sql.Timestamp;
...@@ -779,6 +781,7 @@ public class DataDockServiceImpl { ...@@ -779,6 +781,7 @@ public class DataDockServiceImpl {
InputStream inputStream = file.getInputStream(); InputStream inputStream = file.getInputStream();
ExcelReader excelReader = EasyExcel.read(inputStream).build(); ExcelReader excelReader = EasyExcel.read(inputStream).build();
List<ReadSheet> sheetList = excelReader.excelExecutor().sheetList(); // 获取所有 sheet List<ReadSheet> sheetList = excelReader.excelExecutor().sheetList(); // 获取所有 sheet
checkTemplateVersion(file, sheetList);
for (ReadSheet readSheet : sheetList) { for (ReadSheet readSheet : sheetList) {
String sheetName = readSheet.getSheetName(); String sheetName = readSheet.getSheetName();
...@@ -2889,4 +2892,42 @@ public class DataDockServiceImpl { ...@@ -2889,4 +2892,42 @@ public class DataDockServiceImpl {
equ.put("inspectConclusion",inspectionDetectionInfo.getInspectConclusion()); equ.put("inspectConclusion",inspectionDetectionInfo.getInspectConclusion());
} }
} }
/**
* 校验上传的文件是否使用正确版本的模板
*
*
* @param file file
* @param sheetList sheetList
* @author yangyang
* @date 2025/7/4 15:19
*/
private void checkTemplateVersion(MultipartFile file, List<ReadSheet> sheetList) throws IOException {
List<String> errorMessages = new ArrayList<>(1);
for (ReadSheet readSheet : sheetList) {
String sheetName = readSheet.getSheetName();
if (!sheetName.contains("版本信息")) {
continue;
}
int sheetNo = readSheet.getSheetNo();
EasyExcel.read(file.getInputStream(), EquipInfoExcelDto.class, new AnalysisEventListener<EquipInfoExcelDto>() {
@Override
public void invoke(EquipInfoExcelDto data, AnalysisContext context) {
if (!DataDockTemplateVersion.isSameVersion(data.getTemplateKey(), data.getTemplateVersion())) {
errorMessages.add(DataDockTemplateVersion.ERROR_MESSAGE);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}).headRowNumber(1).sheet(sheetNo, sheetName).doRead();
}
if (!ValidationUtil.isEmpty(errorMessages)) {
throw new BadRequest(JSON.toJSONString(errorMessages));
}
}
} }
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