|
@@ -1,18 +1,37 @@
|
|
package com.ruoyi.project.sems.service.impl;
|
|
package com.ruoyi.project.sems.service.impl;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.ruoyi.framework.config.RuoYiConfig;
|
|
|
|
+import com.ruoyi.framework.web.controller.BaseController;
|
|
|
|
+import com.ruoyi.project.plant.domain.TStaffmgr;
|
|
|
|
+import com.ruoyi.project.sems.domain.*;
|
|
|
|
+import com.ruoyi.project.sems.service.*;
|
|
|
|
+import com.ruoyi.project.system.domain.SysDictData;
|
|
|
|
+import com.ruoyi.project.training.domain.TTraining;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.ruoyi.project.sems.mapper.TSpecReportMapper;
|
|
import com.ruoyi.project.sems.mapper.TSpecReportMapper;
|
|
-import com.ruoyi.project.sems.domain.TSpecReport;
|
|
|
|
-import com.ruoyi.project.sems.service.ITSpecReportService;
|
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -24,9 +43,22 @@ import javax.servlet.http.HttpServletResponse;
|
|
@Service
|
|
@Service
|
|
public class TSpecReportServiceImpl implements ITSpecReportService
|
|
public class TSpecReportServiceImpl implements ITSpecReportService
|
|
{
|
|
{
|
|
- @Autowired
|
|
|
|
|
|
+ @Resource
|
|
private TSpecReportMapper tSpecReportMapper;
|
|
private TSpecReportMapper tSpecReportMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevDtService tSpecdevDtService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevDzsbService tSpecdevDzsbService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevGlService tSpecdevGlService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevYlgdService tSpecdevYlgdService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevYlrqService tSpecdevYlrqService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ITSpecdevCcService tSpecdevCcService;
|
|
|
|
|
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(BaseController.class);
|
|
/**
|
|
/**
|
|
* 查询特种设备报告
|
|
* 查询特种设备报告
|
|
*
|
|
*
|
|
@@ -58,35 +90,193 @@ public class TSpecReportServiceImpl implements ITSpecReportService
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional
|
|
public int insertTSpecReport(TSpecReport tSpecReport, HttpServletResponse response)
|
|
public int insertTSpecReport(TSpecReport tSpecReport, HttpServletResponse response)
|
|
{
|
|
{
|
|
|
|
+ tSpecReportMapper.insertTSpecReport(tSpecReport);
|
|
try {
|
|
try {
|
|
String tempUrl = "static/word/sems/report/sems-report.xlsx"; // 模板文件
|
|
String tempUrl = "static/word/sems/report/sems-report.xlsx"; // 模板文件
|
|
|
|
+ // 生成的路径
|
|
|
|
+ String fileDir = RuoYiConfig.getProfile() + "/" + "sems/spec-sems";
|
|
InputStream is = null;
|
|
InputStream is = null;
|
|
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
|
|
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
|
|
XSSFWorkbook wb1 = new XSSFWorkbook(is);
|
|
XSSFWorkbook wb1 = new XSSFWorkbook(is);
|
|
|
|
|
|
SXSSFWorkbook wb = new SXSSFWorkbook(wb1, 1000);
|
|
SXSSFWorkbook wb = new SXSSFWorkbook(wb1, 1000);
|
|
// 替换excel模板数据
|
|
// 替换excel模板数据
|
|
-// replaceExcelCbps(wb, trainingId);
|
|
|
|
- response.setContentType("application/octet-stream");// 下载,默认就是下载
|
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
|
- response.setHeader("Content-Disposition",
|
|
|
|
- "attachment;fileName=" + URLEncoder.encode(tSpecReport.getReportName() + ".xlsx", "UTF-8"));
|
|
|
|
- // 刷新缓冲
|
|
|
|
- response.flushBuffer();
|
|
|
|
- OutputStream ouputStream = response.getOutputStream();
|
|
|
|
- wb.write(ouputStream);
|
|
|
|
- ouputStream.flush();
|
|
|
|
- ouputStream.close();
|
|
|
|
|
|
+ replaceExcel(wb);
|
|
|
|
+ replaceExcelExpire(wb);
|
|
|
|
+ // Save the generated file
|
|
|
|
+ File dir = new File(fileDir);
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
+ logger.info("目录不存在,创建文件夹{}!", fileDir);
|
|
|
|
+ dir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ FileOutputStream fos = null;
|
|
|
|
+ String filePath = fileDir + "/" + tSpecReport.getId() + "semsReport.xlsx";
|
|
|
|
+ fos = new FileOutputStream(filePath);
|
|
|
|
+ wb.write(fos);
|
|
|
|
+
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //过期渲染
|
|
|
|
+ private void replaceExcelExpire(SXSSFWorkbook wb) {
|
|
|
|
+ Sheet sheet;
|
|
|
|
+ if (wb instanceof SXSSFWorkbook) {
|
|
|
|
+ SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
|
|
|
|
+ sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
|
|
|
|
+ } else {
|
|
|
|
+ sheet = wb.getSheetAt(0);
|
|
|
|
+ }
|
|
|
|
+ List<TSpecReport> ylrqList = tSpecReportMapper.selectExpriedYlrq(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(ylrqList));
|
|
|
|
+ Row row = sheet.getRow(3);
|
|
|
|
+ Cell cell = row.getCell(1);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ CellStyle originalStyle = cell.getCellStyle();
|
|
|
|
+ cell.setCellStyle(originalStyle);
|
|
|
|
+ cell.setCellValue(getDevTotal(ylrqList));
|
|
|
|
+
|
|
|
|
+ List<TSpecReport> ylgdList = tSpecReportMapper.selectExpriedYlgd(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(ylgdList));
|
|
|
|
+ Row row2 = sheet.getRow(3);
|
|
|
|
+ Cell cell2 = row2.getCell(4);
|
|
|
|
+ cell2.setCellValue(getDevTotal(ylgdList));
|
|
|
|
|
|
|
|
+ List<TSpecReport> glList = tSpecReportMapper.selectExpriedGl(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(glList));
|
|
|
|
+ Row row3 = sheet.getRow(3);
|
|
|
|
+ Cell cell3 = row3.getCell(7);
|
|
|
|
+ cell3.setCellValue(getDevTotal(glList));
|
|
|
|
|
|
- return tSpecReportMapper.insertTSpecReport(tSpecReport);
|
|
|
|
|
|
+ List<TSpecReport> dtList = tSpecReportMapper.selectExpriedDt(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(dtList));
|
|
|
|
+ Row row4 = sheet.getRow(3);
|
|
|
|
+ Cell cell4 = row4.getCell(10);
|
|
|
|
+ cell4.setCellValue(getDevTotal(dtList));
|
|
|
|
+
|
|
|
|
+ List<TSpecReport> dzsbList = tSpecReportMapper.selectExpriedDzsb(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(dzsbList));
|
|
|
|
+ Row row5 = sheet.getRow(3);
|
|
|
|
+ Cell cell5 = row5.getCell(13);
|
|
|
|
+ cell5.setCellValue(getDevTotal(dzsbList));
|
|
|
|
+
|
|
|
|
+ List<TSpecReport> ccList = tSpecReportMapper.selectExpriedCc(new TSpecReport());
|
|
|
|
+ logger.info(JSON.toJSONString(ccList));
|
|
|
|
+ Row row6 = sheet.getRow(3);
|
|
|
|
+ Cell cell6 = row6.getCell(16);
|
|
|
|
+ cell6.setCellValue(getDevTotal(ccList));
|
|
|
|
+
|
|
|
|
+ sheet.shiftRows(6, sheet.getLastRowNum(), 1);
|
|
|
|
+ cpoyRow(6 ,sheet );
|
|
|
|
+ sheet.shiftRows(6, sheet.getLastRowNum(), 1);
|
|
|
|
+ cpoyRow(6 ,sheet );
|
|
|
|
+ sheet.shiftRows(6, sheet.getLastRowNum(), 1);
|
|
|
|
+ cpoyRow(6 ,sheet );
|
|
|
|
+ sheet.shiftRows(6, sheet.getLastRowNum(), 1);
|
|
|
|
+ cpoyRow(6 ,sheet );
|
|
|
|
+ sheet.shiftRows(6, sheet.getLastRowNum(), 1);
|
|
|
|
+ cpoyRow(6 ,sheet );
|
|
|
|
+ // 合并区域从第0行第0列到第0行第3列
|
|
|
|
+ CellRangeAddress mergedRegion = new CellRangeAddress(
|
|
|
|
+ 3, // 起始行
|
|
|
|
+ 12, // 结束行
|
|
|
|
+ 0, // 起始列
|
|
|
|
+ 0 // 结束列
|
|
|
|
+ );
|
|
|
|
+ sheet.addMergedRegion(mergedRegion);
|
|
}
|
|
}
|
|
|
|
+ // Excel 渲染
|
|
|
|
+ private void replaceExcel(SXSSFWorkbook wb) {
|
|
|
|
+ Sheet sheet;
|
|
|
|
+ if (wb instanceof SXSSFWorkbook) {
|
|
|
|
+ SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
|
|
|
|
+ sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
|
|
|
|
+ } else {
|
|
|
|
+ sheet = wb.getSheetAt(0);
|
|
|
|
+ }
|
|
|
|
+ //压力容器
|
|
|
|
+ int ylrqAll = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row = sheet.getRow(2);
|
|
|
|
+ Cell cell = row.getCell(1);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ CellStyle originalStyle = cell.getCellStyle();
|
|
|
|
+ cell.setCellStyle(originalStyle);
|
|
|
|
+ cell.setCellValue(ylrqAll + "(台)");
|
|
|
|
+
|
|
|
|
+ //压力管道
|
|
|
|
+ int ylgdAll = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row2 = sheet.getRow(2);
|
|
|
|
+ Cell cell2 = row2.getCell(4);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ cell2.setCellValue(ylgdAll + "(条)");
|
|
|
|
+ //锅炉
|
|
|
|
+ int glAll = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row3 = sheet.getRow(2);
|
|
|
|
+ Cell cell3 = row3.getCell(7);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ cell3.setCellValue(glAll + "(套)");
|
|
|
|
+ //电梯
|
|
|
|
+ int dtAll = tSpecdevDtService.count(new QueryWrapper<TSpecdevDt>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row4 = sheet.getRow(2);
|
|
|
|
+ Cell cell4 = row4.getCell(10);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ cell4.setCellValue(dtAll + "(台)");
|
|
|
|
+ //吊装设备
|
|
|
|
+ int dzsbAll = tSpecdevDzsbService.count(new QueryWrapper<TSpecdevDzsb>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row5 = sheet.getRow(2);
|
|
|
|
+ Cell cell5 = row5.getCell(13);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ cell5.setCellValue(dzsbAll + "(条)");
|
|
|
|
+ //叉车
|
|
|
|
+ int ccAll = tSpecdevCcService.count(new QueryWrapper<TSpecdevCc>()
|
|
|
|
+ .eq("STATUS" , 1)
|
|
|
|
+ .eq("del_flag" , 0)
|
|
|
|
+ );
|
|
|
|
+ Row row6 = sheet.getRow(2);
|
|
|
|
+ Cell cell6 = row6.getCell(16);
|
|
|
|
+ // 获取单元格样式
|
|
|
|
+ cell6.setCellValue(ccAll + "(辆)");
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int getDevTotal (List<TSpecReport> list){
|
|
|
|
+ int num = 0;
|
|
|
|
+ for (TSpecReport t : list
|
|
|
|
+ ) {
|
|
|
|
+ num = num + t.getDevNum();
|
|
|
|
+ }
|
|
|
|
+ return num;
|
|
|
|
+ }
|
|
|
|
+ void cpoyRow (int rowNum ,Sheet sheet ){
|
|
|
|
+ Row newRow = sheet.createRow(rowNum);
|
|
|
|
+ Row oldRow = sheet.getRow(rowNum+1);
|
|
|
|
+ for (int i = 0; i < 22; i++) {
|
|
|
|
+ Cell newCell = newRow.createCell(i);
|
|
|
|
+ Cell oldCell = oldRow.getCell(i);
|
|
|
|
+ CellStyle originalStyle = oldCell.getCellStyle();
|
|
|
|
+ newCell.setCellStyle(originalStyle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 修改特种设备报告
|
|
* 修改特种设备报告
|
|
*
|
|
*
|