微调
This commit is contained in:
@@ -83,7 +83,7 @@ public class ReportController extends BaseController {
|
||||
public HttpResult<PqReportVO> getById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.getById(id), methodDescribe);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.getByReportId(id), methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface IPqReportService extends IService<PqReport> {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
PqReportVO getById(String id);
|
||||
PqReportVO getByReportId(String id);
|
||||
|
||||
/**
|
||||
* 新增报告
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -131,7 +132,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqReportVO getById(String id) {
|
||||
public PqReportVO getByReportId(String id) {
|
||||
PqReport pqReport = this.baseMapper.selectById(id);
|
||||
PqReportVO pqReportVO = new PqReportVO();
|
||||
BeanUtils.copyProperties(pqReport, pqReportVO);
|
||||
@@ -304,6 +305,10 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
@Override
|
||||
public void generateReport(DevReportParam devReportParam) {
|
||||
AdPlan plan = adPlanService.getById(devReportParam.getPlanId());
|
||||
if (ObjectUtil.isNotNull(plan.getReportTemplateId())) {
|
||||
this.generateReportByPlan(plan, devReportParam);
|
||||
} else {
|
||||
// 根据设备类型找到报告模板
|
||||
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
||||
if (Objects.isNull(pqDevVO)) {
|
||||
@@ -341,26 +346,83 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
out.close();
|
||||
|
||||
System.out.println("报告生成成功!");
|
||||
this.updateDevAndPlanState(devReportParam.getDevId(), devReportParam.getPlanId());
|
||||
} catch (IOException e) {
|
||||
log.error("生成报告文件失败", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据计划绑定的报告模板生成报告
|
||||
*
|
||||
* @param plan
|
||||
* @param devReportParam
|
||||
*/
|
||||
private void generateReportByPlan(AdPlan plan, DevReportParam devReportParam) {
|
||||
// 根据设备类型找到报告模板
|
||||
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("设备类型缺失,请联系管理员!");
|
||||
}
|
||||
PqReport report = this.lambdaQuery().eq(PqReport::getId, plan.getAssociateReport()).eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (Objects.isNull(report)) {
|
||||
throw new BusinessException("报告模板缺失,请联系管理员!");
|
||||
}
|
||||
|
||||
FileSystemResource resource = new FileSystemResource(report.getBasePath());
|
||||
try (InputStream inputStream = resource.getInputStream()) {
|
||||
// 加载Word文档
|
||||
XWPFDocument baseModelDocument = new XWPFDocument(inputStream);
|
||||
// 处理基础模版中的信息
|
||||
dealBaseModel(baseModelDocument, pqDevVO, devType);
|
||||
// 处理数据页中的信息
|
||||
dealDataModel(baseModelDocument, devReportParam, pqDevVO);
|
||||
// 处理需要输出的目录地址 基础路径+设备类型+装置编号.docx
|
||||
// 最终文件输出的路径
|
||||
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
||||
ensureDirectoryExists(dirPath); // 确保目录存在
|
||||
FileOutputStream out = new FileOutputStream(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(".docx"));
|
||||
// 4. 保存新的Word文档
|
||||
try {
|
||||
baseModelDocument.write(out);
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException("生成报告文件失败");
|
||||
}
|
||||
out.close();
|
||||
|
||||
System.out.println("报告生成成功!");
|
||||
|
||||
this.updateDevAndPlanState(devReportParam.getDevId(), devReportParam.getPlanId());
|
||||
} catch (IOException e) {
|
||||
log.error("生成报告文件失败", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDevAndPlanState(String devId, String planId) {
|
||||
// 将改设备的报告生成状态调整为已生成
|
||||
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), DevReportStateEnum.GENERATED.getValue());
|
||||
iPqDevService.updatePqDevReportState(devId, DevReportStateEnum.GENERATED.getValue());
|
||||
|
||||
// 判断该计划下是否所有设备报告已生成,如果已生成则将计划的报告状态给为已生成
|
||||
int count = iPqDevService.countUnReportDev(devReportParam.getPlanId());
|
||||
int count = iPqDevService.countUnReportDev(planId);
|
||||
LambdaUpdateWrapper<AdPlan> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(AdPlan::getId, devReportParam.getPlanId());
|
||||
updateWrapper.eq(AdPlan::getId, planId);
|
||||
if (count == 0) {
|
||||
updateWrapper.set(AdPlan::getReportState, PlanReportStateEnum.REPORT_STATE_ALL_GENERATED.getValue());
|
||||
} else {
|
||||
updateWrapper.set(AdPlan::getReportState, PlanReportStateEnum.REPORT_STATE_PARTIALLY_GENERATED.getValue());
|
||||
}
|
||||
adPlanService.update(updateWrapper);
|
||||
} catch (IOException e) {
|
||||
log.error("生成报告文件失败", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadReport(DevReportParam devReportParam, HttpServletResponse response) {
|
||||
PqDevVO pqDevVO = iPqDevService.getPqDevById(devReportParam.getDevId());
|
||||
|
||||
@@ -39,16 +39,16 @@
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml-full</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.poi</groupId>-->
|
||||
<!-- <artifactId>poi-ooxml</artifactId>-->
|
||||
<!-- <version>5.2.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.poi</groupId>-->
|
||||
<!-- <artifactId>poi-ooxml-full</artifactId>-->
|
||||
<!-- <version>5.2.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
||||
|
||||
XSSFSheet sheet = wb.createSheet("sheet1");
|
||||
|
||||
createPieChart(sheet, collect.keySet().stream().collect(Collectors.toList()), collect.values().stream().collect(Collectors.toList()));
|
||||
//createPieChart(sheet, collect.keySet().stream().collect(Collectors.toList()), collect.values().stream().collect(Collectors.toList()));
|
||||
|
||||
wb.write(outputStream);
|
||||
wb.close();
|
||||
@@ -174,61 +174,61 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建饼图
|
||||
*
|
||||
* @param sheet
|
||||
* @param categoryList
|
||||
* @param sheetDataList
|
||||
*/
|
||||
private void createPieChart(XSSFSheet sheet, List<String> categoryList, List<Long> sheetDataList) {
|
||||
int row1 = 0;
|
||||
int row2 = 8;
|
||||
int col1 = 0;
|
||||
int col2 = 30;
|
||||
// 设置图表列宽
|
||||
for (int i = 0; i < row2; i++) {
|
||||
sheet.setColumnWidth(i, 6000);
|
||||
}
|
||||
//y轴显示数据
|
||||
String[] headArray = categoryList.stream().collect(Collectors.toList()).toArray(new String[]{});
|
||||
|
||||
// Create a chart
|
||||
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, row2, col2);
|
||||
XSSFChart chart = drawing.createChart(anchor);
|
||||
//标题是否覆盖图表
|
||||
chart.setTitleOverlay(false);
|
||||
//设置图表标题
|
||||
chart.setTitleText("分析结果");
|
||||
// 创建图表系列
|
||||
XDDFChartLegend legend = chart.getOrAddLegend();
|
||||
legend.setPosition(LegendPosition.TOP);
|
||||
|
||||
//动态数据
|
||||
//x轴数据
|
||||
XDDFDataSource<String> xData = XDDFDataSourcesFactory.fromArray(headArray);
|
||||
//饼图数据
|
||||
XDDFPieChartData data = (XDDFPieChartData) chart.createData(ChartTypes.PIE, null, null);
|
||||
data.setVaryColors(true);
|
||||
|
||||
Double[] yArray = sheetDataList.stream().collect(Collectors.toList()).toArray(new Double[]{});
|
||||
//y轴数据
|
||||
XDDFNumericalDataSource<Double> yData = XDDFDataSourcesFactory.fromArray(yArray);
|
||||
XDDFChartData.Series series = data.addSeries(xData, yData);
|
||||
|
||||
//series.setTitle("title", null);
|
||||
series.setShowLeaderLines(true);
|
||||
// 隐藏图例标识、系列名称、分类名称和数值
|
||||
XDDFPieChartData.Series s = (XDDFPieChartData.Series) series;
|
||||
CTPieSer ctPieSer = s.getCTPieSer();
|
||||
showCateName(ctPieSer, false);
|
||||
showVal(ctPieSer, false);
|
||||
showLegendKey(ctPieSer, false);
|
||||
showSerName(ctPieSer, false);
|
||||
|
||||
chart.plot(data);
|
||||
}
|
||||
// /**
|
||||
// * 创建饼图
|
||||
// *
|
||||
// * @param sheet
|
||||
// * @param categoryList
|
||||
// * @param sheetDataList
|
||||
// */
|
||||
// private void createPieChart(XSSFSheet sheet, List<String> categoryList, List<Long> sheetDataList) {
|
||||
// int row1 = 0;
|
||||
// int row2 = 8;
|
||||
// int col1 = 0;
|
||||
// int col2 = 30;
|
||||
// // 设置图表列宽
|
||||
// for (int i = 0; i < row2; i++) {
|
||||
// sheet.setColumnWidth(i, 6000);
|
||||
// }
|
||||
// //y轴显示数据
|
||||
// String[] headArray = categoryList.stream().collect(Collectors.toList()).toArray(new String[]{});
|
||||
//
|
||||
// // Create a chart
|
||||
// XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||
// ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, row2, col2);
|
||||
// XSSFChart chart = drawing.createChart(anchor);
|
||||
// //标题是否覆盖图表
|
||||
// chart.setTitleOverlay(false);
|
||||
// //设置图表标题
|
||||
// chart.setTitleText("分析结果");
|
||||
// // 创建图表系列
|
||||
// XDDFChartLegend legend = chart.getOrAddLegend();
|
||||
// legend.setPosition(LegendPosition.TOP);
|
||||
//
|
||||
// //动态数据
|
||||
// //x轴数据
|
||||
// XDDFDataSource<String> xData = XDDFDataSourcesFactory.fromArray(headArray);
|
||||
// //饼图数据
|
||||
// XDDFPieChartData data = (XDDFPieChartData) chart.createData(ChartTypes.PIE, null, null);
|
||||
// data.setVaryColors(true);
|
||||
//
|
||||
// Double[] yArray = sheetDataList.stream().collect(Collectors.toList()).toArray(new Double[]{});
|
||||
// //y轴数据
|
||||
// XDDFNumericalDataSource<Double> yData = XDDFDataSourcesFactory.fromArray(yArray);
|
||||
// XDDFChartData.Series series = data.addSeries(xData, yData);
|
||||
//
|
||||
// //series.setTitle("title", null);
|
||||
// series.setShowLeaderLines(true);
|
||||
// // 隐藏图例标识、系列名称、分类名称和数值
|
||||
// XDDFPieChartData.Series s = (XDDFPieChartData.Series) series;
|
||||
// CTPieSer ctPieSer = s.getCTPieSer();
|
||||
// showCateName(ctPieSer, false);
|
||||
// showVal(ctPieSer, false);
|
||||
// showLegendKey(ctPieSer, false);
|
||||
// showSerName(ctPieSer, false);
|
||||
//
|
||||
// chart.plot(data);
|
||||
// }
|
||||
|
||||
// 控制值系列名称是否显示
|
||||
private void showSerName(CTPieSer series, boolean val) {
|
||||
|
||||
Reference in New Issue
Block a user