项目集成华为obs查看波形文件
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
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;
|
||||
@@ -13,6 +16,7 @@ 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;
|
||||
@@ -42,6 +46,12 @@ public class AlgorithmController extends BaseController {
|
||||
@Resource
|
||||
private MinIoProperties minIoProperties;
|
||||
|
||||
@Resource
|
||||
private GeneralInfo generalInfo;
|
||||
|
||||
@Resource
|
||||
private OBSUtil obsUtil;
|
||||
|
||||
/**
|
||||
* 算法保存
|
||||
*
|
||||
@@ -56,10 +66,10 @@ public class AlgorithmController extends BaseController {
|
||||
String methodDescribe = getMethodDescribe("getAlgorithmSave");
|
||||
RStatFile rStatFile = BeanUtil.copyProperties(param, RStatFile.class);
|
||||
boolean b = rStatFileService.updateById(rStatFile);
|
||||
if(b){
|
||||
if (b) {
|
||||
// minIoUtils.removeObjects( minIoProperties.getBucket(),param.getAddress());
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}else{
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -79,16 +89,19 @@ public class AlgorithmController extends BaseController {
|
||||
*/
|
||||
@PostMapping("/common/upload")
|
||||
@ResponseBody
|
||||
public HttpResult<MinIoUploadResDTO> uploadFile(MultipartFile file)
|
||||
{
|
||||
try
|
||||
{
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), "algorithm/");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, upload, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
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);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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;
|
||||
@@ -26,6 +28,7 @@ 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;
|
||||
@@ -98,21 +101,35 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
@Resource
|
||||
private InfluxDbConfig influxDbConfig;
|
||||
|
||||
@Resource
|
||||
private OBSUtil obsUtil;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addCustomReportTemplate(ReportTemplateParam reportTemplateParam) {
|
||||
checkName(reportTemplateParam, false);
|
||||
|
||||
MultipartFile fileContent = reportTemplateParam.getFileContent();
|
||||
String fileName = fileContent.getName();
|
||||
//检验模板json数据规范
|
||||
try {
|
||||
String content = MultipartFileToString(reportTemplateParam.getFileContent());
|
||||
String content = MultipartFileToString(fileContent);
|
||||
new JSONArray(content);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent());
|
||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
||||
//为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());
|
||||
}
|
||||
|
||||
|
||||
//新增模板表
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
@@ -137,10 +154,11 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
@Override
|
||||
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
|
||||
checkName(reportTemplateParam, true);
|
||||
|
||||
MultipartFile fileContent = reportTemplateParam.getFileContent();
|
||||
String fileName = fileContent.getName();
|
||||
//检验模板json数据规范
|
||||
try {
|
||||
String content = MultipartFileToString(reportTemplateParam.getFileContent());
|
||||
String content = MultipartFileToString(fileContent);
|
||||
new JSONArray(content);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
@@ -148,12 +166,18 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
//删除之前的文件
|
||||
ExcelRptTemp excelRptTempOld = excelRptTempMapper.selectById(reportTemplateParam.getId());
|
||||
minIoUtils.removeObject(minIoProperties.getBucket(), excelRptTempOld.getContent());
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(reportTemplateParam.getFileContent());
|
||||
reportTemplateParam.setContent(minIoUploadResDTO.getMinFileName());
|
||||
|
||||
//为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());
|
||||
}
|
||||
//修改模板数据
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||
@@ -240,10 +264,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
lambdaQuery.eq(ExcelRpt::getLineId, reportSearchParam.getLineId()).eq(ExcelRpt::getTempId, reportSearchParam.getTempId());
|
||||
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
||||
String content;
|
||||
if (excelRpts.size() > 0){
|
||||
if (excelRpts.size() > 0) {
|
||||
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), excelRpts.get(0).getContent(), 7 * 24 * 60 * 60);
|
||||
}else{
|
||||
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), analyzeReport(reportSearchParam,excelRptTemp), 7 * 24 * 60 * 60);
|
||||
} else {
|
||||
content = minIoUtils.getObjectUrl(minIoProperties.getBucket(), analyzeReport(reportSearchParam, excelRptTemp), 7 * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
//拼接数据
|
||||
@@ -364,7 +388,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
/**
|
||||
* 解析报表数据
|
||||
*/
|
||||
private String analyzeReport(ReportSearchParam reportSearchParam,ExcelRptTemp excelRptTemp){
|
||||
private String analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp) {
|
||||
//根据content,获取v值并进行处理
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
JSONArray jsonArray = null;
|
||||
@@ -394,7 +418,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
if (vItem.length == 4) {
|
||||
//$HA[_25]#B#max#classId$
|
||||
reportTemplateDTO.setTemplateName(vItem[0]);
|
||||
reportTemplateDTO.setPhase(vItem[1].substring(0,1));
|
||||
reportTemplateDTO.setPhase(vItem[1].substring(0, 1));
|
||||
reportTemplateDTO.setStatMethod(vItem[2].toUpperCase());
|
||||
reportTemplateDTO.setClassId(vItem[3]);
|
||||
} else if (vItem.length == 3) {
|
||||
@@ -462,11 +486,22 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
});
|
||||
}
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
String newContent;
|
||||
File newFile = stringToFile(jsonArray.toString());
|
||||
MultipartFile newMultipartFile = getMultipartFile(newFile);
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(newMultipartFile);
|
||||
String newContent = minIoUploadResDTO.getMinFileName();
|
||||
//为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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//存入报表库
|
||||
ExcelRpt excelRpt = new ExcelRpt();
|
||||
@@ -479,7 +514,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//根据模板激活状态,判断是否进库(修改State字段:0未进库 1已进库)
|
||||
if (DataStateEnum.ENABLE.getCode().equals(reportSearchParam.getActivation())) {
|
||||
excelRpt.setState(DataStateEnum.ENABLE.getCode());
|
||||
}else{
|
||||
} else {
|
||||
excelRpt.setState(DataStateEnum.DELETED.getCode());
|
||||
}
|
||||
excelRptMapper.insert(excelRpt);
|
||||
@@ -496,9 +531,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
//sql拼接示例:select MAX(IHA2) as IHA2 from power_quality_data where Phase = 'A' and LineId='1324564568' and Stat_Method='max' tz('Asia/Shanghai')
|
||||
|
||||
//cp95函数特殊处理 PERCENTILE(field_key, N)
|
||||
if (InfluxDBSqlConstant.CP95.equals(method)){
|
||||
if (InfluxDBSqlConstant.CP95.equals(method)) {
|
||||
sql.append(method).append(InfluxDBSqlConstant.LBK).append(data.getTemplateName()).append(InfluxDBSqlConstant.NUM_95).append(InfluxDBSqlConstant.RBK).append(InfluxDBSqlConstant.AS_VALUE);
|
||||
}else{
|
||||
} else {
|
||||
sql.append(method).append(InfluxDBSqlConstant.LBK).append(data.getTemplateName()).append(InfluxDBSqlConstant.RBK).append(InfluxDBSqlConstant.AS_VALUE);
|
||||
}
|
||||
sql.append(InfluxDBSqlConstant.FROM).append(data.getClassId()).append(InfluxDBSqlConstant.WHERE).append(InfluxDBTableConstant.LINE_ID).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(reportSearchParam.getLineId()).append(InfluxDBSqlConstant.QM);
|
||||
@@ -508,7 +543,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
|
||||
//data_flicker、data_fluc、data_plt 无 value_type
|
||||
if (!InfluxDBTableConstant.DATA_FLICKER.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_FLUC.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_PLT.equals(data.getClassId())){
|
||||
if (!InfluxDBTableConstant.DATA_FLICKER.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_FLUC.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_PLT.equals(data.getClassId())) {
|
||||
sql.append(InfluxDBSqlConstant.AND).append(InfluxDBTableConstant.VALUE_TYPE).append(InfluxDBSqlConstant.EQ).append(InfluxDBSqlConstant.QM).append(data.getStatMethod()).append(InfluxDBSqlConstant.QM);
|
||||
}
|
||||
sql.append(InfluxDBSqlConstant.TZ);
|
||||
@@ -520,7 +555,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
List<QueryResult.Result> results = queryResult.getResults();
|
||||
if (results.size() != 0) {
|
||||
QueryResult.Result result = results.get(0);
|
||||
if (result.getSeries() != null){
|
||||
if (result.getSeries() != null) {
|
||||
List<QueryResult.Series> seriess = result.getSeries();
|
||||
if (seriess.size() != 0) {
|
||||
QueryResult.Series series = seriess.get(0);
|
||||
@@ -545,10 +580,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
* @param file 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private MinIoUploadResDTO contentToMinio(MultipartFile file) {
|
||||
private MinIoUploadResDTO contentToMinio(MultipartFile file, String dir) {
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), "report/");
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), dir);
|
||||
return upload;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
||||
@@ -566,7 +601,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String line = " ";
|
||||
while ((line = in.readLine()) != null){
|
||||
while ((line = in.readLine()) != null) {
|
||||
buffer.append(line);
|
||||
}
|
||||
return buffer.toString();
|
||||
@@ -575,7 +610,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
/**
|
||||
* 字符串写入指定文件
|
||||
*
|
||||
* @param res 原字符串
|
||||
* @param res 原字符串
|
||||
* @return 成功标记
|
||||
*/
|
||||
public File stringToFile(String res) {
|
||||
@@ -584,7 +619,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
String businessTempPath = generalInfo.getBusinessTempPath();
|
||||
File distFile = new File(businessTempPath + File.separator + "temp.json");
|
||||
try {
|
||||
if (!distFile.getParentFile().exists()) distFile.getParentFile().mkdirs();
|
||||
if (!distFile.getParentFile().exists()){
|
||||
distFile.getParentFile().mkdirs();
|
||||
}
|
||||
bufferedReader = new BufferedReader(new StringReader(res));
|
||||
bufferedWriter = new BufferedWriter(new FileWriter(distFile));
|
||||
bufferedWriter.write("");
|
||||
|
||||
Reference in New Issue
Block a user