全面修复和测试引入easypoi的bug,处理dict转换问题
This commit is contained in:
+8
-3
@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Results;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.easypoi.EasyPoiDictHandlerImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -74,6 +76,7 @@ public class JeroController<T, S extends IService<T>> {
|
||||
mv.addObject(FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
|
||||
mv.addObject(CLASS, clazz);
|
||||
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
mv.addObject(PARAMS,exportParams);
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||
return mv;
|
||||
@@ -113,6 +116,7 @@ public class JeroController<T, S extends IService<T>> {
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i);
|
||||
exportParams.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
//map.put("title",exportParams);//表格Title
|
||||
map.put(PARAMS,exportParams);//表格Title
|
||||
@@ -157,8 +161,9 @@ public class JeroController<T, S extends IService<T>> {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
ImportParams params = new ImportParams();
|
||||
/*params.setTitleRows(2);
|
||||
params.setHeadRows(1);*/
|
||||
params.setDictHandler(SpringContextUtils.getApplicationContext().getBean(EasyPoiDictHandlerImpl.class));
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
|
||||
@@ -172,7 +177,7 @@ public class JeroController<T, S extends IService<T>> {
|
||||
return Results.OK("文件导入成功!数据行数:" + list.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Results.error("文件导入失败:" + e.getMessage());
|
||||
return Results.error("文件导入失败,请联系管理员");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class SysDictItemCore implements Serializable {
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Excel(name = "排序", width = 15, type=4)
|
||||
@Excel(name = "排序", width = 15, type = 10)
|
||||
private Integer sortOrder;
|
||||
|
||||
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package com.jero.config.easypoi;
|
||||
|
||||
import cn.afterturn.easypoi.handler.inter.IExcelDictHandler;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.jero.common.api.CommonAPI;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 针对easypoi的@Excel的dict属性,做字典值转换的方法
|
||||
* 需要进行字段转换必须使用:
|
||||
* exportParams.setDictHandler(new EasyPoiDictHandlerImpl());
|
||||
* 来实现转换处理
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EasyPoiDictHandlerImpl implements IExcelDictHandler {
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private CommonAPI commonAPI;
|
||||
|
||||
@Override
|
||||
public List<Map> getList(String dict) {
|
||||
if (StrUtil.isEmpty(dict)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DictModel> dictList = commonAPI.queryDictItemsByCode(dict);
|
||||
if (dictList != null && !dictList.isEmpty()){
|
||||
List<Map> result = new ArrayList<>();
|
||||
for (DictModel t : dictList) {
|
||||
if(t!=null){
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("text", t.getText());
|
||||
map.put("value", t.getValue());
|
||||
result.add(map);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toName(String dict, Object obj, String name, Object value) {
|
||||
if (ObjectUtil.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String valueStr = String.valueOf(value);
|
||||
|
||||
List<DictModel> dictList = commonAPI.queryDictItemsByCode(dict);
|
||||
for (DictModel t : dictList) {
|
||||
if(t!=null && valueStr.equals(t.getValue())){
|
||||
return t.getText();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toValue(String dict, Object obj, String name, Object value) {
|
||||
if (ObjectUtil.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String valueStr = String.valueOf(value);
|
||||
|
||||
List<DictModel> dictList = commonAPI.queryDictItemsByCode(dict);
|
||||
for (DictModel t : dictList) {
|
||||
if(t!=null && valueStr.equals(t.getText())){
|
||||
return t.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user