|
...
|
...
|
@@ -34,6 +34,7 @@ import java.io.IOException; |
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
...
|
...
|
@@ -55,9 +56,62 @@ public class JeecgController<T, S extends IService<T>> { |
|
|
|
private String upLoadPath;
|
|
|
|
/**
|
|
|
|
* 导出excel
|
|
|
|
*
|
|
|
|
*月工时导出
|
|
|
|
* @param request
|
|
|
|
*/
|
|
|
|
protected ModelAndView exportXlsWorkTime(HttpServletRequest request, T object, Class<T> clazz, String title) {
|
|
|
|
// Step.1 组装查询条件
|
|
|
|
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
|
|
|
try {
|
|
|
|
// 获取 undertaker 字段
|
|
|
|
Field name = clazz.getDeclaredField("undertaker");
|
|
|
|
name.setAccessible(true);
|
|
|
|
String undertaker = (String) name.get(object);
|
|
|
|
if(undertaker!=null && !undertaker.isEmpty()){
|
|
|
|
String undertaker2 = undertaker.replace("*", ""); // 移除通配符 *
|
|
|
|
queryWrapper.like("undertaker", "%" + undertaker2 + "%");
|
|
|
|
}
|
|
|
|
// 获取 yan_time 字段
|
|
|
|
Field yan_time = clazz.getDeclaredField("yanTime");
|
|
|
|
yan_time.setAccessible(true);
|
|
|
|
Date yanTime = (Date) yan_time.get(object);
|
|
|
|
if(yanTime!=null){
|
|
|
|
Date salaryMonth = yanTime;
|
|
|
|
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
|
String outputDateString = outputFormat.format(salaryMonth);
|
|
|
|
queryWrapper.apply("DATE_FORMAT(yan_time, '%Y-%m') = '" + outputDateString + "'");
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
|
|
|
|
|
// Step.2 获取导出数据
|
|
|
|
List<T> pageList = service.list(queryWrapper);
|
|
|
|
List<T> exportList = null;
|
|
|
|
|
|
|
|
// 过滤选中数据
|
|
|
|
String selections = request.getParameter("selections");
|
|
|
|
if (oConvertUtils.isNotEmpty(selections)) {
|
|
|
|
List<String> selectionList = Arrays.asList(selections.split(","));
|
|
|
|
exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
|
|
|
|
} else {
|
|
|
|
exportList = pageList;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step.3 AutoPoi 导出Excel
|
|
|
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
|
//此处设置的filename无效 ,前端会重更新设置一下
|
|
|
|
mv.addObject(NormalExcelConstants.FILE_NAME, title);
|
|
|
|
mv.addObject(NormalExcelConstants.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(NormalExcelConstants.PARAMS,exportParams);
|
|
|
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
|
|
|
return mv;
|
|
|
|
}
|
|
|
|
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title) {
|
|
|
|
// Step.1 组装查询条件
|
|
|
|
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
|
...
|
...
|
|