代码调整
This commit is contained in:
@@ -2,6 +2,7 @@ package com.njcn.harmonic.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -182,11 +183,11 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void viewCustomReportTemplateById(String id,HttpServletResponse response){
|
||||
public void viewCustomReportTemplateById(String id, HttpServletResponse response) {
|
||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
||||
try{
|
||||
fileStorageUtil.downloadStream(response,excelRptTemp.getContent());
|
||||
}catch (Exception exception){
|
||||
try {
|
||||
fileStorageUtil.downloadStream(response, excelRptTemp.getContent());
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(HarmonicResponseEnum.REPORT_TEMPLATE_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
@@ -221,22 +222,28 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
|
||||
@Override
|
||||
public void getCustomReport(ReportSearchParam reportSearchParam, HttpServletResponse response) {
|
||||
public void getCustomReport(ReportSearchParam reportSearchParam, HttpServletResponse response) {
|
||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(reportSearchParam.getTempId());
|
||||
if (Objects.isNull(excelRptTemp)) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_ACTIVE);
|
||||
}
|
||||
//先查询库里是否存在已解析的报表数据,存在直接返回/不存在解析数据
|
||||
LambdaQueryWrapper<ExcelRpt> lambdaQuery = new LambdaQueryWrapper<>();
|
||||
lambdaQuery.eq(ExcelRpt::getLineId, reportSearchParam.getLineId()).eq(ExcelRpt::getTempId, reportSearchParam.getTempId());
|
||||
List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
|
||||
try{
|
||||
if (excelRpts.size() > 0) {
|
||||
fileStorageUtil.downloadStream(response, excelRpts.get(0).getContent());
|
||||
lambdaQuery
|
||||
.eq(ExcelRpt::getLineId, reportSearchParam.getLineId())
|
||||
.eq(ExcelRpt::getTempId, reportSearchParam.getTempId())
|
||||
//年季月周日
|
||||
.eq(ExcelRpt::getType, reportSearchParam.getType())
|
||||
//报表日期
|
||||
.eq(ExcelRpt::getDataDate, reportSearchParam.getStartTime());
|
||||
ExcelRpt excelRpts = excelRptMapper.selectOne(lambdaQuery);
|
||||
try {
|
||||
if (Objects.nonNull(excelRpts)) {
|
||||
fileStorageUtil.downloadStream(response, excelRpts.getContent());
|
||||
} else {
|
||||
fileStorageUtil.downloadStream(response, analyzeReport(reportSearchParam, excelRptTemp));
|
||||
}
|
||||
}catch (Exception exception){
|
||||
} catch (Exception exception) {
|
||||
throw new BusinessException(HarmonicResponseEnum.REPORT_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
@@ -351,18 +358,18 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析报表数据
|
||||
*/
|
||||
private String analyzeReport(ReportSearchParam reportSearchParam, ExcelRptTemp excelRptTemp) {
|
||||
//根据content,获取v值并进行处理
|
||||
List<ReportTemplateDTO> reportTemplateDTOList = new ArrayList<>();
|
||||
JSONArray jsonArray = null;
|
||||
JSONArray jsonArray ;
|
||||
InputStream fileStream = null;
|
||||
try {
|
||||
//通过文件服务器获取
|
||||
// String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||
// jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||
InputStream fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent());
|
||||
fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent());
|
||||
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
@@ -405,6 +412,12 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
}finally {
|
||||
try {
|
||||
fileStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
List<ReportTemplateDTO> endList = new ArrayList<>();
|
||||
@@ -502,8 +515,16 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
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);
|
||||
//时间范围处理
|
||||
sql
|
||||
.append(InfluxDBSqlConstant.AND)
|
||||
.append("time ").append(InfluxDBSqlConstant.GE).append("'").append(reportSearchParam.getStartTime()).append(InfluxDBSqlConstant.START_TIME).append("'")
|
||||
.append(InfluxDBSqlConstant.AND)
|
||||
.append("time ").append(InfluxDBSqlConstant.LT).append("'").append(reportSearchParam.getEndTime()).append(InfluxDBSqlConstant.END_TIME).append("'");
|
||||
|
||||
|
||||
sql.append(InfluxDBSqlConstant.TZ);
|
||||
System.out.println(sql);
|
||||
//根据不同的库表赋值
|
||||
QueryResult queryResult = influxDbUtils.query(String.valueOf(sql));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user