报表调整
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
package com.njcn.gather.report.controller;
|
package com.njcn.gather.report.controller;
|
||||||
|
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.LogUtil;
|
import com.njcn.common.utils.LogUtil;
|
||||||
import com.njcn.gather.report.pojo.DevReportParam;
|
import com.njcn.gather.report.pojo.DevReportParam;
|
||||||
import com.njcn.gather.report.service.IReportService;
|
import com.njcn.gather.report.service.IReportService;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -38,11 +41,26 @@ public class ReportController extends BaseController {
|
|||||||
@PostMapping("/generateReport")
|
@PostMapping("/generateReport")
|
||||||
@ApiOperation("生成测试报告")
|
@ApiOperation("生成测试报告")
|
||||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
public void generateReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
|
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
|
||||||
String methodDescribe = getMethodDescribe("list");
|
String methodDescribe = getMethodDescribe("generateReport");
|
||||||
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
|
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
|
||||||
reportService.generateReport(devReportParam,response);
|
reportService.generateReport(devReportParam);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载报告
|
||||||
|
*/
|
||||||
|
@OperateInfo
|
||||||
|
@PostMapping("/downloadReport")
|
||||||
|
@ApiOperation("下载测试报告")
|
||||||
|
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||||
|
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
|
||||||
|
String methodDescribe = getMethodDescribe("downloadReport");
|
||||||
|
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
|
||||||
|
reportService.downloadReport(devReportParam,response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* @data 2025/1/9 20:59
|
* @data 2025/1/9 20:59
|
||||||
*/
|
*/
|
||||||
public interface IReportService {
|
public interface IReportService {
|
||||||
void generateReport(DevReportParam devReportParam, HttpServletResponse response);
|
void generateReport(DevReportParam devReportParam);
|
||||||
|
|
||||||
|
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import com.njcn.gather.detection.pojo.vo.DetectionData;
|
|||||||
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
|
||||||
import com.njcn.gather.device.device.service.IPqDevService;
|
import com.njcn.gather.device.device.service.IPqDevService;
|
||||||
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
|
import com.njcn.gather.device.pojo.enums.DevReportStateEnum;
|
||||||
import com.njcn.gather.device.script.pojo.po.PqScript;
|
|
||||||
import com.njcn.gather.device.script.pojo.po.PqScriptCheckData;
|
import com.njcn.gather.device.script.pojo.po.PqScriptCheckData;
|
||||||
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
|
import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
|
||||||
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
|
import com.njcn.gather.device.script.service.IPqScriptCheckDataService;
|
||||||
@@ -29,14 +28,12 @@ import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
|||||||
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
||||||
import com.njcn.gather.storage.service.AdHarmonicService;
|
import com.njcn.gather.storage.service.AdHarmonicService;
|
||||||
import com.njcn.gather.storage.service.AdNonHarmonicService;
|
import com.njcn.gather.storage.service.AdNonHarmonicService;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
import io.swagger.models.auth.In;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -55,6 +52,12 @@ import java.util.*;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ReportServiceImpl implements IReportService {
|
public class ReportServiceImpl implements IReportService {
|
||||||
|
|
||||||
|
@Value("${report.template:D:\\template\\}")
|
||||||
|
private String templatePath;
|
||||||
|
|
||||||
|
@Value("${report.reportDir:D:\\report}")
|
||||||
|
private String reportPath;
|
||||||
|
|
||||||
private final IPqDevService iPqDevService;
|
private final IPqDevService iPqDevService;
|
||||||
|
|
||||||
private final IDictDataService dictDataService;
|
private final IDictDataService dictDataService;
|
||||||
@@ -73,40 +76,44 @@ public class ReportServiceImpl implements IReportService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateReport(DevReportParam devReportParam, HttpServletResponse response) {
|
public void generateReport(DevReportParam devReportParam) {
|
||||||
// 读取模板文件
|
// 读取模板文件
|
||||||
Resource baseModel = new ClassPathResource("model/BaseModel.docx");
|
ClassPathResource resource = new ClassPathResource("/model/BaseModel.docx");
|
||||||
try (FileInputStream baseModelFis = new FileInputStream(baseModel.getFile())) {
|
try (InputStream inputStream = resource.getInputStream()) {
|
||||||
// 加载Word文档
|
// 加载Word文档
|
||||||
XWPFDocument baseModelDocument = new XWPFDocument(baseModelFis);
|
XWPFDocument baseModelDocument = new XWPFDocument(inputStream);
|
||||||
|
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
||||||
|
if (Objects.isNull(pqDevVO)) {
|
||||||
|
throw new BusinessException("请检查装置是否存在!");
|
||||||
|
}
|
||||||
|
// 获取设备型号
|
||||||
|
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||||
|
if (Objects.isNull(devType)) {
|
||||||
|
throw new BusinessException("设备类型丢失,请联系管理员!");
|
||||||
|
}
|
||||||
// 处理基础模版中的信息
|
// 处理基础模版中的信息
|
||||||
dealBaseModel(baseModelDocument, devReportParam);
|
dealBaseModel(baseModelDocument, pqDevVO);
|
||||||
// 处理数据页中的信息
|
// 处理数据页中的信息
|
||||||
dealDataModel(baseModelDocument, devReportParam);
|
dealDataModel(baseModelDocument, devReportParam, pqDevVO);
|
||||||
// //最终文件输出的路径
|
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
|
||||||
// FileOutputStream out = new FileOutputStream("C:\\Users\\hongawen\\Desktop\\testModel\\BaseDataModel" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_TIME_PATTERN) + ".docx");
|
// 最终文件输出的路径
|
||||||
// // 4. 保存新的Word文档
|
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
||||||
// try {
|
ensureDirectoryExists(dirPath); // 确保目录存在
|
||||||
// baseModelDocument.write(out);
|
FileOutputStream out = new FileOutputStream(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(".docx"));
|
||||||
// } catch (IOException e) {
|
// 4. 保存新的Word文档
|
||||||
// throw new BusinessException("生成报告文件失败");
|
try {
|
||||||
// }
|
baseModelDocument.write(out);
|
||||||
// out.close();
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException("生成报告文件失败");
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
|
||||||
// 设置响应头
|
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
|
||||||
String fileName = "调试报告" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_TIME_PATTERN) + ".docx";
|
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
|
||||||
// 保存新的Word文档到响应输出流
|
|
||||||
baseModelDocument.write(response.getOutputStream());
|
|
||||||
response.getOutputStream().flush();
|
|
||||||
System.out.println("报告生成成功!");
|
System.out.println("报告生成成功!");
|
||||||
|
|
||||||
// 将改设备的报告生成状态调整为已生成
|
// 将改设备的报告生成状态调整为已生成
|
||||||
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), 1);
|
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), 1);
|
||||||
|
|
||||||
// 判断该计划下是否所有设备报告已生成,如果已生成则将计划状态改为已完成
|
// 判断该计划下是否所有设备报告已生成,如果已生成则将计划的报告状态给为已生成
|
||||||
int count = iPqDevService.countUnReportDev(devReportParam.getPlanId());
|
int count = iPqDevService.countUnReportDev(devReportParam.getPlanId());
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
LambdaUpdateWrapper<AdPlan> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<AdPlan> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
@@ -116,21 +123,63 @@ public class ReportServiceImpl implements IReportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("生成报告文件失败", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadReport(DevReportParam devReportParam, HttpServletResponse response) {
|
||||||
|
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
||||||
|
if (Objects.isNull(pqDevVO)) {
|
||||||
|
throw new BusinessException("请检查装置是否存在!");
|
||||||
|
}
|
||||||
|
// 获取设备型号
|
||||||
|
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||||
|
if (Objects.isNull(devType)) {
|
||||||
|
throw new BusinessException("设备类型丢失,请联系管理员!");
|
||||||
|
}
|
||||||
|
// 找到该文件的路径
|
||||||
|
String filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(".docx");
|
||||||
|
File reportFile = new File(filePath);
|
||||||
|
if (!reportFile.exists()) {
|
||||||
|
// 如果文件不存在,则将改设备的报告生成状态调整为未生成
|
||||||
|
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), 0);
|
||||||
|
throw new BusinessException("报告文件不存在,请重新生成报告!");
|
||||||
|
} else {
|
||||||
|
try (FileInputStream fis = new FileInputStream(reportFile);
|
||||||
|
OutputStream os = response.getOutputStream()) {
|
||||||
|
|
||||||
|
// 设置响应头
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||||
|
String fileName = pqDevVO.getCreateId() + ".docx";
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||||
|
|
||||||
|
// 将文件内容写入响应输出流
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
// 刷新输出流
|
||||||
|
os.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理基础模版中的信息,非数据页报告
|
* 处理基础模版中的信息,非数据页报告
|
||||||
*
|
*
|
||||||
* @param baseModelDocument 模板文件
|
* @param baseModelDocument 模板文件
|
||||||
* @param devReportParam 被检设备参数
|
|
||||||
*/
|
*/
|
||||||
private void dealBaseModel(XWPFDocument baseModelDocument, DevReportParam devReportParam) {
|
private void dealBaseModel(XWPFDocument baseModelDocument, PqDevVO pqDevVO) {
|
||||||
// 首先获取非数据页中需要的信息
|
// 首先获取非数据页中需要的信息
|
||||||
Map<String, String> baseModelMap = new HashMap<>(16);
|
Map<String, String> baseModelMap = new HashMap<>(16);
|
||||||
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
|
||||||
// 获取设备型号
|
// 获取设备型号
|
||||||
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
DevType devType = devTypeService.getById(pqDevVO.getDevType());
|
||||||
baseModelMap.put("${devType}", devType.getName());
|
baseModelMap.put("${devType}", devType.getName());
|
||||||
@@ -170,15 +219,13 @@ public class ReportServiceImpl implements IReportService {
|
|||||||
* @param baseModelDocument 非数据页的内容
|
* @param baseModelDocument 非数据页的内容
|
||||||
* @param devReportParam 查询参数
|
* @param devReportParam 查询参数
|
||||||
*/
|
*/
|
||||||
private void dealDataModel(XWPFDocument baseModelDocument, DevReportParam devReportParam) throws IOException {
|
private void dealDataModel(XWPFDocument baseModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO) throws IOException {
|
||||||
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
|
||||||
AdPlan adPlan = adPlanService.getById(devReportParam.getPlanId());
|
AdPlan adPlan = adPlanService.getById(devReportParam.getPlanId());
|
||||||
String scriptId = adPlan.getScriptId();
|
String scriptId = adPlan.getScriptId();
|
||||||
Integer devChns = pqDevVO.getDevChns();
|
Integer devChns = pqDevVO.getDevChns();
|
||||||
for (int i = 1; i <= devChns; i++) {
|
for (int i = 1; i <= devChns; i++) {
|
||||||
Resource dataModel = new ClassPathResource("model/BaseDataModel.docx");
|
ClassPathResource resource = new ClassPathResource("/model/BaseDataModel.docx");
|
||||||
FileInputStream dataModelFis = new FileInputStream(dataModel.getFile());
|
XWPFDocument dataModelDocumentTemp = new XWPFDocument(resource.getInputStream());
|
||||||
XWPFDocument dataModelDocumentTemp = new XWPFDocument(dataModelFis);
|
|
||||||
|
|
||||||
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam();
|
SingleNonHarmParam singleNonHarmParam = new SingleNonHarmParam();
|
||||||
singleNonHarmParam.setPlanCode(adPlan.getCode());
|
singleNonHarmParam.setPlanCode(adPlan.getCode());
|
||||||
@@ -492,4 +539,17 @@ public class ReportServiceImpl implements IReportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ensureDirectoryExists(String directoryPath) {
|
||||||
|
File directory = new File(directoryPath);
|
||||||
|
if (!directory.exists()) {
|
||||||
|
boolean created = directory.mkdirs();
|
||||||
|
if (!created) {
|
||||||
|
throw new BusinessException("目录创建失败: " + directoryPath);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("目录已存在: " + directoryPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,12 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn.gather</groupId>
|
||||||
|
<artifactId>detection</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
|
|||||||
@@ -23,5 +23,7 @@ public interface PqDevMapper extends MPJBaseMapper<PqDev> {
|
|||||||
List<PreDetection> selectDevInfo(@Param("devIds") List<String> devIds);
|
List<PreDetection> selectDevInfo(@Param("devIds") List<String> devIds);
|
||||||
|
|
||||||
void finishPlan(@Param("planId")String planId);
|
void finishPlan(@Param("planId")String planId);
|
||||||
|
|
||||||
|
void updateReportState(@Param("id")String id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,5 +52,9 @@
|
|||||||
<update id="finishPlan" >
|
<update id="finishPlan" >
|
||||||
update ad_plan set Test_State = 2 where id = #{planId}
|
update ad_plan set Test_State = 2 where id = #{planId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="updateReportState" >
|
||||||
|
update pq_dev set Report_State = 1 where id = #{id}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -501,6 +501,9 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
if (result.containsKey(pqDev.getId())) {
|
if (result.containsKey(pqDev.getId())) {
|
||||||
Integer checkState;
|
Integer checkState;
|
||||||
if (pqDev.getReCheckNum() >= config.getMaxTime()) {
|
if (pqDev.getReCheckNum() >= config.getMaxTime()) {
|
||||||
|
// 装置报告生成 todo...
|
||||||
|
this.baseMapper.updateReportState(pqDev.getId());
|
||||||
|
// 装置归档
|
||||||
checkState = CheckStateEnum.DOCUMENTED.getValue();
|
checkState = CheckStateEnum.DOCUMENTED.getValue();
|
||||||
}else{
|
}else{
|
||||||
checkState = CheckStateEnum.CHECKED.getValue();
|
checkState = CheckStateEnum.CHECKED.getValue();
|
||||||
|
|||||||
@@ -74,3 +74,7 @@ Flicker:
|
|||||||
log:
|
log:
|
||||||
homeDir: D:\logs
|
homeDir: D:\logs
|
||||||
commonLevel: info
|
commonLevel: info
|
||||||
|
report:
|
||||||
|
template: D:\\template
|
||||||
|
reportDir: D:\\report
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user