导出导入
@SuppressWarnings(“rawtypes”)
@AddOperaLog(info = “导出员工报工信息”, level = LogConstant.MIDDLE_LOG_LEVEL, eventType = LogConstant.BUSINESS_EVENT_TYPE, operateType = LogConstant.MODIFY_OPERATE_TYPE)
@RequestMapping(value = “/exportExcel”, method = RequestMethod.POST)
public void exportExcel(JobBookingVo entity, HttpServletRequest request, HttpServletResponse response,
RedirectAttributes redirectAttributes) throws Exception {
// 初始化表头
String[] tittle = { “序号”, “人员编号”, “填报日期”, “人员姓名”, “人员类型”, “人员部门”, “项目部门”, “项目经理”, “项目编号”, “项目名称”, “里程碑”, “工作地点”,
“工时(H)”, “报工状态”, “结算状态”, “是否补录” };
JobBooking job = new JobBooking();
SpringBeanUtils.copyPropertiesIgnoreNull(entity, job);
// 根据项目Id 查询项目信息
List datas = jobBookingService.findInfoByCondition(job);
// 根据人员编码获取人资信息
datas = setJobBookingInfo(request, datas);
// 初始化
List<Object[]> list = new ArrayList<>();
// 获取数据字典数据
List dictList = getDictList();
Object[] obj = null;
int a = 0;
for (JobBooking jobBooking : datas) {
obj = new Object[tittle.length];
a++;
// 序号
obj[0] = a;
// 人员编号
if (StringUtils.isNotEmpty(jobBooking.getEmployeeCode()))
obj[1] = jobBooking.getEmployeeCode();
// 填报日期
if (jobBooking.getWorkDate() != null)
obj[2] = DateUtils.formatDate(jobBooking.getWorkDate(), “yyyy-MM-dd”);
list.add(obj);
}
ExportExcelUtils ec = new ExportExcelUtils("员工报工_" + DateUtils.formartTime(new Date()) + ".xls", "员工报工", tittle,list, response);
ec.export();
}
-------------------以上是导出方法—ExportExcelUtils方法在framework里面------
@AddOperaLog(info = “导入员工报工信息”, level = LogConstant.MIDDLE_LOG_LEVEL, eventType = LogConstant.BUSINESS_EVENT_TYPE, operateType = LogConstant.MODIFY_OPERATE_TYPE)
@RequestMapping(value = “/importJobBookingInfo”, method = RequestMethod.POST)
public WrappedResult importJobBookingInfo(@RequestParam(value = “fu_UploadFile”) MultipartFile file,
@RequestParam(value = “projectId”) String projectId) {
try {
if (file == null)
throw new IllegalArgumentException(“参数有误!”);
// 文件后缀名判断
String originalFileName = file.getOriginalFilename();
if (StringUtils.isEmpty(originalFileName)
|| (!originalFileName.endsWith(".xls") && (!originalFileName.endsWith(".xlsx")))) {
throw new IllegalArgumentException(“文件格式不正确!”);
}
// 读取Excel数据到List中
List<ArrayList> list = ImportExcelUtils.readExcel(file);
// 导入处理
List errMsgList = jobBookingService.importJobBookingInfo(list, projectId, getDictList());
// 判断是否存在错误信息
if (errMsgList == null || errMsgList.isEmpty()) {
return wrapResult(true, null, null, “导入成功!”);
}
return wrapResult(false, errMsgList, null, “导入失败!”);
} catch (Exception ex) {
logger.error(ex.getMessage());
}
return wrapResult(false, null, null, “导入失败!”);
}
------------------以上是导入方法--------
-