|
@@ -1,15 +1,26 @@
|
|
|
package com.nokia.tsl_data.service;
|
|
|
|
|
|
+import com.nokia.common.io.excel.entity.CellRect;
|
|
|
+import com.nokia.common.io.excel.poi.PoiUtil;
|
|
|
+import com.nokia.tsl_data.dao.MobileComplaintMapper;
|
|
|
import com.nokia.tsl_data.dao.SysDataDictionaryRepository;
|
|
|
+import com.nokia.tsl_data.dao.TslMapper;
|
|
|
+import com.nokia.tsl_data.properties.OutputProperties;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.ss.util.RegionUtil;
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.text.DateFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -28,21 +39,103 @@ import java.util.Map;
|
|
|
public class TslReportService {
|
|
|
|
|
|
private final TslDataService tslDataService;
|
|
|
+ private final OutputProperties outputProperties;
|
|
|
+ private final TslMapper tslMapper;
|
|
|
+ private final MobileComplaintMapper mobileComplaintMapper;
|
|
|
private final SysDataDictionaryRepository sysDataDictionaryRepository;
|
|
|
|
|
|
private XSSFWorkbook workbook = null;
|
|
|
|
|
|
private static final DateFormat DAY_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
|
- public TslReportService(TslDataService tslDataService, SysDataDictionaryRepository sysDataDictionaryRepository) {
|
|
|
+ public TslReportService(TslDataService tslDataService, OutputProperties outputProperties, TslMapper tslMapper, MobileComplaintMapper mobileComplaintMapper, SysDataDictionaryRepository sysDataDictionaryRepository) {
|
|
|
this.tslDataService = tslDataService;
|
|
|
+ this.outputProperties = outputProperties;
|
|
|
+ this.tslMapper = tslMapper;
|
|
|
+ this.mobileComplaintMapper = mobileComplaintMapper;
|
|
|
this.sysDataDictionaryRepository = sysDataDictionaryRepository;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 截图任务
|
|
|
+ */
|
|
|
+ public void screenShot(String day) {
|
|
|
+ String fileName = outputProperties.getOutputFileNamePrefix() + day + ".xlsx";
|
|
|
+ File file = Paths.get(outputProperties.getOutputPath(), day, fileName).toFile();
|
|
|
+ if (!file.exists()) {
|
|
|
+ throw new RuntimeException(String.format("无法截图,文件%s不存在", file.getAbsolutePath()));
|
|
|
+ }
|
|
|
+ try (Workbook workbook = WorkbookFactory.create(file);) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(new SimpleDateFormat("yyyyMMdd").parse(day));
|
|
|
+ int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
+ BufferedImage screenShot;
|
|
|
+ // 截图1
|
|
|
+ String area = "A1:" + CellRect.getColumnName(dayOfMonth + 7) + "15";
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("管理端-移网质量类"), area, "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-1-投诉率.png").toFile());
|
|
|
+
|
|
|
+ // 新截图
|
|
|
+ String area2 = "A1:" + CellRect.getColumnName(dayOfMonth + 7) + "15";
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("客户端-战略考核"), area2, "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-2-客户端-战略考核.png").toFile());
|
|
|
+
|
|
|
+ // 截图2
|
|
|
+ if (!day.endsWith("01")) {
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("管理端-重复投诉率"), "A1:G16", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-3-重复投诉率.png").toFile());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 截图3 4
|
|
|
+ Sheet sheet = workbook.getSheet("投诉处理时长、超时工单概况");
|
|
|
+ screenShot = PoiUtil.screenShot(sheet, "A1:D15", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-4-超时工单.png").toFile());
|
|
|
+ screenShot = PoiUtil.screenShot(sheet, "G1:J14", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-5-处理时长.png").toFile());
|
|
|
+
|
|
|
+ // 截图5
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("客户端-投诉问题解决满意度"), "A1:D15", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-6-满意率.png").toFile());
|
|
|
+
|
|
|
+ // 截图6
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("客户端-投诉问题解决率"), "A1:D15", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-7-解决率.png").toFile());
|
|
|
+
|
|
|
+ // 截图7
|
|
|
+ screenShot = PoiUtil.screenShot(workbook.getSheet("客户端-投诉问题响应率"), "A1:D15", "微软雅黑");
|
|
|
+ ImageIO.write(screenShot, "png", Paths.get(outputProperties.getOutputPath(), day, day + "-8-响应率.png").toFile());
|
|
|
+ } catch (EncryptedDocumentException | IOException | ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成报表
|
|
|
+ */
|
|
|
+ public void generateReport(String day) {
|
|
|
+ String fileName = outputProperties.getOutputFileNamePrefix() + day + ".xlsx";
|
|
|
+ File file = Paths.get(outputProperties.getOutputPath(), day).toFile();
|
|
|
+ if (!file.exists()) {
|
|
|
+ boolean mkdirs = file.mkdirs();
|
|
|
+ System.out.println(mkdirs);
|
|
|
+ }
|
|
|
+ String dayId = day.substring(0, 4) + "-" + day.substring(4, 6) + "-" + day.substring(6);
|
|
|
+ int qualityCountForDay = tslMapper.selectQualityCountForDay(dayId);
|
|
|
+ if (qualityCountForDay == 0) {
|
|
|
+ throw new RuntimeException("he_d_high_quality表缺少数据");
|
|
|
+ }
|
|
|
+ int compCountForDay = mobileComplaintMapper.selectCompCountForDay(day);
|
|
|
+ if (compCountForDay == 0) {
|
|
|
+ throw new RuntimeException("he_d_mobile_comp表缺少数据");
|
|
|
+ }
|
|
|
+ workbookToFile(day, Paths.get(file.getAbsolutePath(), fileName).toFile());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 写入workbook
|
|
|
*/
|
|
|
- public void workbookToFile(String day, String path) {
|
|
|
+ private void workbookToFile(String day, File file) {
|
|
|
// 每次需要重置workbook
|
|
|
workbook = new XSSFWorkbook();
|
|
|
// 按照顺序写入各个sheet
|
|
@@ -56,11 +149,12 @@ public class TslReportService {
|
|
|
getSheet3(day);
|
|
|
// 客户端-投诉问题解决满意度 客户端-投诉问题解决率 客户端-投诉问题响应率
|
|
|
getSheet4_6(day);
|
|
|
- try (OutputStream outputStream = new FileOutputStream(path)) {
|
|
|
+ try (OutputStream outputStream = new FileOutputStream(file)) {
|
|
|
workbook.write(outputStream);
|
|
|
workbook.close();
|
|
|
workbook = null;
|
|
|
} catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
log.error("写入失败。。。" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
@@ -960,7 +1054,7 @@ public class TslReportService {
|
|
|
private void setConditionalFormatting(Sheet sheet, CellRangeAddress rangeAddress) {
|
|
|
SheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
|
|
ConditionalFormattingRule rule = conditionalFormatting.createConditionalFormattingColorScaleRule();
|
|
|
- XSSFColor[] colors = new XSSFColor[] {
|
|
|
+ XSSFColor[] colors = new XSSFColor[]{
|
|
|
new XSSFColor(), new XSSFColor(), new XSSFColor()
|
|
|
};
|
|
|
colors[0].setARGBHex("FF63BE7B");
|
|
@@ -969,7 +1063,7 @@ public class TslReportService {
|
|
|
|
|
|
rule.getColorScaleFormatting().setColors(colors);
|
|
|
|
|
|
- CellRangeAddress[] cellRangeAddresses = new CellRangeAddress[] {
|
|
|
+ CellRangeAddress[] cellRangeAddresses = new CellRangeAddress[]{
|
|
|
rangeAddress
|
|
|
};
|
|
|
|
|
@@ -983,7 +1077,7 @@ public class TslReportService {
|
|
|
private void setConditionalFormatting2(Sheet sheet, CellRangeAddress rangeAddress) {
|
|
|
SheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
|
|
ConditionalFormattingRule rule = conditionalFormatting.createConditionalFormattingColorScaleRule();
|
|
|
- XSSFColor[] colors = new XSSFColor[] {
|
|
|
+ XSSFColor[] colors = new XSSFColor[]{
|
|
|
new XSSFColor(), new XSSFColor(), new XSSFColor()
|
|
|
};
|
|
|
colors[0].setARGBHex("FFF8696B");
|
|
@@ -992,7 +1086,7 @@ public class TslReportService {
|
|
|
|
|
|
rule.getColorScaleFormatting().setColors(colors);
|
|
|
|
|
|
- CellRangeAddress[] cellRangeAddresses = new CellRangeAddress[] {
|
|
|
+ CellRangeAddress[] cellRangeAddresses = new CellRangeAddress[]{
|
|
|
rangeAddress
|
|
|
};
|
|
|
|