导出工具bug修复 委员信息数据统计 导出带数据

This commit is contained in:
yuezhihang
2022-03-03 17:53:07 +08:00
parent aeb78eb36d
commit ea3ad20b56
3 changed files with 109 additions and 9 deletions
@@ -135,16 +135,18 @@ public class ExcelExportUtilByWk {
} catch (NoSuchFieldException e) {
log.warn(e.getMessage());
}
field.setAccessible(true);
try {
Object fieldVal = field.get(o);
if (null!=map.get(i).exportFormat() && !"".equals(map.get(i).exportFormat())) {
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : TrainFormDate.dealWithTimeZoneyyyy(String.valueOf(fieldVal),map.get(i).exportFormat()));
}else {
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : String.valueOf(fieldVal));
if (null!=field) {
field.setAccessible(true);
try {
Object fieldVal = field.get(o);
if (null != map.get(i).exportFormat() && !"".equals(map.get(i).exportFormat())) {
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : TrainFormDate.dealWithTimeZoneyyyy(String.valueOf(fieldVal), map.get(i).exportFormat()));
} else {
cell1.setCellValue("null".equals(String.valueOf(fieldVal)) ? "" : String.valueOf(fieldVal));
}
} catch (IllegalAccessException e) {
log.warn(e.getMessage());
}
} catch (IllegalAccessException e) {
log.warn(e.getMessage());
}
}
@@ -1,18 +1,37 @@
package com.adc.da.slrs.wgdCensusZ.controller;
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.processModel.utils.ExcelExportUtilByWk;
import com.adc.da.slrs.processModel.utils.ExcelImportUtilByWk;
import com.adc.da.slrs.wgdCensusZ.entity.WgdAssocInfo;
import com.adc.da.slrs.wgdCensusZ.entity.WgdCommiInfo;
import com.adc.da.slrs.wgdCensusZ.service.IWgdCommiInfoService;
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 io.swagger.annotations.Api;
import com.adc.da.base.web.BaseController;
import org.springframework.web.multipart.MultipartFile;
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;
import java.util.UUID;
/**
* <p>
@@ -42,6 +61,67 @@ public class WgdCommiInfoController extends BaseController<WgdCommiInfo> {
return Result.success(pageInfo);
}
@GetMapping("/exportAllCommiInfos")
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<WgdCommiInfo> datas=new ArrayList<>();
if (null!=idList) {
List<String> ids = new ArrayList<>(Arrays.asList(idList.split(",")));
QueryWrapper<WgdCommiInfo> wrapper=new QueryWrapper<>();
wrapper.in("id",ids);
datas = iWgdCommiInfoService.list(wrapper);
} else {
datas = iWgdCommiInfoService.getAllWgdCommiInfos();
}
workbook = ExcelExportUtilByWk.exportWithData(exportParams,WgdCommiInfo.class,datas);
os = response.getOutputStream();
workbook.write(os);
os.flush();
} catch (IOException e) {
throw new AdcDaBaseException("下载文件失败,请重试");
} finally {
IOUtils.closeQuietly(os);
}
}
@ApiOperation(value = "|SarFileSplitItemsEO|导入")
@PostMapping(value = "/importAllCommiInfos")
public ResponseMessage<List<WgdCommiInfo>> importSplitItemsZip(@RequestParam(value = "file", required = false) MultipartFile file) throws Exception {
List<WgdCommiInfo> res= ExcelImportUtilByWk.readExcelpublic(WgdCommiInfo.class,file);
QueryWrapper<WgdCommiInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.select(WgdCommiInfo.class, info -> !info.getColumn().equals("id"));
List<WgdCommiInfo> wgdAssocInfos=iWgdCommiInfoService.list(queryWrapper);
List<WgdCommiInfo> remove=new ArrayList<>();
res.forEach(wgdAssocInfo -> {
if (wgdAssocInfos.contains(wgdAssocInfo)){
remove.add(wgdAssocInfo);
}
});
res.removeAll(remove);
res.forEach(wgdAssocInfo -> {
wgdAssocInfo.setId(String.valueOf(UUID.randomUUID()));
});
if (iWgdCommiInfoService.saveOrUpdateBatch(res)) {
return Result.success();
}else {
return Result.error();
}
}
@GetMapping("getCommiInfoById")
public ResponseMessage<Object> getWgdCommiInfoById(String id) {//查询详情
return Result.success(iWgdCommiInfoService.getWgdCommiInfoById(id));
@@ -2,7 +2,9 @@ package com.adc.da.slrs.wgdCensusZ.entity;
import java.util.Date;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.adc.da.base.page.BasePage;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -28,49 +30,65 @@ public class WgdCommiInfo extends BasePage {
private String id;
@ApiModelProperty(value = "提报单位名称")
@Excel(name = "提报单位名称", orderNum = "0",width = 20.0)
private String unit;
@ApiModelProperty(value = "协会名称-标委会")
@Excel(name = "协会名称-标委会", orderNum = "1",width = 20.0)
private String scName;
@ApiModelProperty(value = "协会名称-分标委")
@Excel(name = "协会名称-分标委", orderNum = "2",width = 20.0)
private String sscName;
@ApiModelProperty(value = "协会名称-工作组")
@Excel(name = "协会名称-工作组", orderNum = "3",width = 20.0)
private String wgName;
@ApiModelProperty(value = "会员角色")
@Excel(name = "会员角色", orderNum = "4",width = 20.0)
private String role;
@ApiModelProperty(value = "参与人")
@Excel(name = "参与人", orderNum = "5",width = 20.0)
private String attend;
@ApiModelProperty(value = "本届入会时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "本届入会时间", orderNum = "6",width = 20.0 , exportFormat = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
private Date curTime;
@ApiModelProperty(value = "职务")
@Excel(name = "职务", orderNum = "7",width = 20.0)
private String job;
@ApiModelProperty(value = "所在部门")
@Excel(name = "所在部门", orderNum = "8",width = 20.0)
private String department;
@ApiModelProperty(value = "联系方式")
@Excel(name = "联系方式", orderNum = "9",width = 20.0)
private String tel;
@ApiModelProperty(value = "任期")
@Excel(name = "任期", orderNum = "10",width = 20.0)
private String term;
@ApiModelProperty(value = "证书")
@Excel(name = "证书", orderNum = "11",width = 20.0)
private String certificate;
@ApiModelProperty(value = "账号")
@Excel(name = "账号", orderNum = "12",width = 20.0)
private String account;
@ApiModelProperty(value = "密码")
@Excel(name = "密码", orderNum = "13",width = 20.0)
private String password;
@ApiModelProperty(value = "备注")
@Excel(name = "备注", orderNum = "14",width = 20.0)
private String remark;