Browse Source

importBarFiles修改

jwy
review512jwy@163.com 4 days ago
parent
commit
937f7bd68d
  1. 2
      data-center-business-controller/src/main/java/com/techsor/datacenter/business/controller/MonitoringAssetController.java
  2. 111
      data-center-business-service/src/main/java/com/techsor/datacenter/business/service/async/AsyncExcelProcessingService.java
  3. 68
      data-center-business-util/src/main/java/com/techsor/datacenter/business/util/CommonUtil.java

2
data-center-business-controller/src/main/java/com/techsor/datacenter/business/controller/MonitoringAssetController.java

@ -314,7 +314,7 @@ public class MonitoringAssetController {
@Operation(summary = "import pdfs and images")
@RequestMapping(value = "/edit/importBarFiles", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public SimpleDataResponse uploadBarFiles(
public SimpleDataResponse importBarFiles(
@RequestPart("files") MultipartFile detailFile,
@Parameter(name="wsClientId", description = "websocket client id", required = false) @RequestParam(required = true) String wsClientId,
@Parameter(name="LoginName", description ="Login name", required=true, schema = @Schema(defaultValue = "admin")) @RequestHeader(required=true) String LoginName,

111
data-center-business-service/src/main/java/com/techsor/datacenter/business/service/async/AsyncExcelProcessingService.java

@ -6,6 +6,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import com.techsor.datacenter.business.util.CommonUtil;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
@ -99,15 +101,6 @@ public class AsyncExcelProcessingService {
BasicSpace space = new BasicSpace();
space.setSpaceId(oldSpace.getSpaceId());
// 处理旧图片
String oldImagesIntroduction = oldSpace.getImagesIntroduction();
if(StringUtils.isNotBlank(oldImagesIntroduction)) {
Map<String, S3FileInfoEntity> oldImages = JSON.parseObject(oldImagesIntroduction, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldImages.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
/**20250515需求,直接更新旧数据,不用保留原来的文件**/
Map<String, S3FileInfoEntity> newImagesMap = new HashMap<>();
@ -130,7 +123,17 @@ public class AsyncExcelProcessingService {
baseDir.resolve("img"), currentUnix, languageType, storageS3FolderImage, s3FileMapping);
setImgDescription(newImagesMap, img3Name, img3Description);
space.setImagesIntroduction(JSON.toJSONString(newImagesMap));
if (MapUtils.isNotEmpty(newImagesMap)) {
space.setImagesIntroduction(JSON.toJSONString(newImagesMap));
// 处理旧图片
String oldImagesIntroduction = oldSpace.getImagesIntroduction();
if(StringUtils.isNotBlank(oldImagesIntroduction)) {
Map<String, S3FileInfoEntity> oldImages = JSON.parseObject(oldImagesIntroduction, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldImages.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
}
// 处理PDF
processAndSetPdfEquipment(space, oldSpace, row, columnIndices, languageType, baseDir, currentUnix, "buildingDevice",
@ -146,7 +149,9 @@ public class AsyncExcelProcessingService {
processAndSetPdfEquipment(space, oldSpace, row, columnIndices, languageType, baseDir, currentUnix, "otherDevice",
"getPdfOtherEquipment", "setPdfOtherEquipment", s3FileMapping, storageS3FolderPdf);
basicSpaceMapperExt.updateByPrimaryKeySelective(space);
if (CommonUtil.hasAnyOtherFieldNotEmpty(space, "spaceId")) {
basicSpaceMapperExt.updateByPrimaryKeySelective(space);
}
}
@ -181,24 +186,26 @@ public class AsyncExcelProcessingService {
private void processAndSetPdfEquipment(BasicSpace space, SpacePageVO oldSpace, Row row, Map<String, Integer> columnIndices,
Integer languageType, Path baseDir, long currentUnix, String equipmentType,
String getterMethod, String setterMethod, Map<String, String> s3FileMapping, String storageS3FolderPdf) throws Exception {
// 获取旧设备数据
String oldPdfEquipment = (String) oldSpace.getClass().getMethod(getterMethod).invoke(oldSpace);
if (StringUtils.isNotBlank(oldPdfEquipment)) {
Map<String, S3FileInfoEntity> oldPdfEquipmentMap = JSON.parseObject(oldPdfEquipment, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldPdfEquipmentMap.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
// 处理文件
/**20250515需求,直接更新旧数据,不用保留原来的文件**/
Map<String, S3FileInfoEntity> newPdfEquipmentMap = new HashMap<>();
commonOpt.processFile(newPdfEquipmentMap,
commonOpt.getCellValue(row.getCell(columnIndices.get(msgLanguageChange.getParameterMapByCode(languageType, equipmentType)))),
baseDir.resolve("pdf"), currentUnix, languageType, storageS3FolderPdf, s3FileMapping);
// 设置更新后的设备数据
space.getClass().getMethod(setterMethod, String.class).invoke(space, JSON.toJSONString(newPdfEquipmentMap));
if (MapUtils.isNotEmpty(newPdfEquipmentMap)) {
// 设置更新后的设备数据
space.getClass().getMethod(setterMethod, String.class).invoke(space, JSON.toJSONString(newPdfEquipmentMap));
// 删除旧设备数据
String oldPdfEquipment = (String) oldSpace.getClass().getMethod(getterMethod).invoke(oldSpace);
if (StringUtils.isNotBlank(oldPdfEquipment)) {
Map<String, S3FileInfoEntity> oldPdfEquipmentMap = JSON.parseObject(oldPdfEquipment, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldPdfEquipmentMap.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
}
}
@ -247,15 +254,6 @@ public class AsyncExcelProcessingService {
BasicMonitoringAsset asset = new BasicMonitoringAsset();
asset.setEquipmentId(oldAsset.getAssetId());
// 处理图片
String oldImagesIntroduction = oldAsset.getImagesIntroduction();
if(StringUtils.isNotBlank(oldImagesIntroduction)) {
Map<String, S3FileInfoEntity> oldImages = JSON.parseObject(oldImagesIntroduction, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldImages.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
Map<String, S3FileInfoEntity> newImagesMap = new HashMap<>();
@ -276,17 +274,29 @@ public class AsyncExcelProcessingService {
commonOpt.processFile(newImagesMap, img3Name,
baseDir.resolve("img"), currentUnix, languageType, storageS3FolderImage, s3FileMapping);
setImgDescription(newImagesMap, img3Name, img3Description);
asset.setImagesIntroduction(JSON.toJSONString(newImagesMap));
if (MapUtils.isNotEmpty(newImagesMap)) {
asset.setImagesIntroduction(JSON.toJSONString(newImagesMap));
// 处理图片
String oldImagesIntroduction = oldAsset.getImagesIntroduction();
if(StringUtils.isNotBlank(oldImagesIntroduction)) {
Map<String, S3FileInfoEntity> oldImages = JSON.parseObject(oldImagesIntroduction, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldImages.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
}
// 处理PDF
processAndSetPdfEquipment(asset, oldAsset, row, columnIndices, languageType, baseDir, currentUnix, "userManual",
"getPdfUserManual", "setPdfUserManual", s3FileMapping, storageS3FolderPdf);
processAndSetPdfEquipment(asset, oldAsset, row, columnIndices, languageType, baseDir, currentUnix, "deviceFile",
"getPdfDeviceImage", "setPdfDeviceImage", s3FileMapping, storageS3FolderPdf);
basicMonitoringAssetMapperExt.updateByPrimaryKeySelective(asset);
if (CommonUtil.hasAnyOtherFieldNotEmpty(asset, "equipmentId")) {
basicMonitoringAssetMapperExt.updateByPrimaryKeySelective(asset);
}
}
@ -309,23 +319,24 @@ public class AsyncExcelProcessingService {
private void processAndSetPdfEquipment(BasicMonitoringAsset asset, MonitoringAssetPageVO oldAsset, Row row, Map<String, Integer> columnIndices,
Integer languageType, Path baseDir, long currentUnix, String equipmentType,
String getterMethod, String setterMethod, Map<String, String> s3FileMapping, String storageS3FolderPdf) throws Exception {
// 获取旧设备数据
String oldPdfEquipment = (String) oldAsset.getClass().getMethod(getterMethod).invoke(oldAsset);
if (StringUtils.isNotBlank(oldPdfEquipment)) {
Map<String, S3FileInfoEntity> oldPdfEquipmentMap = JSON.parseObject(oldPdfEquipment, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldPdfEquipmentMap.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
// 处理文件
Map<String, S3FileInfoEntity> newPdfEquipmentMap = new HashMap<>();
commonOpt.processFile(newPdfEquipmentMap,
commonOpt.getCellValue(row.getCell(columnIndices.get(msgLanguageChange.getParameterMapByCode(languageType, equipmentType)))),
baseDir.resolve("pdf"), currentUnix, languageType, storageS3FolderPdf, s3FileMapping);
// 设置更新后的设备数据
asset.getClass().getMethod(setterMethod, String.class).invoke(asset, JSON.toJSONString(newPdfEquipmentMap));
if (MapUtils.isNotEmpty(newPdfEquipmentMap)) {
// 设置更新后的设备数据
asset.getClass().getMethod(setterMethod, String.class).invoke(asset, JSON.toJSONString(newPdfEquipmentMap));
// 删除旧设备数据
String oldPdfEquipment = (String) oldAsset.getClass().getMethod(getterMethod).invoke(oldAsset);
if (StringUtils.isNotBlank(oldPdfEquipment)) {
Map<String, S3FileInfoEntity> oldPdfEquipmentMap = JSON.parseObject(oldPdfEquipment, new TypeReference<Map<String, S3FileInfoEntity>>() {});
for (Map.Entry<String, S3FileInfoEntity> entry : oldPdfEquipmentMap.entrySet()) {
commonOpt.deleteS3File(entry.getValue().getS3Path());
}
}
}
}

68
data-center-business-util/src/main/java/com/techsor/datacenter/business/util/CommonUtil.java

@ -1,5 +1,6 @@
package com.techsor.datacenter.business.util;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
@ -837,4 +838,71 @@ public class CommonUtil {
}
/**
* 判断除指定字段外是否所有字段都为空
*
* @param obj 校验对象
* @param excludeFields 排除字段名 spaceId / equipmentId
* @return true = 其它字段全部为空
*/
public static boolean allOtherFieldsEmpty(Object obj, String... excludeFields) {
if (obj == null) {
return true;
}
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {
String fieldName = field.getName();
// 跳过 serialVersionUID
if ("serialVersionUID".equals(fieldName)) {
continue;
}
boolean skip = false;
if (excludeFields != null) {
for (String exclude : excludeFields) {
if (exclude.equals(fieldName)) {
skip = true;
break;
}
}
}
if (skip) {
continue;
}
field.setAccessible(true);
try {
Object value = field.get(obj);
if (value == null) {
continue;
}
if (value instanceof String) {
if (!((String) value).trim().isEmpty()) {
return false; // 有值
}
} else {
return false; // 非 String,只要不为 null 就算有值
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return true;
}
/**
* 判断除指定字段外是否至少有一个字段有值
*/
public static boolean hasAnyOtherFieldNotEmpty(Object obj, String... excludeFields) {
return !allOtherFieldsEmpty(obj, excludeFields);
}
}

Loading…
Cancel
Save