From df689228b3c1d57d51676f7320fe5ed763fa9706 Mon Sep 17 00:00:00 2001 From: walton <1239357677@qq.com> Date: Thu, 24 Oct 2024 16:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E7=8F=AD=E7=AC=AC=E4=B8=89=E7=89=88?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operational/duty/entity/ImsDutyMainEntity.java | 9 +- .../operational/duty/vo/ImsSchedulingNewVo.java | 42 + .../duty/controller/ImsDutyMainController.java | 57 +- .../duty/service/IImsDutyMainService.java | 2 + .../duty/service/impl/ImsDutyMainServiceImpl.java | 3435 +++++++++++--------- 5 files changed, 1914 insertions(+), 1631 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java index cd5f5ed..0956703 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java @@ -37,11 +37,13 @@ public class ImsDutyMainEntity extends TenantEntity { @ApiModelProperty(value = "值班组id") private Long dutyGroupId; - + @TableField(exist = false) + @ApiModelProperty(value = "值班组名称") + private String dutyGroupName; /** * 值班人IDS, ID之间用^隔开 */ - @ApiModelProperty(value = "值班人IDS, ID之间用^隔开") + @ApiModelProperty(value = "值班人IDS,ID之间用^隔开") private String dutyPersonIds; /** * 值班日期 @@ -72,4 +74,7 @@ public class ImsDutyMainEntity extends TenantEntity { @ApiModelProperty(value = "备注") private String remark; + @TableField(exist = false) + private Long manageId;//值班长id + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java new file mode 100644 index 0000000..1d9c3b6 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java @@ -0,0 +1,42 @@ +package com.hnac.hzims.operational.duty.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +@Data +public class ImsSchedulingNewVo implements Serializable { + @ApiModelProperty(value = "班组ID 通过^隔开",required = true) + private String groupIds; + +// @ApiModelProperty(value = "班组名称 通过^隔开",required = true) +// private String groupNames; + + @ApiModelProperty(value = "班次ID 通过^隔开",required = true) + private String classIds; + + @ApiModelProperty(value = "班次名称 通过^隔开",required = true) + private String classNames; + + @ApiModelProperty(value = "开始时间",required = true) + private String startDate; + @ApiModelProperty(value = "结束时间",required = true) + private String endDate; + + private Long deptId;//机构id + + @ApiModelProperty("人员类型: 1、班组 2 、人员") + private Integer personType; + + //人员组 + List> personIds; //人员用 managerId 值长id personIds 人员ids 多个^隔开(不包含值长id) + + @ApiModelProperty("班次类型ID") + @JsonSerialize(nullsUsing = NullSerializer.class) + private Long dutyClassTypeId; +} 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 df367b4..34be27c 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 @@ -11,10 +11,7 @@ import com.hnac.hzims.operational.duty.entity.ImsDutyMainReportExcel; import com.hnac.hzims.operational.duty.service.IImsDutyMainService; import com.hnac.hzims.operational.duty.utils.ExcelMergeHandler; import com.hnac.hzims.operational.duty.utils.ExcelTool; -import com.hnac.hzims.operational.duty.vo.ChangeDutyMainVo; -import com.hnac.hzims.operational.duty.vo.ExchangeGroupLeader; -import com.hnac.hzims.operational.duty.vo.HomePageDutyMainInfoVo; -import com.hnac.hzims.operational.duty.vo.ImsSchedulingVo; +import com.hnac.hzims.operational.duty.vo.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -122,37 +119,37 @@ public class ImsDutyMainController extends BladeController { return imsDutyMainService.getSchedulingV2(imsSchedulingVo); } - /** - * 导入排班 - */ - @PostMapping("/importScheduling") + @PostMapping("/schedulingNew") @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("请选择年月"); + @ApiOperation(value = "排班管理", notes = "") + public R schedulingNew(@Valid @RequestBody ImsSchedulingNewVo vo) { + if (null == vo.getDeptId()) { + return R.fail("请选择机构"); } - if(deptId == null){ - return R.fail("请选择部门"); + if (null == AuthUtil.getTenantId()) { + return R.fail("请登录"); } - return imsDutyMainService.importScheduling(file,yearMonth,deptId); + return imsDutyMainService.getSchedulingV3(vo); } -// /** -// * 排班管理 -// */ -// @PostMapping("/scheduling") -// @ApiOperationSupport(order = 8) -// @ApiOperation(value = "排班管理", notes = "") -// public R schedulingV2(@Valid @RequestBody ImsSchedulingVo imsSchedulingVo) { -// if (null == imsSchedulingVo.getCreateDept()) { -// imsSchedulingVo.setCreateDept(Long.valueOf(AuthUtil.getDeptId())); -// } -// return imsDutyMainService.getScheduling(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/service/IImsDutyMainService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java index 7dccf17..97e09e9 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 @@ -62,6 +62,8 @@ public interface IImsDutyMainService extends BaseService { R getSchedulingV2(ImsSchedulingVo imsSchedulingVo); + R getSchedulingV3(ImsSchedulingNewVo vo); + R importScheduling(MultipartFile file,String yearMonth,Long deptId); R getSchedulingList(int year, int month, Long deptId); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java index 0879de3..aac5356 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java @@ -45,6 +45,7 @@ import java.io.IOException; import java.io.InputStream; import java.sql.Time; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -303,438 +304,534 @@ public class ImsDutyMainServiceImpl 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()); + public R getSchedulingV3(ImsSchedulingNewVo vo) { + String startDate=vo.getStartDate(); + String endDate=vo.getEndDate(); + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); + try { + Date start=sdf.parse(startDate); + Date end=sdf.parse(endDate); + Date now=new Date(); + if(start.compareTo(now) <= 0){ + return R.fail("开始时间应从明天开始"); + } + if(end.compareTo(now) <= 0){ + return R.fail("结束时间应从明天开始"); + } + }catch (Exception e){ + return R.fail("开始时间格式不对"); + } + + //判断是否符合排班规则。 + String[] start = startDate.split("-"); + String[] end = endDate.split("-"); + Calendar cal = Calendar.getInstance(); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH) + 1;//获取月份 + int day = cal.get(Calendar.DAY_OF_MONTH); + String date1 = getDate(year, month, day); + String date2 = DateUtils.dayStringDate(date1, 1, true); + if (!vo.getStartDate().equals(date2)) { + String minusOnedDay = DateUtils.dayStringDate(vo.getStartDate(), 1, false); + log.info("--------------Auth:" + AuthUtil.getDeptId() + "--------createDept:" + vo.getDeptId()); + List imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, vo.getDeptId()); + if (CollectionUtil.isEmpty(imsDutyMainEntities)) { + return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); + } + } + List dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2])); + if (Integer.valueOf(start[0]) < year) { + return R.fail("年份必须大于或等于当前年份!"); + } + if (Integer.valueOf(start[0]) == year && Integer.valueOf(start[1]) < month) { + return R.fail("时间必须大于或等于当前时间"); + } + List imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + ge(ImsDutyMainEntity::getDutyDate, vo.getStartDate()); + le(ImsDutyMainEntity::getDutyDate, vo.getEndDate()); + eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); + }}); + List imsDutyMainPersonEntities = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ + ge(ImsDutyMainPersonEntity::getDutyDate, vo.getStartDate()); + le(ImsDutyMainPersonEntity::getDutyDate, vo.getEndDate()); + eq(ImsDutyMainPersonEntity::getCreateDept, vo.getDeptId()); + }}); + if (CollectionUtil.isNotEmpty(imsDutyMainPersonEntities) || CollectionUtil.isNotEmpty(imsDutyMainEntities2)) { + if (CollectionUtil.isNotEmpty(dates)) { + //重新修改已有的排版,先删除,在添加 + this.baseMapper.delete(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); + in(ImsDutyMainEntity::getDutyDate, dates); + }}); + imsDutyMainPersonMapper.delete(new LambdaQueryWrapper() {{ + in(ImsDutyMainPersonEntity::getDutyDate, dates); + eq(ImsDutyMainPersonEntity::getCreateDept, vo.getDeptId()); + }}); } } + String subDayDate = DateUtils.dayDate(DateUtil.parse(vo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE); + //获取最后一个排班的信息 + ImsDutyMainEntity preDutyMain = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getDutyDate, subDayDate); + eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); + ne(ImsDutyMainEntity::getStatus, "-1"); + orderByDesc(ImsDutyMainEntity::getId).last("LIMIT 1"); + }}); + String proDutyMainId=null; - 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()); + List imsDutyMainEntityList=getImsDutyMainEntityList(vo,dates); + if(imsDutyMainEntityList!=null && !imsDutyMainEntityList.isEmpty()){ + ImsDutyMainEntity entity=imsDutyMainEntityList.get(0); + if(preDutyMain!=null) { + Long dutyMainId = preDutyMain.getId(); + proDutyMainId =String.valueOf(dutyMainId); + entity.setPreDutyId(dutyMainId); } + dealCreator(entity,vo.getDeptId()); + }else{ + return R.fail("排班失败"); } - } - //判断用户是否在系统中存在 - 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 mainPersonEntityList=new ArrayList<>(); + for(ImsDutyMainEntity imsDutyMainEntity:imsDutyMainEntityList) { + String[] personIds=imsDutyMainEntity.getDutyPersonIds().split("\\^"); + List collect=Arrays.asList(personIds).stream().map(e->Long.valueOf(e)).collect(Collectors.toList()); + //每个人员对应一条排班-人员计划 + for (Long personId : collect) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = new ImsDutyMainPersonEntity(); + imsDutyMainPersonEntity.setClassId(imsDutyMainEntity.getClassId()); + imsDutyMainPersonEntity.setCreateDept(imsDutyMainEntity.getCreateDept()); + imsDutyMainPersonEntity.setDutyGroupName(imsDutyMainEntity.getDutyGroupName()); + imsDutyMainPersonEntity.setDutyGroupId(imsDutyMainEntity.getDutyGroupId()); + 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(personId); + long id1 = IdWorker.getId(imsDutyMainPersonEntity); + imsDutyMainPersonEntity.setId(id1); + imsDutyMainPersonEntity.setDutyChargePerson(imsDutyMainEntity.getManageId()); + mainPersonEntityList.add(imsDutyMainPersonEntity); + } } + + log.error("=排班====imsDutyMainEntityList{}====mainPersonEntityList:{}",imsDutyMainEntityList,mainPersonEntityList); + ThreadTask.dutyTask(imsDutyMainEntityList, mainPersonEntityList, vo.getEndDate(), proDutyMainId, vo.getDeptId(), vo.getDutyClassTypeId()); + + return R.success("排班成功"); } - //批量保存 - this.saveBatch(dutyMainList); - iImsDutyMainPersonService.saveBatch(dutyMainPList); + private void dealCreator(ImsDutyMainEntity entity,Long deptId){ + entity.setCreateDept(deptId); + entity.setCreateUser(AuthUtil.getUserId()); + entity.setCreateTime(new Date()); + entity.setTenantId(AuthUtil.getTenantId()); + entity.setIsDeleted(0); + entity.setStatus(0); + entity.setUpdateUser(AuthUtil.getUserId()); + entity.setUpdateTime(new Date()); + } - return R.success("导入成功"); - } + private List getImsDutyMainEntityList(ImsSchedulingNewVo vo,List dates){ + List list=new ArrayList<>(); - private ImsDutyGroupEntity getGroupByManageId(List groups,Long managerId){ - for(ImsDutyGroupEntity entity:groups){ - if(entity.getManagerId().equals(managerId)){ - return entity; + ////班次信息 + String[] classIdArr=vo.getClassIds().split("\\^"); + List classIds=Arrays.asList(classIdArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList()); + String[] classNameArr=vo.getClassNames().split("\\^"); + Map classMap=new HashMap<>(); + for(int i=0;i groupIds=Arrays.asList(groupIdsArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList()); + LambdaQueryWrapper groupWrapper=new LambdaQueryWrapper<>(); + groupWrapper.in(ImsDutyGroupEntity::getId,groupIds); + List groupEntities=dutyGroupMapper.selectList(groupWrapper); + Map groupMap=groupEntities.stream().collect(Collectors.toMap(ImsDutyGroupEntity::getId,Function.identity())); + + List groupPEntities = imsDutyGroupPService.selectByGroupIds(groupIds); + Map> personMap=groupPEntities.stream().collect(Collectors.groupingBy(ImsDutyGroupPEntity::getGroupId)); + + //班组信息 + List> groups=new ArrayList<>(); + for(Long groupId :groupIds){ + Map map=new HashMap<>(); + map.put("groupId",String.valueOf(groupId)); + ImsDutyGroupEntity groupEntity=groupMap.get(groupId); + map.put("groupName",groupEntity.getGroupName()); + map.put("managerId",String.valueOf(groupEntity.getManagerId())); + List groupPList=personMap.get(groupId); + List personIds=groupPList.stream().map(e->String.valueOf(e.getPersonId())).collect(Collectors.toList()); + String personStrIds=personIds.stream().collect(Collectors.joining("^")); + map.put("personIds",personStrIds);//包含了值长id + groups.add(map); + } + dealImsDutyMainEntityList(list,dates,classIds,groups,classMap); + }else if(vo.getPersonType().intValue() == 2){//人员 + List> persons=vo.getPersonIds(); + for(Map person:persons){ + String personIds=person.get("personIds"); + person.put("personIds",person.get("managerId")+"^"+personIds); + } + dealImsDutyMainEntityList(list,dates,classIds,persons,classMap); } - } - 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; - } + return list; + } - private String beforeDutyDate(String date){ - LocalDate today = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + private void dealImsDutyMainEntityList(List list,List dates, + List classIds, + List> persons,Map classMap){ + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); + int dateCount=dates.size(); + int classCount=classIds.size(); + int count=dateCount * classCount;//总工共排多少个 - LocalDate yesterday = today.minusDays(1); // 获取前一天的日期 + List> allPerson=new ArrayList<>();//总数队列 - // 如果需要格式化日期,可以使用DateTimeFormatter - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - return yesterday.format(formatter); - } + while (allPerson.size() < count){ + for(Map person:persons){ + allPerson.add(person); + } + } - private Long getByName(List users,String name){ - for(User user:users){ - if(user.getName().equals(name)){ - return user.getId(); + try { + for (int i = 0; i < dateCount; i++) { + String ts = dates.get(i); + for (int j = 0; j < classCount; j++) { + int personIndex = (i * classCount) + j; + Map person = allPerson.get(personIndex); + Long classId = classIds.get(j); + ImsDutyMainEntity res = new ImsDutyMainEntity(); + res.setId(IdWorker.getId()); + if (person.get("groupId") != null) { + res.setDutyGroupId(Long.valueOf(person.get("groupId").toString())); + } + if (person.get("groupName") != null) { + res.setDutyGroupName(person.get("groupName").toString()); + } + res.setDutyPersonIds(person.get("personIds")); + res.setDutyDate(sdf.parse(ts)); + res.setClassId(classId); + res.setClassName(classMap.get(classId)); + res.setManageId(Long.valueOf(person.get("managerId"))); + list.add(res); + } + } + }catch (ParseException e){ + log.error("日期格式不对"); } } - return null; - } - /** - * 轮询排班 - * - * @param imsSchedulingVo - * @param dates - * @param imsDutyMainEntity1 - * @return - */ - private R pollSchedulingV2(ImsSchedulingVo imsSchedulingVo, List dates, ImsDutyMainEntity imsDutyMainEntity1) { - String[] groupIdsSplit; - int dutyNum; - //轮询排班分为:班组还是灵活;如果是2.灵活人员排班,则不需要查数据库,直接存对应信息 - if (2 == imsSchedulingVo.getPersonType()) { - Map> rosters = imsSchedulingVo.getRosters(); - groupIdsSplit = rosters.keySet().toArray(new String[0]); - dutyNum = groupIdsSplit.length; - } else { - groupIdsSplit = imsSchedulingVo.getGroupIds().split("\\^"); - String[] groupNamesSplit = imsSchedulingVo.getGroupNames().split("\\^"); - dutyNum = groupNamesSplit.length; - } - String[] classIdsSplit = imsSchedulingVo.getClassIds().split("\\^"); - String[] classNamesSplit = imsSchedulingVo.getClassNames().split("\\^"); - int classNum = classNamesSplit.length; - int allClass = 0; - List imsDutyMainEntityList = new ArrayList<>(); - List imsDutyMainPersonEntityList = new ArrayList<>(); - String proDutyMainId = null; - for (int i = 1; i <= dates.size(); i++) { - String date = dates.get(i - 1); - for (int j = 1; j <= classNum; j++) { - //总排班数加1 - allClass++; - int temp, tempSub = 0; - temp = allClass % dutyNum; - //班组下标,确定取哪个班组 - tempSub = temp - 1; - //如果整除,取最后一个班组 - if (temp == 0) { - tempSub = dutyNum - 1; + @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(); } - ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - imsDutyMainEntity.setClassId(Long.valueOf(classIdsSplit[j - 1])); - imsDutyMainEntity.setClassName(classNamesSplit[j - 1]); - imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); - imsDutyMainEntity.setStatus(0); - imsDutyMainEntity.setCreateTime(new Date()); - if (Func.isBlank(proDutyMainId)) { - if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { - proDutyMainId = imsDutyMainEntity1.getId().toString(); + } + List entityList = excelToolListener.getDataList(); + if(entityList==null || entityList.isEmpty()){ + return R.fail("请在表格中填写数据"); + } + List 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()); } } - if (StringUtil.isNotBlank(proDutyMainId)) { - imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); - } - imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); - List collect; - Long managerId; - String groupName =""; - if (2 == imsSchedulingVo.getPersonType()) { - List idList = imsSchedulingVo.getRosters().get(groupIdsSplit[tempSub]); - collect = idList.stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); - managerId = Long.valueOf(groupIdsSplit[tempSub]); - } else { - String groupId = groupIdsSplit[tempSub]; - imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupIdsSplit[tempSub])); - //查询预备排班的班组人员,为空,则失败 - List longList = Arrays.asList(imsSchedulingVo.getGroupIds().split("\\^")) - .parallelStream() - .map(a -> Long.parseLong(a.trim())) - .collect(Collectors.toList()); - List list = imsDutyGroupPService.selectByGroupIds(longList); - collect = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> - iter.getPersonId()).collect(Collectors.toList()); - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(groupId); - groupName = imsDutyGroupEntity.getGroupName(); - if (ObjectUtil.isNotEmpty(imsDutyGroupEntity) && ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())) { - managerId = imsDutyGroupEntity.getManagerId(); - } else { - return R.fail("该班组没有值班组组长"); + + + 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()); } } - String ids = StringUtils.join(collect, "^"); - imsDutyMainEntity.setDutyPersonIds(ids); + } + //判断用户是否在系统中存在 + 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; } - imsDutyMainEntityList.add(imsDutyMainEntity); - proDutyMainId = id == null ? "" : imsDutyMainEntity.getId() + ""; - //值班人员表同步保存一份 - copyPersonByDutyMain(imsSchedulingVo, managerId, groupName, imsDutyMainPersonEntityList, imsDutyMainEntity, collect); } + return null; } - ThreadTask.dutyTask(imsDutyMainEntityList, imsDutyMainPersonEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); - return R.success("操作成功,系统正在排班中,请稍后查看"); - } - private static void copyPersonByDutyMain(ImsSchedulingVo imsSchedulingVo, Long managerId, String groupName, List imsDutyMainPersonEntityList, ImsDutyMainEntity imsDutyMainEntity, List collect) { - //每个人员对应一条排班-人员计划 - for (Long personId : collect) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = new ImsDutyMainPersonEntity(); - imsDutyMainPersonEntity.setClassId(imsDutyMainEntity.getClassId()); - imsDutyMainPersonEntity.setCreateDept(imsDutyMainEntity.getCreateDept()); - imsDutyMainPersonEntity.setDutyGroupName(groupName); - imsDutyMainPersonEntity.setDutyGroupId(imsSchedulingVo.getGroupId()); - 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(personId); - long id1 = IdWorker.getId(imsDutyMainPersonEntity); - imsDutyMainPersonEntity.setId(id1); - imsDutyMainPersonEntity.setDutyChargePerson(managerId); - imsDutyMainPersonEntityList.add(imsDutyMainPersonEntity); + 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; } - } - /** - * 周期排班 - * - * @param imsSchedulingVo - * @param dates - * @param imsDutyMainEntity1 - * @return - */ - private R cycleSchedulingTowV2(ImsSchedulingVo imsSchedulingVo, List dates, ImsDutyMainEntity imsDutyMainEntity1) { - if (imsSchedulingVo.getTemplate()) { - if (!doSaveTemplate(imsSchedulingVo)) { - return R.fail("模版名称已存在"); - } - } - List imsDutyMainEntityList = new ArrayList<>(); - List personEntityList = new ArrayList<>(); - String proDutyMainId = ""; - String[] dutyArrIds = imsSchedulingVo.getDutyArrIds(); - for (int i = 1; i <= dates.size(); i++) { - String date = dates.get(i - 1); - for (int j = 1; j <= dutyArrIds.length; j++) { - String classId = dutyArrIds[j - 1]; - //按值班周期的天数取模 - int temp = i % imsSchedulingVo.getDutyNum(); - //值班下标 - int tempSub = temp - 1; - //如果整除,取最后一个值班 - if (temp == 0) { - tempSub = imsSchedulingVo.getDutyNum() - 1; - } - String groupId; - String[] split; - if (imsSchedulingVo.getPersonType() == 1) { - //获取对应班组的值班班次 - groupId = imsSchedulingVo.getDutyOrderIds().get(classId)[tempSub]; - } else { - //灵活排班,无实际作用,只是为了groupId能够初始化 - groupId = ""; + 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(); } - //人员IDS - String personIds = ""; - if ("0".equals(classId)) { - //班组排班比灵活排班,多保存一部分没有排到班的信息 - if (imsSchedulingVo.getPersonType() == 1) { - split = groupId.split(","); - if (ObjectUtil.isNotEmpty(split)) { - for (String dutyGroupId : split) { - //查询班组信息 - Long num = Long.valueOf(StringUtils.isNotEmpty(dutyGroupId) ? dutyGroupId : "0"); - List list = imsDutyGroupPService.selectByGroupIds(Arrays.asList(num)); - List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(dutyGroupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(collectPerson)) { - personIds = StringUtils.join(collectPerson, "^"); - } - if (StringUtil.isNotBlank(dutyGroupId)) { - ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date); - imsDutyMainEntity.setStatus(-1); - imsDutyMainEntity.setDutyPersonIds(personIds); - imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); - Long id = IdWorker.getId(); - imsDutyMainEntity.setId(id); - imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); - imsDutyMainEntityList.add(imsDutyMainEntity); - } - } - } + } + return null; + } + + /** + * 轮询排班 + * + * @param imsSchedulingVo + * @param dates + * @param imsDutyMainEntity1 + * @return + */ + private R pollSchedulingV2(ImsSchedulingVo imsSchedulingVo, List dates, ImsDutyMainEntity imsDutyMainEntity1) { + String[] groupIdsSplit; + int dutyNum; + //轮询排班分为:班组还是灵活;如果是2.灵活人员排班,则不需要查数据库,直接存对应信息 + if (2 == imsSchedulingVo.getPersonType()) { + Map> rosters = imsSchedulingVo.getRosters(); + groupIdsSplit = rosters.keySet().toArray(new String[0]); + dutyNum = groupIdsSplit.length; + } else { + groupIdsSplit = imsSchedulingVo.getGroupIds().split("\\^"); + String[] groupNamesSplit = imsSchedulingVo.getGroupNames().split("\\^"); + dutyNum = groupNamesSplit.length; + } + String[] classIdsSplit = imsSchedulingVo.getClassIds().split("\\^"); + String[] classNamesSplit = imsSchedulingVo.getClassNames().split("\\^"); + int classNum = classNamesSplit.length; + int allClass = 0; + List imsDutyMainEntityList = new ArrayList<>(); + List imsDutyMainPersonEntityList = new ArrayList<>(); + String proDutyMainId = null; + for (int i = 1; i <= dates.size(); i++) { + String date = dates.get(i - 1); + for (int j = 1; j <= classNum; j++) { + //总排班数加1 + allClass++; + int temp, tempSub = 0; + temp = allClass % dutyNum; + //班组下标,确定取哪个班组 + tempSub = temp - 1; + //如果整除,取最后一个班组 + if (temp == 0) { + tempSub = dutyNum - 1; } - } else { ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - //人员ID - List collectPerson; - //负责人ID - Long managerId = 0L; - String groupName = null; - if (imsSchedulingVo.getPersonType() == 1) { - //查询班组信息 - Long num = Long.valueOf(StringUtils.isNotEmpty(groupId) ? groupId : "0"); - List list = imsDutyGroupPService.selectByGroupIds(Arrays.asList(num)); - collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(collectPerson)) { - personIds = StringUtils.join(collectPerson, "^"); + imsDutyMainEntity.setClassId(Long.valueOf(classIdsSplit[j - 1])); + imsDutyMainEntity.setClassName(classNamesSplit[j - 1]); + imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); + imsDutyMainEntity.setStatus(0); + imsDutyMainEntity.setCreateTime(new Date()); + if (Func.isBlank(proDutyMainId)) { + if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { + proDutyMainId = imsDutyMainEntity1.getId().toString(); } - imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupId)); + } + if (StringUtil.isNotBlank(proDutyMainId)) { + imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); + } + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + List collect; + Long managerId; + String groupName =""; + if (2 == imsSchedulingVo.getPersonType()) { + List idList = imsSchedulingVo.getRosters().get(groupIdsSplit[tempSub]); + collect = idList.stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); + managerId = Long.valueOf(groupIdsSplit[tempSub]); + } else { + String groupId = groupIdsSplit[tempSub]; + imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupIdsSplit[tempSub])); + //查询预备排班的班组人员,为空,则失败 + List longList = Arrays.asList(imsSchedulingVo.getGroupIds().split("\\^")) + .parallelStream() + .map(a -> Long.parseLong(a.trim())) + .collect(Collectors.toList()); + List list = imsDutyGroupPService.selectByGroupIds(longList); + collect = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> + iter.getPersonId()).collect(Collectors.toList()); ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(groupId); groupName = imsDutyGroupEntity.getGroupName(); if (ObjectUtil.isNotEmpty(imsDutyGroupEntity) && ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())) { managerId = imsDutyGroupEntity.getManagerId(); + } else { + return R.fail("该班组没有值班组组长"); } - } else { - //灵活排版没有班组信息 - FlexibleSchedulingVo flexibleSchedulingVo = imsSchedulingVo.getFlexible().get(classId).get(tempSub); - collectPerson = flexibleSchedulingVo.getPersonIds().stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); - personIds = StringUtils.join(collectPerson, "^"); - managerId = Long.valueOf(flexibleSchedulingVo.getChargeId()); } - setMainEntity(imsDutyMainEntity, classId, date); + String ids = StringUtils.join(collect, "^"); + imsDutyMainEntity.setDutyPersonIds(ids); + Long id = IdWorker.getId(); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); if (Func.isBlank(proDutyMainId)) { if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { proDutyMainId = imsDutyMainEntity1.getId().toString(); @@ -743,282 +840,422 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, imsSchedulingVo.getCreateDept()); - if (CollectionUtil.isEmpty(imsDutyMainEntities)) { - return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); + private static void copyPersonByDutyMain(ImsSchedulingVo imsSchedulingVo, Long managerId, String groupName, List imsDutyMainPersonEntityList, ImsDutyMainEntity imsDutyMainEntity, List collect) { + //每个人员对应一条排班-人员计划 + for (Long personId : collect) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = new ImsDutyMainPersonEntity(); + imsDutyMainPersonEntity.setClassId(imsDutyMainEntity.getClassId()); + imsDutyMainPersonEntity.setCreateDept(imsDutyMainEntity.getCreateDept()); + imsDutyMainPersonEntity.setDutyGroupName(groupName); + imsDutyMainPersonEntity.setDutyGroupId(imsSchedulingVo.getGroupId()); + 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(personId); + long id1 = IdWorker.getId(imsDutyMainPersonEntity); + imsDutyMainPersonEntity.setId(id1); + imsDutyMainPersonEntity.setDutyChargePerson(managerId); + imsDutyMainPersonEntityList.add(imsDutyMainPersonEntity); } } - List dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2])); + /** + * 周期排班 + * + * @param imsSchedulingVo + * @param dates + * @param imsDutyMainEntity1 + * @return + */ + private R cycleSchedulingTowV2(ImsSchedulingVo imsSchedulingVo, List dates, ImsDutyMainEntity imsDutyMainEntity1) { + if (imsSchedulingVo.getTemplate()) { + if (!doSaveTemplate(imsSchedulingVo)) { + return R.fail("模版名称已存在"); + } + } + List imsDutyMainEntityList = new ArrayList<>(); + List personEntityList = new ArrayList<>(); + String proDutyMainId = ""; + String[] dutyArrIds = imsSchedulingVo.getDutyArrIds(); + for (int i = 1; i <= dates.size(); i++) { + String date = dates.get(i - 1); + for (int j = 1; j <= dutyArrIds.length; j++) { + String classId = dutyArrIds[j - 1]; + //按值班周期的天数取模 + int temp = i % imsSchedulingVo.getDutyNum(); + //值班下标 + int tempSub = temp - 1; + //如果整除,取最后一个值班 + if (temp == 0) { + tempSub = imsSchedulingVo.getDutyNum() - 1; + } + String groupId; + String[] split; + if (imsSchedulingVo.getPersonType() == 1) { + //获取对应班组的值班班次 + groupId = imsSchedulingVo.getDutyOrderIds().get(classId)[tempSub]; + } else { + //灵活排班,无实际作用,只是为了groupId能够初始化 + groupId = ""; + } + //人员IDS + String personIds = ""; + if ("0".equals(classId)) { + //班组排班比灵活排班,多保存一部分没有排到班的信息 + if (imsSchedulingVo.getPersonType() == 1) { + split = groupId.split(","); + if (ObjectUtil.isNotEmpty(split)) { + for (String dutyGroupId : split) { + //查询班组信息 + Long num = Long.valueOf(StringUtils.isNotEmpty(dutyGroupId) ? dutyGroupId : "0"); + List list = imsDutyGroupPService.selectByGroupIds(Arrays.asList(num)); + List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(dutyGroupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collectPerson)) { + personIds = StringUtils.join(collectPerson, "^"); + } + if (StringUtil.isNotBlank(dutyGroupId)) { + ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); + setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date); + imsDutyMainEntity.setStatus(-1); + imsDutyMainEntity.setDutyPersonIds(personIds); + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + Long id = IdWorker.getId(); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); + imsDutyMainEntityList.add(imsDutyMainEntity); + } + } + } + } + } else { + ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); + //人员ID + List collectPerson; + //负责人ID + Long managerId = 0L; + String groupName = null; + if (imsSchedulingVo.getPersonType() == 1) { + //查询班组信息 + Long num = Long.valueOf(StringUtils.isNotEmpty(groupId) ? groupId : "0"); + List list = imsDutyGroupPService.selectByGroupIds(Arrays.asList(num)); + collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collectPerson)) { + personIds = StringUtils.join(collectPerson, "^"); + } + imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupId)); + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(groupId); + groupName = imsDutyGroupEntity.getGroupName(); + if (ObjectUtil.isNotEmpty(imsDutyGroupEntity) && ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())) { + managerId = imsDutyGroupEntity.getManagerId(); + } + } else { + //灵活排版没有班组信息 + FlexibleSchedulingVo flexibleSchedulingVo = imsSchedulingVo.getFlexible().get(classId).get(tempSub); + collectPerson = flexibleSchedulingVo.getPersonIds().stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); + personIds = StringUtils.join(collectPerson, "^"); + managerId = Long.valueOf(flexibleSchedulingVo.getChargeId()); + } + setMainEntity(imsDutyMainEntity, classId, date); + if (Func.isBlank(proDutyMainId)) { + if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { + proDutyMainId = imsDutyMainEntity1.getId().toString(); + } + } + if (StringUtil.isNotBlank(proDutyMainId)) { + imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); + } + if (StringUtil.isNotBlank(personIds)) { + imsDutyMainEntity.setDutyPersonIds(personIds); + } + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + Long id = IdWorker.getId(imsDutyMainEntity); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); + imsDutyMainEntityList.add(imsDutyMainEntity); + proDutyMainId = id == null ? "" : imsDutyMainEntity.getId().toString(); + imsDutyMainEntity1=imsDutyMainEntity; + //同步保存到排班计划-人员表 + copyPersonByDutyMain(imsSchedulingVo, managerId, groupName, personEntityList, imsDutyMainEntity, collectPerson); + } + } + } + ThreadTask.dutyTask(imsDutyMainEntityList, personEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); + return R.success("操作成功,系统正在排班中,请稍后查看"); + } + + + private R pollScheduling(ImsSchedulingVo imsSchedulingVo) { + String[] start = imsSchedulingVo.getStartDate().split("-"); + String[] end = imsSchedulingVo.getEndDate().split("-"); + Calendar cal = Calendar.getInstance(); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH) + 1;//获取月份 + int day = cal.get(Calendar.DAY_OF_MONTH); + String date1 = getDate(year, month, day); + String date2 = DateUtils.dayStringDate(date1, 1, true); + if (!imsSchedulingVo.getStartDate().equals(date2)) { + String minusOnedDay = DateUtils.dayStringDate(imsSchedulingVo.getStartDate(), 1, false); + log.info("--------------Auth:" + AuthUtil.getDeptId() + "--------createDept:" + imsSchedulingVo.getCreateDept()); + List imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, imsSchedulingVo.getCreateDept()); + if (CollectionUtil.isEmpty(imsDutyMainEntities)) { + return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); + } + } - if (imsSchedulingVo.isCompose() == false) { - List imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - ge(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getStartDate()); - le(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getEndDate()); - eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - }}); - if (CollectionUtil.isNotEmpty(imsDutyMainEntities2)) { - return R.data(1); + List dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2])); + + if (imsSchedulingVo.isCompose() == false) { + List imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + ge(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getStartDate()); + le(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getEndDate()); + eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); + }}); + if (CollectionUtil.isNotEmpty(imsDutyMainEntities2)) { + return R.data(1); + } } - } - String[] groupIdsSplit = imsSchedulingVo.getGroupIds().split("\\^"); - String[] groupNamesSplit = imsSchedulingVo.getGroupNames().split("\\^"); - int dutyNum = groupNamesSplit.length; - String[] classIdsSplit = imsSchedulingVo.getClassIds().split("\\^"); - String[] classNamesSplit = imsSchedulingVo.getClassNames().split("\\^"); - int classNum = classNamesSplit.length; - int allClass = 0; + String[] groupIdsSplit = imsSchedulingVo.getGroupIds().split("\\^"); + String[] groupNamesSplit = imsSchedulingVo.getGroupNames().split("\\^"); + int dutyNum = groupNamesSplit.length; + String[] classIdsSplit = imsSchedulingVo.getClassIds().split("\\^"); + String[] classNamesSplit = imsSchedulingVo.getClassNames().split("\\^"); + int classNum = classNamesSplit.length; + int allClass = 0; + + if (Integer.valueOf(start[0]) < year) { + return R.fail("年份必须大于或等于当前年份!"); + } + if (Integer.valueOf(start[0]) == year && Integer.valueOf(start[0]) < month) { + return R.fail("月份必须大于或等于当前年份!"); + } + if (CollectionUtil.isNotEmpty(dates)) { + this.baseMapper.delete(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); + in(ImsDutyMainEntity::getDutyDate, dates); + }}); + } + //查询所有班组人员 + List list = imsDutyGroupPService.list(); - if (Integer.valueOf(start[0]) < year) { - return R.fail("年份必须大于或等于当前年份!"); - } - if (Integer.valueOf(start[0]) == year && Integer.valueOf(start[0]) < month) { - return R.fail("月份必须大于或等于当前年份!"); - } - if (CollectionUtil.isNotEmpty(dates)) { - this.baseMapper.delete(new LambdaQueryWrapper() {{ + String subDayDate = DateUtils.dayDate(DateUtil.parse(imsSchedulingVo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE); + + ImsDutyMainEntity imsDutyMainEntity1 = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getDutyDate, subDayDate); eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - in(ImsDutyMainEntity::getDutyDate, dates); + ne(ImsDutyMainEntity::getStatus, "-1"); + orderByDesc(ImsDutyMainEntity::getId).last("LIMIT 1"); }}); - } - //查询所有班组人员 - List list = imsDutyGroupPService.list(); - String subDayDate = DateUtils.dayDate(DateUtil.parse(imsSchedulingVo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE); + List imsDutyMainEntityList = new ArrayList<>(); + + String proDutyMainId = ""; + for (int i = 1; i <= dates.size(); i++) { + String date = dates.get(i - 1); + for (int j = 1; j <= classNum; j++) { + + //总排班数加1 + //allClass++; + int temp, tempSub = 0; + allClass++; + temp = allClass % dutyNum; + //班组下标,确定取哪个班组 + tempSub = temp - 1; + //如果整除,取最后一个班组 + if (temp == 0) { + tempSub = dutyNum - 1; + } - ImsDutyMainEntity imsDutyMainEntity1 = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getDutyDate, subDayDate); - eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - ne(ImsDutyMainEntity::getStatus, "-1"); - orderByDesc(ImsDutyMainEntity::getId).last("LIMIT 1"); - }}); + ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); + imsDutyMainEntity.setClassId(Long.valueOf(classIdsSplit[j - 1])); + imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupIdsSplit[tempSub])); + imsDutyMainEntity.setClassName(classNamesSplit[j - 1]); + imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); + imsDutyMainEntity.setStatus(0); + imsDutyMainEntity.setCreateTime(new Date()); + if (Func.isBlank(proDutyMainId)) { + if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { + proDutyMainId = imsDutyMainEntity1.getId().toString(); + } + } + if (StringUtil.isNotBlank(proDutyMainId)) { + imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); + } + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + String groupId = groupIdsSplit[tempSub]; + List collect = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> + iter.getPersonId()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collect)) { + String ids = StringUtils.join(collect, "^"); + imsDutyMainEntity.setDutyPersonIds(ids); + } else { + return R.fail("班组存在人员为空,禁止排班!"); + } + Long id = IdWorker.getId(); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); + imsDutyMainEntityList.add(imsDutyMainEntity); + proDutyMainId = id == null ? "" : imsDutyMainEntity.getId() + ""; + } + + } + ThreadTask.dutyTask(imsDutyMainEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); + return R.success("操作成功,系统正在排班中,请稍后查看"); + } + + /** + * 获取两个日期之间的所有日期 + * + * @param startYear + * @param startMonth + * @param startDay + * @param endYear + * @param endMonth + * @param endDay + * @return + */ + public static List getTwoPeriodsAll(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) { + List list = new ArrayList<>(); + Calendar start = Calendar.getInstance(); + start.set(startYear, startMonth - 1, startDay); + Long startTIme = start.getTimeInMillis(); + Calendar end = Calendar.getInstance(); + end.set(endYear, endMonth - 1, endDay); + Long endTime = end.getTimeInMillis(); + + Long oneDay = 1000 * 60 * 60 * 24L; + + Long time = startTIme; + while (time <= endTime) { + Date d = new Date(time); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + list.add(df.format(d)); + time += oneDay; + } + return list; - List imsDutyMainEntityList = new ArrayList<>(); - - String proDutyMainId = ""; - for (int i = 1; i <= dates.size(); i++) { - String date = dates.get(i - 1); - for (int j = 1; j <= classNum; j++) { - - //总排班数加1 - //allClass++; - int temp, tempSub = 0; - allClass++; - temp = allClass % dutyNum; - //班组下标,确定取哪个班组 - tempSub = temp - 1; - //如果整除,取最后一个班组 - if (temp == 0) { - tempSub = dutyNum - 1; - } + } - ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - imsDutyMainEntity.setClassId(Long.valueOf(classIdsSplit[j - 1])); - imsDutyMainEntity.setDutyGroupId(Long.valueOf(groupIdsSplit[tempSub])); - imsDutyMainEntity.setClassName(classNamesSplit[j - 1]); - imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); - imsDutyMainEntity.setStatus(0); - imsDutyMainEntity.setCreateTime(new Date()); - if (Func.isBlank(proDutyMainId)) { - if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { - proDutyMainId = imsDutyMainEntity1.getId().toString(); - } - } - if (StringUtil.isNotBlank(proDutyMainId)) { - imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); + + public String getDate(int year, int month, int day) { + String date = ""; + if (month < 10) { + if (day < 10) { + date = year + "-" + 0 + month + "-" + 0 + day; + } else { + date = year + "-" + 0 + month + "-" + day; } - imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); - String groupId = groupIdsSplit[tempSub]; - List collect = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> - iter.getPersonId()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(collect)) { - String ids = StringUtils.join(collect, "^"); - imsDutyMainEntity.setDutyPersonIds(ids); + } else { + if (day < 10) { + date = year + "-" + month + "-" + 0 + day; } else { - return R.fail("班组存在人员为空,禁止排班!"); + date = year + "-" + month + "-" + day; } - Long id = IdWorker.getId(); - imsDutyMainEntity.setId(id); - imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); - imsDutyMainEntityList.add(imsDutyMainEntity); - proDutyMainId = id == null ? "" : imsDutyMainEntity.getId() + ""; } - + return date; } - ThreadTask.dutyTask(imsDutyMainEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); - return R.success("操作成功,系统正在排班中,请稍后查看"); - } - - /** - * 获取两个日期之间的所有日期 - * - * @param startYear - * @param startMonth - * @param startDay - * @param endYear - * @param endMonth - * @param endDay - * @return - */ - public static List getTwoPeriodsAll(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) { - List list = new ArrayList<>(); - Calendar start = Calendar.getInstance(); - start.set(startYear, startMonth - 1, startDay); - Long startTIme = start.getTimeInMillis(); - Calendar end = Calendar.getInstance(); - end.set(endYear, endMonth - 1, endDay); - Long endTime = end.getTimeInMillis(); - - Long oneDay = 1000 * 60 * 60 * 24L; - - Long time = startTIme; - while (time <= endTime) { - Date d = new Date(time); - DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - list.add(df.format(d)); - time += oneDay; - } - return list; - } + /** + * 查询已排班记录 + * + * @param month + * @return + */ + @Override + public R getSchedulingList(int year, int month, Long deptId) { + String yearAndMonth = ""; - public String getDate(int year, int month, int day) { - String date = ""; - if (month < 10) { - if (day < 10) { - date = year + "-" + 0 + month + "-" + 0 + day; + if (month < 10) { + yearAndMonth = year + "-0" + month; } else { - date = year + "-" + 0 + month + "-" + day; + yearAndMonth = year + "-" + month; } - } else { - if (day < 10) { - date = year + "-" + month + "-" + 0 + day; + List imsSchedulingVos = this.baseMapper.selectByDateList(yearAndMonth, deptId); + if (CollectionUtil.isEmpty(imsSchedulingVos)) { + return R.success("该月未排班"); + } + int days = getDaysByYearMonth(year, month); + Map> map = new HashMap(); + for (int i = 1; i <= days; i++) { + String date = getDate(year, month, i); + List collect = imsSchedulingVos.stream().filter(o -> DateUtil.format(o.getDutyDate(), DateUtil.PATTERN_DATE).equals(date)).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); + map.put(date, collect); + } + return R.data(new TreeMap<>(map)); + } + + /** + * 查询已排班记录 + * + * @param year + * @param month + * @param deptId + * @return + */ + @Override + public R getSchedulingListV2(int year, int month, Long deptId) { + String yearAndMonth = ""; + + if (month < 10) { + yearAndMonth = year + "-0" + month; } else { - date = year + "-" + month + "-" + day; + yearAndMonth = year + "-" + month; } - } - return date; - } - - - /** - * 查询已排班记录 - * - * @param month - * @return - */ - @Override - public R getSchedulingList(int year, int month, Long deptId) { - String yearAndMonth = ""; - - if (month < 10) { - yearAndMonth = year + "-0" + month; - } else { - yearAndMonth = year + "-" + month; - } - List imsSchedulingVos = this.baseMapper.selectByDateList(yearAndMonth, deptId); - if (CollectionUtil.isEmpty(imsSchedulingVos)) { - return R.success("该月未排班"); - } - int days = getDaysByYearMonth(year, month); - Map> map = new HashMap(); - for (int i = 1; i <= days; i++) { - String date = getDate(year, month, i); - List collect = imsSchedulingVos.stream().filter(o -> DateUtil.format(o.getDutyDate(), DateUtil.PATTERN_DATE).equals(date)).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); - map.put(date, collect); - } - return R.data(new TreeMap<>(map)); - } - - /** - * 查询已排班记录 - * - * @param year - * @param month - * @param deptId - * @return - */ - @Override - public R getSchedulingListV2(int year, int month, Long deptId) { - String yearAndMonth = ""; - - if (month < 10) { - yearAndMonth = year + "-0" + month; - } else { - yearAndMonth = year + "-" + month; - } - List imsSchedulingVos = this.baseMapper.selectByDateListV2(yearAndMonth, deptId); - if (CollectionUtil.isEmpty(imsSchedulingVos)) { - return R.success("该月未排班"); - } - int days = getDaysByYearMonth(year, month); - Map> map = new HashMap(); - for (int i = 1; i <= days; i++) { - String date = getDate(year, month, i); - List collect = imsSchedulingVos.stream().filter(o -> DateUtil.format(o.getDutyDate(), DateUtil.PATTERN_DATE).equals(date)).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); - collect = collect.stream().map(s -> { - //灵活排班把班组名称拼接成人员名称 - if (s.getGroupId() == null) { - String[] split = s.getDutyPersonIds().split("\\^"); - if (null != split && split.length > 0) { - for (int j = 0; j < split.length; j++) { - User user = UserCache.getUser(Long.valueOf(split[j])); - if (ObjectUtil.isNotEmpty(user)) { - if (j == split.length - 1) { - s.setName(s.getName() + user.getName()); - } else { - s.setName(s.getName() + user.getName() + "、"); + List imsSchedulingVos = this.baseMapper.selectByDateListV2(yearAndMonth, deptId); + if (CollectionUtil.isEmpty(imsSchedulingVos)) { + return R.success("该月未排班"); + } + int days = getDaysByYearMonth(year, month); + Map> map = new HashMap(); + for (int i = 1; i <= days; i++) { + String date = getDate(year, month, i); + List collect = imsSchedulingVos.stream().filter(o -> DateUtil.format(o.getDutyDate(), DateUtil.PATTERN_DATE).equals(date)).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); + collect = collect.stream().map(s -> { + //灵活排班把班组名称拼接成人员名称 + if (s.getGroupId() == null) { + String[] split = s.getDutyPersonIds().split("\\^"); + if (null != split && split.length > 0) { + for (int j = 0; j < split.length; j++) { + User user = UserCache.getUser(Long.valueOf(split[j])); + if (ObjectUtil.isNotEmpty(user)) { + if (j == split.length - 1) { + s.setName(s.getName() + user.getName()); + } else { + s.setName(s.getName() + user.getName() + "、"); + } } } } + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); + s.setName(s.getName() + imsDutyGroupEntity.getGroupName()); } - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); - s.setName(s.getName() + imsDutyGroupEntity.getGroupName()); - } - return s; - }).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); - map.put(date, collect); + return s; + }).sorted(Comparator.comparing(ImsSchedulingVo::getId)).collect(Collectors.toList()); + map.put(date, collect); + } + return R.data(new TreeMap<>(map)); } - return R.data(new TreeMap<>(map)); - } /* @Override @@ -1044,489 +1281,489 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl(map)); }*/ - @Override - public R getMainIdByPerson(Long id) { - List list = new ArrayList<>(); - ImsDutyMainEntity imsDutyMainEntity = this.baseMapper.selectById(id); - String ids = imsDutyMainEntity.getDutyPersonIds(); - if (StringUtil.isBlank(ids)) { - return R.data(""); - } - String[] split = ids.split("\\^"); - if (null != split && split.length > 0) { - for (String s : split) { - ImsDutyMainVO vo = new ImsDutyMainVO(); - User user = UserCache.getUser(Long.valueOf(s)); - if (ObjectUtil.isNotEmpty(user)) { - vo.setUserId(s); + @Override + public R getMainIdByPerson(Long id) { + List list = new ArrayList<>(); + ImsDutyMainEntity imsDutyMainEntity = this.baseMapper.selectById(id); + String ids = imsDutyMainEntity.getDutyPersonIds(); + if (StringUtil.isBlank(ids)) { + return R.data(""); + } + String[] split = ids.split("\\^"); + if (null != split && split.length > 0) { + for (String s : split) { + ImsDutyMainVO vo = new ImsDutyMainVO(); + User user = UserCache.getUser(Long.valueOf(s)); if (ObjectUtil.isNotEmpty(user)) { - vo.setUserName(user.getName()); + vo.setUserId(s); + if (ObjectUtil.isNotEmpty(user)) { + vo.setUserName(user.getName()); + } + vo.setId(id); + list.add(vo); } - vo.setId(id); - list.add(vo); } } - } - return R.data(list); - } + return R.data(list); + } - @Override - public R getMainIdByPersonV2(Long id) { - List list = new ArrayList<>(); - ImsDutyMainEntity imsDutyMainEntity = this.baseMapper.selectById(id); - if (ObjectUtils.isEmpty(imsDutyMainEntity) || StringUtil.isBlank(imsDutyMainEntity.getDutyPersonIds())) { - return R.data(""); - } - String ids = imsDutyMainEntity.getDutyPersonIds(); - String[] split = ids.split("\\^"); - if (null != split && split.length > 0) { - for (String s : split) { - ImsDutyMainVO vo = new ImsDutyMainVO(); - User user = UserCache.getUser(Long.valueOf(s)); - if (ObjectUtil.isNotEmpty(user)) { - vo.setUserId(s); + @Override + public R getMainIdByPersonV2(Long id) { + List list = new ArrayList<>(); + ImsDutyMainEntity imsDutyMainEntity = this.baseMapper.selectById(id); + if (ObjectUtils.isEmpty(imsDutyMainEntity) || StringUtil.isBlank(imsDutyMainEntity.getDutyPersonIds())) { + return R.data(""); + } + String ids = imsDutyMainEntity.getDutyPersonIds(); + String[] split = ids.split("\\^"); + if (null != split && split.length > 0) { + for (String s : split) { + ImsDutyMainVO vo = new ImsDutyMainVO(); + User user = UserCache.getUser(Long.valueOf(s)); if (ObjectUtil.isNotEmpty(user)) { - vo.setUserName(user.getName()); + vo.setUserId(s); + if (ObjectUtil.isNotEmpty(user)) { + vo.setUserName(user.getName()); + } + vo.setId(id); + list.add(vo); } - vo.setId(id); - list.add(vo); } } - } - Long managerId; - if (null != (imsDutyMainEntity.getDutyGroupId())) { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); - managerId = imsDutyGroupEntity.getManagerId(); - - } else { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, imsDutyMainEntity.getId()); - last("limit 1;"); - }}); - managerId = imsDutyMainPersonEntity.getDutyChargePerson(); - } - list = list.stream().map(s -> { - if (s.getUserId().equals(managerId.toString())) { - s.setUserName(s.getUserName() + "(值班组组长)"); - } - return s; - }).collect(Collectors.toList()); - return R.data(list); - } - - /** - * 获取当前值班班组 主页任务统计 - * - * @return - */ - @Override - public ImsSchedulingVo getTheManinGroup() { - ImsDutyMainEntity entity = this.baseMapper.selectOne(new QueryWrapper() {{ - eq("STATUS", 1).last("limit 1"); - }}); - - return this.baseMapper.selectByIdOneV2(entity.getId(), null); - } - - - /** - * 新增排班模版 - * - * @param vo - */ - private boolean doSaveTemplate(ImsSchedulingVo vo) { - List list = iImsDutyMainTemplateService.list(new LambdaQueryWrapper() {{ - eq(ImsDutyMainTemplateEntity::getTemplateName, vo.getTemplateName()); - eq(ImsDutyMainTemplateEntity::getType, vo.getPersonType()); - }}); - if (CollectionUtil.isNotEmpty(list)) { - return false; - } - ImsDutyMainTemplateEntity entity = new ImsDutyMainTemplateEntity(); - if (1 == vo.getPersonType()) { - String dutyOrderIds = JSONObject.toJSONString(vo.getDutyOrderIds(), SerializerFeature.WriteMapNullValue); - entity.setDutyOrderIds(dutyOrderIds); - entity.setFlexible(null); - entity.setType(1); - } else { - String flexible = JSONObject.toJSONString(vo.getFlexible(), SerializerFeature.WriteMapNullValue); - entity.setFlexible(flexible); - String dutyOrderIds = JSONObject.toJSONString(vo.getDutyOrderIds(), SerializerFeature.WriteMapNullValue); - entity.setDutyOrderIds(dutyOrderIds); - entity.setType(2); - } - String dutyArrIds = JSONObject.toJSONString(vo.getDutyArrIds(), SerializerFeature.WriteMapNullValue); - entity.setDutyNum(vo.getDutyNum()); - entity.setTemplateName(vo.getTemplateName()); - entity.setDutyArrIds(dutyArrIds); - entity.setDutyClassTypeId(vo.getDutyClassTypeId()); - entity.setCreateDept(vo.getCreateDept()); - iImsDutyMainTemplateService.save(entity); - return true; - } + Long managerId; + if (null != (imsDutyMainEntity.getDutyGroupId())) { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); + managerId = imsDutyGroupEntity.getManagerId(); - @Override - public List getDutyMainStatisticsByClassId(LocalDate startDate, LocalDate endDate, List deptIdList) { - List dutyReportVOList = new ArrayList<>(); - //获取当月值班记录 - List imsDutyMainEntityList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - ge(ImsDutyMainEntity::getDutyDate, startDate); - le(ImsDutyMainEntity::getDutyDate, endDate); - in(ImsDutyMainEntity::getCreateDept, deptIdList); - ne(ImsDutyMainEntity::getStatus, -1); - }}); - //按班组组合值班记录 - Map> listByGroup = imsDutyMainEntityList.stream().filter(o -> ObjectUtil.isNotEmpty(o.getDutyGroupId())).collect(Collectors.groupingBy(ImsDutyMainEntity::getDutyGroupId)); - listByGroup.forEach((k, v) -> { - //获取班组名 - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(k); - if (ObjectUtil.isNotEmpty(imsDutyGroupEntity)) { - DutyReportVO dutyReportVO = new DutyReportVO(); - dutyReportVO.setClassGroupName(imsDutyGroupEntity.getGroupName()); - dutyReportVO.setImsDutyMainEntityList(v); - dutyReportVO.setDutyNum(v.size()); - //发现问题数量 - List operPhenomenonEntityList = operPhenomenonMapper.selectList(new LambdaQueryWrapper() {{ - ge(OperPhenomenonEntity::getCreateTime, startDate); - le(OperPhenomenonEntity::getCreateTime, endDate); - in(OperPhenomenonEntity::getCreateDept, deptIdList); - eq(OperPhenomenonEntity::getSourceCode, DefectConstant.DefectSourceEnum.ZB.getStatus()); - }}); - dutyReportVO.setFindProblemNum(operPhenomenonEntityList.size()); - //获取值班ID - List dutyIdList = v.stream().map(ImsDutyMainEntity::getId).collect(Collectors.toList()); - //获取交接班异常记录 - List imsDutyRecEntityList = imsDutyRecMapper.selectList(new LambdaQueryWrapper() {{ - in(ImsDutyRecEntity::getDutyId, dutyIdList); + } else { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, imsDutyMainEntity.getId()); + last("limit 1;"); }}); - //延迟交接班 - List delayList = imsDutyRecEntityList.stream().filter(rec -> rec.getDelayStatus() == 1).collect(Collectors.toList()); - //异常交接班 - List exceptionList = imsDutyRecEntityList.stream().filter(rec -> DutyRecStatus.ANOMALY.getVal().equals(rec.getStatus())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(delayList)) { - dutyReportVO.setDelayChangeShifts(String.valueOf(delayList.size())); - } - if (CollectionUtil.isNotEmpty(exceptionList)) { - dutyReportVO.setExceptionChangeShifts(String.valueOf(exceptionList.size())); - } - dutyReportVOList.add(dutyReportVO); + managerId = imsDutyMainPersonEntity.getDutyChargePerson(); } - }); - return dutyReportVOList; - } + list = list.stream().map(s -> { + if (s.getUserId().equals(managerId.toString())) { + s.setUserName(s.getUserName() + "(值班组组长)"); + } + return s; + }).collect(Collectors.toList()); + return R.data(list); + } + + /** + * 获取当前值班班组 主页任务统计 + * + * @return + */ + @Override + public ImsSchedulingVo getTheManinGroup() { + ImsDutyMainEntity entity = this.baseMapper.selectOne(new QueryWrapper() {{ + eq("STATUS", 1).last("limit 1"); + }}); - @Override - public List getDutyMainStatisticsByClassId(Map params) { - LocalDate startDate = LocalDate.parse(params.get("startDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - LocalDate endDate = LocalDate.parse(params.get("endDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); - List deptId = (List) params.get("deptId"); - return getDutyMainStatisticsByClassId(startDate, endDate, deptId); - } + return this.baseMapper.selectByIdOneV2(entity.getId(), null); + } - @Override - public List> getDutyConclusion(Map params) { - return imsDutyGroupPMapper.getDutyConclusion(params); - } + /** + * 新增排班模版 + * + * @param vo + */ + private boolean doSaveTemplate(ImsSchedulingVo vo) { + List list = iImsDutyMainTemplateService.list(new LambdaQueryWrapper() {{ + eq(ImsDutyMainTemplateEntity::getTemplateName, vo.getTemplateName()); + eq(ImsDutyMainTemplateEntity::getType, vo.getPersonType()); + }}); + if (CollectionUtil.isNotEmpty(list)) { + return false; + } + ImsDutyMainTemplateEntity entity = new ImsDutyMainTemplateEntity(); + if (1 == vo.getPersonType()) { + String dutyOrderIds = JSONObject.toJSONString(vo.getDutyOrderIds(), SerializerFeature.WriteMapNullValue); + entity.setDutyOrderIds(dutyOrderIds); + entity.setFlexible(null); + entity.setType(1); + } else { + String flexible = JSONObject.toJSONString(vo.getFlexible(), SerializerFeature.WriteMapNullValue); + entity.setFlexible(flexible); + String dutyOrderIds = JSONObject.toJSONString(vo.getDutyOrderIds(), SerializerFeature.WriteMapNullValue); + entity.setDutyOrderIds(dutyOrderIds); + entity.setType(2); + } + String dutyArrIds = JSONObject.toJSONString(vo.getDutyArrIds(), SerializerFeature.WriteMapNullValue); + entity.setDutyNum(vo.getDutyNum()); + entity.setTemplateName(vo.getTemplateName()); + entity.setDutyArrIds(dutyArrIds); + entity.setDutyClassTypeId(vo.getDutyClassTypeId()); + entity.setCreateDept(vo.getCreateDept()); + iImsDutyMainTemplateService.save(entity); + return true; + } + + @Override + public List getDutyMainStatisticsByClassId(LocalDate startDate, LocalDate endDate, List deptIdList) { + List dutyReportVOList = new ArrayList<>(); + //获取当月值班记录 + List imsDutyMainEntityList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + ge(ImsDutyMainEntity::getDutyDate, startDate); + le(ImsDutyMainEntity::getDutyDate, endDate); + in(ImsDutyMainEntity::getCreateDept, deptIdList); + ne(ImsDutyMainEntity::getStatus, -1); + }}); + //按班组组合值班记录 + Map> listByGroup = imsDutyMainEntityList.stream().filter(o -> ObjectUtil.isNotEmpty(o.getDutyGroupId())).collect(Collectors.groupingBy(ImsDutyMainEntity::getDutyGroupId)); + listByGroup.forEach((k, v) -> { + //获取班组名 + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(k); + if (ObjectUtil.isNotEmpty(imsDutyGroupEntity)) { + DutyReportVO dutyReportVO = new DutyReportVO(); + dutyReportVO.setClassGroupName(imsDutyGroupEntity.getGroupName()); + dutyReportVO.setImsDutyMainEntityList(v); + dutyReportVO.setDutyNum(v.size()); + //发现问题数量 + List operPhenomenonEntityList = operPhenomenonMapper.selectList(new LambdaQueryWrapper() {{ + ge(OperPhenomenonEntity::getCreateTime, startDate); + le(OperPhenomenonEntity::getCreateTime, endDate); + in(OperPhenomenonEntity::getCreateDept, deptIdList); + eq(OperPhenomenonEntity::getSourceCode, DefectConstant.DefectSourceEnum.ZB.getStatus()); + }}); + dutyReportVO.setFindProblemNum(operPhenomenonEntityList.size()); + //获取值班ID + List dutyIdList = v.stream().map(ImsDutyMainEntity::getId).collect(Collectors.toList()); + //获取交接班异常记录 + List imsDutyRecEntityList = imsDutyRecMapper.selectList(new LambdaQueryWrapper() {{ + in(ImsDutyRecEntity::getDutyId, dutyIdList); + }}); + //延迟交接班 + List delayList = imsDutyRecEntityList.stream().filter(rec -> rec.getDelayStatus() == 1).collect(Collectors.toList()); + //异常交接班 + List exceptionList = imsDutyRecEntityList.stream().filter(rec -> DutyRecStatus.ANOMALY.getVal().equals(rec.getStatus())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(delayList)) { + dutyReportVO.setDelayChangeShifts(String.valueOf(delayList.size())); + } + if (CollectionUtil.isNotEmpty(exceptionList)) { + dutyReportVO.setExceptionChangeShifts(String.valueOf(exceptionList.size())); + } + dutyReportVOList.add(dutyReportVO); + } + }); + return dutyReportVOList; + } - @Override - public DutyPersonalReportVO getPersonalDutyMain(Map params) { - return imsDutyGroupPMapper.getPersonalDutyMain(params); - } + @Override + public List getDutyMainStatisticsByClassId(Map params) { + LocalDate startDate = LocalDate.parse(params.get("startDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + LocalDate endDate = LocalDate.parse(params.get("endDate").toString(), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE)); + List deptId = (List) params.get("deptId"); + return getDutyMainStatisticsByClassId(startDate, endDate, deptId); + } - @Override - public Integer getMainJoinGroupId(List list) { - return this.baseMapper.selectMainJoinGroupId(list); - } + @Override + public List> getDutyConclusion(Map params) { + return imsDutyGroupPMapper.getDutyConclusion(params); + } - @Override - public List getDutyMainByDept(List list) { - return getDutyMainByDeptV2(list); - } - @Override - public List getDutyMainByDeptV2(List list) { - List imsDutyMainMergeVos = this.baseMapper.selectDutyMainByDeptV2(list); - imsDutyMainMergeVos = imsDutyMainMergeVos.stream().map(s -> { - if (null == s.getGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, s.getDutyId()); - last("limit 1"); - }}); - s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); - s.setGroupName(imsDutyGroupEntity.getGroupName()); - s.setGroupId(imsDutyGroupEntity.getId()); - s.setManagerId(imsDutyGroupEntity.getManagerId()); - } - return s; - }).collect(Collectors.toList()); - return imsDutyMainMergeVos; - } + @Override + public DutyPersonalReportVO getPersonalDutyMain(Map params) { + return imsDutyGroupPMapper.getPersonalDutyMain(params); + } - @Override - public void doSaveBasch(List list) { - this.saveBatch(list); - } + @Override + public Integer getMainJoinGroupId(List list) { + return this.baseMapper.selectMainJoinGroupId(list); + } - @Override - public ImsDutyRecEntity dutyRec(List dutyIds) { - return imsDutyRecMapper.selectOne(new LambdaQueryWrapper() {{ - in(ImsDutyRecEntity::getDutyId, dutyIds); - eq(ImsDutyRecEntity::getStatus, 2).last(" LIMIT 1"); - }}); - } + @Override + public List getDutyMainByDept(List list) { + return getDutyMainByDeptV2(list); + } - /** - * 数据清理 - * - * @param deptId 机构ID - * @param startDate 开始时间 - * @param endDate 结束时间 - * @return - */ - @Override - public R dataDelete(Long deptId, String startDate, String endDate) { - ImsDutyMainEntity entity = new ImsDutyMainEntity(); - entity.setIsDeleted(1); - return R.status(this.update(entity, new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getCreateDept, deptId); - ge(ImsDutyMainEntity::getDutyDate, startDate); - le(ImsDutyMainEntity::getDutyDate, endDate); - }})); - } + @Override + public List getDutyMainByDeptV2(List list) { + List imsDutyMainMergeVos = this.baseMapper.selectDutyMainByDeptV2(list); + imsDutyMainMergeVos = imsDutyMainMergeVos.stream().map(s -> { + if (null == s.getGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, s.getDutyId()); + last("limit 1"); + }}); + s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); + s.setGroupName(imsDutyGroupEntity.getGroupName()); + s.setGroupId(imsDutyGroupEntity.getId()); + s.setManagerId(imsDutyGroupEntity.getManagerId()); + } + return s; + }).collect(Collectors.toList()); + return imsDutyMainMergeVos; + } - @Override - public List getSchedulingVoByDateList(String startDate, String endDate) { - return this.baseMapper.selectSchedulingVoByDateList(startDate, endDate); - } + @Override + public void doSaveBasch(List list) { + this.saveBatch(list); + } + @Override + public ImsDutyRecEntity dutyRec(List dutyIds) { + return imsDutyRecMapper.selectOne(new LambdaQueryWrapper() {{ + in(ImsDutyRecEntity::getDutyId, dutyIds); + eq(ImsDutyRecEntity::getStatus, 2).last(" LIMIT 1"); + }}); + } - @Override - public List getHomePageDutyInfo(Long deptId) { - List list = new ArrayList<>(); - List dutyMainInfoVos = getDutyDataV2(deptId); - if (CollectionUtil.isNotEmpty(dutyMainInfoVos)) { - for (DutyMainInfoVo dutyMainInfoVo : dutyMainInfoVos) { - HomePageDutyMainInfoVo vo = new HomePageDutyMainInfoVo(); - if (Func.isNotBlank(dutyMainInfoVo.getDutyPersonIds())) { - List auditVoList = new ArrayList<>(); - for (String personId : dutyMainInfoVo.getDutyPersonIds().split("\\^")) { - if (!personId.equals(dutyMainInfoVo.getManagerId())) { - AuditVo user = getUser(Long.valueOf(personId)); - if (ObjectUtil.isNotEmpty(user)) { - auditVoList.add(user); + /** + * 数据清理 + * + * @param deptId 机构ID + * @param startDate 开始时间 + * @param endDate 结束时间 + * @return + */ + @Override + public R dataDelete(Long deptId, String startDate, String endDate) { + ImsDutyMainEntity entity = new ImsDutyMainEntity(); + entity.setIsDeleted(1); + return R.status(this.update(entity, new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getCreateDept, deptId); + ge(ImsDutyMainEntity::getDutyDate, startDate); + le(ImsDutyMainEntity::getDutyDate, endDate); + }})); + } + + @Override + public List getSchedulingVoByDateList(String startDate, String endDate) { + return this.baseMapper.selectSchedulingVoByDateList(startDate, endDate); + } + + + @Override + public List getHomePageDutyInfo(Long deptId) { + List list = new ArrayList<>(); + List dutyMainInfoVos = getDutyDataV2(deptId); + if (CollectionUtil.isNotEmpty(dutyMainInfoVos)) { + for (DutyMainInfoVo dutyMainInfoVo : dutyMainInfoVos) { + HomePageDutyMainInfoVo vo = new HomePageDutyMainInfoVo(); + if (Func.isNotBlank(dutyMainInfoVo.getDutyPersonIds())) { + List auditVoList = new ArrayList<>(); + for (String personId : dutyMainInfoVo.getDutyPersonIds().split("\\^")) { + if (!personId.equals(dutyMainInfoVo.getManagerId())) { + AuditVo user = getUser(Long.valueOf(personId)); + if (ObjectUtil.isNotEmpty(user)) { + auditVoList.add(user); + } } } + dutyMainInfoVo.setAuditList(auditVoList); + } + User managerUser = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); + if (ObjectUtil.isNotEmpty(managerUser)) { + dutyMainInfoVo.setManagerName(managerUser.getName()); + dutyMainInfoVo.setManagerPhone(managerUser.getPhone()); } - dutyMainInfoVo.setAuditList(auditVoList); - } - User managerUser = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); - if (ObjectUtil.isNotEmpty(managerUser)) { - dutyMainInfoVo.setManagerName(managerUser.getName()); - dutyMainInfoVo.setManagerPhone(managerUser.getPhone()); - } - List generatingCapacityList = groupGeneratingCapacityMapper.selectList(new LambdaQueryWrapper() {{ - eq(DutyGroupGeneratingCapacityEntity::getStartTime, dutyMainInfoVo.getStartTime()); - eq(DutyGroupGeneratingCapacityEntity::getEndTime, dutyMainInfoVo.getEndTime()); - eq(DutyGroupGeneratingCapacityEntity::getDutyDept, dutyMainInfoVo.getCreateDept()); - eq(DutyGroupGeneratingCapacityEntity::getDateTime, DateUtil.format(dutyMainInfoVo.getDutyDate(), DateUtil.PATTERN_DATE)); - }}); - if (CollectionUtil.isNotEmpty(generatingCapacityList)) { - double generatingCapacity = generatingCapacityList.stream().mapToDouble(DutyGroupGeneratingCapacityEntity::getGeneratingCapacity).sum(); - dutyMainInfoVo.setGeneratingCapacity(generatingCapacity); - } - vo.setHeadInfo(dutyMainInfoVo); - DutyMainInfoVo corryVo = getNextDutyDataV2(dutyMainInfoVo.getId()); - if (ObjectUtil.isNotEmpty(corryVo) && Func.isNotBlank(corryVo.getDutyPersonIds())) { - List auditVoList = new ArrayList<>(); - for (String personId : corryVo.getDutyPersonIds().split("\\^")) { - if (!personId.equals(corryVo.getManagerId())) { - AuditVo user = getUser(Long.valueOf(personId)); - if (ObjectUtil.isNotEmpty(user)) { - auditVoList.add(user); + List generatingCapacityList = groupGeneratingCapacityMapper.selectList(new LambdaQueryWrapper() {{ + eq(DutyGroupGeneratingCapacityEntity::getStartTime, dutyMainInfoVo.getStartTime()); + eq(DutyGroupGeneratingCapacityEntity::getEndTime, dutyMainInfoVo.getEndTime()); + eq(DutyGroupGeneratingCapacityEntity::getDutyDept, dutyMainInfoVo.getCreateDept()); + eq(DutyGroupGeneratingCapacityEntity::getDateTime, DateUtil.format(dutyMainInfoVo.getDutyDate(), DateUtil.PATTERN_DATE)); + }}); + if (CollectionUtil.isNotEmpty(generatingCapacityList)) { + double generatingCapacity = generatingCapacityList.stream().mapToDouble(DutyGroupGeneratingCapacityEntity::getGeneratingCapacity).sum(); + dutyMainInfoVo.setGeneratingCapacity(generatingCapacity); + } + vo.setHeadInfo(dutyMainInfoVo); + DutyMainInfoVo corryVo = getNextDutyDataV2(dutyMainInfoVo.getId()); + if (ObjectUtil.isNotEmpty(corryVo) && Func.isNotBlank(corryVo.getDutyPersonIds())) { + List auditVoList = new ArrayList<>(); + for (String personId : corryVo.getDutyPersonIds().split("\\^")) { + if (!personId.equals(corryVo.getManagerId())) { + AuditVo user = getUser(Long.valueOf(personId)); + if (ObjectUtil.isNotEmpty(user)) { + auditVoList.add(user); + } } } + corryVo.setAuditList(auditVoList); + vo.setCorryInfo(corryVo); + User carryManagerUser = UserCache.getUser(Long.valueOf(corryVo.getManagerId())); + if (ObjectUtil.isNotEmpty(carryManagerUser)) { + corryVo.setManagerName(carryManagerUser.getName()); + corryVo.setManagerPhone(carryManagerUser.getPhone()); + } } - corryVo.setAuditList(auditVoList); - vo.setCorryInfo(corryVo); - User carryManagerUser = UserCache.getUser(Long.valueOf(corryVo.getManagerId())); - if (ObjectUtil.isNotEmpty(carryManagerUser)) { - corryVo.setManagerName(carryManagerUser.getName()); - corryVo.setManagerPhone(carryManagerUser.getPhone()); - } + list.add(vo); } - list.add(vo); } - } - return list; - } - - @Override - public List getDutyDurationDate() { - //获取当班信息 - List dutyList = getDutyDataV2(null); - dutyList.forEach(dutyVO -> { - Time startTime = dutyVO.getStartTime(); - Time endTime = dutyVO.getEndTime(); - LocalDateTime localDateTime = LocalDateTime.ofInstant(dutyVO.getDutyDate().toInstant(), ZoneId.systemDefault()); - LocalDateTime startDate = localDateTime.withHour(startTime.getHours()).withMinute(startTime.getMinutes()).withSecond(00); - LocalDateTime endDate = localDateTime.withHour(endTime.getHours()).withMinute(endTime.getMinutes()).withSecond(00); - if (startDate.isAfter(endDate)) { - endDate = endDate.plusDays(1); - } - dutyVO.setStartDate(startDate); - dutyVO.setEndDate(endDate); - }); - log.info("当前值班传输对象为:{}", JSONObject.toJSONString(dutyList)); - return dutyList; - } - - - /** - * 查询排班数据 - * - * @param deptIdList - * @return - */ - @Override - public List getDutyData(List deptIdList) { - if (CollectionUtil.isEmpty(deptIdList)) { - return null; - } - // 查询区域当前值班 - List dutyInfoVoList = this.baseMapper.getDutyDataV2(deptIdList); - if (CollectionUtil.isEmpty(dutyInfoVoList)) { - return null; - } - //修改数据结构后:分灵活排班和班组排班拿负责人 - dutyInfoVoList = dutyInfoVoList.stream().peek(s -> { - if (null == s.getGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); - last(" limit 1"); - }}); - s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); - s.setGroupName(imsDutyGroupEntity.getGroupName()); - s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + return list; + } + + @Override + public List getDutyDurationDate() { + //获取当班信息 + List dutyList = getDutyDataV2(null); + dutyList.forEach(dutyVO -> { + Time startTime = dutyVO.getStartTime(); + Time endTime = dutyVO.getEndTime(); + LocalDateTime localDateTime = LocalDateTime.ofInstant(dutyVO.getDutyDate().toInstant(), ZoneId.systemDefault()); + LocalDateTime startDate = localDateTime.withHour(startTime.getHours()).withMinute(startTime.getMinutes()).withSecond(00); + LocalDateTime endDate = localDateTime.withHour(endTime.getHours()).withMinute(endTime.getMinutes()).withSecond(00); + if (startDate.isAfter(endDate)) { + endDate = endDate.plusDays(1); + } + dutyVO.setStartDate(startDate); + dutyVO.setEndDate(endDate); + }); + log.info("当前值班传输对象为:{}", JSONObject.toJSONString(dutyList)); + return dutyList; + } + + + /** + * 查询排班数据 + * + * @param deptIdList + * @return + */ + @Override + public List getDutyData(List deptIdList) { + if (CollectionUtil.isEmpty(deptIdList)) { + return null; } - }).collect(Collectors.toList()); - dutyInfoVoList.forEach(item -> { - // 负责人 - User user = UserCache.getUser(Long.valueOf(item.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - item.setManagerName(user.getName()); - item.setManagerPhone(user.getPhone()); + // 查询区域当前值班 + List dutyInfoVoList = this.baseMapper.getDutyDataV2(deptIdList); + if (CollectionUtil.isEmpty(dutyInfoVoList)) { + return null; } - // FIXME 上网 - item.setOnlineCapacity(0.0); - // 发电量 - item.setGeneratingCapacity(0); - // 上一班组 - NextDutyInfoVo upDutyInfoVo = this.getUpDutyInfo(item); - item.setUpDutyInfoVo(upDutyInfoVo); - // 下一班组 - NextDutyInfoVo nextDutyInfoVo = this.getNextDutyInfo(item); - item.setNextDutyInfoVo(nextDutyInfoVo); - }); - return dutyInfoVoList; - } - - @Override - public R getAllPersonInfo(Long deptId) { - R> allUserList = userClient.userList("200000",deptId); - return allUserList; - } - - @Override - public R getDutyEmergencyEntityById(Long deptId, Long personId) { - ImsDutyMainEntity entity = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getStatus, DutyMainStatus.EXEC.getVal()); - eq(ImsDutyMainEntity::getCreateDept, deptId); - like(ImsDutyMainEntity::getDutyPersonIds, AuthUtil.getUserId()).last(" limit 1"); - }}); - if (ObjectUtil.isEmpty(entity)) { - return R.success("您当前未值班"); - } - ImsSchedulingVo imsSchedulingVo = getByIdOneV2(entity.getId(), null); - R userR = userClient.userInfoById(imsSchedulingVo.getManagerId()); - imsSchedulingVo.setManagerName(userR.getData().getName()); - imsSchedulingVo.setCreateDept(userR.getData().getCreateDept()); - return R.data(imsSchedulingVo); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public R updateDutyMainInfoVoById(ChangeDutyMainVo changeDutyMainVo) { - List imsDutyMainEntities = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - ge(ImsDutyMainEntity::getDutyDate, changeDutyMainVo.getChangeStartDate()); - le(ImsDutyMainEntity::getDutyDate, changeDutyMainVo.getChangeEndtDate()); - eq(ImsDutyMainEntity::getCreateDept, changeDutyMainVo.getCreateDept()); - eq(ImsDutyMainEntity::getClassId, changeDutyMainVo.getClassId()); - eq(ImsDutyMainEntity::getIsDeleted, 0); - }}); - if (CollectionUtil.isEmpty(imsDutyMainEntities)) { - return R.fail("暂无对应排班计划"); - } - List mainIds = imsDutyMainEntities.stream().map(ImsDutyMainEntity::getId).collect(Collectors.toList()); - List personEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ - in(ImsDutyMainPersonEntity::getDutyMainId, mainIds); - eq(ImsDutyMainPersonEntity::getIsDeleted, 0); - - }}); - if (CollectionUtil.isEmpty(personEntityList)) { - //如果人员计划表中,无值,需要填充对应信息(只有排班-班组,人员计划表才有可能无值) - //对上一个版本做兼容 - for (ImsDutyMainEntity imsDutyMainEntity : imsDutyMainEntities) { - String[] dutyPersonIds = imsDutyMainEntity.getDutyPersonIds().split("\\^"); - List personIdlist = Arrays.asList(dutyPersonIds); - List collect = personIdlist.stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); - ImsSchedulingVo imsSchedulingVo = new ImsSchedulingVo(); - imsSchedulingVo.setGroupId(imsDutyMainEntity.getDutyGroupId()); - imsSchedulingVo.setPersonType(1); - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); - copyPersonByDutyMain(imsSchedulingVo, imsDutyGroupEntity.getManagerId(), imsDutyGroupEntity.getGroupName(), personEntityList, imsDutyMainEntity, collect); + //修改数据结构后:分灵活排班和班组排班拿负责人 + dutyInfoVoList = dutyInfoVoList.stream().peek(s -> { + if (null == s.getGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); + last(" limit 1"); + }}); + s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); + s.setGroupName(imsDutyGroupEntity.getGroupName()); + s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } + }).collect(Collectors.toList()); + dutyInfoVoList.forEach(item -> { + // 负责人 + User user = UserCache.getUser(Long.valueOf(item.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + item.setManagerName(user.getName()); + item.setManagerPhone(user.getPhone()); + } + // FIXME 上网 + item.setOnlineCapacity(0.0); + // 发电量 + item.setGeneratingCapacity(0); + // 上一班组 + NextDutyInfoVo upDutyInfoVo = this.getUpDutyInfo(item); + item.setUpDutyInfoVo(upDutyInfoVo); + // 下一班组 + NextDutyInfoVo nextDutyInfoVo = this.getNextDutyInfo(item); + item.setNextDutyInfoVo(nextDutyInfoVo); + }); + return dutyInfoVoList; + } + + @Override + public R getAllPersonInfo(Long deptId) { + R> allUserList = userClient.userList("200000",deptId); + return allUserList; + } + + @Override + public R getDutyEmergencyEntityById(Long deptId, Long personId) { + ImsDutyMainEntity entity = this.baseMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getStatus, DutyMainStatus.EXEC.getVal()); + eq(ImsDutyMainEntity::getCreateDept, deptId); + like(ImsDutyMainEntity::getDutyPersonIds, AuthUtil.getUserId()).last(" limit 1"); + }}); + if (ObjectUtil.isEmpty(entity)) { + return R.success("您当前未值班"); } - } - //调出时,做是否是班组组长的判断 - List personId = changeDutyMainVo.getPersonId(); - HashSet manageIds=new HashSet<>(); - HashSet personHashSet=new HashSet<>(); - for (ImsDutyMainEntity imsDutyMainEntity : imsDutyMainEntities) { - if (imsDutyMainEntity.getDutyGroupId()!=null){ - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); - manageIds.add(imsDutyGroupEntity.getManagerId().toString()); + ImsSchedulingVo imsSchedulingVo = getByIdOneV2(entity.getId(), null); + R userR = userClient.userInfoById(imsSchedulingVo.getManagerId()); + imsSchedulingVo.setManagerName(userR.getData().getName()); + imsSchedulingVo.setCreateDept(userR.getData().getCreateDept()); + return R.data(imsSchedulingVo); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public R updateDutyMainInfoVoById(ChangeDutyMainVo changeDutyMainVo) { + List imsDutyMainEntities = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + ge(ImsDutyMainEntity::getDutyDate, changeDutyMainVo.getChangeStartDate()); + le(ImsDutyMainEntity::getDutyDate, changeDutyMainVo.getChangeEndtDate()); + eq(ImsDutyMainEntity::getCreateDept, changeDutyMainVo.getCreateDept()); + eq(ImsDutyMainEntity::getClassId, changeDutyMainVo.getClassId()); + eq(ImsDutyMainEntity::getIsDeleted, 0); + }}); + if (CollectionUtil.isEmpty(imsDutyMainEntities)) { + return R.fail("暂无对应排班计划"); } - String[] dutyMainPersonIds = imsDutyMainEntity.getDutyPersonIds().split("\\^"); - List personIdlist = new ArrayList<>(Arrays.asList(dutyMainPersonIds)); - personHashSet.addAll(personIdlist); - } - //调入调出,对人员做重复判断 - for (String s : personId) { - if (1==changeDutyMainVo.getType()) { - if (personHashSet.contains(s)) { - return R.fail("不可重复值班"); + List mainIds = imsDutyMainEntities.stream().map(ImsDutyMainEntity::getId).collect(Collectors.toList()); + List personEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ + in(ImsDutyMainPersonEntity::getDutyMainId, mainIds); + eq(ImsDutyMainPersonEntity::getIsDeleted, 0); + + }}); + if (CollectionUtil.isEmpty(personEntityList)) { + //如果人员计划表中,无值,需要填充对应信息(只有排班-班组,人员计划表才有可能无值) + //对上一个版本做兼容 + for (ImsDutyMainEntity imsDutyMainEntity : imsDutyMainEntities) { + String[] dutyPersonIds = imsDutyMainEntity.getDutyPersonIds().split("\\^"); + List personIdlist = Arrays.asList(dutyPersonIds); + List collect = personIdlist.stream().map(s -> Long.valueOf(s)).collect(Collectors.toList()); + ImsSchedulingVo imsSchedulingVo = new ImsSchedulingVo(); + imsSchedulingVo.setGroupId(imsDutyMainEntity.getDutyGroupId()); + imsSchedulingVo.setPersonType(1); + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); + copyPersonByDutyMain(imsSchedulingVo, imsDutyGroupEntity.getManagerId(), imsDutyGroupEntity.getGroupName(), personEntityList, imsDutyMainEntity, collect); } - }else { - if (!personHashSet.contains(s)) { - return R.fail("该人员暂无排班计划"); + } + //调出时,做是否是班组组长的判断 + List personId = changeDutyMainVo.getPersonId(); + HashSet manageIds=new HashSet<>(); + HashSet personHashSet=new HashSet<>(); + for (ImsDutyMainEntity imsDutyMainEntity : imsDutyMainEntities) { + if (imsDutyMainEntity.getDutyGroupId()!=null){ + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(imsDutyMainEntity.getDutyGroupId()); + manageIds.add(imsDutyGroupEntity.getManagerId().toString()); + } + String[] dutyMainPersonIds = imsDutyMainEntity.getDutyPersonIds().split("\\^"); + List personIdlist = new ArrayList<>(Arrays.asList(dutyMainPersonIds)); + personHashSet.addAll(personIdlist); + } + //调入调出,对人员做重复判断 + for (String s : personId) { + if (1==changeDutyMainVo.getType()) { + if (personHashSet.contains(s)) { + return R.fail("不可重复值班"); + } + }else { + if (!personHashSet.contains(s)) { + return R.fail("该人员暂无排班计划"); + } } } - } - //值班组长无法调走 - List dutyChargePersonIds = personEntityList.stream().filter(s -> s.getDutyChargePerson()!=null) - .map(s -> s.getDutyChargePerson().toString()).collect(Collectors.toList()); - manageIds.addAll(dutyChargePersonIds); - for (String s : personId) { - if (manageIds.contains(s)) { - return R.fail("值班组长无法调走"); + //值班组长无法调走 + List dutyChargePersonIds = personEntityList.stream().filter(s -> s.getDutyChargePerson()!=null) + .map(s -> s.getDutyChargePerson().toString()).collect(Collectors.toList()); + manageIds.addAll(dutyChargePersonIds); + for (String s : personId) { + if (manageIds.contains(s)) { + return R.fail("值班组长无法调走"); + } } - } // personId.stream().map(s -> { // for (String manageId : manageIds) { // if (s.equals(manageId)){ @@ -1535,613 +1772,613 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl addPersonEntityList = new ArrayList<>(); - List updateDutyMainEntities = imsDutyMainEntities.stream().map(s -> { - String[] dutyMainPersonIds = s.getDutyPersonIds().split("\\^"); - List personIdlist = new ArrayList<>(Arrays.asList(dutyMainPersonIds)); - if (1 == changeDutyMainVo.getType()) { - personIdlist.addAll(personId); - } else { - personIdlist.removeAll(personId); - } - String resIds = StringUtils.join(personIdlist, "^"); - s.setDutyPersonIds(resIds); - //如果是班组排班,调班之后,则需要转换为灵活排班,加上排班名字 - if (s.getDutyGroupId() != null) { - s.setDutyGroupId(null); - } - return s; - }).collect(Collectors.toList()); - //之前原有的排版-人员表,需要修改的部分 - List updatePersonEntityList= personEntityList.stream().map(sig -> { - if (sig.getDutyGroupId() != null) { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(sig.getDutyGroupId()); - sig.setDutyGroupName(imsDutyGroupEntity.getGroupName()); - sig.setDutyGroupId(null); - } - long id = IdWorker.getId(sig); - sig.setId(id); - return sig; - }).collect(Collectors.toList()); - //如果是添加,填充对应人员的排版人员表 - if(1 == changeDutyMainVo.getType()) { - for (String addId : personId) { - for (Long mainId : mainIds) { - //copy修改后的数据, - List collect = updatePersonEntityList.stream().filter(s -> mainId.equals(s.getDutyMainId())).collect(Collectors.toList()); - ImsDutyMainPersonEntity imsDutyMainPersonEntity=collect.get(0); - ImsDutyMainPersonEntity addEntity = new ImsDutyMainPersonEntity(); - BeanUtil.copy(imsDutyMainPersonEntity, addEntity); - addEntity.setDutyPerson(Long.valueOf(addId)); - long id1 = IdWorker.getId(imsDutyMainPersonEntity); - addEntity.setId(id1); - addPersonEntityList.add(addEntity); + List addPersonEntityList = new ArrayList<>(); + List updateDutyMainEntities = imsDutyMainEntities.stream().map(s -> { + String[] dutyMainPersonIds = s.getDutyPersonIds().split("\\^"); + List personIdlist = new ArrayList<>(Arrays.asList(dutyMainPersonIds)); + if (1 == changeDutyMainVo.getType()) { + personIdlist.addAll(personId); + } else { + personIdlist.removeAll(personId); + } + String resIds = StringUtils.join(personIdlist, "^"); + s.setDutyPersonIds(resIds); + //如果是班组排班,调班之后,则需要转换为灵活排班,加上排班名字 + if (s.getDutyGroupId() != null) { + s.setDutyGroupId(null); + } + return s; + }).collect(Collectors.toList()); + //之前原有的排版-人员表,需要修改的部分 + List updatePersonEntityList= personEntityList.stream().map(sig -> { + if (sig.getDutyGroupId() != null) { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(sig.getDutyGroupId()); + sig.setDutyGroupName(imsDutyGroupEntity.getGroupName()); + sig.setDutyGroupId(null); + } + long id = IdWorker.getId(sig); + sig.setId(id); + return sig; + }).collect(Collectors.toList()); + //如果是添加,填充对应人员的排版人员表 + if(1 == changeDutyMainVo.getType()) { + for (String addId : personId) { + for (Long mainId : mainIds) { + //copy修改后的数据, + List collect = updatePersonEntityList.stream().filter(s -> mainId.equals(s.getDutyMainId())).collect(Collectors.toList()); + ImsDutyMainPersonEntity imsDutyMainPersonEntity=collect.get(0); + ImsDutyMainPersonEntity addEntity = new ImsDutyMainPersonEntity(); + BeanUtil.copy(imsDutyMainPersonEntity, addEntity); + addEntity.setDutyPerson(Long.valueOf(addId)); + long id1 = IdWorker.getId(imsDutyMainPersonEntity); + addEntity.setId(id1); + addPersonEntityList.add(addEntity); + } } + updatePersonEntityList.addAll(addPersonEntityList); } - updatePersonEntityList.addAll(addPersonEntityList); - } - if (2 == changeDutyMainVo.getType()) { - for (String s : personId) { - updatePersonEntityList=updatePersonEntityList.stream().filter( - sig -> !sig.getDutyPerson().equals(s)) - .collect(Collectors.toList()); + if (2 == changeDutyMainVo.getType()) { + for (String s : personId) { + updatePersonEntityList=updatePersonEntityList.stream().filter( + sig -> !sig.getDutyPerson().equals(s)) + .collect(Collectors.toList()); + } } + //更新排班-班组表,删除排班人员表,再添加排班班组人员表 + this.updateBatchById(updateDutyMainEntities); + List list = personEntityList.stream().map(s -> Long.valueOf(s.getId())).collect(Collectors.toList()); + iImsDutyMainPersonService.deleteLogic(list); + iImsDutyMainPersonService.saveBatch(updatePersonEntityList); + return R.success("修改成功"); } - //更新排班-班组表,删除排班人员表,再添加排班班组人员表 - this.updateBatchById(updateDutyMainEntities); - List list = personEntityList.stream().map(s -> Long.valueOf(s.getId())).collect(Collectors.toList()); - iImsDutyMainPersonService.deleteLogic(list); - iImsDutyMainPersonService.saveBatch(updatePersonEntityList); - return R.success("修改成功"); - } - - @Override - public List getExcelDutyData(Integer year, Integer month, Long deptId) { - List dutyMainReportExcelList = new ArrayList<>(); - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - - String yearAndMonth = ""; - - if (month < 10) { - yearAndMonth = year + "-0" + month; - } else { - yearAndMonth = year + "-" + month; - } - - // 获取部门所有班次 - LambdaQueryWrapper classWrapper = new LambdaQueryWrapper(); - classWrapper.eq(ImsDutyClassEntity::getCreateDept, deptId); - List deptDutyClassList = iImsDutyClassService.list(classWrapper); - Map deptDutyClassMap = deptDutyClassList.stream().collect(Collectors.toMap(ImsDutyClassEntity::getId, Function.identity())); - - // 获取部门的所有组员 - List allUserList = userClient.userList("200000",deptId).getData(); - Map deptUserMap = allUserList.stream().collect(Collectors.toMap(User::getId, User::getName)); - - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ImsDutyMainEntity::getCreateDept, deptId); - wrapper.like(ImsDutyMainEntity::getDutyDate, yearAndMonth); - // 获取部门一个月的排班 - List dutyMainList = this.baseMapper.selectList(wrapper); - - // 获取部门所有分组 - LambdaQueryWrapper groupWrapper = new LambdaQueryWrapper(); - groupWrapper.eq(ImsDutyGroupEntity::getCreateDept, deptId); - List deptDutyGroupList = dutyGroupMapper.selectList(groupWrapper); - Map deptDutyGroupMap = deptDutyGroupList.stream().collect(Collectors.toMap(ImsDutyGroupEntity::getId, Function.identity())); - - // 获取部门所有没有分组的组员 - LambdaQueryWrapper personWrapper = new LambdaQueryWrapper(); - personWrapper.eq(ImsDutyMainPersonEntity::getCreateDept, deptId); - personWrapper.like(ImsDutyMainPersonEntity::getDutyDate, yearAndMonth); - List deptPersonList = imsDutyMainPersonMapper.selectList(personWrapper); - - // 获取本月天数 - int days = getDaysByYearMonth(year, month); - for (int i = 1; i <= days; i++) { - String dateStr = getDate(year, month, i); - List restUserList = userClient.userList("200000",deptId).getData(); + @Override + public List getExcelDutyData(Integer year, Integer month, Long deptId) { + List dutyMainReportExcelList = new ArrayList<>(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - // 获取一天的排班 - List dutyMainDayList = dutyMainList.stream().filter(var -> dateFormat.format(var.getDutyDate()).equals(dateStr)).collect(Collectors.toList()); + String yearAndMonth = ""; - // 循环获取当前日期每个班次组员id - for (ImsDutyMainEntity imsDutyMainEntity : dutyMainDayList) { - ImsDutyMainReportExcel reportExcel = new ImsDutyMainReportExcel(); - - ImsDutyClassEntity imsDutyClass = deptDutyClassMap.get(imsDutyMainEntity.getClassId()); - reportExcel.setDutyDate(dateStr); - reportExcel.setClassName(imsDutyClass.getClassName() + "(" + imsDutyClass.getStartTime() + " - " + imsDutyClass.getEndTime() + ")"); - - List personIds; - String managerName; - if (Func.isNotEmpty(imsDutyMainEntity.getDutyGroupId())) { - // 存在分组id需要从分组中获取组长和组员 - LambdaQueryWrapper groupPWrapper = new LambdaQueryWrapper(); - groupPWrapper.eq(ImsDutyGroupPEntity::getGroupId, imsDutyMainEntity.getDutyGroupId()); - List list = imsDutyGroupPService.list(groupPWrapper); + if (month < 10) { + yearAndMonth = year + "-0" + month; + } else { + yearAndMonth = year + "-" + month; + } - managerName = deptUserMap.get(deptDutyGroupMap.get(imsDutyMainEntity.getDutyGroupId()).getManagerId()); - personIds = list.stream() + // 获取部门所有班次 + LambdaQueryWrapper classWrapper = new LambdaQueryWrapper(); + classWrapper.eq(ImsDutyClassEntity::getCreateDept, deptId); + List deptDutyClassList = iImsDutyClassService.list(classWrapper); + Map deptDutyClassMap = deptDutyClassList.stream().collect(Collectors.toMap(ImsDutyClassEntity::getId, Function.identity())); + + // 获取部门的所有组员 + List allUserList = userClient.userList("200000",deptId).getData(); + Map deptUserMap = allUserList.stream().collect(Collectors.toMap(User::getId, User::getName)); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImsDutyMainEntity::getCreateDept, deptId); + wrapper.like(ImsDutyMainEntity::getDutyDate, yearAndMonth); + // 获取部门一个月的排班 + List dutyMainList = this.baseMapper.selectList(wrapper); + + // 获取部门所有分组 + LambdaQueryWrapper groupWrapper = new LambdaQueryWrapper(); + groupWrapper.eq(ImsDutyGroupEntity::getCreateDept, deptId); + List deptDutyGroupList = dutyGroupMapper.selectList(groupWrapper); + Map deptDutyGroupMap = deptDutyGroupList.stream().collect(Collectors.toMap(ImsDutyGroupEntity::getId, Function.identity())); + + // 获取部门所有没有分组的组员 + LambdaQueryWrapper personWrapper = new LambdaQueryWrapper(); + personWrapper.eq(ImsDutyMainPersonEntity::getCreateDept, deptId); + personWrapper.like(ImsDutyMainPersonEntity::getDutyDate, yearAndMonth); + List deptPersonList = imsDutyMainPersonMapper.selectList(personWrapper); + + // 获取本月天数 + int days = getDaysByYearMonth(year, month); + for (int i = 1; i <= days; i++) { + String dateStr = getDate(year, month, i); + + List restUserList = userClient.userList("200000",deptId).getData(); + + // 获取一天的排班 + List dutyMainDayList = dutyMainList.stream().filter(var -> dateFormat.format(var.getDutyDate()).equals(dateStr)).collect(Collectors.toList()); + + // 循环获取当前日期每个班次组员id + for (ImsDutyMainEntity imsDutyMainEntity : dutyMainDayList) { + ImsDutyMainReportExcel reportExcel = new ImsDutyMainReportExcel(); + + ImsDutyClassEntity imsDutyClass = deptDutyClassMap.get(imsDutyMainEntity.getClassId()); + reportExcel.setDutyDate(dateStr); + reportExcel.setClassName(imsDutyClass.getClassName() + "(" + imsDutyClass.getStartTime() + " - " + imsDutyClass.getEndTime() + ")"); + + List personIds; + String managerName; + if (Func.isNotEmpty(imsDutyMainEntity.getDutyGroupId())) { + // 存在分组id需要从分组中获取组长和组员 + LambdaQueryWrapper groupPWrapper = new LambdaQueryWrapper(); + groupPWrapper.eq(ImsDutyGroupPEntity::getGroupId, imsDutyMainEntity.getDutyGroupId()); + List list = imsDutyGroupPService.list(groupPWrapper); + + managerName = deptUserMap.get(deptDutyGroupMap.get(imsDutyMainEntity.getDutyGroupId()).getManagerId()); + personIds = list.stream() // 过滤出组长 - .filter(s->!s.getPersonId().equals(deptDutyGroupMap.get(imsDutyMainEntity.getDutyGroupId()).getManagerId())) - .map(ImsDutyGroupPEntity::getPersonId).collect(Collectors.toList()); - } else { - // 不存在分组id从排班人员中获取组长和组员 - List personList = deptPersonList.stream().filter(var -> var.getDutyMainId().equals(imsDutyMainEntity.getId())).collect(Collectors.toList()); - managerName = deptUserMap.get(personList.get(0).getDutyChargePerson()); - personIds = personList.stream().filter(s->!s.getDutyPerson().equals(personList.get(0).getDutyChargePerson())).map(ImsDutyMainPersonEntity::getDutyPerson).collect(Collectors.toList()); - } + .filter(s->!s.getPersonId().equals(deptDutyGroupMap.get(imsDutyMainEntity.getDutyGroupId()).getManagerId())) + .map(ImsDutyGroupPEntity::getPersonId).collect(Collectors.toList()); + } else { + // 不存在分组id从排班人员中获取组长和组员 + List personList = deptPersonList.stream().filter(var -> var.getDutyMainId().equals(imsDutyMainEntity.getId())).collect(Collectors.toList()); + managerName = deptUserMap.get(personList.get(0).getDutyChargePerson()); + personIds = personList.stream().filter(s->!s.getDutyPerson().equals(personList.get(0).getDutyChargePerson())).map(ImsDutyMainPersonEntity::getDutyPerson).collect(Collectors.toList()); + } - String personNames = ""; - // 获取排班组员名称 - for (int j = 0; j < personIds.size(); j++) { - Long userId = personIds.get(j); - String userName = deptUserMap.get(userId); - // 把排班的组员从休息名单中移除 - restUserList.removeIf(user -> user.getId().equals(userId)); - if (ObjectUtil.isNotEmpty(userName)) { - if (j == personIds.size() - 1) { - personNames += userName; - } else { - personNames += userName + "、"; + String personNames = ""; + // 获取排班组员名称 + for (int j = 0; j < personIds.size(); j++) { + Long userId = personIds.get(j); + String userName = deptUserMap.get(userId); + // 把排班的组员从休息名单中移除 + restUserList.removeIf(user -> user.getId().equals(userId)); + if (ObjectUtil.isNotEmpty(userName)) { + if (j == personIds.size() - 1) { + personNames += userName; + } else { + personNames += userName + "、"; + } } } + reportExcel.setManagerName(managerName); + reportExcel.setPersonNames(personNames); + dutyMainReportExcelList.add(reportExcel); } - reportExcel.setManagerName(managerName); - reportExcel.setPersonNames(personNames); - dutyMainReportExcelList.add(reportExcel); - } - // 剩下组员都休息,添加休息排班 - ImsDutyMainReportExcel restReportExcel = new ImsDutyMainReportExcel(); - restReportExcel.setDutyDate(dateStr); - restReportExcel.setClassName("休息"); - restReportExcel.setManagerName("无班组长"); - String personNames = ""; - // 获取休息组员的名称 - for (int j = 0; j < restUserList.size(); j++) { - User user = restUserList.get(j); - if (ObjectUtil.isNotEmpty(user)) { - if (j == restUserList.size() - 1) { - personNames += user.getName(); - } else { - personNames += user.getName() + "、"; + // 剩下组员都休息,添加休息排班 + ImsDutyMainReportExcel restReportExcel = new ImsDutyMainReportExcel(); + restReportExcel.setDutyDate(dateStr); + restReportExcel.setClassName("休息"); + restReportExcel.setManagerName("无班组长"); + String personNames = ""; + // 获取休息组员的名称 + for (int j = 0; j < restUserList.size(); j++) { + User user = restUserList.get(j); + if (ObjectUtil.isNotEmpty(user)) { + if (j == restUserList.size() - 1) { + personNames += user.getName(); + } else { + personNames += user.getName() + "、"; + } } } + restReportExcel.setPersonNames(personNames); + dutyMainReportExcelList.add(restReportExcel); } - restReportExcel.setPersonNames(personNames); - dutyMainReportExcelList.add(restReportExcel); + return dutyMainReportExcelList; } - return dutyMainReportExcelList; - } - @Override - public R changDutyMainGroupLeader(ExchangeGroupLeader changeGroupLeader) { - if(changeGroupLeader == null){ - return R.fail("传入换班数据不能为空"); - } - if(!changeGroupLeader.getFromDeptId().equals(changeGroupLeader.getToDeptId())){ - return R.fail("不同机构间不能换班"); - } + @Override + public R changDutyMainGroupLeader(ExchangeGroupLeader changeGroupLeader) { + if(changeGroupLeader == null){ + return R.fail("传入换班数据不能为空"); + } + if(!changeGroupLeader.getFromDeptId().equals(changeGroupLeader.getToDeptId())){ + return R.fail("不同机构间不能换班"); + } - if(changeGroupLeader.getFromDate().compareTo(changeGroupLeader.getToDate())>0){ - return R.fail("换班日期不能大于被换班日期"); - } + if(changeGroupLeader.getFromDate().compareTo(changeGroupLeader.getToDate())>0){ + return R.fail("换班日期不能大于被换班日期"); + } - if(changeGroupLeader.getFromDate().compareTo(changeGroupLeader.getToDate()) == 0 - && changeGroupLeader.getFromClassId().equals(changeGroupLeader.getToClassId())){ - return R.fail("同一日期同一班次无须换班"); - } + if(changeGroupLeader.getFromDate().compareTo(changeGroupLeader.getToDate()) == 0 + && changeGroupLeader.getFromClassId().equals(changeGroupLeader.getToClassId())){ + return R.fail("同一日期同一班次无须换班"); + } - List aDutyList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getDutyDate, changeGroupLeader.getFromDate()); - eq(ImsDutyMainEntity::getCreateDept, changeGroupLeader.getFromDeptId()); - eq(ImsDutyMainEntity::getClassId, changeGroupLeader.getFromClassId()); - eq(ImsDutyMainEntity::getIsDeleted, 0); - }}); + List aDutyList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getDutyDate, changeGroupLeader.getFromDate()); + eq(ImsDutyMainEntity::getCreateDept, changeGroupLeader.getFromDeptId()); + eq(ImsDutyMainEntity::getClassId, changeGroupLeader.getFromClassId()); + eq(ImsDutyMainEntity::getIsDeleted, 0); + }}); - if(aDutyList== null|| aDutyList.isEmpty()){ - return R.fail("换班人无排班计划"); - } + if(aDutyList== null|| aDutyList.isEmpty()){ + return R.fail("换班人无排班计划"); + } - List bDutyList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getDutyDate, changeGroupLeader.getToDate()); - eq(ImsDutyMainEntity::getCreateDept, changeGroupLeader.getToDeptId()); - eq(ImsDutyMainEntity::getClassId, changeGroupLeader.getToClassId()); - eq(ImsDutyMainEntity::getIsDeleted, 0); - }}); - if(bDutyList== null|| bDutyList.isEmpty()){ - return R.fail("被换班人无排班计划"); - } + List bDutyList = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getDutyDate, changeGroupLeader.getToDate()); + eq(ImsDutyMainEntity::getCreateDept, changeGroupLeader.getToDeptId()); + eq(ImsDutyMainEntity::getClassId, changeGroupLeader.getToClassId()); + eq(ImsDutyMainEntity::getIsDeleted, 0); + }}); + if(bDutyList== null|| bDutyList.isEmpty()){ + return R.fail("被换班人无排班计划"); + } - ImsDutyMainEntity aDutyMainEntity=aDutyList.get(0); - //查询换换班是否在值班 - if(aDutyMainEntity.getStatus()!=0){ - return R.fail("换班人待值班状态才能换班"); - } + ImsDutyMainEntity aDutyMainEntity=aDutyList.get(0); + //查询换换班是否在值班 + if(aDutyMainEntity.getStatus()!=0){ + return R.fail("换班人待值班状态才能换班"); + } - ImsDutyGroupEntity aGroupEntity = dutyGroupMapper.selectById(aDutyMainEntity.getDutyGroupId()); - Long aManagerId=aGroupEntity.getManagerId(); - List aPersonEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, aDutyMainEntity.getId()); - eq(ImsDutyMainPersonEntity::getIsDeleted, 0); - }}); + ImsDutyGroupEntity aGroupEntity = dutyGroupMapper.selectById(aDutyMainEntity.getDutyGroupId()); + Long aManagerId=aGroupEntity.getManagerId(); + List aPersonEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, aDutyMainEntity.getId()); + eq(ImsDutyMainPersonEntity::getIsDeleted, 0); + }}); - ImsDutyMainEntity bDutyMainEntity=bDutyList.get(0); - //查询换换班是否在值班 - if(bDutyMainEntity.getStatus()!=0){ - return R.fail("被换班人待值班状态才能换班"); - } - ImsDutyGroupEntity bGroupEntity = dutyGroupMapper.selectById(bDutyMainEntity.getDutyGroupId()); - Long bManagerId=bGroupEntity.getManagerId(); - List bPersonEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, bDutyMainEntity.getId()); - eq(ImsDutyMainPersonEntity::getIsDeleted, 0); - }}); + ImsDutyMainEntity bDutyMainEntity=bDutyList.get(0); + //查询换换班是否在值班 + if(bDutyMainEntity.getStatus()!=0){ + return R.fail("被换班人待值班状态才能换班"); + } + ImsDutyGroupEntity bGroupEntity = dutyGroupMapper.selectById(bDutyMainEntity.getDutyGroupId()); + Long bManagerId=bGroupEntity.getManagerId(); + List bPersonEntityList = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, bDutyMainEntity.getId()); + eq(ImsDutyMainPersonEntity::getIsDeleted, 0); + }}); - String aPersonIds=aDutyMainEntity.getDutyPersonIds(); - String bPersonIds=bDutyMainEntity.getDutyPersonIds(); - //更新duty_main - ImsDutyMainEntity aEntity= SerializationUtils.clone(aDutyMainEntity); - ImsDutyMainEntity bEntity=SerializationUtils.clone(bDutyMainEntity); + String aPersonIds=aDutyMainEntity.getDutyPersonIds(); + String bPersonIds=bDutyMainEntity.getDutyPersonIds(); + //更新duty_main + ImsDutyMainEntity aEntity= SerializationUtils.clone(aDutyMainEntity); + ImsDutyMainEntity bEntity=SerializationUtils.clone(bDutyMainEntity); - aEntity.setDutyGroupId(bDutyMainEntity.getDutyGroupId()); - aPersonIds=aPersonIds.replaceAll(aManagerId+"",bManagerId+""); - aEntity.setDutyPersonIds(aPersonIds); - this.baseMapper.updateById(aEntity); + aEntity.setDutyGroupId(bDutyMainEntity.getDutyGroupId()); + aPersonIds=aPersonIds.replaceAll(aManagerId+"",bManagerId+""); + aEntity.setDutyPersonIds(aPersonIds); + this.baseMapper.updateById(aEntity); - bEntity.setDutyGroupId(aDutyMainEntity.getDutyGroupId()); - bPersonIds=bPersonIds.replaceAll(bManagerId+"",aManagerId+""); - bEntity.setDutyPersonIds(bPersonIds); - this.baseMapper.updateById(bEntity); + bEntity.setDutyGroupId(aDutyMainEntity.getDutyGroupId()); + bPersonIds=bPersonIds.replaceAll(bManagerId+"",aManagerId+""); + bEntity.setDutyPersonIds(bPersonIds); + this.baseMapper.updateById(bEntity); - //更新 duty_main_person - for(ImsDutyMainPersonEntity entity:aPersonEntityList){ - if(entity.getDutyPerson().equals(aManagerId)){ - entity.setDutyPerson(bManagerId); - } + //更新 duty_main_person + for(ImsDutyMainPersonEntity entity:aPersonEntityList){ + if(entity.getDutyPerson().equals(aManagerId)){ + entity.setDutyPerson(bManagerId); + } // entity.setDutyGroupName(bGroupEntity.getGroupName()); - entity.setDutyChargePerson(bManagerId); - } - iImsDutyMainPersonService.updateBatchById(aPersonEntityList); - - for(ImsDutyMainPersonEntity entity:bPersonEntityList){ - if(entity.getDutyPerson().equals(bManagerId)){ - entity.setDutyPerson(aManagerId); + entity.setDutyChargePerson(bManagerId); } + iImsDutyMainPersonService.updateBatchById(aPersonEntityList); + + for(ImsDutyMainPersonEntity entity:bPersonEntityList){ + if(entity.getDutyPerson().equals(bManagerId)){ + entity.setDutyPerson(aManagerId); + } // entity.setDutyGroupName(aGroupEntity.getGroupName()); - entity.setDutyChargePerson(aManagerId); - } - iImsDutyMainPersonService.updateBatchById(bPersonEntityList); + entity.setDutyChargePerson(aManagerId); + } + iImsDutyMainPersonService.updateBatchById(bPersonEntityList); - return R.success("班组长换班成功"); - } + return R.success("班组长换班成功"); + } - /** - * 获取上一班组 - * - * @param item - * @return - */ - private NextDutyInfoVo getUpDutyInfo(DutyInfoVo item) { - if(ObjectUtil.isEmpty(item.getPreDutyId())){ - return null; - } - DutyMainInfoVo dutyMainInfoVo = this.baseMapper.queryDutyInfoV2(item.getPreDutyId()); - if (null == dutyMainInfoVo.getDutyGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); - last(" LIMIT 1"); - }}); - dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); - dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); - dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); - dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } - if (ObjectUtil.isEmpty(dutyMainInfoVo)) { - return null; + /** + * 获取上一班组 + * + * @param item + * @return + */ + private NextDutyInfoVo getUpDutyInfo(DutyInfoVo item) { + if(ObjectUtil.isEmpty(item.getPreDutyId())){ + return null; + } + DutyMainInfoVo dutyMainInfoVo = this.baseMapper.queryDutyInfoV2(item.getPreDutyId()); + if (null == dutyMainInfoVo.getDutyGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); + last(" LIMIT 1"); + }}); + dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); + dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); + dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); + dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } + if (ObjectUtil.isEmpty(dutyMainInfoVo)) { + return null; + } + // 赋值 + NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); + dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); + dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); + dutyInfoVo.setDateTime(dutyMainInfoVo.getDateTime()); + dutyInfoVo.setStartTime(dutyMainInfoVo.getStartTime()); + dutyInfoVo.setEndTime(dutyMainInfoVo.getEndTime()); + // 负责人 + User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + dutyInfoVo.setManagerName(user.getName()); + dutyInfoVo.setManagerPhone(user.getPhone()); + } + // 发电量 + dutyInfoVo.setGeneratingCapacity(0); + return dutyInfoVo; + } + + /** + * 获取下一班组 + * + * @param item + * @return + */ + private NextDutyInfoVo getNextDutyInfo(DutyInfoVo item) { + DutyMainInfoVo dutyMainInfoVo = getNextDutyDataV2(item.getId()); + if (ObjectUtil.isEmpty(dutyMainInfoVo)) { + return null; + } + // 赋值 + NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); + dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); + dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); + // 负责人 + User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + dutyInfoVo.setManagerName(user.getName()); + dutyInfoVo.setManagerPhone(user.getPhone()); + } + dutyInfoVo.setGeneratingCapacity(0); + return dutyInfoVo; } - // 赋值 - NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); - dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); - dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); - dutyInfoVo.setDateTime(dutyMainInfoVo.getDateTime()); - dutyInfoVo.setStartTime(dutyMainInfoVo.getStartTime()); - dutyInfoVo.setEndTime(dutyMainInfoVo.getEndTime()); - // 负责人 - User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - dutyInfoVo.setManagerName(user.getName()); - dutyInfoVo.setManagerPhone(user.getPhone()); - } - // 发电量 - dutyInfoVo.setGeneratingCapacity(0); - return dutyInfoVo; - } - /** - * 获取下一班组 - * - * @param item - * @return - */ - private NextDutyInfoVo getNextDutyInfo(DutyInfoVo item) { - DutyMainInfoVo dutyMainInfoVo = getNextDutyDataV2(item.getId()); - if (ObjectUtil.isEmpty(dutyMainInfoVo)) { + + private AuditVo getUser(Long personId) { + User user = UserCache.getUser(personId); + if (ObjectUtil.isNotEmpty(user)) { + AuditVo auditVo = new AuditVo(); + auditVo.setPersonId(personId); + auditVo.setPersonName(user.getName()); + auditVo.setPhone(user.getPhone()); + return auditVo; + } return null; } - // 赋值 - NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); - dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); - dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); - // 负责人 - User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - dutyInfoVo.setManagerName(user.getName()); - dutyInfoVo.setManagerPhone(user.getPhone()); - } - dutyInfoVo.setGeneratingCapacity(0); - return dutyInfoVo; - } - private AuditVo getUser(Long personId) { - User user = UserCache.getUser(personId); - if (ObjectUtil.isNotEmpty(user)) { - AuditVo auditVo = new AuditVo(); - auditVo.setPersonId(personId); - auditVo.setPersonName(user.getName()); - auditVo.setPhone(user.getPhone()); - return auditVo; - } - return null; - } + private R cycleSchedulingTow(ImsSchedulingVo imsSchedulingVo) { + Calendar cal = Calendar.getInstance(); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH) + 1;//获取月份 + int day = cal.get(Calendar.DAY_OF_MONTH); + String date1 = getDate(year, month, day); + String date2 = DateUtils.dayStringDate(date1, 1, true); + if (!imsSchedulingVo.getStartDate().equals(date2)) { + String deptId = AuthUtil.getDeptId(); + if (null != imsSchedulingVo.getCreateDept()) { + deptId = imsSchedulingVo.getCreateDept().toString(); + } + String minusOnedDay = DateUtils.dayStringDate(imsSchedulingVo.getStartDate(), 1, false); + List imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, Long.valueOf(deptId)); + if (CollectionUtil.isEmpty(imsDutyMainEntities)) { + return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); + } + } + String[] start = imsSchedulingVo.getStartDate().split("-"); + String[] end = imsSchedulingVo.getEndDate().split("-"); + //日期 + List dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2])); - private R cycleSchedulingTow(ImsSchedulingVo imsSchedulingVo) { - Calendar cal = Calendar.getInstance(); - int year = cal.get(Calendar.YEAR); - int month = cal.get(Calendar.MONTH) + 1;//获取月份 - int day = cal.get(Calendar.DAY_OF_MONTH); - String date1 = getDate(year, month, day); - String date2 = DateUtils.dayStringDate(date1, 1, true); - if (!imsSchedulingVo.getStartDate().equals(date2)) { - String deptId = AuthUtil.getDeptId(); - if (null != imsSchedulingVo.getCreateDept()) { - deptId = imsSchedulingVo.getCreateDept().toString(); - } - String minusOnedDay = DateUtils.dayStringDate(imsSchedulingVo.getStartDate(), 1, false); - List imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, Long.valueOf(deptId)); - if (CollectionUtil.isEmpty(imsDutyMainEntities)) { - return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); + if (imsSchedulingVo.isCompose() == false) { + List imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper() {{ + le(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getEndDate()); + eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); + ge(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getStartDate()); + }}); + if (CollectionUtil.isNotEmpty(imsDutyMainEntities2)) { + return R.data(1); + } } - } - - String[] start = imsSchedulingVo.getStartDate().split("-"); - String[] end = imsSchedulingVo.getEndDate().split("-"); - //日期 - List dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2])); - if (imsSchedulingVo.isCompose() == false) { - List imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper() {{ - le(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getEndDate()); - eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - ge(ImsDutyMainEntity::getDutyDate, imsSchedulingVo.getStartDate()); - }}); - if (CollectionUtil.isNotEmpty(imsDutyMainEntities2)) { - return R.data(1); + if (imsSchedulingVo.getTemplate()) { + if (!doSaveTemplate(imsSchedulingVo)) { + return R.fail("模版名称已存在"); + } } - } - if (imsSchedulingVo.getTemplate()) { - if (!doSaveTemplate(imsSchedulingVo)) { - return R.fail("模版名称已存在"); + String[] dutyArrIds = imsSchedulingVo.getDutyArrIds(); + if (CollectionUtil.isNotEmpty(dates)) { + this.baseMapper.delete(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); + in(ImsDutyMainEntity::getDutyDate, dates); + }}); } - } + String subDayDate = DateUtils.dayDate(DateUtil.parse(imsSchedulingVo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE); - String[] dutyArrIds = imsSchedulingVo.getDutyArrIds(); - if (CollectionUtil.isNotEmpty(dates)) { - this.baseMapper.delete(new LambdaQueryWrapper() {{ + ImsDutyMainEntity imsDutyMainEntity1 = this.getOne(new LambdaQueryWrapper() {{ eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - in(ImsDutyMainEntity::getDutyDate, dates); + eq(ImsDutyMainEntity::getDutyDate, subDayDate); + ne(ImsDutyMainEntity::getStatus, "-1"); + orderByDesc(ImsDutyMainEntity::getId).last(" LIMIT 1"); }}); - } - String subDayDate = DateUtils.dayDate(DateUtil.parse(imsSchedulingVo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE); - - ImsDutyMainEntity imsDutyMainEntity1 = this.getOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getCreateDept, imsSchedulingVo.getCreateDept()); - eq(ImsDutyMainEntity::getDutyDate, subDayDate); - ne(ImsDutyMainEntity::getStatus, "-1"); - orderByDesc(ImsDutyMainEntity::getId).last(" LIMIT 1"); - }}); - //查询所有班组人员 - List list = imsDutyGroupPService.list(); - - - List imsDutyMainEntityList = new ArrayList<>(); - String proDutyMainId = ""; - //排班 - for (int i = 1; i <= dates.size(); i++) { - String date = dates.get(i - 1); - for (int j = 1; j <= dutyArrIds.length; j++) { - String classId = dutyArrIds[j - 1]; - //按值班周期的天数取模 - int temp = i % imsSchedulingVo.getDutyNum(); - //值班下标 - int tempSub = temp - 1; - //如果整除,取最后一个值班 - if (temp == 0) { - tempSub = imsSchedulingVo.getDutyNum() - 1; - } - //获取对应班组的值班班次 - String groupId = imsSchedulingVo.getDutyOrderIds().get(classId)[tempSub]; - //人员IDS - String personIds = ""; - if ("0".equals(classId)) { - String[] split = groupId.split(","); - if (ObjectUtil.isNotEmpty(split)) { - for (String dutyGroupId : split) { - List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(dutyGroupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(collectPerson)) { - personIds = StringUtils.join(collectPerson, "^"); - } - if (StringUtil.isNotBlank(dutyGroupId)) { - ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date); - imsDutyMainEntity.setStatus(-1); - imsDutyMainEntity.setDutyPersonIds(personIds); - imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); - Long id = IdWorker.getId(); - imsDutyMainEntity.setId(id); - imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); - imsDutyMainEntityList.add(imsDutyMainEntity); + //查询所有班组人员 + List list = imsDutyGroupPService.list(); + + + List imsDutyMainEntityList = new ArrayList<>(); + String proDutyMainId = ""; + //排班 + for (int i = 1; i <= dates.size(); i++) { + String date = dates.get(i - 1); + for (int j = 1; j <= dutyArrIds.length; j++) { + String classId = dutyArrIds[j - 1]; + //按值班周期的天数取模 + int temp = i % imsSchedulingVo.getDutyNum(); + //值班下标 + int tempSub = temp - 1; + //如果整除,取最后一个值班 + if (temp == 0) { + tempSub = imsSchedulingVo.getDutyNum() - 1; + } + //获取对应班组的值班班次 + String groupId = imsSchedulingVo.getDutyOrderIds().get(classId)[tempSub]; + //人员IDS + String personIds = ""; + if ("0".equals(classId)) { + String[] split = groupId.split(","); + if (ObjectUtil.isNotEmpty(split)) { + for (String dutyGroupId : split) { + List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(dutyGroupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collectPerson)) { + personIds = StringUtils.join(collectPerson, "^"); + } + if (StringUtil.isNotBlank(dutyGroupId)) { + ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); + setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(dutyGroupId), date); + imsDutyMainEntity.setStatus(-1); + imsDutyMainEntity.setDutyPersonIds(personIds); + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + Long id = IdWorker.getId(); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); + imsDutyMainEntityList.add(imsDutyMainEntity); + } } } - } - } else { - List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(collectPerson)) { - personIds = StringUtils.join(collectPerson, "^"); - } - if (Func.isBlank(personIds)) { - return R.fail("班组存在人员为空,禁止排班!"); - } + } else { + List collectPerson = list.stream().filter(iter -> iter.getGroupId().toString().equals(groupId)).map(iter -> iter.getPersonId()).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(collectPerson)) { + personIds = StringUtils.join(collectPerson, "^"); + } + if (Func.isBlank(personIds)) { + return R.fail("班组存在人员为空,禁止排班!"); + } - ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); - setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(groupId), date); - if (Func.isBlank(proDutyMainId)) { - if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { - proDutyMainId = imsDutyMainEntity1.getId().toString(); + ImsDutyMainEntity imsDutyMainEntity = new ImsDutyMainEntity(); + setMainEntity(imsDutyMainEntity, Long.valueOf(classId), Long.valueOf(groupId), date); + if (Func.isBlank(proDutyMainId)) { + if (ObjectUtil.isNotEmpty(imsDutyMainEntity1)) { + proDutyMainId = imsDutyMainEntity1.getId().toString(); + } + + } + if (StringUtil.isNotBlank(proDutyMainId)) { + imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); } + if (StringUtil.isNotBlank(personIds)) { + imsDutyMainEntity.setDutyPersonIds(personIds); + } + imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); + Long id = IdWorker.getId(imsDutyMainEntity); + imsDutyMainEntity.setId(id); + imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); + imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); + imsDutyMainEntityList.add(imsDutyMainEntity); + proDutyMainId = id == null ? "" : imsDutyMainEntity.getId().toString(); + BeanUtils.copyProperties(imsDutyMainEntity,imsDutyMainEntity1); } - if (StringUtil.isNotBlank(proDutyMainId)) { - imsDutyMainEntity.setPreDutyId(Long.valueOf(proDutyMainId)); - } + } + } - if (StringUtil.isNotBlank(personIds)) { - imsDutyMainEntity.setDutyPersonIds(personIds); + ThreadTask.dutyTask(imsDutyMainEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); + return R.success("操作成功,系统正在排班中,请稍后查看"); + } + + + public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, Long classId, Long groupId, String date) { + imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); + imsDutyMainEntity.setClassId(classId); + imsDutyMainEntity.setDutyGroupId(groupId); + imsDutyMainEntity.setStatus(0); + imsDutyMainEntity.setCreateTime(new Date()); + } + + public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, String classId, String date) { + imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); + imsDutyMainEntity.setClassId(Long.valueOf(classId)); + imsDutyMainEntity.setStatus(0); + imsDutyMainEntity.setCreateTime(new Date()); + } + + /** + * 根据 年、月 获取对应的月份 的 天数 + */ + public static int getDaysByYearMonth(int year, int month) { + Calendar a = Calendar.getInstance(); + a.set(Calendar.YEAR, year); + a.set(Calendar.MONTH, month - 1); + a.set(Calendar.DATE, 1); + a.roll(Calendar.DATE, -1); + int maxDate = a.get(Calendar.DATE); + return maxDate; + } + + /** + * 获取当班 + * + * @return + */ + @Override + public List getDutyData(Long deptId) { + return getDutyDataV2(deptId); + } + + @Override + public List getDutyDataV2(Long deptId) { + List dutyMainInfoVos = this.baseMapper.selectDutyMainInfoVoV2(deptId); + dutyMainInfoVos = dutyMainInfoVos.stream().map(s -> { + if (null == s.getDutyGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); + last("limit 1"); + }}); + if(ObjectUtil.isNotEmpty(imsDutyMainPersonEntity.getDutyChargePerson())){ + s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getDutyGroupId()); + if(imsDutyGroupEntity != null){ + s.setGroupName(imsDutyGroupEntity.getGroupName()); + s.setDutyGroupId(imsDutyGroupEntity.getId()); + if(ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())){ + s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } } - imsDutyMainEntity.setCreateDept(imsSchedulingVo.getCreateDept()); - Long id = IdWorker.getId(imsDutyMainEntity); - imsDutyMainEntity.setId(id); - imsDutyMainEntity.setCreateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setUpdateUser(AuthUtil.getUserId()); - imsDutyMainEntity.setTenantId(AuthUtil.getTenantId()); - imsDutyMainEntityList.add(imsDutyMainEntity); - proDutyMainId = id == null ? "" : imsDutyMainEntity.getId().toString(); - BeanUtils.copyProperties(imsDutyMainEntity,imsDutyMainEntity1); } - } + return s; + }).collect(Collectors.toList()); + return dutyMainInfoVos; } - ThreadTask.dutyTask(imsDutyMainEntityList, imsSchedulingVo.getEndDate(), proDutyMainId, imsSchedulingVo.getCreateDept(), imsSchedulingVo.getDutyClassTypeId()); - return R.success("操作成功,系统正在排班中,请稍后查看"); - } - - - public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, Long classId, Long groupId, String date) { - imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); - imsDutyMainEntity.setClassId(classId); - imsDutyMainEntity.setDutyGroupId(groupId); - imsDutyMainEntity.setStatus(0); - imsDutyMainEntity.setCreateTime(new Date()); - } - - public void setMainEntity(ImsDutyMainEntity imsDutyMainEntity, String classId, String date) { - imsDutyMainEntity.setDutyDate(DateUtil.parse(date, DateUtil.PATTERN_DATE)); - imsDutyMainEntity.setClassId(Long.valueOf(classId)); - imsDutyMainEntity.setStatus(0); - imsDutyMainEntity.setCreateTime(new Date()); - } - - /** - * 根据 年、月 获取对应的月份 的 天数 - */ - public static int getDaysByYearMonth(int year, int month) { - Calendar a = Calendar.getInstance(); - a.set(Calendar.YEAR, year); - a.set(Calendar.MONTH, month - 1); - a.set(Calendar.DATE, 1); - a.roll(Calendar.DATE, -1); - int maxDate = a.get(Calendar.DATE); - return maxDate; - } - - /** - * 获取当班 - * - * @return - */ - @Override - public List getDutyData(Long deptId) { - return getDutyDataV2(deptId); - } + @Override + public DutyMainInfoVo getNextDutyData(Long parentId) { + return this.baseMapper.selectDutyMainInfoSign(parentId); + } - @Override - public List getDutyDataV2(Long deptId) { - List dutyMainInfoVos = this.baseMapper.selectDutyMainInfoVoV2(deptId); - dutyMainInfoVos = dutyMainInfoVos.stream().map(s -> { - if (null == s.getDutyGroupId()) { + @Override + public DutyMainInfoVo getNextDutyDataV2(Long parentId) { + DutyMainInfoVo dutyMainInfoVo = this.baseMapper.selectDutyMainInfoSignV2(parentId); + if(ObjectUtil.isEmpty(dutyMainInfoVo)){ + return new DutyMainInfoVo(); + } + if (null == dutyMainInfoVo.getDutyGroupId()) { ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); + eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); last("limit 1"); }}); - if(ObjectUtil.isNotEmpty(imsDutyMainPersonEntity.getDutyChargePerson())){ - s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + if(ObjectUtil.isNotEmpty(imsDutyMainPersonEntity) && ObjectUtil.isNotEmpty(imsDutyMainPersonEntity.getDutyChargePerson())){ + dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); } } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getDutyGroupId()); - if(imsDutyGroupEntity != null){ - s.setGroupName(imsDutyGroupEntity.getGroupName()); - s.setDutyGroupId(imsDutyGroupEntity.getId()); - if(ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())){ - s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); + dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); + dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); + if(ObjectUtil.isNotEmpty(imsDutyGroupEntity) && ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())){ + dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); } } - return s; - }).collect(Collectors.toList()); - return dutyMainInfoVos; - } - - @Override - public DutyMainInfoVo getNextDutyData(Long parentId) { - return this.baseMapper.selectDutyMainInfoSign(parentId); - } - - @Override - public DutyMainInfoVo getNextDutyDataV2(Long parentId) { - DutyMainInfoVo dutyMainInfoVo = this.baseMapper.selectDutyMainInfoSignV2(parentId); - if(ObjectUtil.isEmpty(dutyMainInfoVo)){ - return new DutyMainInfoVo(); - } - if (null == dutyMainInfoVo.getDutyGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = imsDutyMainPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); - last("limit 1"); - }}); - if(ObjectUtil.isNotEmpty(imsDutyMainPersonEntity) && ObjectUtil.isNotEmpty(imsDutyMainPersonEntity.getDutyChargePerson())){ - dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); - dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); - dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); - if(ObjectUtil.isNotEmpty(imsDutyGroupEntity) && ObjectUtil.isNotEmpty(imsDutyGroupEntity.getManagerId())){ - dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } + return dutyMainInfoVo; } - return dutyMainInfoVo; - } }