|
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.IService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.commons.beanutils.PropertyUtils; |
|
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
|
import org.hibernate.procedure.spi.ParameterRegistrationImplementor; |
|
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
|
import org.jeecg.common.system.vo.LoginUser; |
|
|
|
@ -37,11 +38,15 @@ import java.util.stream.Collectors; |
|
|
|
|
*/ |
|
|
|
|
@Slf4j |
|
|
|
|
public class JeecgController<T, S extends IService<T>> { |
|
|
|
|
|
|
|
|
|
public static final Boolean HAS_QUERY = Boolean.TRUE.booleanValue(); |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
S service; |
|
|
|
|
|
|
|
|
|
@Value("${jeecg.path.upload}") |
|
|
|
|
private String upLoadPath; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 导出excel |
|
|
|
|
* |
|
|
|
@ -53,10 +58,9 @@ public class JeecgController<T, S extends IService<T>> { |
|
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String getRealname="佚名"; |
|
|
|
|
if(sysUser!=null) |
|
|
|
|
{ |
|
|
|
|
getRealname=sysUser.getRealname(); |
|
|
|
|
String getRealname = "佚名"; |
|
|
|
|
if (sysUser != null) { |
|
|
|
|
getRealname = sysUser.getRealname(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Step.2 获取导出数据
|
|
|
|
@ -76,34 +80,35 @@ public class JeecgController<T, S extends IService<T>> { |
|
|
|
|
mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
|
|
|
|
|
mv.addObject(NormalExcelConstants.CLASS, clazz); |
|
|
|
|
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
|
|
|
|
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + getRealname, title); |
|
|
|
|
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + getRealname, title); |
|
|
|
|
exportParams.setImageBasePath(upLoadPath); |
|
|
|
|
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
|
|
|
|
mv.addObject(NormalExcelConstants.PARAMS,exportParams); |
|
|
|
|
mv.addObject(NormalExcelConstants.PARAMS, exportParams); |
|
|
|
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList); |
|
|
|
|
return mv; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据每页sheet数量导出多sheet |
|
|
|
|
* |
|
|
|
|
* @param request |
|
|
|
|
* @param object 实体类 |
|
|
|
|
* @param clazz 实体类class |
|
|
|
|
* @param title 标题 |
|
|
|
|
* @param object 实体类 |
|
|
|
|
* @param clazz 实体类class |
|
|
|
|
* @param title 标题 |
|
|
|
|
* @param exportFields 导出字段自定义 |
|
|
|
|
* @param pageNum 每个sheet的数据条数 |
|
|
|
|
* @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, String exportFields, Integer pageNum) { |
|
|
|
|
// Step.1 组装查询条件
|
|
|
|
|
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); |
|
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
// Step.2 计算分页sheet数据
|
|
|
|
|
double total = service.count(); |
|
|
|
|
int count = (int)Math.ceil(total/pageNum); |
|
|
|
|
int count = (int) Math.ceil(total / pageNum); |
|
|
|
|
// Step.3 多sheet处理
|
|
|
|
|
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>(); |
|
|
|
|
for (int i = 1; i <=count ; i++) { |
|
|
|
|
for (int i = 1; i <= count; i++) { |
|
|
|
|
Page<T> page = new Page<T>(i, pageNum); |
|
|
|
|
IPage<T> pageList = service.page(page, queryWrapper); |
|
|
|
|
List<T> records = pageList.getRecords(); |
|
|
|
@ -117,11 +122,11 @@ public class JeecgController<T, S extends IService<T>> { |
|
|
|
|
exportList = records; |
|
|
|
|
} |
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
|
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i,upLoadPath); |
|
|
|
|
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath); |
|
|
|
|
exportParams.setType(ExcelType.XSSF); |
|
|
|
|
//map.put("title",exportParams);//表格Title
|
|
|
|
|
map.put(NormalExcelConstants.PARAMS,exportParams);//表格Title
|
|
|
|
|
map.put(NormalExcelConstants.CLASS,clazz);//表格对应实体
|
|
|
|
|
map.put(NormalExcelConstants.PARAMS, exportParams);//表格Title
|
|
|
|
|
map.put(NormalExcelConstants.CLASS, clazz);//表格对应实体
|
|
|
|
|
map.put(NormalExcelConstants.DATA_LIST, exportList);//数据集合
|
|
|
|
|
listMap.add(map); |
|
|
|
|
} |
|
|
|
@ -138,9 +143,9 @@ public class JeecgController<T, S extends IService<T>> { |
|
|
|
|
* |
|
|
|
|
* @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); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|