代码调整
This commit is contained in:
@@ -36,6 +36,12 @@ public class GeneralInfo {
|
|||||||
@Value("${business.tempPath}")
|
@Value("${business.tempPath}")
|
||||||
private String businessTempPath;
|
private String businessTempPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地存储目录
|
||||||
|
*/
|
||||||
|
@Value("${business.localStoragePath:f:\\localStoragePath}")
|
||||||
|
private String localStorePath;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* 文件存储方式
|
* 文件存储方式
|
||||||
* 1:本地磁盘
|
* 1:本地磁盘
|
||||||
|
|||||||
@@ -156,4 +156,15 @@ public interface OssPath {
|
|||||||
*/
|
*/
|
||||||
String DATA_CLEAN="dataClean/";
|
String DATA_CLEAN="dataClean/";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 组态Json文件oss路径
|
||||||
|
*/
|
||||||
|
String CONFIGURATIONPATH = "configuration/";
|
||||||
|
/***
|
||||||
|
* 组态Json文件oss文件名
|
||||||
|
*/
|
||||||
|
String CONFIGURATIONNAME = "configuration.json";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.njcn.oss.utils;
|
package com.njcn.oss.utils;
|
||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.lang.UUID;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.huawei.obs.util.OBSUtil;
|
import com.njcn.huawei.obs.util.OBSUtil;
|
||||||
@@ -24,6 +25,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -72,7 +78,7 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
filePath = dir + minIoUtils.minFileName(multipartFile.getOriginalFilename());
|
||||||
obsUtil.uploadMultipart(multipartFile, filePath);
|
obsUtil.uploadMultipart(multipartFile, filePath);
|
||||||
} else {
|
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIossProperties.getBucket(), dir);
|
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.upload(multipartFile, minIossProperties.getBucket(), dir);
|
||||||
@@ -80,6 +86,30 @@ public class FileStorageUtil {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
try {
|
||||||
|
// 确保目录存在
|
||||||
|
Path uploadPath = Paths.get(generalInfo.getLocalStorePath());
|
||||||
|
if (!Files.exists(uploadPath)) {
|
||||||
|
Files.createDirectories(uploadPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成本地文件名(可以添加时间戳或UUID防止重名)
|
||||||
|
String originalFilename = multipartFile.getOriginalFilename();
|
||||||
|
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||||
|
String newFilename = UUID.randomUUID().toString() + fileExtension;
|
||||||
|
|
||||||
|
// 构建完整路径
|
||||||
|
Path filePathPath = uploadPath.resolve(newFilename);
|
||||||
|
|
||||||
|
// 保存文件
|
||||||
|
multipartFile.transferTo(filePathPath.toFile());
|
||||||
|
|
||||||
|
// 返回相对路径或完整路径,根据需求调整
|
||||||
|
filePath = dir + File.separator + newFilename;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException("本地文件上传失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
@@ -122,7 +152,7 @@ public class FileStorageUtil {
|
|||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
filePath = dir + minIoUtils.minFileName(fileName);
|
filePath = dir + minIoUtils.minFileName(fileName);
|
||||||
obsUtil.uploadStream(inputStream, filePath);
|
obsUtil.uploadStream(inputStream, filePath);
|
||||||
} else {
|
} else if (generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
||||||
try {
|
try {
|
||||||
//把名称存入数据
|
//把名称存入数据
|
||||||
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(inputStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
MinIoUploadResDTO minIoUploadResDTO = minIoUtils.uploadStream(inputStream, minIossProperties.getBucket(), dir, minIoUtils.minFileName(fileName));
|
||||||
@@ -130,6 +160,33 @@ public class FileStorageUtil {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR);
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
// 本地存储逻辑
|
||||||
|
try {
|
||||||
|
// 1. 获取本地存储路径
|
||||||
|
String localStoragePath = generalInfo.getLocalStorePath();
|
||||||
|
|
||||||
|
// 2. 确保目录存在(如果不存在则创建)
|
||||||
|
File targetDir = new File(localStoragePath +File.separator+ dir);
|
||||||
|
if (!targetDir.exists()) {
|
||||||
|
boolean created = targetDir.mkdirs();
|
||||||
|
if (!created) {
|
||||||
|
throw new IOException("本地文档目录创建失败: " + targetDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 生成最终文件路径
|
||||||
|
String finalFileName = minIoUtils.minFileName(fileName); // 可选:是否重命名文件
|
||||||
|
File targetFile = new File(targetDir, finalFileName);
|
||||||
|
|
||||||
|
// 4. 写入文件(使用 try-with-resources 确保流关闭)
|
||||||
|
Files.copy(inputStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
// 5. 返回相对路径
|
||||||
|
filePath = dir + finalFileName;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(OssResponseEnum.UPLOAD_FILE_ERROR,e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
@@ -185,8 +242,11 @@ public class FileStorageUtil {
|
|||||||
try {
|
try {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
inputStream = obsUtil.downloadStream(filePath);
|
inputStream = obsUtil.downloadStream(filePath);
|
||||||
} else {
|
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS) {
|
||||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||||
|
}else {
|
||||||
|
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+filePath);
|
||||||
|
inputStream = Files.newInputStream(path);
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||||
@@ -206,8 +266,18 @@ public class FileStorageUtil {
|
|||||||
try {
|
try {
|
||||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||||
inputStream = obsUtil.downloadStream(filePath);
|
inputStream = obsUtil.downloadStream(filePath);
|
||||||
} else {
|
} else if(generalInfo.getBusinessFileStorage() == GeneralConstant.MINIO_OSS){
|
||||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||||
|
}else {
|
||||||
|
// 本地存储处理
|
||||||
|
Path path = Paths.get(generalInfo.getLocalStorePath()+File.separator+filePath);
|
||||||
|
System.out.println("下载文件路径:"+generalInfo.getLocalStorePath()+File.separator+filePath);
|
||||||
|
inputStream = Files.newInputStream(path);
|
||||||
|
|
||||||
|
// 设置下载文件名(从路径中提取)
|
||||||
|
String fileName = path.getFileName().toString();
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||||
}
|
}
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||||
|
|||||||
@@ -16,7 +16,19 @@ public enum RunFlagEnum {
|
|||||||
CHECK(1, "检修"),
|
CHECK(1, "检修"),
|
||||||
STOP(2, "停运"),
|
STOP(2, "停运"),
|
||||||
TEST(3, "调试"),
|
TEST(3, "调试"),
|
||||||
QUIT(4, "退运");
|
QUIT(4, "退运"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GW_FLAG(0,"主网"),
|
||||||
|
PW_FLAG(1,"配网"),
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态
|
* 状态
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.njcn.device.biz.utils;
|
package com.njcn.device.biz.utils;
|
||||||
|
|
||||||
|
import com.njcn.device.biz.enums.RunFlagEnum;
|
||||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||||
import com.njcn.system.enums.DicDataEnum;
|
import com.njcn.system.enums.DicDataEnum;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pqs
|
* pqs
|
||||||
@@ -50,7 +53,7 @@ public class COverlimitUtil {
|
|||||||
threeVoltageUnbalance(overlimit);
|
threeVoltageUnbalance(overlimit);
|
||||||
interharmonicCurrent(overlimit,voltageLevel);
|
interharmonicCurrent(overlimit,voltageLevel);
|
||||||
|
|
||||||
if(lineType == 1) {
|
if(Objects.equals(lineType, RunFlagEnum.PW_FLAG.getStatus())) {
|
||||||
//配网
|
//配网
|
||||||
Float[] iHarmTem = new Float[49];
|
Float[] iHarmTem = new Float[49];
|
||||||
for (int i = 0; i <= 48; i++) {
|
for (int i = 0; i <= 48; i++) {
|
||||||
|
|||||||
@@ -2947,7 +2947,7 @@ public class TerminalBaseServiceImpl extends ServiceImpl<LineMapper, Line> imple
|
|||||||
DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(terminalBaseExcel.getSubvScale(), DicDataTypeEnum.DEV_VOLTAGE_STAND.getName()).getData();
|
DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(terminalBaseExcel.getSubvScale(), DicDataTypeEnum.DEV_VOLTAGE_STAND.getName()).getData();
|
||||||
|
|
||||||
lineDetailMapper.insert(lineDetail);
|
lineDetailMapper.insert(lineDetail);
|
||||||
Overlimit overlimit = new Overlimit(temp.getId(), dictData.getValue(), terminalBaseExcel.getShortCapacity(), terminalBaseExcel.getStandardCapacity(), terminalBaseExcel.getDealCapacity(), terminalBaseExcel.getDevCapacity());
|
Overlimit overlimit = COverlimitUtil.globalAssemble(Float.parseFloat(dictData.getValue()),terminalBaseExcel.getDealCapacity(),terminalBaseExcel.getDevCapacity(),terminalBaseExcel.getShortCapacity(),null,null);
|
||||||
overlimit.setId(temp.getId());
|
overlimit.setId(temp.getId());
|
||||||
overlimitMapper.insert(overlimit);
|
overlimitMapper.insert(overlimit);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user