package cn.besteam.modules.report.biz;
|
|
import cn.besteam.modules.medical.service.IMwCollectRecordService;
|
import cn.besteam.modules.report.dto.DisposalMonthlyReportDTO;
|
import cn.besteam.modules.report.vo.DisposalMonthlyReportVo;
|
import cn.besteam.modules.report.vo.DisposalMonthlyReportVoItemVO;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.modules.system.entity.SysDictItem;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
import cn.besteam.modules.system.service.ISysDictItemService;
|
import cn.hutool.poi.excel.ExcelWriter;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.ss.usermodel.BorderStyle;
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.xssf.usermodel.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.math.BigDecimal;
|
import java.net.URLEncoder;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
@Service
|
@Slf4j
|
public class SupervisionBiz {
|
|
@Autowired
|
private IMwCollectRecordService mwCollectRecordService;
|
|
@Autowired
|
private ISysDepartmentService departmentService;
|
|
@Autowired
|
private ISysDictItemService dictItemService;
|
|
|
|
public DisposalMonthlyReportVo getDisposalMonthlyReport(DisposalMonthlyReportDTO dto){
|
DisposalMonthlyReportVo disposalMonthlyReportVo = new DisposalMonthlyReportVo();
|
String[] split = dto.getDictTypeIds().split(",");
|
|
List<String> dict = new ArrayList<>();
|
List<Integer> dictTypeId = new ArrayList<>();
|
for (String s : split) {
|
SysDictItem dictItem = dictItemService.getById(s);
|
dict.add(dictItem.getItemText());
|
dictTypeId.add(Integer.valueOf(s));
|
}
|
List<List<Object>> maps = new ArrayList<>();
|
List<Object> list = new ArrayList<>();
|
list.add("医疗废物产生量(kg)");
|
list.add(dict);
|
maps.add(list);
|
list = new ArrayList<>();
|
list.add("医疗废物转移量(kg)");
|
list.add(dict.subList(0, dict.size()));
|
maps.add(list);
|
list = new ArrayList<>();
|
list.add("医疗废物库存量(kg)");
|
list.add(dict.subList(0, dict.size()));
|
maps.add(list);
|
disposalMonthlyReportVo.setLegend(JSON.toJSONString(maps));
|
|
List<DisposalMonthlyReportVoItemVO> disposalMonthlyReport = mwCollectRecordService.getDisposalMonthlyReport(dto.getDepartmentId(), dto.getStartTime(), dto.getEndTime(), dto.getKeyWord(), dictTypeId);
|
disposalMonthlyReportVo.setList(disposalMonthlyReport);
|
return disposalMonthlyReportVo;
|
}
|
|
|
public void exportDisposalMonthlyReport(DisposalMonthlyReportDTO dto, HttpServletResponse response) throws Exception{
|
ExcelWriter excelWriter = new ExcelWriter(exportDisposalMonthlyReport(dto, "处置情况月报表"), "处置情况月报表");
|
if (excelWriter != null) {
|
response.setContentType("application/octet-stream;charset=utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("处置情况月报表", "UTF-8") + ".xlsx");
|
excelWriter.flush(response.getOutputStream(), true);
|
excelWriter.close();
|
}
|
}
|
|
|
|
private XSSFWorkbook exportDisposalMonthlyReport(DisposalMonthlyReportDTO dto, String fileName){
|
DisposalMonthlyReportVo disposalMonthlyReport = getDisposalMonthlyReport(dto);
|
JSONArray jsonArray = JSON.parseArray(disposalMonthlyReport.getLegend());
|
JSONArray jsonArray1 = jsonArray.getJSONArray(0).getJSONArray(1);
|
int num = jsonArray1.size() * 3 + 4;//最大列数
|
String[] split = dto.getDictTypeIds().split(",");
|
|
SysDepartment department = departmentService.getById(dto.getDepartmentId());
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
|
SimpleDateFormat sdf1 = new SimpleDateFormat("MM");
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFSheet sheet = workbook.createSheet(fileName);
|
XSSFCellStyle cellStyle = createDefaultCellStyle(workbook);
|
|
// cellStyle.setBorderBottom(BorderStyle.THIN);//下边框
|
// cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
|
// cellStyle.setBorderRight(BorderStyle.THIN);//右边框
|
// cellStyle.setBorderTop(BorderStyle.THIN);
|
XSSFCellStyle leftCellStyle = createDefaultLeftCellStyle(workbook);
|
XSSFCellStyle rightCellStyle = createDefaultRightCellStyle(workbook);
|
|
XSSFRow row = sheet.createRow(0);//表头
|
XSSFCell cell = row.createCell(0);
|
cell.setCellStyle(cellStyle);
|
cell.setCellValue(department.getDepartName() + "医疗卫生机构医疗废物收集处置情况月报表(" +
|
(Integer.valueOf(sdf.format(dto.getStartTime())) == Integer.valueOf(sdf.format(dto.getEndTime())) ? sdf.format(dto.getStartTime()) + "年" + Integer.valueOf(sdf1.format(dto.getStartTime())) + "月 - " + Integer.valueOf(sdf1.format(dto.getEndTime())) + "月" :
|
sdf.format(dto.getStartTime()) + "年" + Integer.valueOf(sdf1.format(dto.getStartTime())) + "月 - " + sdf.format(dto.getEndTime()) + "年" + Integer.valueOf(sdf1.format(dto.getEndTime())) + "月")
|
+ ")");
|
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, num));
|
|
XSSFRow row1 = sheet.createRow(1);//表头
|
int n = Double.valueOf(num / 4).intValue();
|
XSSFCell cell1 = row1.createCell(n * 0);
|
cell1.setCellStyle(leftCellStyle);
|
cell1.setCellValue("填报单位(盖章):");
|
XSSFCell cell2 = row1.createCell(n * 1);
|
cell2.setCellStyle(leftCellStyle);
|
cell2.setCellValue("填表人:");
|
XSSFCell cell3 = row1.createCell(n * 2);
|
cell3.setCellStyle(leftCellStyle);
|
cell3.setCellValue("领导签字:");
|
XSSFCell cell4 = row1.createCell(n * 3);
|
cell4.setCellStyle(rightCellStyle);
|
cell4.setCellValue("填报日期: 年 月 日");
|
|
XSSFRow row2 = sheet.createRow(2);//表头
|
row2.setRowStyle(cellStyle);
|
row2.createCell(0).setCellValue("医疗机构名称");
|
row2.createCell(1).setCellValue("集中收集基层数量");
|
row2.createCell(2).setCellValue("暂存点数量");
|
row2.createCell(3).setCellValue("医疗废物处置公司");
|
row2.createCell(4 + (split.length * 0)).setCellValue("医疗废物产生量");
|
row2.createCell(4 + (split.length * 1)).setCellValue("医疗废物转移量");
|
if(dto.getType()==1){
|
row2.createCell(4 + (split.length * 2)).setCellValue("医疗废物库存量");
|
}
|
|
XSSFRow row3 = sheet.createRow(3);//表头
|
row3.setRowStyle(cellStyle);
|
for (int i = 0; i < jsonArray1.size(); i++) {
|
row3.createCell(i + (4 + (0 * jsonArray1.size()))).setCellValue(jsonArray1.getString(i));
|
row3.createCell(i + (4 + (1 * jsonArray1.size()))).setCellValue(jsonArray1.getString(i));
|
if(dto.getType()==1){
|
row3.createCell(i + (4 + (2 * jsonArray1.size()))).setCellValue(jsonArray1.getString(i));
|
}
|
}
|
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
|
sheet.addMergedRegion(new CellRangeAddress(2, 3, 3, 3));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 4 + (0 * jsonArray1.size()), (4 + (1 * jsonArray1.size())) - 1));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 4 + (1 * jsonArray1.size()), (4 + (2 * jsonArray1.size())) - 1));
|
sheet.addMergedRegion(new CellRangeAddress(2, 2, 4 + (2 * jsonArray1.size()), (4 + (3 * jsonArray1.size())) - 1));
|
|
List<DisposalMonthlyReportVoItemVO> list = disposalMonthlyReport.getList();
|
for (int i = 0; i < list.size(); i++) {
|
DisposalMonthlyReportVoItemVO vo = list.get(i);
|
String name = vo.getName();
|
List<String> checkoutRecord = vo.getCheckoutRecord();
|
List<BigDecimal> data = vo.getData();
|
if(dto.getType()==0){
|
data = data.subList(0, 14);
|
}
|
|
StringBuffer sb = new StringBuffer();
|
if(null != checkoutRecord){
|
for (String s : checkoutRecord) {
|
sb.append(s + "、");
|
}
|
}
|
XSSFRow row4 = sheet.createRow(i + 4);
|
row4.setRowStyle(cellStyle);
|
row4.createCell(0).setCellValue(name);
|
row4.createCell(1).setCellValue(data.get(0).toString());
|
row4.createCell(2).setCellValue(data.get(1).toString());
|
row4.createCell(3).setCellValue(sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "");
|
for (int j = 2; j < data.size(); j++) {
|
row4.createCell(j + 2).setCellValue(data.get(j).toString());
|
}
|
}
|
return workbook;
|
}
|
|
private XSSFCellStyle createDefaultCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
|
private XSSFCellStyle createDefaultLeftCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
|
private XSSFCellStyle createDefaultRightCellStyle(XSSFWorkbook workbook) {
|
|
XSSFCellStyle cellStyle = workbook.createCellStyle();
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.RIGHT);
|
XSSFFont font = workbook.createFont();
|
font.setFontName("宋体");
|
font.setFontHeightInPoints((short) 12);
|
cellStyle.setFont(font);
|
return cellStyle;
|
}
|
}
|