去除autopoi,引入easypoi

This commit is contained in:
lixuetao
2023-11-17 23:35:42 +08:00
parent 95e52713fe
commit b84fded287
87 changed files with 355 additions and 436 deletions
@@ -178,16 +178,23 @@
</dependency>
<!-- AutoPoi Excel工具类-->
<!-- <dependency>-->
<!-- <groupId>org.jeecgframework</groupId>-->
<!-- <artifactId>autopoi-web</artifactId>-->
<!-- <version>${autopoi-web.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>commons-codec</groupId>-->
<!-- <artifactId>commons-codec</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- EasyPoi Excel工具类-->
<dependency>
<groupId>org.jeecgframework</groupId>
<artifactId>autopoi-web</artifactId>
<version>${autopoi-web.version}</version>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
<!-- mini文件存储服务 -->
@@ -10,7 +10,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
@@ -11,12 +11,12 @@ import com.jero.common.util.oConvertUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.EasypoiSingleExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;
@@ -70,13 +70,10 @@ public class JeroController<T, S extends IService<T>> {
}
// Step.3 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
mv.addObject(FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(CLASS, clazz);
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
exportParams.setImageBasePath(upLoadPath);
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
mv.addObject(PARAMS,exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv;
@@ -89,11 +86,10 @@ public class JeroController<T, S extends IService<T>> {
* @param object 实体类
* @param clazz 实体类class
* @param title 标题
* @param exportFields 导出字段自定义
* @param pageNum 每个sheet的数据条数
* @param request
*/
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields,Integer pageNum) {
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title,Integer pageNum) {
// Step.1 组装查询条件
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
@@ -116,7 +112,7 @@ public class JeroController<T, S extends IService<T>> {
exportList = records;
}
Map<String, Object> map = new HashMap<>();
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i,upLoadPath);
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i);
exportParams.setType(ExcelType.XSSF);
//map.put("title",exportParams);//表格Title
map.put(PARAMS,exportParams);//表格Title
@@ -125,23 +121,12 @@ public class JeroController<T, S extends IService<T>> {
listMap.add(map);
}
// Step.4 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
ModelAndView mv = new ModelAndView(new EasypoiSingleExcelView());
mv.addObject(FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.MAP_LIST, listMap);
return mv;
}
/**
* 根据权限导出excel,传入导出字段参数
*
* @param request
*/
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields) {
ModelAndView mv = this.exportXls(request,object,clazz,title);
mv.addObject(NormalExcelConstants.EXPORT_FIELDS,exportFields);
return mv;
}
/**
* 获取对象ID
*
@@ -1,7 +1,7 @@
package com.jero.common.system.base.entity;
import java.io.Serializable;
import org.jeecgframework.poi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import com.baomidou.mybatisplus.annotation.IdType;
@@ -1,5 +1,6 @@
package com.jero.common.system.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -7,7 +8,6 @@ import com.jero.common.aspect.annotation.Dict;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
import java.util.Date;
@@ -58,7 +58,7 @@ public class SysDictItemCore implements Serializable {
/**
* 排序
*/
@Excel(name = "排序", width = 15,type=4)
@Excel(name = "排序", width = 15, type=4)
private Integer sortOrder;
@@ -11,6 +11,7 @@ import java.util.regex.Pattern;
import javax.sql.DataSource;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.jero.common.constant.CommonConstant;
@@ -18,7 +19,6 @@ import com.jero.common.constant.DataBaseConstant;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.filter.FileTypeFilter;
import com.jero.common.util.oss.OssBootUtil;
import org.jeecgframework.poi.util.PoiPublicUtil;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -1,28 +1,28 @@
package com.jero.config;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: Scott
* @Date: 2018/2/7
* @description: autopoi 配置类
*/
@Configuration
public class AutoPoiConfig {
/**
* excel注解字典参数支持(导入导出字典值,自动翻译)
* 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
* 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
* 2、导入的时候,会把男、女翻译成1,2存进数据库;
* @return
*/
@Bean
public ApplicationContextUtil applicationContextUtil() {
return new org.jeecgframework.core.util.ApplicationContextUtil();
}
}
//package com.jero.config;
//
//import org.jeecgframework.core.util.ApplicationContextUtil;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @Author: Scott
// * @Date: 2018/2/7
// * @description: autopoi 配置类
// */
//
//@Configuration
//public class AutoPoiConfig {
//
// /**
// * excel注解字典参数支持(导入导出字典值,自动翻译)
// * 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
// * 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
// * 2、导入的时候,会把男、女翻译成1,2存进数据库;
// * @return
// */
// @Bean
// public ApplicationContextUtil applicationContextUtil() {
// return new org.jeecgframework.core.util.ApplicationContextUtil();
// }
//
//}
@@ -1,65 +1,65 @@
package com.jero.config;
import lombok.extern.slf4j.Slf4j;
import com.jero.common.api.CommonAPI;
import com.jero.common.system.vo.DictModel;
import com.jero.common.util.oConvertUtils;
import org.jeecgframework.dict.service.AutoPoiDictServiceI;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 描述:AutoPoi Excel注解支持字典参数设置
* 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
* 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
* 2、导入的时候,会把男、女翻译成1,2存进数据库;
*
* @Author:scott
* @since2019-04-09
* @Version:1.0
*/
@Slf4j
@Service
public class AutoPoiDictConfig implements AutoPoiDictServiceI {
@Lazy
@Resource
private CommonAPI commonAPI;
/**
* 通过字典查询easypoi,所需字典文本
*
* @Author:scott
* @since2019-04-09
* @return
*/
@Override
public String[] queryDict(String dicTable, String dicCode, String dicText) {
List<String> dictReplaces = new ArrayList<>();
List<DictModel> dictList = null;
// step.1 如果没有字典表则使用系统字典表
if (oConvertUtils.isEmpty(dicTable)) {
dictList = commonAPI.queryDictItemsByCode(dicCode);
} else {
try {
dicText = oConvertUtils.getString(dicText, dicCode);
dictList = commonAPI.queryTableDictItemsByCode(dicTable, dicText, dicCode);
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}
for (DictModel t : dictList) {
if(t!=null){
dictReplaces.add(t.getText() + "_" + t.getValue());
}
}
if (!dictReplaces.isEmpty()) {
log.info("---AutoPoi--Get_DB_Dict------"+ dictReplaces.toString());
return dictReplaces.toArray(new String[dictReplaces.size()]);
}
return new String[0];
}
}
//package com.jero.config;
//
//import lombok.extern.slf4j.Slf4j;
//import com.jero.common.api.CommonAPI;
//import com.jero.common.system.vo.DictModel;
//import com.jero.common.util.oConvertUtils;
//import org.jeecgframework.dict.service.AutoPoiDictServiceI;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 描述:AutoPoi Excel注解支持字典参数设置
// * 举例: @Excel(name = "性别", width = 15, dicCode = "sex")
// * 1、导出的时候会根据字典配置,把值1,2翻译成:男、女;
// * 2、导入的时候,会把男、女翻译成1,2存进数据库;
// *
// * @Author:scott
// * @since2019-04-09
// * @Version:1.0
// */
//@Slf4j
//@Service
//public class AutoPoiDictConfig implements AutoPoiDictServiceI {
// @Lazy
// @Resource
// private CommonAPI commonAPI;
//
// /**
// * 通过字典查询easypoi,所需字典文本
// *
// * @Author:scott
// * @since2019-04-09
// * @return
// */
// @Override
// public String[] queryDict(String dicTable, String dicCode, String dicText) {
// List<String> dictReplaces = new ArrayList<>();
// List<DictModel> dictList = null;
// // step.1 如果没有字典表则使用系统字典表
// if (oConvertUtils.isEmpty(dicTable)) {
// dictList = commonAPI.queryDictItemsByCode(dicCode);
// } else {
// try {
// dicText = oConvertUtils.getString(dicText, dicCode);
// dictList = commonAPI.queryTableDictItemsByCode(dicTable, dicText, dicCode);
// } catch (Exception e) {
// log.error(e.getMessage(),e);
// }
// }
// for (DictModel t : dictList) {
// if(t!=null){
// dictReplaces.add(t.getText() + "_" + t.getValue());
// }
// }
// if (!dictReplaces.isEmpty()) {
// log.info("---AutoPoi--Get_DB_Dict------"+ dictReplaces.toString());
// return dictReplaces.toArray(new String[dictReplaces.size()]);
// }
// return new String[0];
// }
//}
@@ -10,7 +10,7 @@ import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import org.jeecgframework.poi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
@ApiModel(description = "onl_auth_data", value = "onl_auth_data对象")
@@ -11,7 +11,7 @@ import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import org.jeecgframework.poi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
@ApiModel(description = "onl_auth_page", value = "onl_auth_page对象")
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.jeecgframework.poi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import java.io.Serializable;
@@ -40,11 +40,11 @@ import com.jero.generater.modules.online.config.util.DbTableUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -660,8 +660,6 @@ public class OnlCgformApiController {
Entry<String, MultipartFile> var20 = var53.next();
MultipartFile var21 = var20.getValue();
ImportParams var22 = new ImportParams();
var22.setImageList(var12);
var22.setDataHanlder(new CgFormExcelHandler(var10, this.upLoadPath, this.uploadType));
List<Map<String, Object>> var23 = ExcelImportUtil.importExcel(var21.getInputStream(), Map.class, var22);
if (var23 != null) {
Object var24 = "";
@@ -899,7 +897,8 @@ public class OnlCgformApiController {
if ("image".equals(var1.get(var4).getFieldShowType())) {
var6.setType(2);
var6.setExportImageType(3);
var6.setImageBasePath(this.upLoadPath);
// TODO 处理图片路径的问题
// var6.setImageBasePath(this.upLoadPath);
var6.setHeight(50.0D);
var6.setWidth(60.0D);
} else {
@@ -5,11 +5,12 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.util.SpringContextUtils;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import org.jeecgframework.poi.handler.impl.ExcelDataHandlerDefaultImpl;
import org.jeecgframework.poi.util.PoiPublicUtil;
public class CgFormExcelHandler extends ExcelDataHandlerDefaultImpl {
Map<String, OnlCgformField> a;
@@ -38,23 +39,6 @@ public class CgFormExcelHandler extends ExcelDataHandlerDefaultImpl {
return var2;
}
@Override
public void setMapValue(Map<String, Object> map, String originKey, Object value) {
String var4 = this.a(originKey);
if (value instanceof Double) {
map.put(var4, PoiPublicUtil.doubleToString((Double)value));
} else if (value instanceof byte[]) {
byte[] var5 = ((byte[])value);
String var6 = CgformUtil.a(var5, this.c, this.d, this.e);
if (var6 != null) {
map.put(var4, var6);
}
} else {
map.put(var4, value == null ? "" : value.toString());
}
}
private String a(String var1) {
return this.a.containsKey(var1) ? "$mainTable$" + this.a.get(var1).getDbFieldName() : "$subTable$" + var1;
}
@@ -29,7 +29,7 @@ import com.jero.generater.modules.online.config.util.DbTableUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,9 +24,9 @@ import com.jero.generater.modules.online.cgreport.util.SqlUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
@@ -360,13 +360,12 @@ public class OnlCgreportAPI {
var53 = var12.get(var52);
((List)var53).add(var15);
} else {
ExcelExportEntity var23 = new ExcelExportEntity(var52, var52, true);
ExcelExportEntity var23 = new ExcelExportEntity(var52, var52);
var13.add(var23);
((List)var53).add(var15);
}
var12.put(var52, var53);
var16.setColspan(true);
}
var13.add(var16);
@@ -382,8 +381,6 @@ public class OnlCgreportAPI {
Entry<String, Object> var39 = var37.next();
var42 = var39.getKey();
List<String> var43 = (List)var39.getValue();
getVar48(var13, var42, var43);
}
if (!var36.isEmpty()) {
@@ -418,15 +415,6 @@ public class OnlCgreportAPI {
}
}
private void getVar48(ArrayList<ExcelExportEntity> var13, String var42, List<String> var43) {
for (ExcelExportEntity o : var13) {
ExcelExportEntity var48 = o;
if (var42.equals(var48.getName()) && var48.isColspan()) {
var48.setSubColumnList(var43);
}
}
}
private void getVar16(ExcelExportEntity var16, List<DictModel> var19) {
if (var19 != null && !var19.isEmpty()) {
ArrayList<String> var20 = new ArrayList<>();