diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyGroupController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyGroupController.java index c3ded48..6badc2b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyGroupController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyGroupController.java @@ -128,6 +128,13 @@ public class ImsDutyGroupController extends BladeController { @ApiOperationSupport(order = 7) @ApiOperation(value = "设置班组长", notes = "传入imsDutyGroup") public R manager(@Valid @RequestBody ImsDutyGroupEntity imsDutyGroup) { + LambdaQueryWrapper wrapper=new LambdaQueryWrapper<>(); + wrapper.ne(ImsDutyGroupEntity::getId,imsDutyGroup.getId()); + wrapper.ne(ImsDutyGroupEntity::getManagerId,imsDutyGroup.getManagerId()); + List list=imsDutyGroupService.list(wrapper); + if(list!=null && !list.isEmpty()){ + return R.data("该用户已在其他组中设置为班组长"); + } return R.status(imsDutyGroupService.updateById(imsDutyGroup)); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java index 236aa7d..df367b4 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java @@ -19,6 +19,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; +import org.apache.commons.lang.StringUtils; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; @@ -27,6 +28,7 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.system.feign.ISysClient; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; @@ -120,6 +122,25 @@ public class ImsDutyMainController extends BladeController { return imsDutyMainService.getSchedulingV2(imsSchedulingVo); } + /** + * 导入排班 + */ + @PostMapping("/importScheduling") + @ApiOperationSupport(order = 8) + @ApiOperation(value = "导入排班管理(适用一天一班的情况)", notes = "") + public R importScheduling(@RequestParam("file")MultipartFile file, + @RequestParam("yearMonth") String yearMonth,////yearMonth格式 yyyy-MM + @RequestParam("deptId") Long deptId + ) { + if(StringUtils.isBlank(yearMonth)){ + return R.fail("请选择年月"); + } + if(deptId == null){ + return R.fail("请选择部门"); + } + return imsDutyMainService.importScheduling(file,yearMonth,deptId); + } + // /** // * 排班管理 // */ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/entity/SchedulingExcelDTO.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/entity/SchedulingExcelDTO.java new file mode 100644 index 0000000..349c459 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/entity/SchedulingExcelDTO.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.operational.duty.entity; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SchedulingExcelDTO implements Serializable { + @ExcelProperty(value = "日期(必填)",index = 0 ) + @ApiModelProperty(value = "日期-天") + private String day; + /** + * 编码 + */ + @ExcelProperty(value = "主值(必填)",index = 1 ) + @ApiModelProperty(value = "主值") + private String mainDuty; + /** + * 规格 + */ + @ExcelProperty(value = "副值(必填)",index = 2 ) + @ApiModelProperty(value = "副值") + private String deputyDuty; +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java index 73b277f..7dccf17 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java @@ -8,6 +8,7 @@ import com.hnac.hzims.operational.main.vo.DutyPersonalReportVO; import com.hnac.hzims.operational.report.vo.DutyReportVO; import org.springblade.core.mp.base.BaseService; import org.springblade.core.tool.api.R; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; import java.util.List; @@ -61,6 +62,8 @@ public interface IImsDutyMainService extends BaseService { R getSchedulingV2(ImsSchedulingVo imsSchedulingVo); + R importScheduling(MultipartFile file,String yearMonth,Long deptId); + R getSchedulingList(int year, int month, Long deptId); R getSchedulingListV2(int year, int month, Long deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java index c413205..f554ce2 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java @@ -59,24 +59,12 @@ public class ImsDutyGroupServiceImpl extends BaseServiceImpl list = iImsDutyMainService.list(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getDutyGroupId, imsDutyGroup.getId()); - eq(ImsDutyMainEntity::getDutyDate, DateUtil.format(new Date(), DateUtil.PATTERN_DATE)); - }}); - if(CollectionUtil.isNotEmpty(list)){//存在 - if(null == imsDutyGroup.getIsUpdateThatVeryDay()){ - return R.data("1"); - }else if(imsDutyGroup.getIsUpdateThatVeryDay()){ - //更新当天数据 - } - } -*/ //判断是否更新排班 if (imsDutyGroup.getUpdateDuty()) { this.updateDuty(imsDutyGroup.getId()); @@ -133,13 +121,13 @@ public class ImsDutyGroupServiceImpl extends BaseServiceImpl list = JSONArray.parseArray(JSON.toJSONString(entityList), SchedulingExcelDTO.class).stream() + .filter(e->StringUtils.isNotBlank(e.getDay())) + .filter(e->StringUtils.isNotBlank(e.getMainDuty())) + .filter(e->StringUtils.isNotBlank(e.getDeputyDuty())) + .collect(Collectors.toList()); + int days=getMaxDays(yearMonth); + if(list==null || list.isEmpty() || list.size()!=days){ + return R.fail("日期,主值,副值数据不够完整,请补充"); + } + + + R> listR=userClient.userList(AuthUtil.getTenantId(),deptId); + if(listR==null || !listR.isSuccess() || listR.getData()==null || listR.getData().isEmpty()){ + return R.fail("该部门未创建用户"); + } + List users=listR.getData(); + //记录系统中不存在的用户 + Set userNameSet=new HashSet<>(); + Set mainDutyIds=new HashSet<>(); + //获取所有用户名称以及对应的用户id + Map map=new HashMap<>(); + for(SchedulingExcelDTO dto:list){ + Long id=map.get(dto.getMainDuty()); + if(id==null){ + Long tmpId=getByName(users,dto.getMainDuty()); + if(tmpId!=null) { + map.put(dto.getMainDuty(), tmpId); + mainDutyIds.add(tmpId); + }else{ + userNameSet.add(dto.getMainDuty()); + } + } + + + id=map.get(dto.getDeputyDuty()); + if(id==null){ + Long tmpId=getByName(users,dto.getDeputyDuty()); + if(tmpId!=null) { + map.put(dto.getDeputyDuty(), tmpId); + }else{ + userNameSet.add(dto.getDeputyDuty()); + } + } + } + //判断用户是否在系统中存在 + if(userNameSet.size() >=0 ){ + return R.fail("用户("+StringUtils.join(userNameSet,"、")+")在系统中不存在,需要在用户管理中创建!"); + } + + String[] arr=yearMonth.split("-"); + int year=Integer.valueOf(arr[0]); + int month=Integer.valueOf(arr[1]); + List dates = getTwoPeriodsAll(year, month, 1, year, month, days); + //先删除 + this.baseMapper.delete(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getCreateDept, deptId); + in(ImsDutyMainEntity::getDutyDate, dates); + }}); + imsDutyMainPersonMapper.delete(new LambdaQueryWrapper() {{ + in(ImsDutyMainPersonEntity::getDutyDate, dates); + eq(ImsDutyMainPersonEntity::getCreateDept, deptId); + }}); + //查询导入数据的上一班的值班对象 比如10月1号的前一班9月30号 + LambdaQueryWrapper wrapper=new LambdaQueryWrapper<>(); + wrapper.eq(ImsDutyMainEntity::getDutyDate,beforeDutyDate(dates.get(0))); + wrapper.eq(ImsDutyMainEntity::getCreateDept,deptId); + ImsDutyMainEntity beforeEntity=this.getOne(wrapper); + Long beforeDutyId=null; + if(beforeEntity!=null){ + beforeDutyId=beforeEntity.getId(); + } + + //再增加 + //查询最新的班次 + LambdaQueryWrapper wrapper1=new LambdaQueryWrapper<>(); + wrapper1.eq(ImsDutyClassEntity::getCreateDept,deptId); + wrapper1.last(" limit 1"); + List classList=iImsDutyClassService.list(wrapper1); + if(classList==null || classList.isEmpty()){ + return R.fail("该机构还未创建班次"); + } + ImsDutyClassEntity classEntity=classList.get(0); + Long classId=classEntity.getId(); + + //查询班组 + LambdaQueryWrapper wrapper2=new LambdaQueryWrapper<>(); + wrapper2.in(ImsDutyGroupEntity::getManagerId,mainDutyIds); + wrapper2.eq(ImsDutyGroupEntity::getCreateDept,deptId); + List groups=dutyGroupMapper.selectList(wrapper2); + if(groups==null || groups.isEmpty()){ + return R.fail("该机构还未创建班组"); + } + + //组装数据 + List dutyMainList=new ArrayList<>(); + List dutyMainPList=new ArrayList<>(); + for(int i=0;i groups,Long managerId){ + for(ImsDutyGroupEntity entity:groups){ + if(entity.getManagerId().equals(managerId)){ + return entity; + } + } + return null; + } + + private static int getMaxDays(String yearMonthStr){ + String[] arr=yearMonthStr.split("-"); + int year=Integer.valueOf(arr[0]); + int month=Integer.valueOf(arr[1]); + YearMonth yearMonth = YearMonth.of(year, month); + int maxDays = yearMonth.lengthOfMonth(); + return maxDays; + } + + private String beforeDutyDate(String date){ + LocalDate today = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + + LocalDate yesterday = today.minusDays(1); // 获取前一天的日期 + + // 如果需要格式化日期,可以使用DateTimeFormatter + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + return yesterday.format(formatter); + } + + private Long getByName(List users,String name){ + for(User user:users){ + if(user.getName().equals(name)){ + return user.getId(); + } + } + return null; + } + /** * 轮询排班 * @@ -479,7 +692,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl dataList = Collections.synchronizedList(new ArrayList<>()); + + public ExcelToolListener() { + } + + @Override + public void invoke(Object data, AnalysisContext context) { + dataList.add(data); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + log.info("解析完成"); + log.info("------结果集为:{}------", JSONObject.toJSONString(dataList)); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelUtil.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelUtil.java new file mode 100644 index 0000000..b2c5d33 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelUtil.java @@ -0,0 +1,348 @@ +package com.hnac.hzims.operational.duty.utils; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.excel.event.AnalysisEventListener; +import com.alibaba.excel.write.handler.WriteHandler; +import org.apache.poi.ss.formula.functions.T; + +import java.io.File; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author hx + */ +public class ExcelUtil { + /** + * 同步无模型读(默认读取sheet0,从第2行开始读) + * @param filePath + * @return + */ + public static List> syncRead(String filePath){ + return EasyExcelFactory.read(filePath).sheet().doReadSync(); + } + + /** + * 同步无模型读(默认表头占一行,从第2行开始读) + * @param filePath + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static List> syncRead(String filePath, Integer sheetNo){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param inputStream + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(InputStream inputStream, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(inputStream).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param file + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(File file, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(file).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步无模型读(指定sheet和表头占的行数) + * @param filePath + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return List> + */ + public static List> syncRead(String filePath, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).headRowNumber(headRowNum).doReadSync(); + } + + /** + * 同步按模型读(默认读取sheet0,从第2行开始读) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @return + */ + public static List syncReadModel(String filePath, Class clazz){ + return EasyExcelFactory.read(filePath).sheet().head(clazz).doReadSync(); + } + + /** + * 同步按模型读(默认表头占一行,从第2行开始读) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static List syncReadModel(String filePath, Class clazz, Integer sheetNo){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param inputStream + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(InputStream inputStream, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(inputStream).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param file + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(File file, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(file).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 同步按模型读(指定sheet和表头占的行数) + * @param filePath + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static List syncReadModel(String filePath, Class clazz, Integer sheetNo, Integer headRowNum){ + return EasyExcelFactory.read(filePath).sheet(sheetNo).headRowNumber(headRowNum).head(clazz).doReadSync(); + } + + /** + * 异步无模型读(默认读取sheet0,从第2行开始读) + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param filePath 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener){ + EasyExcelFactory.read(filePath, excelListener).sheet().doRead(); + } + + /** + * 异步无模型读(默认表头占一行,从第2行开始读) + * @param filePath 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener, Integer sheetNo){ + EasyExcelFactory.read(filePath, excelListener).sheet(sheetNo).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param inputStream + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(InputStream inputStream, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(inputStream, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param file + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(File file, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(file, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步无模型读(指定sheet和表头占的行数) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + * @return + */ + public static void asyncRead(String filePath, AnalysisEventListener excelListener, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(filePath, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取(默认读取sheet0,从第2行开始读) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet().doRead(); + } + + /** + * 异步按模型读取(默认表头占一行,从第2行开始读) + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz, Integer sheetNo){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet(sheetNo).doRead(); + } + + /** + * 异步按模型读取 + * @param inputStream + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(InputStream inputStream, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(inputStream, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取 + * @param file + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(File file, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(file, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 异步按模型读取 + * @param filePath + * @param excelListener 监听器,在监听器中可以处理行数据LinkedHashMap,表头数据,异常处理等 + * @param clazz 模型的类类型(excel数据会按该类型转换成对象) + * @param sheetNo sheet页号,从0开始 + * @param headRowNum 表头占的行数,从0开始(如果要连表头一起读出来则传0) + */ + public static void asyncReadModel(String filePath, AnalysisEventListener excelListener, Class clazz, Integer sheetNo, Integer headRowNum){ + EasyExcelFactory.read(filePath, clazz, excelListener).sheet(sheetNo).headRowNumber(headRowNum).doRead(); + } + + /** + * 无模板写文件 + * @param filePath + * @param head 表头数据 + * @param data 表内容数据 + */ + public static void write(String filePath, List> head, List> data){ + EasyExcel.write(filePath).head(head).sheet().doWrite(data); + } + + /** + * 无模板写文件 + * @param filePath + * @param head 表头数据 + * @param data 表内容数据 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, List> head, List> data, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath).head(head).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 根据excel模板文件写入文件 + * @param filePath + * @param templateFileName + * @param headClazz + * @param data + */ + public static void writeTemplate(String filePath, String templateFileName, Class headClazz, List data){ + EasyExcel.write(filePath, headClazz).withTemplate(templateFileName).sheet().doWrite(data); + } + + /** + * 根据excel模板文件写入文件 + * @param filePath + * @param templateFileName + * @param data + */ + public static void writeTemplate(String filePath, String templateFileName, List data){ + EasyExcel.write(filePath).withTemplate(templateFileName).sheet().doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + */ + public static void write(String filePath, Class headClazz, List data){ + EasyExcel.write(filePath, headClazz).sheet().doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, Class headClazz, List data, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件 + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param writeHandler 自定义的处理器,比如设置table样式,设置超链接、单元格下拉框等等功能都可以通过这个实现(需要注册多个则自己通过链式去调用) + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void write(String filePath, Class headClazz, List data, WriteHandler writeHandler, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).registerWriteHandler(writeHandler).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件(包含某些字段) + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param includeCols 过滤包含的字段,根据字段名称过滤 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void writeInclude(String filePath, Class headClazz, List data, Set includeCols, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).includeColumnFiledNames(includeCols).sheet(sheetNo, sheetName).doWrite(data); + } + + /** + * 按模板写文件(排除某些字段) + * @param filePath + * @param headClazz 表头模板 + * @param data 数据 + * @param excludeCols 过滤排除的字段,根据字段名称过滤 + * @param sheetNo sheet页号,从0开始 + * @param sheetName sheet名称 + */ + public static void writeExclude(String filePath, Class headClazz, List data, Set excludeCols, Integer sheetNo, String sheetName){ + EasyExcel.write(filePath, headClazz).excludeColumnFiledNames(excludeCols).sheet(sheetNo, sheetName).doWrite(data); + } + + +} +