Commit fe6ce699 authored by tianyiming's avatar tianyiming

Merge remote-tracking branch 'origin/develop_tzs_register' into develop_tzs_register

parents b6a346f4 f8c94a36
package com.yeejoin.amos.boot.module.jg.api.common;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipInfoExcelDto;
import lombok.experimental.UtilityClass;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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
*/
@UtilityClass
public class DataDockTemplateVersionUtils {
/**
* 错误提示
*/
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));
}
/**
* 校验上传的文件是否使用正确版本的模板
*
*
* @param file file
* @author yangyang
* @date 2025/7/4 15:19
*/
public static String checkTemplateVersion(MultipartFile file) throws IOException {
byte[] fileBytes = file.getBytes();
ExcelReader excelReader = EasyExcel.read(new ByteArrayInputStream(fileBytes)).build();
List<ReadSheet> sheetList = excelReader.excelExecutor().sheetList(); // 获取所有 sheet
return checkTemplateVersion(file, sheetList);
}
public static String checkTemplateVersion(MultipartFile file, List<ReadSheet> sheetList) throws IOException {
byte[] fileBytes = file.getBytes();
List<String> errorMessages = new ArrayList<>(1);
for (ReadSheet readSheet : sheetList) {
String sheetName = readSheet.getSheetName();
if (!sheetName.contains("版本信息")) {
continue;
}
int sheetNo = readSheet.getSheetNo();
EasyExcel.read(new ByteArrayInputStream(fileBytes), EquipInfoExcelDto.class, new AnalysisEventListener<EquipInfoExcelDto>() {
@Override
public void invoke(EquipInfoExcelDto data, AnalysisContext context) {
if (!DataDockTemplateVersionUtils.isSameVersion(data.getTemplateKey(), data.getTemplateVersion())) {
errorMessages.add(DataDockTemplateVersionUtils.ERROR_MESSAGE);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}).headRowNumber(1).sheet(sheetNo, sheetName).doRead();
}
return ValidationUtil.isEmpty(errorMessages) ? "" : errorMessages.get(0);
}
}
...@@ -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
...@@ -27,6 +27,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ExcelImportErrorLogDao; ...@@ -27,6 +27,7 @@ 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.common.biz.refresh.DataRefreshEvent; import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersionUtils;
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;
...@@ -781,6 +782,11 @@ public class DataDockServiceImpl { ...@@ -781,6 +782,11 @@ 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
// 判断模板版本号
String templateVersionError = DataDockTemplateVersionUtils.checkTemplateVersion(file, sheetList);
if (!ValidationUtil.isEmpty(templateVersionError)) {
throw new BadRequest(templateVersionError);
}
for (ReadSheet readSheet : sheetList) { for (ReadSheet readSheet : sheetList) {
String sheetName = readSheet.getSheetName(); String sheetName = readSheet.getSheetName();
...@@ -1581,6 +1587,12 @@ public class DataDockServiceImpl { ...@@ -1581,6 +1587,12 @@ public class DataDockServiceImpl {
List<String> resultGDError = new ArrayList<>(); List<String> resultGDError = new ArrayList<>();
List<String> pipelineNumList = new ArrayList<>(); List<String> pipelineNumList = new ArrayList<>();
try { try {
// 判断模板版本号
String templateVersionError = DataDockTemplateVersionUtils.checkTemplateVersion(multipartFile);
if (!ValidationUtil.isEmpty(templateVersionError)) {
resultGDError.add(templateVersionError);
throw new BadRequest(templateVersionError);
}
EasyExcel.read(multipartFile.getInputStream(), PipingExcelDto.class, new AnalysisEventListener<PipingExcelDto>() { EasyExcel.read(multipartFile.getInputStream(), PipingExcelDto.class, new AnalysisEventListener<PipingExcelDto>() {
@Override @Override
public void invoke(PipingExcelDto data, AnalysisContext context) { public void invoke(PipingExcelDto data, AnalysisContext context) {
...@@ -2893,4 +2905,5 @@ public class DataDockServiceImpl { ...@@ -2893,4 +2905,5 @@ public class DataDockServiceImpl {
equ.put("inspectConclusion",inspectionDetectionInfo.getInspectConclusion()); equ.put("inspectConclusion",inspectionDetectionInfo.getInspectConclusion());
} }
} }
} }
...@@ -28,6 +28,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory; ...@@ -28,6 +28,7 @@ import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
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.biz.refresh.DataRefreshEvent; import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.common.biz.service.impl.EquipmentCategoryService; import com.yeejoin.amos.boot.module.common.biz.service.impl.EquipmentCategoryService;
import com.yeejoin.amos.boot.module.jg.api.common.DataDockTemplateVersionUtils;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.entity.*; import com.yeejoin.amos.boot.module.jg.api.entity.*;
import com.yeejoin.amos.boot.module.jg.api.enums.*; import com.yeejoin.amos.boot.module.jg.api.enums.*;
...@@ -3923,6 +3924,12 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste ...@@ -3923,6 +3924,12 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
equCodeList.clear(); equCodeList.clear();
factoryNumList.clear(); factoryNumList.clear();
try { try {
// 判断模板版本号
String templateVersionError = DataDockTemplateVersionUtils.checkTemplateVersion(multipartFile);
if (!ValidationUtil.isEmpty(templateVersionError)) {
resultError.add(templateVersionError);
throw new BadRequest(templateVersionError);
}
EasyExcel.read(multipartFile.getInputStream(), EquipInfoCylinderExcelDto.class, new AnalysisEventListener<EquipInfoCylinderExcelDto>() { EasyExcel.read(multipartFile.getInputStream(), EquipInfoCylinderExcelDto.class, new AnalysisEventListener<EquipInfoCylinderExcelDto>() {
// 每读取一行就调用该方法 // 每读取一行就调用该方法
@Override @Override
......
...@@ -55,6 +55,7 @@ import org.springframework.util.ObjectUtils; ...@@ -55,6 +55,7 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.component.emq.EmqKeeper; import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.exception.BaseException;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; 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;
...@@ -1957,7 +1958,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -1957,7 +1958,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
public JSONArray queryTechParam(String type) { public JSONArray queryTechParam(String type) {
if (ValidationUtil.isEmpty(type)) { if (ValidationUtil.isEmpty(type)) {
throw new BadRequest("需要先选择设备品种,才能选择技术参数"); throw new BaseException("需要先选择设备品种,才能选择技术参数","200","需要先选择设备品种,才能选择技术参数");
} }
List<TechParamItem> paramMetaList = TechParamUtil.getParamMetaList(type); List<TechParamItem> paramMetaList = TechParamUtil.getParamMetaList(type);
JSONArray list = new JSONArray(); JSONArray list = new JSONArray();
......
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