项目集成华为obs查看波形文件

This commit is contained in:
2023-03-08 10:31:36 +08:00
parent 280dfbad29
commit ad044fc2b2
31 changed files with 558 additions and 1506 deletions

View File

@@ -3,23 +3,16 @@ package com.njcn.harmonic.controller.algorithm;
import cn.hutool.core.bean.BeanUtil;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.GeneralConstant;
import com.njcn.common.pojo.constant.OssPath;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
import com.njcn.harmonic.pojo.param.RStatFileVO;
import com.njcn.harmonic.pojo.po.RStatFile;
import com.njcn.harmonic.pojo.vo.PwRStatOrgVO;
import com.njcn.harmonic.service.algorithm.RStatFileService;
import com.njcn.huawei.obs.util.OBSUtil;
import com.njcn.minio.bo.MinIoUploadResDTO;
import com.njcn.minio.config.MinIoProperties;
import com.njcn.minio.utils.MinIoUtils;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -29,7 +22,6 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.*;
@@ -41,16 +33,10 @@ public class AlgorithmController extends BaseController {
private final RStatFileService rStatFileService;
@Resource
private MinIoUtils minIoUtils;
@Resource
private MinIoProperties minIoProperties;
private final FileStorageUtil fileStorageUtil;
@Resource
private GeneralInfo generalInfo;
@Resource
private OBSUtil obsUtil;
/**
* 算法保存
@@ -91,16 +77,7 @@ public class AlgorithmController extends BaseController {
@ResponseBody
public HttpResult<String> uploadFile(MultipartFile file) {
try {
//为2则为华为OBS
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
String fileName = file.getOriginalFilename();
fileName = OssPath.ALGORITHM + minIoUtils.minFileName(fileName);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, obsUtil.multiFileUpload(file, fileName), null);
} else {
//把名称存入数据
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), OssPath.ALGORITHM);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, upload.getMinFileUrl(), null);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, fileStorageUtil.uploadMultipart(file,OssPath.ALGORITHM), null);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, null);
}

View File

@@ -1,5 +1,6 @@
package com.njcn.harmonic.service.impl;
import ch.qos.logback.core.rolling.helper.FileStoreUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
@@ -8,8 +9,6 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.constant.GeneralConstant;
import com.njcn.common.pojo.constant.OssPath;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
@@ -28,14 +27,11 @@ import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
import com.njcn.harmonic.service.CustomReportService;
import com.njcn.huawei.obs.util.OBSUtil;
import com.njcn.influxdb.config.InfluxDbConfig;
import com.njcn.influxdb.param.InfluxDBSqlConstant;
import com.njcn.influxdb.param.InfluxDBTableConstant;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.minio.bo.MinIoUploadResDTO;
import com.njcn.minio.config.MinIoProperties;
import com.njcn.minio.utils.MinIoUtils;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
@@ -92,17 +88,7 @@ public class CustomReportServiceImpl implements CustomReportService {
private final GeneralInfo generalInfo;
@Resource
private MinIoUtils minIoUtils;
@Resource
private MinIoProperties minIoProperties;
@Resource
private InfluxDbConfig influxDbConfig;
@Resource
private OBSUtil obsUtil;
private final FileStorageUtil fileStorageUtil;
@Override
@@ -117,20 +103,7 @@ public class CustomReportServiceImpl implements CustomReportService {
} catch (Exception e) {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
}
//为2则为华为OBS
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
fileName = OssPath.HARMONIC_EXCEL_TEMPLATE + minIoUtils.minFileName(fileName);
obsUtil.multiFileUpload(fileContent,fileName);
reportTemplateParam.setContent(fileName);
} else {
//否则认为是minioss
//文件上传到Minio服务器存入文件名
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent(), OssPath.HARMONIC_EXCEL_TEMPLATE);
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
}
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
//新增模板表
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
@@ -155,7 +128,6 @@ public class CustomReportServiceImpl implements CustomReportService {
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
checkName(reportTemplateParam, true);
MultipartFile fileContent = reportTemplateParam.getFileContent();
String fileName = fileContent.getName();
//检验模板json数据规范
try {
String content = MultipartFileToString(fileContent);
@@ -166,18 +138,8 @@ public class CustomReportServiceImpl implements CustomReportService {
//删除之前的文件
ExcelRptTemp excelRptTempOld = excelRptTempMapper.selectById(reportTemplateParam.getId());
//为2则为华为OBS
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
obsUtil.delete(excelRptTempOld.getContent());
fileName = OssPath.HARMONIC_EXCEL_TEMPLATE + minIoUtils.minFileName(fileName);
obsUtil.multiFileUpload(fileContent,fileName);
reportTemplateParam.setContent(fileName);
}else{
minIoUtils.removeObject(minIoProperties.getBucket(), excelRptTempOld.getContent());
//文件上传到Minio服务器存入文件名
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent(), OssPath.HARMONIC_EXCEL_TEMPLATE);
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
}
fileStorageUtil.deleteFile(excelRptTempOld.getContent());
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
//修改模板数据
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
@@ -218,7 +180,7 @@ public class CustomReportServiceImpl implements CustomReportService {
@Override
public ExcelRptTemp getCustomReportTemplateById(String id) {
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
String contentUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
String contentUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
excelRptTemp.setContent(contentUrl);
return excelRptTemp;
}
@@ -265,9 +227,9 @@ public class CustomReportServiceImpl implements CustomReportService {
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
String content;
if (excelRpts.size() > 0) {
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRpts.get(0).getContent(), 7 * 24 * 60 * 60);
content = fileStorageUtil.getFileUrl(excelRpts.get(0).getContent());
} else {
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), analyzeReport(reportSearchParam, excelRptTemp), 7 * 24 * 60 * 60);
content = fileStorageUtil.getFileUrl(analyzeReport(reportSearchParam, excelRptTemp));
}
//拼接数据
@@ -394,7 +356,7 @@ public class CustomReportServiceImpl implements CustomReportService {
JSONArray jsonArray = null;
try {
//通过文件服务器获取
String objectUrl = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRptTemp.getContent(), 7 * 24 * 60 * 60);
String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
jsonArray.forEach(item -> {
JSONObject jsonObject = (JSONObject) item;
@@ -486,22 +448,9 @@ public class CustomReportServiceImpl implements CustomReportService {
});
}
String newContent;
File newFile = stringToFile(jsonArray.toString());
MultipartFile newMultipartFile = getMultipartFile(newFile);
//为2则为华为OBS
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
newContent = newMultipartFile.getName();
newContent = OssPath.HARMONIC_EXCEL_REPORT + minIoUtils.minFileName(newContent);
obsUtil.multiFileUpload(newMultipartFile,newContent);
}else{
//否则认为是minioss
//文件上传到Minio服务器存入文件名
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(newMultipartFile,OssPath.HARMONIC_EXCEL_REPORT);
newContent = minIoUploadResDTO.getMinFileName();
}
String newContent = fileStorageUtil.uploadMultipart(newMultipartFile, OssPath.HARMONIC_EXCEL_REPORT);
//存入报表库
ExcelRpt excelRpt = new ExcelRpt();
@@ -574,21 +523,6 @@ public class CustomReportServiceImpl implements CustomReportService {
endList.add(data);
}
/**
* 上传文件到Minio
*
* @param file 文件
* @return 成功标记
*/
private MinIoUploadResDTO contentToMinio(MultipartFile file, String dir) {
try {
//把名称存入数据
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), dir);
return upload;
} catch (Exception e) {
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
}
}
/**
* 文件Url 转 String
@@ -619,7 +553,7 @@ public class CustomReportServiceImpl implements CustomReportService {
String businessTempPath = generalInfo.getBusinessTempPath();
File distFile = new File(businessTempPath + File.separator + "temp.json");
try {
if (!distFile.getParentFile().exists()){
if (!distFile.getParentFile().exists()) {
distFile.getParentFile().mkdirs();
}
bufferedReader = new BufferedReader(new StringReader(res));