feat 未合规项整改
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package com.adc.da.common;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TableToExcel {
|
||||
|
||||
public static <T extends Object> Workbook createExcel(Map<String,String> columnMap, List<T> dataList, String sheelName, String fileName) {
|
||||
|
||||
if(sheelName==null)sheelName="sheet1";
|
||||
|
||||
int sheetRow=500;
|
||||
sheetRow=sheetRow<0?200:sheetRow;
|
||||
//第一步,创建一个webbook,对应一个excel文件,内存中sheetRow条记录后提交。
|
||||
Workbook wb=new SXSSFWorkbook(sheetRow);
|
||||
if(columnMap!=null&&dataList!=null) {
|
||||
//获取需要生成的sheet数,以防数据量过大报错
|
||||
int sheetCount=getSheetCount(sheetRow,dataList.size());
|
||||
//循环生成sheet
|
||||
for(int i=0;i<sheetCount;i++) {
|
||||
//第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
|
||||
Sheet sheet=wb.createSheet(sheelName);
|
||||
//第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数有限制short
|
||||
Row titleRow=sheet.createRow(0);
|
||||
|
||||
Set<String> keys=columnMap.keySet();
|
||||
//第一行(标题行)合并并设置标题
|
||||
|
||||
|
||||
//创建表头行
|
||||
Row headRow=sheet.createRow(0);
|
||||
//生成表头行
|
||||
int j=0;
|
||||
for(String key:keys) {
|
||||
Cell hCell=headRow.createCell(j++);
|
||||
hCell.setCellValue(columnMap.get(key));
|
||||
}
|
||||
//从第三行开始填充数据
|
||||
int c=2;
|
||||
for(int k=i*sheetRow;k<dataList.size()&&k<(i+1)*sheetRow;k++) {
|
||||
T t=dataList.get(k);
|
||||
Row dataRow=sheet.createRow(c++);
|
||||
//循环取值进行数据填充
|
||||
int v=0;
|
||||
for(String key:keys) {
|
||||
try {
|
||||
Object val= BeanUtils.getProperty(t, key);
|
||||
if(val instanceof Long) {
|
||||
dataRow.createCell(v++).setCellValue((Long)val);
|
||||
}else if(val instanceof Double){
|
||||
dataRow.createCell(v++).setCellValue((Double)val);
|
||||
}else if(val instanceof Date) {
|
||||
dataRow.createCell(v++).setCellValue((Date)val);
|
||||
}else if(val instanceof Calendar) {
|
||||
dataRow.createCell(v++).setCellValue((Calendar)val);
|
||||
}else if(val instanceof Boolean) {
|
||||
dataRow.createCell(v++).setCellValue((Boolean)val);
|
||||
}else if(val==null) {
|
||||
dataRow.createCell(v++).setCellValue("");
|
||||
}else {
|
||||
dataRow.createCell(v++).setCellValue((String)val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("导出Excel-表格赋值异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
//设置列宽
|
||||
// setColumnWidth(sheet,columnMap);
|
||||
}
|
||||
}
|
||||
return wb;
|
||||
}
|
||||
public static void setColumnWidth(Sheet sheet, Map<String,String> columnMap) {
|
||||
if(sheet!=null&&columnMap!=null) {
|
||||
List<String> list=new ArrayList<String>(columnMap.keySet());
|
||||
for(int i=0;i<list.size();i++) {
|
||||
sheet.autoSizeColumn(i,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static int getSheetCount(int sheelRow,int total) {
|
||||
if(total==0||total<sheelRow)return 1;
|
||||
return total%sheelRow>0?total/sheelRow+1:total/sheelRow;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.adc.da.workFlow.controller;
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.adc.da.FeignClientImpl.workFlowFeignClientImpl;
|
||||
import com.adc.da.Timer.ProcessTimer;
|
||||
import com.adc.da.common.*;
|
||||
@@ -15,7 +16,11 @@ import com.adc.da.sys.common.EmailUtils;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.sys.service.IUserEOService;
|
||||
import com.adc.da.util.LoginUserUtil;
|
||||
import com.adc.da.workFlow.dao.ExportExcelMapper;
|
||||
import com.adc.da.workFlow.entity.ExportExcel;
|
||||
import com.adc.da.workFlow.entity.ExportExcelEO;
|
||||
import com.adc.da.workFlow.entity.ProcessDetailExport;
|
||||
import com.adc.da.workFlow.service.WorkFlowService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -29,6 +34,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -42,6 +48,46 @@ public class WorkFlowController {
|
||||
@Autowired
|
||||
private workFlowFeignClientImpl workFlowFeignClient;
|
||||
|
||||
// @Autowired
|
||||
// private ExportExcelMapper exportExcelMapper;
|
||||
|
||||
@ApiOperation(value = "导出excel")
|
||||
@PostMapping("/export_excel")
|
||||
public void exportExcel(@RequestBody ExportExcelEO exportExcelEO, HttpServletResponse response, HttpServletRequest request) throws IOException {
|
||||
|
||||
// ExportExcel exportExcel = exportExcelMapper.selectById(id);
|
||||
// if(exportExcel==null||exportExcel.getJson()==null)return;
|
||||
// ExportExcelEO exportExcelEO=JSON.parseObject(exportExcel.getJson(),ExportExcelEO.class);
|
||||
|
||||
if(exportExcelEO.getFileName()==null||exportExcelEO.getFileName().trim().length()==0){
|
||||
exportExcelEO.setFileName(UUID.fastUUID().toString(true));
|
||||
}
|
||||
|
||||
Workbook excel = TableToExcel.createExcel(exportExcelEO.getColumnName(), exportExcelEO.getDataList(), null, exportExcelEO.getFileName());
|
||||
|
||||
response.reset();
|
||||
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
|
||||
response.setHeader("Content-disposition", "attachment; filename=" + exportExcelEO.getFileName() + ".xls");
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
|
||||
excel.write(outputStream);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
// @ApiOperation(value = "导出excel数据暂留")
|
||||
// @PostMapping("/save_excel")
|
||||
// public ResponseMessage saveExcel(@RequestBody ExportExcel exportExcel){
|
||||
//
|
||||
// exportExcelMapper.insert(exportExcel);
|
||||
// return Result.success(exportExcel);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "启动流程-以流程定义id")
|
||||
@GetMapping("/activiti_define_start")
|
||||
public ResponseMessage activiti_define_start(@RequestParam("id") String id, @RequestParam("userId") String userId, @RequestParam(value = "bpnId",required = false) String bpnId){
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.adc.da.workFlow.dao;
|
||||
|
||||
|
||||
import com.adc.da.workFlow.entity.ExportExcel;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface ExportExcelMapper extends BaseMapper<ExportExcel> {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.adc.da.workFlow.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.*;
|
||||
|
||||
@TableName("t_export_excel")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ExportExcel {
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Integer id;
|
||||
@TableField(value = "json")
|
||||
private String json;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.adc.da.workFlow.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ExportExcelEO {
|
||||
|
||||
private Map<String,String> columnName;
|
||||
|
||||
private List<Map<String,Object>> dataList;
|
||||
|
||||
private String fileName;
|
||||
|
||||
}
|
||||
@@ -31,4 +31,5 @@ public class WorkFlowService {
|
||||
/**
|
||||
* 后续优化工作流
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
Reference in New Issue
Block a user