Merge branch 'pms'
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
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.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.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;
|
||||
@@ -25,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.*;
|
||||
|
||||
|
||||
@@ -37,10 +33,10 @@ public class AlgorithmController extends BaseController {
|
||||
|
||||
private final RStatFileService rStatFileService;
|
||||
|
||||
@Resource
|
||||
private MinIoUtils minIoUtils;
|
||||
@Resource
|
||||
private MinIoProperties minIoProperties;
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 算法保存
|
||||
@@ -56,10 +52,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 +75,10 @@ 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 {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, fileStorageUtil.uploadMultipart(file,OssPath.ALGORITHM), null);
|
||||
} catch (Exception e) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -26,13 +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.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;
|
||||
@@ -89,31 +88,22 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
private final GeneralInfo generalInfo;
|
||||
|
||||
@Resource
|
||||
private MinIoUtils minIoUtils;
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
@Resource
|
||||
private MinIoProperties minIoProperties;
|
||||
|
||||
@Resource
|
||||
private InfluxDbConfig influxDbConfig;
|
||||
|
||||
@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());
|
||||
|
||||
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
|
||||
//新增模板表
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||
@@ -137,10 +127,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
@Override
|
||||
public boolean updateCustomReportTemplate(ReportTemplateParam.UpdateReportTemplateParam reportTemplateParam) {
|
||||
checkName(reportTemplateParam, true);
|
||||
|
||||
MultipartFile fileContent = reportTemplateParam.getFileContent();
|
||||
//检验模板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 +138,8 @@ 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());
|
||||
|
||||
fileStorageUtil.deleteFile(excelRptTempOld.getContent());
|
||||
reportTemplateParam.setContent(fileStorageUtil.uploadMultipart(fileContent, OssPath.HARMONIC_EXCEL_TEMPLATE));
|
||||
//修改模板数据
|
||||
ExcelRptTemp excelRptTemp = new ExcelRptTemp();
|
||||
BeanUtils.copyProperties(reportTemplateParam, excelRptTemp);
|
||||
@@ -194,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;
|
||||
}
|
||||
@@ -240,10 +226,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){
|
||||
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);
|
||||
if (excelRpts.size() > 0) {
|
||||
content = fileStorageUtil.getFileUrl(excelRpts.get(0).getContent());
|
||||
} else {
|
||||
content = fileStorageUtil.getFileUrl(analyzeReport(reportSearchParam, excelRptTemp));
|
||||
}
|
||||
|
||||
//拼接数据
|
||||
@@ -364,13 +350,13 @@ 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;
|
||||
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;
|
||||
@@ -394,7 +380,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 +448,9 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
});
|
||||
}
|
||||
|
||||
//文件上传到Minio服务器,存入文件名
|
||||
File newFile = stringToFile(jsonArray.toString());
|
||||
MultipartFile newMultipartFile = getMultipartFile(newFile);
|
||||
MinIoUploadResDTO minIoUploadResDTO = contentToMinio(newMultipartFile);
|
||||
String newContent = minIoUploadResDTO.getMinFileName();
|
||||
String newContent = fileStorageUtil.uploadMultipart(newMultipartFile, OssPath.HARMONIC_EXCEL_REPORT);
|
||||
|
||||
//存入报表库
|
||||
ExcelRpt excelRpt = new ExcelRpt();
|
||||
@@ -479,7 +463,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 +480,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 +492,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 +504,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);
|
||||
@@ -539,21 +523,6 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
endList.add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件到Minio
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 成功标记
|
||||
*/
|
||||
private MinIoUploadResDTO contentToMinio(MultipartFile file) {
|
||||
try {
|
||||
//把名称存入数据
|
||||
MinIoUploadResDTO upload = minIoUtils.upload(file, minIoProperties.getBucket(), "report/");
|
||||
return upload;
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件Url 转 String
|
||||
@@ -566,7 +535,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 +544,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
/**
|
||||
* 字符串写入指定文件
|
||||
*
|
||||
* @param res 原字符串
|
||||
* @param res 原字符串
|
||||
* @return 成功标记
|
||||
*/
|
||||
public File stringToFile(String res) {
|
||||
@@ -584,7 +553,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