@@ -238,22 +238,8 @@ public class CustomReportServiceImpl implements CustomReportService {
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())
//年季月周日
.eq(ExcelRpt::getType, reportSearchParam.getType())
//报表日期
.eq(ExcelRpt::getDataDate, reportSearchParam.getStartTime());*/
try {
/* List<ExcelRpt> excelRpts = excelRptMapper.selectList(lambdaQuery);
if (CollUtil.isNotEmpty(excelRpts)) {
fileStorageUtil.downloadStream(response, excelRpts.get(0).getContent());
} else {*/
analyzeReport ( reportSearchParam , excelRptTemp , response ) ;
/*}*/
} catch ( Exception exception ) {
log . error ( exception . getMessage ( ) ) ;
exception . printStackTrace ( ) ;
@@ -604,12 +590,11 @@ public class CustomReportServiceImpl implements CustomReportService {
System . out . println ( sql ) ;
if ( data . get ( 0 ) . getTemplateName ( ) . equals ( " freq_dev " ) | | data . get ( 0 ) . getTemplateName ( ) . equals ( " freq " ) ) {
System . out . println ( sql ) ;
}
long l = System . currentTimeMillis ( ) ;
List < Map < String , Object > > mapList = SqlRunner . db ( ) . selectList ( sql . toString ( ) ) ;
long la = System . currentTimeMillis ( ) ;
System . out . println ( " 当前sql结束花费时长: " + ( la - l ) + " ms " ) ;
if ( CollUtil . isEmpty ( mapList ) ) {
data = data . stream ( ) . peek ( item - > item . setValue ( " / " ) ) . collect ( Collectors . toList ( ) ) ;
} else {
@@ -695,7 +680,7 @@ public class CustomReportServiceImpl implements CustomReportService {
List < ReportTemplateDTO > endList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( reportTemplateDTOList ) ) {
long deal = System . currentTimeMillis ( ) ;
//开始组织sql
reportTemplateDTOList = reportTemplateDTOList . stream ( )
@@ -704,6 +689,7 @@ public class CustomReportServiceImpl implements CustomReportService {
Map < String , List < ReportTemplateDTO > > classMap = reportTemplateDTOList . stream ( ) . collect ( Collectors . groupingBy ( ReportTemplateDTO : : getResourceId ) ) ;
Map < String , ReportTemplateDTO > assNoPassMap = new HashMap < > ( ) ;
long deal = System . currentTimeMillis ( ) ;
classMap . forEach ( ( classKey , templateValue ) - > {
Map < String , List < ReportTemplateDTO > > valueTypeMap = templateValue . stream ( ) . collect ( Collectors . groupingBy ( ReportTemplateDTO : : getStatMethod ) ) ;
@@ -757,13 +743,10 @@ public class CustomReportServiceImpl implements CustomReportService {
}
if ( CollUtil . isNotEmpty ( endList ) ) {
long jie = System . currentTimeMillis ( ) ;
//数据单位信息
Map < String , String > unit = unitMap( reportSearchParam. getLineId( ) ) ;
//Map<String, String> unit = unitMap( reportSearchParam. getLineId()) ;
//进行反向赋值到模板
//1、根据itemName分组
Map < String , List < ReportTemplateDTO > > assMap = endList . stream ( ) . collect ( Collectors . groupingBy ( ReportTemplateDTO : : getItemName ) ) ;
@@ -832,7 +815,7 @@ public class CustomReportServiceImpl implements CustomReportService {
//解决数据单位问题 @指标#类型@
if ( v . charAt ( 0 ) = = '@' & & v . contains ( " # " ) ) {
String replace = v . replace ( " @ " , " " ) ;
son . set ( " v " , unit . getOrDefault( replace, " / " ) ) ;
// son.set("v", unit. getOrDefault( replace, "/")) ;
}
}
@@ -846,38 +829,10 @@ public class CustomReportServiceImpl implements CustomReportService {
long daochu = System . currentTimeMillis ( ) ;
InputStream reportStream = IoUtil . toStream ( jsonArray . toString ( ) , CharsetUtil . UTF_8 ) ;
//String newContent = fileStorageUtil.uploadStream(reportStream, OssPath.HARMONIC_EXCEL_REPORT, FileUtil.generateFileName("json")) ;
response . setContentType ( " application/octet-stream;charset=UTF-8 " ) ;
response . setHeader ( " Content-Disposition " , " attachment;filename= " + " aa " ) ;
//入库前判断是否有了,有了就更新
/* ExcelRpt excelRpt = new ExcelRpt();
excelRpt.setName(excelRptTemp.getName());
excelRpt.setLineId(reportSearchParam.getLineId());
excelRpt.setDataDate(DateUtil.parse(reportSearchParam.getStartTime()));
excelRpt.setTempId(excelRptTemp.getId());
excelRpt.setContent(newContent);
excelRpt.setType(reportSearchParam.getType());
excelRpt.setState(DataStateEnum.ENABLE.getCode());
excelRptMapper.insert(excelRpt);*/
OutputStream toClient = null ;
try {
toClient = new BufferedOutputStream ( response . getOutputStream ( ) ) ;
//通过IOUtils对接输入输出流, 实现文件下载
IOUtils . copy ( reportStream , toClient ) ;
toClient . flush ( ) ;
} catch ( Exception e ) {
throw new BusinessException ( OssResponseEnum . DOWNLOAD_FILE_STREAM_ERROR ) ;
} finally {
IOUtils . closeQuietly ( reportStream ) ;
IOUtils . closeQuietly ( toClient ) ;
long daochuEnd = System . currentTimeMillis ( ) ;
System . out . println ( " 导出耗时 " + ( daochuEnd - daochu ) / 1000 + " S " ) ;
}
//导出自定义报表
downReport ( jsonArray , response ) ;
long daochuEnd = System . currentTimeMillis ( ) ;
System . out . println ( " 导出耗时 " + ( daochuEnd - daochu ) / 1000 + " S " ) ;
}
@@ -963,6 +918,7 @@ public class CustomReportServiceImpl implements CustomReportService {
/**
* 获取测点限值
* @author cdf
* @date 2023/10/23
*/
@@ -977,7 +933,6 @@ public class CustomReportServiceImpl implements CustomReportService {
sql . append ( reportLimitList . get ( i ) . getTemplateName ( ) ) . append ( " , " ) ;
}
}
sql . append ( " from " ) . append ( reportLimitList . get ( 0 ) . getResourceId ( ) ) . append ( " where id =' " ) . append ( reportSearchParam . getLineId ( ) ) . append ( " ' " ) ;
limitMap = excelRptTempMapper . dynamicSqlMap ( sql . toString ( ) ) ;
@@ -990,6 +945,31 @@ public class CustomReportServiceImpl implements CustomReportService {
return limitMap ;
}
/**
* 报告下载
*/
private void downReport ( JSONArray jsonArray , HttpServletResponse response ) {
InputStream reportStream = IoUtil . toStream ( jsonArray . toString ( ) , CharsetUtil . UTF_8 ) ;
//String newContent = fileStorageUtil.uploadStream(reportStream, OssPath.HARMONIC_EXCEL_REPORT, FileUtil.generateFileName("json"));
response . setContentType ( " application/octet-stream;charset=UTF-8 " ) ;
response . setHeader ( " Content-Disposition " , " attachment;filename= " + " aa " ) ;
//入库前判断是否有了,有了就更新
OutputStream toClient = null ;
try {
toClient = new BufferedOutputStream ( response . getOutputStream ( ) ) ;
//通过IOUtils对接输入输出流, 实现文件下载
IOUtils . copy ( reportStream , toClient ) ;
toClient . flush ( ) ;
} catch ( Exception e ) {
throw new BusinessException ( OssResponseEnum . DOWNLOAD_FILE_STREAM_ERROR ) ;
} finally {
IOUtils . closeQuietly ( reportStream ) ;
IOUtils . closeQuietly ( toClient ) ;
}
}
}