代码调整
This commit is contained in:
@@ -27,6 +27,12 @@
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>minioss-springboot-starter</artifactId>
|
||||
|
||||
@@ -14,7 +14,9 @@ public enum OssResponseEnum {
|
||||
* A00550 ~ A00649
|
||||
*/
|
||||
UPLOAD_FILE_ERROR("A00551","上传文件服务器错误,请检查数据"),
|
||||
DOWNLOAD_FILE_ERROR("A00554","下载文件URL不存在,请检查数据")
|
||||
DOWNLOAD_FILE_URL_ERROR("A00554","下载文件URL不存在,请检查数据"),
|
||||
DOWNLOAD_FILE_STREAM_ERROR("A00555","文件服务器下载文件流异常"),
|
||||
DOWNLOAD_FILE_ERROR("A00556","文件服务器下载异常")
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.njcn.oss.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.huawei.obs.util.OBSUtil;
|
||||
@@ -10,10 +12,14 @@ import com.njcn.oss.constant.GeneralConstant;
|
||||
import com.njcn.oss.enums.OssResponseEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
@@ -111,6 +117,79 @@ public class FileStorageUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 根据文件路径获取文件流
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 23:04
|
||||
* @param filePath 文件在服务器的路径
|
||||
*/
|
||||
public InputStream getFileStream(String filePath){
|
||||
InputStream inputStream;
|
||||
try {
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
inputStream = obsUtil.downloadStream(filePath);
|
||||
} else {
|
||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||
}
|
||||
}catch (Exception exception){
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
}
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
/***
|
||||
* 根据文件路径获取文件流并下载
|
||||
* @author hongawen
|
||||
* @date 2023/3/7 23:04
|
||||
* @param filePath 文件在服务器的路径
|
||||
*/
|
||||
public void downloadStream(HttpServletResponse response, String filePath) throws IOException {
|
||||
InputStream inputStream;
|
||||
OutputStream toClient = null;
|
||||
try{
|
||||
if (generalInfo.getBusinessFileStorage() == GeneralConstant.HUAWEI_OBS) {
|
||||
inputStream = obsUtil.downloadStream(filePath);
|
||||
} else {
|
||||
inputStream = minIoUtils.downloadStream(minIossProperties.getBucket(), filePath);
|
||||
}
|
||||
}catch (Exception exception){
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
}
|
||||
String fileType = filePath.substring(filePath.lastIndexOf('.')).toLowerCase();
|
||||
switch (fileType){
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
case "png":
|
||||
case "gif":
|
||||
response.setContentType(MediaType.IMAGE_PNG_VALUE);
|
||||
break;
|
||||
case "pdf":
|
||||
response.setContentType("application/pdf");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + filePath);
|
||||
break;
|
||||
default:
|
||||
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + filePath);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
toClient = new BufferedOutputStream(response.getOutputStream());
|
||||
//通过IOUtils对接输入输出流,实现文件下载
|
||||
IOUtils.copy(inputStream, toClient);
|
||||
toClient.flush();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(OssResponseEnum.DOWNLOAD_FILE_STREAM_ERROR);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
IOUtils.closeQuietly(toClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* 根据文件路径删除指定文件对象
|
||||
* @author hongawen
|
||||
|
||||
@@ -141,8 +141,8 @@ public class EventBootApplicationTest {
|
||||
String cfgPath = OssPath.WAVE_DIR+"192.168.1.190/PQMonitor_PQM1_002438_20210508_092859_938.CFG";
|
||||
String datPath = OssPath.WAVE_DIR+"192.168.1.190/PQMonitor_PQM1_002438_20210508_092859_938.DAT";
|
||||
|
||||
InputStream cfgStream =obsUtil.fileDownload(cfgPath);
|
||||
InputStream datStream =obsUtil.fileDownload(datPath);
|
||||
InputStream cfgStream =obsUtil.downloadStream(cfgPath);
|
||||
InputStream datStream =obsUtil.downloadStream(datPath);
|
||||
|
||||
if(Objects.isNull(cfgStream) || Objects.isNull(datStream)){
|
||||
throw new FileNotFoundException(EventResponseEnum.ANALYSEWAVE_NOT_FOUND.getMessage());
|
||||
|
||||
@@ -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;
|
||||
try{
|
||||
if (excelRpts.size() > 0) {
|
||||
content = fileStorageUtil.getFileUrl(excelRpts.get(0).getContent());
|
||||
fileStorageUtil.downloadStream(response, excelRpts.get(0).getContent());
|
||||
} else {
|
||||
content = fileStorageUtil.getFileUrl(analyzeReport(reportSearchParam, excelRptTemp));
|
||||
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
|
||||
*
|
||||
|
||||
@@ -3,9 +3,7 @@ package com.njcn.prepare.harmonic.service.mysql.Impl.line;
|
||||
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.constant.BizParamConstant;
|
||||
@@ -96,8 +94,10 @@ public class ReportServiceImpl implements ReportService {
|
||||
for (ExcelRptTemp excelRptTemp : reportTemplateList) {
|
||||
try {
|
||||
//获取content解析数据
|
||||
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()));
|
||||
dataList = getDataList(jsonArray);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(HarmonicResponseEnum.CUSTOM_REPORT_JSON);
|
||||
|
||||
Reference in New Issue
Block a user