代码调整
This commit is contained in:
@@ -27,6 +27,9 @@ public enum HarmonicResponseEnum {
|
||||
CUSTOM_REPORT_ACTIVE("A00556","不存在激活的自定义报告模板"),
|
||||
CUSTOM_REPORT_EMPTY("A00557","自定义报表模板异常,模板数据为空"),
|
||||
CUSTOM_REPORT_FILE("A00558","上传文件服务器错误,请检查数据"),
|
||||
|
||||
REPORT_DOWNLOAD_ERROR("A00559","报表文件下载异常"),
|
||||
REPORT_TEMPLATE_DOWNLOAD_ERROR("A00560","报表模板下载异常"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -23,6 +23,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -124,6 +126,19 @@ public class CustomReportController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, excelRptTemp, methodDescribe);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id回显模板
|
||||
* @author qijian
|
||||
* @date 2022/10/14
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/viewCustomReportTemplateById")
|
||||
@ApiOperation("根据id查询模板详情")
|
||||
@ApiImplicitParam(name = "id", value = "id", required = true)
|
||||
public void viewCustomReportTemplateById(@RequestParam("id") String id,HttpServletResponse response){
|
||||
customReportService.viewCustomReportTemplateById(id,response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改自定义报表模板
|
||||
* @author qijian
|
||||
@@ -219,10 +234,10 @@ public class CustomReportController extends BaseController {
|
||||
@PostMapping("/getCustomReport")
|
||||
@ApiOperation("获取报表")
|
||||
@ApiImplicitParam(name = "reportSearchParam", value = "查询体", required = false)
|
||||
public HttpResult<List<String>> getCustomReport(@RequestBody ReportSearchParam reportSearchParam){
|
||||
public void getCustomReport(@RequestBody ReportSearchParam reportSearchParam, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("getCustomReport");
|
||||
List<String> res = customReportService.getCustomReport(reportSearchParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
|
||||
customReportService.getCustomReport(reportSearchParam,response);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
|
||||
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
|
||||
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -66,11 +68,13 @@ public interface CustomReportService {
|
||||
|
||||
/**
|
||||
* 替换报表数据并返回
|
||||
*
|
||||
* @param reportSearchParam 请求参数
|
||||
* @param response
|
||||
* @author qijian
|
||||
* @date 2022/10/18
|
||||
*/
|
||||
List<String> getCustomReport(ReportSearchParam reportSearchParam);
|
||||
void getCustomReport(ReportSearchParam reportSearchParam, HttpServletResponse response);
|
||||
|
||||
|
||||
/**
|
||||
@@ -100,4 +104,6 @@ public interface CustomReportService {
|
||||
* @date 2022/10/18
|
||||
*/
|
||||
List<ReportTemplateVO> getTemplateByDept(String id);
|
||||
|
||||
void viewCustomReportTemplateById(String id, HttpServletResponse response);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
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;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.json.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
@@ -31,6 +28,7 @@ import com.njcn.influxdb.param.InfluxDBSqlConstant;
|
||||
import com.njcn.influxdb.param.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.enums.OssResponseEnum;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.user.api.DeptFeignClient;
|
||||
@@ -50,7 +48,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -180,11 +178,20 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
@Override
|
||||
public ExcelRptTemp getCustomReportTemplateById(String id) {
|
||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
||||
String contentUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||
excelRptTemp.setContent(contentUrl);
|
||||
return excelRptTemp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void viewCustomReportTemplateById(String id,HttpServletResponse response){
|
||||
ExcelRptTemp excelRptTemp = excelRptTempMapper.selectById(id);
|
||||
try{
|
||||
fileStorageUtil.downloadStream(response,excelRptTemp.getContent());
|
||||
}catch (Exception exception){
|
||||
throw new BusinessException(HarmonicResponseEnum.REPORT_TEMPLATE_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportTemplateVO> getTemplateList(ReportSearchParam reportSearchParam) {
|
||||
return excelRptTempMapper.getReportTemplateList(reportSearchParam);
|
||||
@@ -214,28 +221,25 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getCustomReport(ReportSearchParam reportSearchParam) {
|
||||
List<String> results = new ArrayList<>();
|
||||
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);
|
||||
String content;
|
||||
if (excelRpts.size() > 0) {
|
||||
content = fileStorageUtil.getFileUrl(excelRpts.get(0).getContent());
|
||||
} else {
|
||||
content = fileStorageUtil.getFileUrl(analyzeReport(reportSearchParam, excelRptTemp));
|
||||
try{
|
||||
if (excelRpts.size() > 0) {
|
||||
fileStorageUtil.downloadStream(response, excelRpts.get(0).getContent());
|
||||
} else {
|
||||
fileStorageUtil.downloadStream(response, analyzeReport(reportSearchParam, excelRptTemp));
|
||||
}
|
||||
}catch (Exception exception){
|
||||
throw new BusinessException(HarmonicResponseEnum.REPORT_DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
//拼接数据
|
||||
results.add(excelRptTemp.getReportForm());
|
||||
results.add(content);
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -356,8 +360,10 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
JSONArray jsonArray = null;
|
||||
try {
|
||||
//通过文件服务器获取
|
||||
String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||
jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||
// String objectUrl = fileStorageUtil.getFileUrl(excelRptTemp.getContent());
|
||||
// jsonArray = JSONUtil.parseArray(urlToString(objectUrl));
|
||||
InputStream fileStream = fileStorageUtil.getFileStream(excelRptTemp.getContent());
|
||||
jsonArray = new JSONArray(new JSONTokener(fileStream, new JSONConfig()));
|
||||
jsonArray.forEach(item -> {
|
||||
JSONObject jsonObject = (JSONObject) item;
|
||||
JSONArray itemArr = (JSONArray) jsonObject.get("celldata");
|
||||
@@ -471,6 +477,7 @@ public class CustomReportServiceImpl implements CustomReportService {
|
||||
return newContent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 组装influxDB查询sql,查询value并封装endlist
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user