Browse Source

增加一个导入排班

master
walton 1 month ago
parent
commit
95c60349f7
  1. 7
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyGroupController.java
  2. 21
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java
  3. 26
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/entity/SchedulingExcelDTO.java
  4. 3
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java
  5. 30
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java
  6. 225
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java
  7. 33
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelToolListener.java
  8. 348
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelUtil.java

7
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) @ApiOperationSupport(order = 7)
@ApiOperation(value = "设置班组长", notes = "传入imsDutyGroup") @ApiOperation(value = "设置班组长", notes = "传入imsDutyGroup")
public R manager(@Valid @RequestBody ImsDutyGroupEntity imsDutyGroup) { public R manager(@Valid @RequestBody ImsDutyGroupEntity imsDutyGroup) {
LambdaQueryWrapper<ImsDutyGroupEntity> wrapper=new LambdaQueryWrapper<>();
wrapper.ne(ImsDutyGroupEntity::getId,imsDutyGroup.getId());
wrapper.ne(ImsDutyGroupEntity::getManagerId,imsDutyGroup.getManagerId());
List<ImsDutyGroupEntity> list=imsDutyGroupService.list(wrapper);
if(list!=null && !list.isEmpty()){
return R.data("该用户已在其他组中设置为班组长");
}
return R.status(imsDutyGroupService.updateById(imsDutyGroup)); return R.status(imsDutyGroupService.updateById(imsDutyGroup));
} }

21
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.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; 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.core.tool.utils.Func;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
@ -120,6 +122,25 @@ public class ImsDutyMainController extends BladeController {
return imsDutyMainService.getSchedulingV2(imsSchedulingVo); 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);
}
// /** // /**
// * 排班管理 // * 排班管理
// */ // */

26
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;
}

3
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 com.hnac.hzims.operational.report.vo.DutyReportVO;
import org.springblade.core.mp.base.BaseService; import org.springblade.core.mp.base.BaseService;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
@ -61,6 +62,8 @@ public interface IImsDutyMainService extends BaseService<ImsDutyMainEntity> {
R getSchedulingV2(ImsSchedulingVo imsSchedulingVo); R getSchedulingV2(ImsSchedulingVo imsSchedulingVo);
R importScheduling(MultipartFile file,String yearMonth,Long deptId);
R getSchedulingList(int year, int month, Long deptId); R getSchedulingList(int year, int month, Long deptId);
R getSchedulingListV2(int year, int month, Long deptId); R getSchedulingListV2(int year, int month, Long deptId);

30
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyGroupServiceImpl.java

@ -59,24 +59,12 @@ public class ImsDutyGroupServiceImpl extends BaseServiceImpl<ImsDutyGroupMapper,
if (ObjectUtil.isNotEmpty(user)) { if (ObjectUtil.isNotEmpty(user)) {
tenantId = user.getTenantId(); tenantId = user.getTenantId();
} }
boolean flag = this.saveImsDutyGroupPEntity(imsDutyGroup.getPersonId(), tenantId, imsDutyGroup.getId()); boolean flag = this.saveImsDutyGroupPEntity(imsDutyGroup.getPersonId(), tenantId, imsDutyGroup.getId());
if (flag == false) { // if (flag == false) {
return R.fail("当前选择人员已全部存在分组"); // return R.fail("当前选择人员已全部存在分组");
} // }
/* //先查看该班组今天是否存在
List<ImsDutyMainEntity> list = iImsDutyMainService.list(new LambdaQueryWrapper<ImsDutyMainEntity>() {{
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()) { if (imsDutyGroup.getUpdateDuty()) {
this.updateDuty(imsDutyGroup.getId()); this.updateDuty(imsDutyGroup.getId());
@ -133,13 +121,13 @@ public class ImsDutyGroupServiceImpl extends BaseServiceImpl<ImsDutyGroupMapper,
imsDutyGroupPEntity.setTenantId(tenantId); imsDutyGroupPEntity.setTenantId(tenantId);
imsDutyGroupPEntity.setGroupId(groupId); imsDutyGroupPEntity.setGroupId(groupId);
imsDutyGroupPEntity.setPersonId(Long.parseLong(personIds[i])); imsDutyGroupPEntity.setPersonId(Long.parseLong(personIds[i]));
if (imsDutyGroupPMapper.selectPersonIsExist(imsDutyGroupPEntity) < 1) { // if (imsDutyGroupPMapper.selectPersonIsExist(imsDutyGroupPEntity) < 1) {
list.add(imsDutyGroupPEntity); list.add(imsDutyGroupPEntity);
} // }
}
if (CollectionUtil.isEmpty(list)) {
return false;
} }
// if (CollectionUtil.isEmpty(list)) {
// return false;
// }
return imsDutyGroupPService.saveBatch(list); return imsDutyGroupPService.saveBatch(list);
} }

225
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java

@ -1,5 +1,7 @@
package com.hnac.hzims.operational.duty.service.impl; package com.hnac.hzims.operational.duty.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -16,6 +18,7 @@ import com.hnac.hzims.operational.duty.enume.JoinStatus;
import com.hnac.hzims.operational.duty.mapper.*; import com.hnac.hzims.operational.duty.mapper.*;
import com.hnac.hzims.operational.duty.scheduled.ThreadTask; import com.hnac.hzims.operational.duty.scheduled.ThreadTask;
import com.hnac.hzims.operational.duty.service.*; import com.hnac.hzims.operational.duty.service.*;
import com.hnac.hzims.operational.duty.utils.ExcelToolListener;
import com.hnac.hzims.operational.duty.vo.*; import com.hnac.hzims.operational.duty.vo.*;
import com.hnac.hzims.operational.main.vo.DutyPersonalReportVO; import com.hnac.hzims.operational.main.vo.DutyPersonalReportVO;
import com.hnac.hzims.operational.report.vo.DutyReportVO; import com.hnac.hzims.operational.report.vo.DutyReportVO;
@ -26,6 +29,7 @@ import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*; import org.springblade.core.tool.utils.*;
import org.springblade.system.cache.SysCache;
import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient; import org.springblade.system.user.feign.IUserClient;
@ -34,19 +38,24 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Time; import java.sql.Time;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.hnac.hzims.operational.duty.utils.ExcelUtil.asyncReadModel;
/** /**
* 服务实现类 * 服务实现类
* *
@ -87,7 +96,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
if (null == imsDutyMain.getClassId()) { if (null == imsDutyMain.getClassId()) {
return R.fail("班次ID不能为空"); return R.fail("班次ID不能为空");
} }
/*if (StringUtils.isEmpty(imsDutyMain.getClassName())) { /*if (StringUtils.isEmpty(imsDutyMain.getClassName())) {
return R.fail("班次名称为空"); return R.fail("班次名称为空");
}*/ }*/
//判断值班人员同一天同一班次是否排过班 //判断值班人员同一天同一班次是否排过班
@ -293,6 +302,210 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
return cycleSchedulingTowV2(imsSchedulingVo, dates, imsDutyMainEntity1); return cycleSchedulingTowV2(imsSchedulingVo, dates, imsDutyMainEntity1);
} }
@Override
public R importScheduling(MultipartFile file,String yearMonth,Long deptId) {
String filename = file.getOriginalFilename();
ExcelToolListener excelToolListener = new ExcelToolListener();
if (org.springframework.util.StringUtils.isEmpty(filename)) {
return R.fail("请上传文件!");
} else if (!org.springframework.util.StringUtils.endsWithIgnoreCase(filename, ".xls") && !org.springframework.util.StringUtils.endsWithIgnoreCase(filename, ".xlsx")) {
return R.fail("请上传正确的excel文件!");
} else {
try {
InputStream inputStream = file.getInputStream();
asyncReadModel(inputStream, excelToolListener, SchedulingExcelDTO.class, 0, 2);
} catch (IOException e) {
e.printStackTrace();
}
}
List entityList = excelToolListener.getDataList();
if(entityList==null || entityList.isEmpty()){
return R.fail("请在表格中填写数据");
}
List<SchedulingExcelDTO> 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<List<User>> listR=userClient.userList(AuthUtil.getTenantId(),deptId);
if(listR==null || !listR.isSuccess() || listR.getData()==null || listR.getData().isEmpty()){
return R.fail("该部门未创建用户");
}
List<User> users=listR.getData();
//记录系统中不存在的用户
Set<String> userNameSet=new HashSet<>();
Set<Long> mainDutyIds=new HashSet<>();
//获取所有用户名称以及对应的用户id
Map<String,Long> 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<String> dates = getTwoPeriodsAll(year, month, 1, year, month, days);
//先删除
this.baseMapper.delete(new LambdaQueryWrapper<ImsDutyMainEntity>() {{
eq(ImsDutyMainEntity::getCreateDept, deptId);
in(ImsDutyMainEntity::getDutyDate, dates);
}});
imsDutyMainPersonMapper.delete(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{
in(ImsDutyMainPersonEntity::getDutyDate, dates);
eq(ImsDutyMainPersonEntity::getCreateDept, deptId);
}});
//查询导入数据的上一班的值班对象 比如10月1号的前一班9月30号
LambdaQueryWrapper<ImsDutyMainEntity> 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<ImsDutyClassEntity> wrapper1=new LambdaQueryWrapper<>();
wrapper1.eq(ImsDutyClassEntity::getCreateDept,deptId);
wrapper1.last(" limit 1");
List<ImsDutyClassEntity> classList=iImsDutyClassService.list(wrapper1);
if(classList==null || classList.isEmpty()){
return R.fail("该机构还未创建班次");
}
ImsDutyClassEntity classEntity=classList.get(0);
Long classId=classEntity.getId();
//查询班组
LambdaQueryWrapper<ImsDutyGroupEntity> wrapper2=new LambdaQueryWrapper<>();
wrapper2.in(ImsDutyGroupEntity::getManagerId,mainDutyIds);
wrapper2.eq(ImsDutyGroupEntity::getCreateDept,deptId);
List<ImsDutyGroupEntity> groups=dutyGroupMapper.selectList(wrapper2);
if(groups==null || groups.isEmpty()){
return R.fail("该机构还未创建班组");
}
//组装数据
List<ImsDutyMainEntity> dutyMainList=new ArrayList<>();
List<ImsDutyMainPersonEntity> dutyMainPList=new ArrayList<>();
for(int i=0;i<dates.size();i++){
String date=dates.get(i);
SchedulingExcelDTO dto=list.get(i);
//排班主表
ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity();
Long managerId=map.get(dto.getMainDuty());
ImsDutyGroupEntity dutyGroup=getGroupByManageId(groups,managerId);
setMainEntity(imsDutyMainEntity, classId, dutyGroup.getId(), date);
imsDutyMainEntity.setStatus(-1);
String personIds=managerId+"^"+map.get(dto.getDeputyDuty());
imsDutyMainEntity.setDutyPersonIds(personIds);
imsDutyMainEntity.setCreateDept(deptId);
Long id = IdWorker.getId();
imsDutyMainEntity.setId(id);
imsDutyMainEntity.setPreDutyId(beforeDutyId);
imsDutyMainEntity.setCreateUser(AuthUtil.getUserId());
imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId());
imsDutyMainEntity.setTenantId(AuthUtil.getTenantId());
dutyMainList.add(imsDutyMainEntity);
beforeDutyId = id;
//排班人员表
String[] personIdArr=personIds.split("^");
for(String personId:personIdArr) {
ImsDutyMainPersonEntity imsDutyMainPersonEntity = new ImsDutyMainPersonEntity();
imsDutyMainPersonEntity.setClassId(imsDutyMainEntity.getClassId());
imsDutyMainPersonEntity.setCreateDept(imsDutyMainEntity.getCreateDept());
imsDutyMainPersonEntity.setDutyGroupName(dutyGroup.getGroupName());
imsDutyMainPersonEntity.setDutyGroupId(dutyGroup.getId());
imsDutyMainPersonEntity.setDutyDate(imsDutyMainEntity.getDutyDate());
imsDutyMainPersonEntity.setStatus(imsDutyMainEntity.getStatus());
imsDutyMainPersonEntity.setCreateTime(imsDutyMainEntity.getCreateTime());
imsDutyMainPersonEntity.setDutyMainId(imsDutyMainEntity.getId());
imsDutyMainPersonEntity.setCreateUser(imsDutyMainEntity.getCreateUser());
imsDutyMainPersonEntity.setUpdateUser(imsDutyMainEntity.getUpdateUser());
imsDutyMainPersonEntity.setTenantId(imsDutyMainEntity.getTenantId());
imsDutyMainPersonEntity.setDutyPerson(Long.valueOf(personId));
long id1 = IdWorker.getId(imsDutyMainPersonEntity);
imsDutyMainPersonEntity.setId(id1);
imsDutyMainPersonEntity.setDutyChargePerson(managerId);
dutyMainPList.add(imsDutyMainPersonEntity);
}
}
//批量保存
this.saveBatch(dutyMainList);
iImsDutyMainPersonService.saveBatch(dutyMainPList);
return R.success("导入成功");
}
private ImsDutyGroupEntity getGroupByManageId(List<ImsDutyGroupEntity> 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<User> 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<ImsDutyMainMapper, I
} }
if (StringUtil.isNotBlank(dutyGroupId)) { if (StringUtil.isNotBlank(dutyGroupId)) {
ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity();
setMainEntity(imsDutyMainEntity, classId, Long.valueOf(dutyGroupId), date); setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date);
imsDutyMainEntity.setStatus(-1); imsDutyMainEntity.setStatus(-1);
imsDutyMainEntity.setDutyPersonIds(personIds); imsDutyMainEntity.setDutyPersonIds(personIds);
imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept());
@ -1782,7 +1995,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
} }
if (StringUtil.isNotBlank(dutyGroupId)) { if (StringUtil.isNotBlank(dutyGroupId)) {
ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity();
setMainEntity(imsDutyMainEntity, classId, Long.valueOf(dutyGroupId), date); setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date);
imsDutyMainEntity.setStatus(-1); imsDutyMainEntity.setStatus(-1);
imsDutyMainEntity.setDutyPersonIds(personIds); imsDutyMainEntity.setDutyPersonIds(personIds);
imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept());
@ -1805,7 +2018,7 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
} }
ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity();
setMainEntity(imsDutyMainEntity, classId, Long.valueOf(groupId), date); setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(groupId), date);
if (Func.isBlank(proDutyMainId)) { if (Func.isBlank(proDutyMainId)) {
if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) {
proDutyMainId = imsDutyMainEntity1.getId().toString(); proDutyMainId = imsDutyMainEntity1.getId().toString();
@ -1837,9 +2050,9 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
} }
public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, String classId, Long groupId, String date) { public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, Long classId, Long groupId, String date) {
imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE));
imsDutyMainEntity.setClassId(Long.valueOf(classId)); imsDutyMainEntity.setClassId(classId);
imsDutyMainEntity.setDutyGroupId(groupId); imsDutyMainEntity.setDutyGroupId(groupId);
imsDutyMainEntity.setStatus(0); imsDutyMainEntity.setStatus(0);
imsDutyMainEntity.setCreateTime(new Date()); imsDutyMainEntity.setCreateTime(new Date());

33
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/utils/ExcelToolListener.java

@ -0,0 +1,33 @@
package com.hnac.hzims.operational.duty.utils;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Slf4j
@Data
public class ExcelToolListener extends AnalysisEventListener {
/**保存数据**/
private List<Object> 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));
}
}

348
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<Map<Integer, String>> syncRead(String filePath){
return EasyExcelFactory.read(filePath).sheet().doReadSync();
}
/**
* 同步无模型读默认表头占一行从第2行开始读
* @param filePath
* @param sheetNo sheet页号从0开始
* @return
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<Map<colNum, cellValue>>
*/
public static List<Map<Integer, String>> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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<List<String>> head, List<List<Object>> 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<List<String>> head, List<List<Object>> 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<String> 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<String> excludeCols, Integer sheetNo, String sheetName){
EasyExcel.write(filePath, headClazz).excludeColumnFiledNames(excludeCols).sheet(sheetNo, sheetName).doWrite(data);
}
}
Loading…
Cancel
Save