package cn.besteam.modules.medical.service.impl; import cn.besteam.modules.medical.dto.ServicePeriodLogDTO; import cn.besteam.modules.medical.dto.ServicePeriodLogListDTO; import cn.besteam.modules.medical.entity.MwServicePeriodLog; import cn.besteam.modules.medical.mapper.MwServicePeriodLogMapper; import cn.besteam.modules.medical.service.IMwServicePeriodLogService; import cn.besteam.modules.system.vo.CollectAppletAuthorizationListVO; import cn.besteam.modules.system.vo.MonthlySmsAuthorizationListVO; import cn.hutool.poi.excel.ExcelWriter; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.net.URLEncoder; import java.util.Date; import java.util.List; @Service public class MwServicePeriodLogServiceImpl extends ServiceImpl implements IMwServicePeriodLogService { @Override public IPage getServicePeriodLog(ServicePeriodLogDTO dto, Integer pageNo, Integer pageSize) { pageNo = dto.getPageNo(); pageSize = dto.getPageSize(); Page pageParam = new Page<>(pageNo, pageSize); if(dto.getServiceType() != null && dto.getServiceType()==0){ dto.setServiceType(null); } if(dto.getDepartmentId()!=-1) { IPage servicePeriodLog = this.baseMapper.getServicePeriodLog(pageParam, dto); return servicePeriodLog; }else { IPage servicePeriodLog = this.baseMapper.getServicePeriodLog1(pageParam, dto); return servicePeriodLog; } } @Override public void exportServicePeriodLog(ServicePeriodLogDTO dto, HttpServletResponse response) throws Exception{ ExcelWriter excelWriter = new ExcelWriter(exportServicePeriodLog(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(); } } @Override public void saveLog(Integer valueOf, Double serviceCharge, Date expireDate, Integer reminderDays, Integer serviceUnit, String note, Integer userId,Integer i) { this.baseMapper.saveLog(valueOf,serviceCharge,expireDate,reminderDays,serviceUnit,note,userId,i); } private XSSFWorkbook exportServicePeriodLog(ServicePeriodLogDTO dto, String fileName){ IPage servicePeriodLog = getServicePeriodLog(dto, 1, 100000); List records = servicePeriodLog.getRecords(); XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(fileName); XSSFCellStyle cellStyle = createDefaultCellStyle(workbook); XSSFRow row = sheet.createRow(0);//表头 XSSFCell cell = row.createCell(0); cell.setCellStyle(cellStyle); cell.setCellValue("服务期操作记录"); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7)); XSSFRow row2 = sheet.createRow(0);//表头 XSSFCell cel20 = row2.createCell(0); cel20.setCellValue("操作时间"); cel20.setCellStyle(cellStyle); XSSFCell cel21 = row2.createCell(1); cel21.setCellValue("区域"); cel21.setCellStyle(cellStyle); XSSFCell cel22 = row2.createCell(2); cel22.setCellValue("医院名称"); cel22.setCellStyle(cellStyle); XSSFCell cel23 = row2.createCell(3); cel23.setCellValue("操作内容"); cel23.setCellStyle(cellStyle); XSSFCell cel24 = row2.createCell(4); cel24.setCellValue("操作前"); cel24.setCellStyle(cellStyle); XSSFCell cel25 = row2.createCell(5); cel25.setCellValue("操作后"); cel25.setCellStyle(cellStyle); XSSFCell cel26 = row2.createCell(6); cel26.setCellValue("备注"); cel26.setCellStyle(cellStyle); XSSFCell cel27 = row2.createCell(7); cel27.setCellValue("操作人"); cel27.setCellStyle(cellStyle); for (int i = 1; i < records.size(); i++) { XSSFRow row1 = sheet.createRow(i);//表头 XSSFCell cel2 = row1.createCell(0); cel2.setCellStyle(cellStyle); cel2.setCellValue(records.get(i).getOperationTime()); cel2.setCellStyle(cellStyle); XSSFCell cel3 = row1.createCell(1); cel3.setCellValue(records.get(i).getDepartmentName()); cel3.setCellStyle(cellStyle); XSSFCell cel4 = row1.createCell(2); cel4.setCellValue(records.get(i).getHospital()); cel4.setCellStyle(cellStyle); XSSFCell cel5 = row1.createCell(3); cel5.setCellValue(records.get(i).getServiceType() == 1 ? "修改到期时间" : "修改服务费"); cel5.setCellStyle(cellStyle); XSSFCell cel6 = row1.createCell(4); cel6.setCellValue(records.get(i).getHistoricalData()); cel6.setCellStyle(cellStyle); XSSFCell cel7 = row1.createCell(5); cel7.setCellValue(records.get(i).getCurrentData()); cel7.setCellStyle(cellStyle); XSSFCell cel8 = row1.createCell(6); cel8.setCellValue(records.get(i).getNote()); cel8.setCellStyle(cellStyle); XSSFCell cel9 = row1.createCell(7); cel9.setCellValue(records.get(i).getOperator()); cel9.setCellStyle(cellStyle); } 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; } }