feat(征求意见): 导出
This commit is contained in:
+14
@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -61,4 +63,16 @@ public class ConsultationController {
|
||||
public Result<List<ProcessFbConsultationList>> queryDetailByBusinessId(String businessId) {
|
||||
return Result.OK(consultationService.queryDetailByBusinessId(businessId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 征求意见详情-导出
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@AutoLog(value = "征求意见详情-导出")
|
||||
@ApiOperation(value = "征求意见详情-导出")
|
||||
@GetMapping("/exportExcel")
|
||||
public void exportExcel(String businessId, HttpServletRequest request, HttpServletResponse response) {
|
||||
consultationService.exportExcel(businessId, request, response);
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.jero.modules.activiti.process.fb.entity.ProcessFbConsultationList;
|
||||
import com.jero.modules.activiti.process.fb.entity.ProcessFbStandardConsultation;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -29,4 +31,12 @@ public interface IConsultationService {
|
||||
* @return
|
||||
*/
|
||||
List<ProcessFbConsultationList> queryDetailByBusinessId(String businessId);
|
||||
|
||||
/**
|
||||
* 征求意见详情-导出
|
||||
* @param businessId
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
void exportExcel(String businessId, HttpServletRequest request, HttpServletResponse response);
|
||||
}
|
||||
|
||||
+139
-1
@@ -3,7 +3,9 @@ package com.jero.modules.laws.consultation.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.activiti.process.fb.entity.ProcessFbConsultationList;
|
||||
import com.jero.modules.activiti.process.fb.entity.ProcessFbStandardConsultation;
|
||||
import com.jero.modules.activiti.process.fb.service.IProcessFbConsultationListService;
|
||||
@@ -11,13 +13,24 @@ import com.jero.modules.activiti.process.fb.service.IProcessFbStandardConsultati
|
||||
import com.jero.modules.laws.consultation.service.IConsultationService;
|
||||
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
|
||||
import com.jero.modules.laws.standard.service.ILawsDomesticStandardService;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -36,15 +49,18 @@ public class ConsultationServiceImpl implements IConsultationService {
|
||||
private final IProcessFbConsultationListService processFbConsultationListService;
|
||||
private final ILawsDomesticStandardService lawsDomesticStandardService;
|
||||
private final ISysDepartService sysDepartService;
|
||||
private final IOSSFileService ossFileService;
|
||||
|
||||
public ConsultationServiceImpl(IProcessFbStandardConsultationService processFbStandardConsultationService,
|
||||
IProcessFbConsultationListService processFbConsultationListService,
|
||||
ILawsDomesticStandardService lawsDomesticStandardService,
|
||||
ISysDepartService sysDepartService) {
|
||||
ISysDepartService sysDepartService,
|
||||
IOSSFileService ossFileService) {
|
||||
this.processFbStandardConsultationService = processFbStandardConsultationService;
|
||||
this.processFbConsultationListService = processFbConsultationListService;
|
||||
this.lawsDomesticStandardService = lawsDomesticStandardService;
|
||||
this.sysDepartService = sysDepartService;
|
||||
this.ossFileService = ossFileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,4 +107,126 @@ public class ConsultationServiceImpl implements IConsultationService {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportExcel(String businessId, HttpServletRequest request, HttpServletResponse response) {
|
||||
List<ProcessFbConsultationList> processFbConsultationLists = queryDetailByBusinessId(businessId);
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
String name = new String("意见详情".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
||||
// sheet页
|
||||
XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
|
||||
// 列宽
|
||||
sheet.setDefaultColumnWidth(20);
|
||||
|
||||
//样式
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
// 水平、垂直居中
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
|
||||
// 表头
|
||||
createHead(sheet, cellStyle);
|
||||
// 内容
|
||||
setContent(processFbConsultationLists, sheet, cellStyle);
|
||||
|
||||
//输出Excel文件
|
||||
OutputStream output = response.getOutputStream();
|
||||
response.reset();
|
||||
//设置响应头
|
||||
response.setContentType("application/excel");
|
||||
response.setHeader("Content-Disposition","attachment;filename="+ name +".xlsx");
|
||||
workbook.write(output);
|
||||
output.close();
|
||||
}catch (Exception e){
|
||||
if(LanguageEnum.CN.getValue().equals(MessageUtils.getLanguage().getValue())) {
|
||||
throw new JeroBootException("导出失败!");
|
||||
}else{
|
||||
throw new JeroBootException("Export failure!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setContent(List<ProcessFbConsultationList> processFbConsultationLists, XSSFSheet sheet, CellStyle cellStyle) {
|
||||
for (int i = 0; i < processFbConsultationLists.size(); i++) {
|
||||
int index = i + 2;
|
||||
Row headerRow = sheet.createRow(index);
|
||||
ProcessFbConsultationList processFbConsultation = processFbConsultationLists.get(i);
|
||||
// 条款号
|
||||
Cell cell1 = headerRow.createCell(0);
|
||||
cell1.setCellValue(processFbConsultation.getChapterNumber());
|
||||
cell1.setCellStyle(cellStyle);
|
||||
// 条款名称
|
||||
Cell cell2 = headerRow.createCell(1);
|
||||
cell2.setCellValue(processFbConsultation.getChapterName());
|
||||
cell2.setCellStyle(cellStyle);
|
||||
// 修改前
|
||||
Cell cell3 = headerRow.createCell(2);
|
||||
cell3.setCellValue(processFbConsultation.getModificationBefore());
|
||||
cell3.setCellStyle(cellStyle);
|
||||
// 修改后
|
||||
Cell cell4 = headerRow.createCell(3);
|
||||
cell4.setCellValue(processFbConsultation.getModificationAfter());
|
||||
cell4.setCellStyle(cellStyle);
|
||||
// 修改理由
|
||||
Cell cell5 = headerRow.createCell(4);
|
||||
cell5.setCellValue(processFbConsultation.getModificationReason());
|
||||
cell5.setCellStyle(cellStyle);
|
||||
// 提出部门
|
||||
Cell cell6 = headerRow.createCell(5);
|
||||
cell6.setCellValue(processFbConsultation.getDepart());
|
||||
cell6.setCellStyle(cellStyle);
|
||||
// 提出人
|
||||
Cell cell7 = headerRow.createCell(6);
|
||||
cell7.setCellValue(processFbConsultation.getDesignEngineerName());
|
||||
cell7.setCellStyle(cellStyle);
|
||||
// 处理意见
|
||||
Cell cell8 = headerRow.createCell(7);
|
||||
cell8.setCellValue(processFbConsultation.getIsAdopt_dictText());
|
||||
cell8.setCellStyle(cellStyle);
|
||||
// 依据描述
|
||||
Cell cell9 = headerRow.createCell(8);
|
||||
cell9.setCellValue(processFbConsultation.getBasisDescription());
|
||||
cell9.setCellStyle(cellStyle);
|
||||
// 佐证材料
|
||||
if (StringUtils.isNotBlank(processFbConsultation.getBasisFile())){
|
||||
Cell cell10 = headerRow.createCell(9);
|
||||
List<String> fileIds = Arrays.asList(processFbConsultation.getBasisFile().split(","));
|
||||
List<OSSFile> fileList = ossFileService.list(new LambdaQueryWrapper<OSSFile>().in(OSSFile::getId, fileIds));
|
||||
cell10.setCellValue(fileList.stream().map(OSSFile::getFileName).collect(Collectors.joining(",")));
|
||||
cell10.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createHead(XSSFSheet sheet, CellStyle cellStyle) {
|
||||
String[] firstHead = {"条款号", "条款名称", "修改意见内容(包括理由或依据)", "提出部门", "提出人", "处理意见", "依据描述", "佐证材料"};
|
||||
String[] secondHead = {"修改前", "修改后", "修改理由"};
|
||||
// 创建第一行
|
||||
Row headerRowFirst = sheet.createRow(0);
|
||||
for (int i = 0; i < firstHead.length; i++) {
|
||||
int index = i;
|
||||
if (i > 2){
|
||||
index = i + 2;
|
||||
}
|
||||
Cell cell = headerRowFirst.createCell(index);
|
||||
cell.setCellValue(firstHead[i]);
|
||||
cell.setCellStyle(cellStyle);
|
||||
CellRangeAddress region;
|
||||
if (index == 2){
|
||||
// 横向合并单元格
|
||||
region = new CellRangeAddress(0, 0, index, index + 2);
|
||||
}else {
|
||||
// 纵向合并单元格
|
||||
region = new CellRangeAddress(0, 1, index, index);
|
||||
}
|
||||
sheet.addMergedRegionUnsafe(region);
|
||||
}
|
||||
// 创建第二行
|
||||
Row headerRowSecond = sheet.createRow(1);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Cell cell = headerRowSecond.createCell(i + 2);
|
||||
cell.setCellValue(secondHead[i]);
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user