作者 雷海东

月工时导入

... ... @@ -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());
... ...
... ... @@ -54,7 +54,8 @@ public class ViewWorkTimeController extends JeecgController<ViewWorkTime, IViewW
QueryWrapper<ViewWorkTime> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByDesc("yan_time");
if(viewWorkTime.getUndertaker()!=null && !viewWorkTime.getUndertaker().isEmpty()){
queryWrapper.like("undertaker", "%" + viewWorkTime.getUndertaker() + "%");
String undertaker = viewWorkTime.getUndertaker().replace("*", ""); // 移除通配符 *
queryWrapper.like("undertaker", "%" + undertaker + "%");
}
if(viewWorkTime.getYanTime()!=null){
Date salaryMonth = viewWorkTime.getYanTime();
... ... @@ -148,7 +149,7 @@ public class ViewWorkTimeController extends JeecgController<ViewWorkTime, IViewW
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, ViewWorkTime viewWorkTime) {
return super.exportXls(request, viewWorkTime, ViewWorkTime.class, "月工时信息");
return super.exportXlsWorkTime(request, viewWorkTime, ViewWorkTime.class, "月工时信息");
}
/**
... ...
... ... @@ -45,13 +45,19 @@ public class ViewWorkTime implements Serializable {
// @Excel(name = "工序", width = 15)
@ApiModelProperty(value = "工序")
private java.lang.String workingProcedure;
/**验收时间*/
@Excel(name = "月份", width = 15, format = "yyyy-MM")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM")
@DateTimeFormat(pattern="yyyy-MM")
@ApiModelProperty(value = "月份")
private java.util.Date yanTime;
/**承接人*/
@Excel(name = "承接人", width = 15)
@ApiModelProperty(value = "承接人")
@Excel(name = "姓名", width = 15)
@ApiModelProperty(value = "姓名")
private java.lang.String undertaker;
/**工时*/
@Excel(name = "工时", width = 15)
@ApiModelProperty(value = "工时")
@Excel(name = "月总工时", width = 15)
@ApiModelProperty(value = "月总工时")
private java.math.BigDecimal workHours;
/**派发时间*/
// @Excel(name = "派发时间", width = 15, format = "yyyy-MM-dd")
... ... @@ -63,12 +69,7 @@ public class ViewWorkTime implements Serializable {
// @Excel(name = "派发人", width = 15)
@ApiModelProperty(value = "派发人")
private java.lang.String dispatchRen;
/**验收时间*/
@Excel(name = "验收时间", width = 15, format = "yyyy-MM")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM")
@DateTimeFormat(pattern="yyyy-MM")
@ApiModelProperty(value = "验收时间")
private java.util.Date yanTime;
/**验收人*/
// @Excel(name = "验收人", width = 15)
@ApiModelProperty(value = "验收人")
... ...