|
|
|
@ -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,6 +304,242 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
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<ImsDutyMainEntity> imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, vo.getDeptId()); |
|
|
|
|
if (CollectionUtil.isEmpty(imsDutyMainEntities)) { |
|
|
|
|
return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<String> 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<ImsDutyMainEntity> imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper<ImsDutyMainEntity>() {{ |
|
|
|
|
ge(ImsDutyMainEntity::getDutyDate, vo.getStartDate()); |
|
|
|
|
le(ImsDutyMainEntity::getDutyDate, vo.getEndDate()); |
|
|
|
|
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); |
|
|
|
|
}}); |
|
|
|
|
List<ImsDutyMainPersonEntity> imsDutyMainPersonEntities = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{ |
|
|
|
|
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<ImsDutyMainEntity>() {{ |
|
|
|
|
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); |
|
|
|
|
in(ImsDutyMainEntity::getDutyDate, dates); |
|
|
|
|
}}); |
|
|
|
|
imsDutyMainPersonMapper.delete(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{ |
|
|
|
|
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<ImsDutyMainEntity>() {{ |
|
|
|
|
eq(ImsDutyMainEntity::getDutyDate, subDayDate); |
|
|
|
|
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId()); |
|
|
|
|
ne(ImsDutyMainEntity::getStatus, "-1"); |
|
|
|
|
orderByDesc(ImsDutyMainEntity::getId).last("LIMIT 1"); |
|
|
|
|
}}); |
|
|
|
|
|
|
|
|
|
String proDutyMainId=null; |
|
|
|
|
|
|
|
|
|
List<ImsDutyMainEntity> 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("排班失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//统一处理preDutyId
|
|
|
|
|
for(int i=1,count=imsDutyMainEntityList.size();i<count;i++){ |
|
|
|
|
ImsDutyMainEntity entity=imsDutyMainEntityList.get(i); |
|
|
|
|
dealCreator(entity,vo.getDeptId()); |
|
|
|
|
ImsDutyMainEntity preEntity=imsDutyMainEntityList.get(i-1); |
|
|
|
|
entity.setPreDutyId(preEntity.getId()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// this.saveBatch(imsDutyMainEntityList);
|
|
|
|
|
|
|
|
|
|
List<ImsDutyMainPersonEntity> mainPersonEntityList=new ArrayList<>(); |
|
|
|
|
for(ImsDutyMainEntity imsDutyMainEntity:imsDutyMainEntityList) { |
|
|
|
|
String[] personIds=imsDutyMainEntity.getDutyPersonIds().split("\\^"); |
|
|
|
|
List<Long> 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("排班成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<ImsDutyMainEntity> getImsDutyMainEntityList(ImsSchedulingNewVo vo,List<String> dates){ |
|
|
|
|
List<ImsDutyMainEntity> list=new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
////班次信息
|
|
|
|
|
String[] classIdArr=vo.getClassIds().split("\\^"); |
|
|
|
|
List<Long> classIds=Arrays.asList(classIdArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList()); |
|
|
|
|
String[] classNameArr=vo.getClassNames().split("\\^"); |
|
|
|
|
Map<Long,String> classMap=new HashMap<>(); |
|
|
|
|
for(int i=0;i<classIds.size();i++){ |
|
|
|
|
classMap.put(classIds.get(i),classNameArr[i]); |
|
|
|
|
} |
|
|
|
|
if(vo.getPersonType().intValue() == 1){//班组
|
|
|
|
|
String[] groupIdsArr=vo.getGroupIds().split("\\^"); |
|
|
|
|
List<Long> groupIds=Arrays.asList(groupIdsArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList()); |
|
|
|
|
LambdaQueryWrapper<ImsDutyGroupEntity> groupWrapper=new LambdaQueryWrapper<>(); |
|
|
|
|
groupWrapper.in(ImsDutyGroupEntity::getId,groupIds); |
|
|
|
|
List<ImsDutyGroupEntity> groupEntities=dutyGroupMapper.selectList(groupWrapper); |
|
|
|
|
Map<Long,ImsDutyGroupEntity> groupMap=groupEntities.stream().collect(Collectors.toMap(ImsDutyGroupEntity::getId,Function.identity())); |
|
|
|
|
|
|
|
|
|
List<ImsDutyGroupPEntity> groupPEntities = imsDutyGroupPService.selectByGroupIds(groupIds); |
|
|
|
|
Map<Long,List<ImsDutyGroupPEntity>> personMap=groupPEntities.stream().collect(Collectors.groupingBy(ImsDutyGroupPEntity::getGroupId)); |
|
|
|
|
|
|
|
|
|
//班组信息
|
|
|
|
|
List<Map<String,String>> groups=new ArrayList<>(); |
|
|
|
|
for(Long groupId :groupIds){ |
|
|
|
|
Map<String,String> 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<ImsDutyGroupPEntity> groupPList=personMap.get(groupId); |
|
|
|
|
List<String> 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<Map<String,String>> persons=vo.getPersonIds(); |
|
|
|
|
for(Map<String,String> person:persons){ |
|
|
|
|
String personIds=person.get("personIds"); |
|
|
|
|
person.put("personIds",person.get("managerId")+"^"+personIds); |
|
|
|
|
} |
|
|
|
|
dealImsDutyMainEntityList(list,dates,classIds,persons,classMap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void dealImsDutyMainEntityList(List<ImsDutyMainEntity> list,List<String> dates, |
|
|
|
|
List<Long> classIds, |
|
|
|
|
List<Map<String,String>> persons,Map<Long,String> classMap){ |
|
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
int dateCount=dates.size(); |
|
|
|
|
int classCount=classIds.size(); |
|
|
|
|
int count=dateCount * classCount;//总工共排多少个
|
|
|
|
|
|
|
|
|
|
List<Map<String,String>> allPerson=new ArrayList<>();//总数队列
|
|
|
|
|
|
|
|
|
|
while (allPerson.size() < count){ |
|
|
|
|
for(Map<String,String> person:persons){ |
|
|
|
|
allPerson.add(person); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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<String, String> 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("日期格式不对"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public R importScheduling(MultipartFile file,String yearMonth,Long deptId) { |
|
|
|
|
String filename = file.getOriginalFilename(); |
|
|
|
|
ExcelToolListener excelToolListener = new ExcelToolListener(); |
|
|
|
|