后端通用生成excel 以及 协会信息数据统计带数据导出

This commit is contained in:
yuezhihang
2022-03-03 15:26:42 +08:00
parent 48a0181942
commit b9e440c92c
6 changed files with 348 additions and 11 deletions
@@ -1,17 +1,35 @@
package com.adc.da.slrs.wgdCensusZ.controller;
import com.adc.da.excel.poi.excel.ExcelExportUtil;
import com.adc.da.excel.poi.excel.entity.ExportParams;
import com.adc.da.excel.poi.excel.entity.enums.ExcelType;
import com.adc.da.http.PageInfo;
import com.adc.da.http.ResponseMessage;
import com.adc.da.http.Result;
import com.adc.da.slrs.msgDynamicInfo.common.ReadExcel;
import com.adc.da.slrs.msgDynamicInfo.dto.MsgDynamicInfoExportDto;
import com.adc.da.slrs.msgDynamicInfo.page.MsgDynamicInfoEOPage;
import com.adc.da.slrs.processModel.utils.ExcelExportUtilByWk;
import com.adc.da.slrs.wgdCensusZ.service.IWgdAssocInfoService;
import com.adc.da.util.exception.AdcDaBaseException;
import com.adc.da.util.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.adc.da.slrs.wgdCensusZ.entity.WgdAssocInfo;
import io.swagger.annotations.Api;
import com.adc.da.base.web.BaseController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -34,6 +52,40 @@ public class WgdAssocInfoController extends BaseController<WgdAssocInfo> {
return Result.success(iWgdAssocInfoService.getAllWgdAssocInfos());
}
@GetMapping("exportAllAssocInfos")
public void exportAllAssocInfos(String idList, String exportName, HttpServletResponse response, HttpServletRequest request){//查询所有
OutputStream os = null;
Workbook workbook = null;
try {
if(StringUtils.isEmpty(exportName) ||exportName.equals("null")){
exportName="协会信息数据统计";
}
response.setHeader("Content-Disposition",
"attachment; filename=" + ReadExcel.encodeFileName(exportName+".xlsx", request));
response.setContentType("application/force-download");
ExportParams exportParams = new ExportParams();
exportParams.setType(ExcelType.XSSF);
exportParams.setSheetName(exportName);
List<WgdAssocInfo> datas=new ArrayList<>();
if (null!=idList) {
List<String> ids = new ArrayList<>(Arrays.asList(idList.split(",")));
QueryWrapper<WgdAssocInfo> wrapper=new QueryWrapper<>();
wrapper.in("id",ids);
datas = iWgdAssocInfoService.list(wrapper);
} else {
datas = iWgdAssocInfoService.getAllWgdAssocInfos();
}
workbook = ExcelExportUtilByWk.exportWithData(exportParams,WgdAssocInfo.class,datas);
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (IOException e) {
throw new AdcDaBaseException("下载文件失败,请重试");
} finally {
IOUtils.closeQuietly(os);
}
}
@ApiOperation("查询")
@GetMapping("queryAllAssocInfos")
public ResponseMessage<Object> queryAllWgdAssocInfos(WgdAssocInfo wgdAssocInfo){//多条件查询
@@ -3,6 +3,8 @@ package com.adc.da.slrs.wgdCensusZ.entity;
import java.util.Date;
import com.adc.da.base.page.BasePage;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -28,117 +30,155 @@ public class WgdAssocInfo extends BasePage {
private String id;
@ApiModelProperty(value = "协会名称-标委会")
@Excel(name = "协会名称-标委会", orderNum = "0",width = 20.0)
private String scName;
@ApiModelProperty(value = "协会名称-分标委")
@Excel(name = "协会名称-分标委", orderNum = "1",width = 20.0)
private String sscName;
@ApiModelProperty(value = "协会名称-工作组")
@Excel(name = "协会名称-分标委", orderNum = "2",width = 20.0)
private String wgName;
@ApiModelProperty(value = "会员角色")
@Excel(name = "会员角色", orderNum = "3",width = 20.0)
private String role;
@ApiModelProperty(value = "参与人")
@Excel(name = "参与人", orderNum = "4",width = 20.0)
private String attend;
@ApiModelProperty(value = "标准")
@Excel(name = "标准", orderNum = "5",width = 20.0)
private String standard;
@ApiModelProperty(value = "标准负责人")
@Excel(name = "标准负责人", orderNum = "6",width = 20.0)
private String charge;
@ApiModelProperty(value = "责任领导")
@Excel(name = "责任领导", orderNum = "7",width = 20.0)
private String leader;
@ApiModelProperty(value = "初始入会时间")
@Excel(name = "初始入会时间", orderNum = "8",width = 20.0 , exportFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date iniTime;
@ApiModelProperty(value = "本届入会时间")
@Excel(name = "本届入会时间", orderNum = "9",width = 20.0 , exportFormat = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date curTime;
@ApiModelProperty(value = "费用标准")
@Excel(name = "费用标准", orderNum = "10",width = 20.0)
private String costStandard;
@ApiModelProperty(value = "费用列支")
@Excel(name = "费用列支", orderNum = "11",width = 20.0)
private String costOutlay;
@ApiModelProperty(value = "上次缴纳时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "上次缴纳时间", orderNum = "12",width = 20.0 , exportFormat = "yyyy-MM-dd HH:mm:ss")
private Date lastPayTime;
@ApiModelProperty(value = "缴费年限")
@Excel(name = "缴费年限", orderNum = "13",width = 20.0)
private String payPeriod;
@ApiModelProperty(value = "经办人")
@Excel(name = "经办人", orderNum = "14",width = 20.0)
private String handler;
@ApiModelProperty(value = "部门")
@Excel(name = "部门", orderNum = "15",width = 20.0)
private String department;
@ApiModelProperty(value = "协会性质")
@Excel(name = "协会性质", orderNum = "16",width = 20.0)
private String asProper;
@ApiModelProperty(value = "协会状态")
@Excel(name = "协会状态", orderNum = "17",width = 20.0)
private String asStatus;
@ApiModelProperty(value = "协会联络人")
@Excel(name = "协会联络人", orderNum = "18",width = 20.0)
private String asContact;
@ApiModelProperty(value = "协会联络人电话")
@Excel(name = "协会联络人电话", orderNum = "19",width = 20.0)
private String tel;
@ApiModelProperty(value = "协会联络人邮箱")
@Excel(name = "协会联络人邮箱", orderNum = "20",width = 20.0)
private String mail;
@ApiModelProperty(value = "2017缴费")
@Excel(name = "2017缴费", orderNum = "21",width = 20.0)
private String p17;
@ApiModelProperty(value = "2018缴费")
@Excel(name = "2018缴费", orderNum = "22",width = 20.0)
private String p18;
@ApiModelProperty(value = "2019缴费")
@Excel(name = "2019缴费", orderNum = "23",width = 20.0)
private String p19;
@ApiModelProperty(value = "2020缴费")
@Excel(name = "2020缴费", orderNum = "24",width = 20.0)
private String p20;
@ApiModelProperty(value = "2021缴费")
@Excel(name = "2021缴费", orderNum = "25",width = 20.0)
private String p21;
@ApiModelProperty(value = "2022缴费")
@Excel(name = "2022缴费", orderNum = "26",width = 20.0)
private String p22;
@ApiModelProperty(value = "2023缴费")
@Excel(name = "2023缴费", orderNum = "27",width = 20.0)
private String p23;
@ApiModelProperty(value = "2024缴费")
@Excel(name = "2024缴费", orderNum = "28",width = 20.0)
private String p24;
@ApiModelProperty(value = "2025缴费")
@Excel(name = "2025缴费", orderNum = "29",width = 20.0)
private String p25;
@ApiModelProperty(value = "2026缴费")
@Excel(name = "2026缴费", orderNum = "30",width = 20.0)
private String p26;
@ApiModelProperty(value = "2027缴费")
@Excel(name = "2027缴费", orderNum = "31",width = 20.0)
private String p27;
@ApiModelProperty(value = "2028缴费")
@Excel(name = "2028缴费", orderNum = "32",width = 20.0)
private String p28;
@ApiModelProperty(value = "2029缴费")
@Excel(name = "2029缴费", orderNum = "33",width = 20.0)
private String p29;
@ApiModelProperty(value = "2030缴费")
@Excel(name = "2030缴费", orderNum = "34",width = 20.0)
private String p30;
@ApiModelProperty(value = "2031缴费")
@Excel(name = "2031缴费", orderNum = "35",width = 20.0)
private String p31;
@ApiModelProperty(value = "2032缴费")
@Excel(name = "2032缴费", orderNum = "36",width = 20.0)
private String p32;