瀏覽代碼

提交导出报告代码

tags/V1.0.1^2
wanjing 1 年之前
父節點
當前提交
e8519e65af
共有 12 個檔案被更改,包括 522 行新增23 行删除
  1. +0
    -21
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/config/WebSocketConfig.java
  2. +25
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java
  3. +54
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/AirDataExport.java
  4. +85
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/report/ExportReportRequest.java
  5. +12
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/AirDataExportMapper.java
  6. +17
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/AirDataServiceImpl.java
  7. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/IAirDataService.java
  8. +191
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/report/ExportReportService.java
  9. +74
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/report/GenerateReportWordService.java
  10. +2
    -2
      tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml
  11. +10
    -0
      tuoheng-service/tuoheng-admin/src/main/resources/mapper/AirDataExportMapper.xml
  12. +42
    -0
      tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/ExportReportServiceTest.java

+ 0
- 21
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/config/WebSocketConfig.java 查看文件

@@ -1,21 +0,0 @@
package com.tuoheng.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
public class WebSocketConfig {

/**
* ServerEndpointExporter 作用
* <p>
* 这个Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint
*
* @return
*/
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}

+ 25
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/AirDataController.java 查看文件

@@ -1,11 +1,18 @@
package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.service.airData.IAirDataService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @Author ChengWang
* @Date 2023/5/23
@@ -17,4 +24,22 @@ public class AirDataController {

@Autowired
private IAirDataService airDataService;

/**
* 获取列表
*/
@GetMapping("/list")
public JsonResult getList() {
return null;
}

/**
* 导出报告
*/
@GetMapping("/export")
public void exportReport(ExportReportRequest request) {
// log.info("进入导出报告接口");
airDataService.exportReport(request);
}

}

+ 54
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/domain/AirDataExport.java 查看文件

@@ -0,0 +1,54 @@
package com.tuoheng.admin.entity.domain;

import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
* 大气数据报告导出记录 th_air_data_export
*
* @team tuoheng
* @author wanjing
* @date 2023-05-24
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("th_air_data_export")
public class AirDataExport extends BaseEntity {

private static final long serialVersionUID = 1L;

/**
* 租户ID
*/
private String tenantId;

/**
* 任务ID
*/
private String inspectionId;

/**
* 大气数据类型ID
*/
private String airDataTypeId;

/**
* 导出类型:data(数据); report(报告)
*/
private String exportType;

/**
* 网格大小
*/
private Integer gridSize;

/**
* 阿里云文件地址
*/
private String ossUrl;

}

+ 85
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/request/report/ExportReportRequest.java 查看文件

@@ -0,0 +1,85 @@
package com.tuoheng.admin.entity.request.report;

import com.tuoheng.common.core.common.BaseQuery;
import lombok.Data;

/**
* 查询报告分页列表请求实体
*
* @author wanjing
* @team tuoheng
* @date 2022-12-05
*/
@Data
public class ExportReportRequest extends BaseQuery {

/**
* 任务ID
*/
private String inspectionId;

/**
* 大气数据类型
*/
private String airDataTypeId;

/**
* 网格大小
*/
private Integer gridSize;

/**
* 采样点数量
*/
private String samplingPointsNum;

/**
* 检测区域网格平均尺寸
*/
private String averageGridSize;

/**
* 总检测区域网格面积
*/
private String gridArea;

/**
* 检测区域中心点经纬度
*/
private String centerPointLongitudeAndLatitude;

/**
* 检测区域平均浓度
*/
private String averageConcentration;

/**
* 网格浓度最高值
*/
private String gridConcentrationMax;

/**
* 网格浓度最小值
*/
private String gridConcentrationMix;

/**
* 单点浓度最高值
*/
private String singlePointConcentrationMax;

/**
* 单点浓度最低值
*/
private String singlePointConcentrationMix;

/**
* 图片oss地址
*/
private String ossUrl;

/**
* 标准图片oss地址
*/
private String standardOssUrl;
}

+ 12
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/mapper/AirDataExportMapper.java 查看文件

@@ -0,0 +1,12 @@
package com.tuoheng.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.admin.entity.domain.AirDataExport;


/**
* @Author ChengWang
* @Date 2023/5/23
*/
public interface AirDataExportMapper extends BaseMapper<AirDataExport> {
}

+ 17
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/AirDataServiceImpl.java 查看文件

@@ -1,9 +1,13 @@
package com.tuoheng.admin.service.airData;

import com.tuoheng.admin.entity.domain.AirData;
import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.mapper.AirDataMapper;
import com.tuoheng.admin.service.airData.report.ExportReportService;
import com.tuoheng.common.core.common.BaseServiceImpl;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
@@ -13,4 +17,17 @@ import org.springframework.stereotype.Service;
@Service
@Slf4j
public class AirDataServiceImpl extends BaseServiceImpl<AirDataMapper, AirData> implements IAirDataService {

@Autowired
private ExportReportService eportReportService;

/**
*
* 导出报告
*
* @return
*/
public JsonResult exportReport(ExportReportRequest request) {
return eportReportService.exportReport(request);
}
}

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/IAirDataService.java 查看文件

@@ -1,11 +1,21 @@
package com.tuoheng.admin.service.airData;

import com.tuoheng.admin.entity.domain.AirData;
import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.common.core.common.IBaseService;
import com.tuoheng.common.core.utils.JsonResult;

/**
* @Author ChengWang
* @Date 2023/5/23
*/
public interface IAirDataService extends IBaseService<AirData> {

/**
*
* 导出报告
*
* @return
*/
JsonResult exportReport(ExportReportRequest request);
}

+ 191
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/report/ExportReportService.java 查看文件

@@ -0,0 +1,191 @@
package com.tuoheng.admin.service.airData.report;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tuoheng.admin.entity.domain.AirData;
import com.tuoheng.admin.entity.domain.AirDataExport;
import com.tuoheng.admin.entity.domain.AirDataType;
import com.tuoheng.admin.entity.domain.Inspection;
import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.AirDataExportMapper;
import com.tuoheng.admin.mapper.AirDataMapper;
import com.tuoheng.admin.mapper.AirDataTypeMapper;
import com.tuoheng.admin.mapper.InspectionMapper;
import com.tuoheng.admin.utils.AliyunOSSUtil;
import com.tuoheng.common.core.config.UploadFileConfig;
import com.tuoheng.common.core.exception.ServiceException;
import com.tuoheng.common.core.utils.FileUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Slf4j
@Service
public class ExportReportService {

@Autowired
private InspectionMapper inspectionMapper;

@Autowired
private AirDataMapper airDataMapper;

@Autowired
private AirDataTypeMapper airDataTypeMapper;

@Autowired
private AirDataExportMapper airDataExportMapper;

@Autowired
private GenerateReportWordService generateReportWordService;

@Autowired
private AliyunOSSUtil aliyunOSSUtil;

public JsonResult exportReport(ExportReportRequest request) {
JsonResult result = this.check(request);
if (0 != result.getCode()) {
log.info("导出报告:校验失败:{}", result.getMsg());
return result;
}

AirDataExport airDataExport = this.checkAirDataExport(request);
if (ObjectUtil.isNotEmpty(airDataExport)) {
return JsonResult.success(airDataExport);
}

Inspection inspection = (Inspection) result.getData();
AirDataType airDataType = airDataTypeMapper.selectById(request.getAirDataTypeId());

String filename = inspection.getCode() + "-" + airDataType.getDataType() + "(" +request.getGridSize() + ")浓度分布报告" + ".doc";
String filePath = UploadFileConfig.uploadFolder + "/report/" + filename;
File fd = new File(UploadFileConfig.uploadFolder + "/report");
if (!fd.exists()) {
fd.mkdirs();
}

AirData beginAirData = airDataMapper.selectOne(new LambdaQueryWrapper<AirData>()
.eq(AirData::getInspectionId, request.getInspectionId())
.eq(AirData::getMark, MarkEnum.VALID.getCode())
.orderByDesc(AirData::getCUtcTime)
.last(" limit 1"));

AirData endAirData = airDataMapper.selectOne(new LambdaQueryWrapper<AirData>()
.eq(AirData::getInspectionId, request.getInspectionId())
.eq(AirData::getMark, MarkEnum.VALID.getCode())
.orderByAsc(AirData::getCUtcTime)
.last(" limit 1"));

// 生成word
File f = new File(filePath);
if (!f.exists() || f.length() < 1000) {
String detectionTime = "";
if (ObjectUtil.isNotEmpty(beginAirData)) {
detectionTime += beginAirData.getCUtcTime();
}
detectionTime += "至";
if (ObjectUtil.isNotEmpty(endAirData)) {
detectionTime += endAirData.getCUtcTime();
}

String analyticalMethods = "激光散射";

result = generateReportWordService.buildWord(filePath, request, airDataType, detectionTime, inspection.getEquipmentMountCode(), analyticalMethods);
if (0 != result.getCode()) {
log.info("导出报告业务:生成word失败:{}", result.getMsg());
return result;
}
}

// 上传到oss
String ossUrl = this.uploadOss(filePath, filename);

// 记录
this.insertAirDataExport(request, inspection, airDataType, ossUrl);

// 删除原文件
// FileUtils.deleteFile(filePath);

return JsonResult.success();
}

/**
* 检查参数
*
* @param request
* @return
*/
private JsonResult check(ExportReportRequest request) {
if (StringUtils.isEmpty(request.getInspectionId())) {
log.info("导出报告,任务ID为空,inspectionId={}", request.getInspectionId());
throw new ServiceException("任务ID为空");
}
if (StringUtils.isEmpty(request.getAirDataTypeId())) {
log.info("导出报告,大气数据类型为空,airDataType={}", request.getAirDataTypeId());
throw new ServiceException("大气数据类型为空");
}
if (StringUtils.isEmpty(request.getOssUrl())) {
log.info("导出报告,大气数据图片为空,ossUrl={}", request.getOssUrl());
throw new ServiceException("大气数据图片为空");
}
Inspection inspection = inspectionMapper.selectById(request.getInspectionId());
if (ObjectUtil.isEmpty(inspection)) {
log.info("导出报告,任务不存在,inspectionId={}", request.getInspectionId());
throw new ServiceException("任务不存在");
}
return JsonResult.success(inspection);
}

private AirDataExport checkAirDataExport(ExportReportRequest request) {
AirDataExport airDataExport = airDataExportMapper.selectOne(new LambdaQueryWrapper<AirDataExport>()
.eq(AirDataExport::getInspectionId, request.getInspectionId())
.eq(AirDataExport::getAirDataTypeId, request.getAirDataTypeId())
.eq(AirDataExport::getExportType, "report")
.eq(AirDataExport::getGridSize, request.getGridSize())
.eq(AirDataExport::getMark, MarkEnum.VALID.getCode()));
return airDataExport;
}

private String uploadOss(String filePath, String filename) {
File file = new File(filePath);
InputStream in = null;
String fileUrl = "";
try {
in = new FileInputStream(file);
aliyunOSSUtil.uploadFile2OSS(in, filename);
fileUrl = aliyunOSSUtil.getFileUrl(filename);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return fileUrl;
}

/**
* @param request
* @param inspection
* @param airDataType
* @param ossUrl
*/
private void insertAirDataExport(ExportReportRequest request, Inspection inspection, AirDataType airDataType, String ossUrl) {
// 记录
AirDataExport airDataExport = new AirDataExport();
airDataExport.setTenantId(inspection.getTenantId());
airDataExport.setInspectionId(request.getInspectionId());
airDataExport.setExportType("report");
airDataExport.setAirDataTypeId(airDataType.getId());
airDataExport.setGridSize(request.getGridSize());
airDataExport.setOssUrl(ossUrl);

Integer count = airDataExportMapper.insert(airDataExport);
if (count <= 0) {
log.info("添加大气数据报告导出记录失败");
}
}
}

+ 74
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/airData/report/GenerateReportWordService.java 查看文件

@@ -0,0 +1,74 @@
package com.tuoheng.admin.service.airData.report;

import com.lowagie.text.*;
import com.tuoheng.admin.entity.domain.AirDataType;
import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.utils.WordUtils;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Slf4j
@Service
public class GenerateReportWordService {

@Autowired
private UserMapper userMapper;

/**
* @param filepath
* @param request
* @param airDataType
* @param detectionTime
* @param equipmentMountCode
* @param analyticalMethods
* @return
*/
public JsonResult buildWord(String filepath, ExportReportRequest request, AirDataType airDataType, String detectionTime, String equipmentMountCode, String analyticalMethods) {
WordUtils wordUtils = new WordUtils();
wordUtils.getDocument().setPageSize(PageSize.A4);
wordUtils.getDocument().setMargins(71f, 71f, 72f, 72f);
try {
wordUtils.openDocument(filepath);

// 标题
// String titleName = airDataType.getDataType() + "报告";
// wordUtils.insertTitlePattern(titleName, wordUtils.rtfGsBt1);

wordUtils.insertContext(airDataType.getDataType() + "浓度分布", 10, Font.BOLD, Element.ALIGN_LEFT, 20, 0, 0);

wordUtils.insertContext("检测时间:" + detectionTime, 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("监测设备:" + equipmentMountCode, 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("分析方法:" + analyticalMethods, 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("采样点数量:" + request.getSamplingPointsNum(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("检测区域网格平均尺寸:" + request.getAverageGridSize(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("总检测区域网格面积:" + request.getGridArea(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext("检测区域中心点经纬度:" + request.getCenterPointLongitudeAndLatitude(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext(airDataType.getDataType() + "检测区域平均浓度:" + request.getAverageConcentration(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext(airDataType.getDataType() + "网格浓度最高值:" + request.getGridConcentrationMax(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext(airDataType.getDataType() + "网格浓度最小值:" + request.getGridConcentrationMix(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext(airDataType.getDataType() + "单点浓度最高值:" + request.getSinglePointConcentrationMax(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertContext(airDataType.getDataType() + "单点浓度最低值:" + request.getSinglePointConcentrationMix(), 10, Font.NORMAL, Element.ALIGN_LEFT, 20, 0, 0);
wordUtils.insertImg(request.getOssUrl(), Image.ALIGN_CENTER, 400, 500, 100, 100, 100, 0);
wordUtils.insertImg(request.getStandardOssUrl(), Image.ALIGN_CENTER, 100, 500, 100, 100, 100, 0);
} catch (DocumentException e) {
log.info("生成报告word异常");
throw new RuntimeException(e);
} catch (IOException e) {
log.info("生成报告word异常");
throw new RuntimeException(e);
} finally {
try {
wordUtils.closeDocument();
} catch (DocumentException e) {
throw new RuntimeException(e);
}
}
return JsonResult.success();
}

}

+ 2
- 2
tuoheng-service/tuoheng-admin/src/main/resources/application-local.yml 查看文件

@@ -131,7 +131,7 @@ file:
#静态资源对外暴露的访问路径
staticAccessPath: /**
#静态资源实际存储路径
uploadFolder: /data/java/tuoheng_air_monitor/uploads/
uploadFolder: /data/java/tuoheng_airmonitor/uploads/


# 自定义配置
@@ -162,7 +162,7 @@ tuoheng:
#静态资源对外暴露的访问路径
staticAccessPath: /**
#静态资源实际存储路径
uploadFolder: /data/java/tuoheng_air_monitor/uploads/
uploadFolder: /data/java/tuoheng_airmonitor/uploads/

#阿里云
aliyuncsVod:

+ 10
- 0
tuoheng-service/tuoheng-admin/src/main/resources/mapper/AirDataExportMapper.xml 查看文件

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuoheng.admin.mapper.AirDataExportMapper">




</mapper>

+ 42
- 0
tuoheng-service/tuoheng-admin/src/test/java/com/tuoheng/admin/service/ExportReportServiceTest.java 查看文件

@@ -0,0 +1,42 @@
package com.tuoheng.admin.service;

import com.tuoheng.admin.entity.request.report.ExportReportRequest;
import com.tuoheng.admin.entity.request.third.DspCallbackRequest;
import com.tuoheng.admin.service.airData.report.ExportReportService;
import com.tuoheng.admin.service.third.dsp.IDspCallbackService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExportReportServiceTest {

@Autowired
private ExportReportService exportReportService;

@Test
public void testxportReport() {
ExportReportRequest request = new ExportReportRequest();
request.setInspectionId("e53dc6189ec300fe063c30f5972a5fe1");
request.setAirDataTypeId("1");
request.setOssUrl("https://img2.woyaogexing.com/2023/05/23/1ec4a4a1560ca19c8c1775251dabb620.png");
request.setStandardOssUrl("https://img2.woyaogexing.com/2023/05/23/1ec4a4a1560ca19c8c1775251dabb620.png");
request.setSamplingPointsNum("510"); // 采样点数量
request.setAverageGridSize("84.9635米X849635米(7218803平方米)"); // 检测区域网格平均尺寸
request.setGridArea("346502.563(平方米)"); // 总检测区域网格面积
request.setCenterPointLongitudeAndLatitude("1187743E318280N"); // 检测区域中心点经纬度
request.setAverageConcentration("20037ug/m3"); // 检测区域平均浓度
request.setGridConcentrationMax("24714u/m31187726E318253N"); // 网格浓度最高值
request.setGridConcentrationMix("16000ug/m3(1187761E318291N)"); // 网格浓度最小值
request.setSinglePointConcentrationMax("25000ug/m3(1187718318252N)2022/04/29 14:06:40"); // 单点浓度最高值
request.setSinglePointConcentrationMix("16000ug/m3(1187753318286 N)2022/04/2914:02:21"); // 单点浓度最低值

// exportReportService.exportReport(request);
}

}

Loading…
取消
儲存