|
@@ -0,0 +1,113 @@
|
|
|
+package com.persagy.fm.scheduling.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.collect.Sets;
|
|
|
+import com.persagy.fm.common.response.PageList;
|
|
|
+import com.persagy.fm.scheduling.dao.WorkScheduleMapper;
|
|
|
+import com.persagy.fm.scheduling.model.WorkSchedule;
|
|
|
+import com.persagy.fm.scheduling.transform.WorkScheduleTransform;
|
|
|
+import com.persagy.fm.scheduling.vo.request.ScheduleListQueryVO;
|
|
|
+import com.persagy.fm.scheduling.vo.request.UpdateScheduleVO;
|
|
|
+import com.persagy.fm.scheduling.vo.response.OnePersonScheduleVO;
|
|
|
+import com.persagy.fm.scheduling.vo.response.StatisticalInfoVO;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.ConcurrentMap;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class WorkScheduleService {
|
|
|
+
|
|
|
+ private final WorkScheduleMapper workScheduleMapper;
|
|
|
+ private final WorkScheduleTransform workScheduleTransform;
|
|
|
+
|
|
|
+
|
|
|
+ public PageList<OnePersonScheduleVO> scheduleList(ScheduleListQueryVO vo) {
|
|
|
+
|
|
|
+ //todo 根据父级部门id 获取下面所有子级部门的部门id
|
|
|
+ final Set<String> departmentIds = Sets.newHashSet();
|
|
|
+ QueryWrapper<WorkSchedule> wrapper = new QueryWrapper<WorkSchedule>().eq("project_id", vo.getProjectId())
|
|
|
+ .in("department_id", departmentIds)
|
|
|
+ .eq("year", vo.getYear())
|
|
|
+ .eq("month", vo.getMonth());
|
|
|
+
|
|
|
+ Page<WorkSchedule> page = new Page<WorkSchedule>().setSize(vo.getPageSize()).setCurrent(vo.getPageNum());
|
|
|
+
|
|
|
+
|
|
|
+ Page<WorkSchedule> workSchedulePage = workScheduleMapper.selectPage(page, wrapper);
|
|
|
+ final List<WorkSchedule> records = workSchedulePage.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(records)) return new PageList<>(Lists.newArrayList(), 0);
|
|
|
+ ConcurrentMap<String, List<WorkSchedule>> personSchedulesMap = records.stream()
|
|
|
+ .collect(Collectors.groupingByConcurrent(WorkSchedule::getPersonId));
|
|
|
+
|
|
|
+ //todo 根据personIds 获取用户信息
|
|
|
+ Set<String> personIds = personSchedulesMap.keySet();
|
|
|
+
|
|
|
+ List<OnePersonScheduleVO> personScheduleList = personSchedulesMap
|
|
|
+ .entrySet()
|
|
|
+ .stream().map(entry -> {
|
|
|
+ List<WorkSchedule> value = entry.getValue();
|
|
|
+ AtomicInteger workHours = new AtomicInteger();
|
|
|
+ AtomicInteger remainWorkMinutes = new AtomicInteger();
|
|
|
+ List<StatisticalInfoVO.OneStatisticalInfo> oneStatisticalInfos = value.stream()
|
|
|
+ .collect(Collectors.groupingByConcurrent(WorkSchedule::getWorkTimeType))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(keyValue -> new StatisticalInfoVO.OneStatisticalInfo()
|
|
|
+ .setWorkTimeType(keyValue.getKey())
|
|
|
+ .setTimes(keyValue.getValue().size()))
|
|
|
+ .peek(a -> {
|
|
|
+ //todo 根据工作时间的配置 去处理工作时间的统计问题
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<OnePersonScheduleVO.WorkScheduleVO> workScheduleVOS = value.stream()
|
|
|
+ .map(workScheduleTransform::toWorkScheduleVO)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return new OnePersonScheduleVO()
|
|
|
+ .setStatisticalInfoVO(new StatisticalInfoVO()
|
|
|
+ .setStatisticalInfos(oneStatisticalInfos)
|
|
|
+ .setWorkHours(workHours.get())
|
|
|
+ .setWorkMinutes(remainWorkMinutes.get()))
|
|
|
+ .setPersonInfo(new OnePersonScheduleVO.PersonInfo().setPersonId(entry.getKey()))
|
|
|
+ .setWorkScheduleVOS(workScheduleVOS);
|
|
|
+ })
|
|
|
+
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return new PageList<>(personScheduleList, workSchedulePage.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean updateSchedule(UpdateScheduleVO vo) {
|
|
|
+ List<UpdateScheduleVO.ScheduleVO> scheduleVOS = vo.getScheduleVOS();
|
|
|
+ if (CollectionUtils.isEmpty(scheduleVOS)) return true;
|
|
|
+ Set<String> ids = scheduleVOS.stream()
|
|
|
+ .map(UpdateScheduleVO.ScheduleVO::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ final List<Object> usefulIds = Lists.newArrayList();
|
|
|
+ List<WorkSchedule> workSchedules = workScheduleMapper.selectBatchIds(ids);
|
|
|
+ if (CollectionUtils.isEmpty(workSchedules)) throw new RuntimeException("排班数据id无效");
|
|
|
+ if (workSchedules.size() < ids.size()) {
|
|
|
+ final Set<String> dbIds = workSchedules.stream().map(WorkSchedule::getId).collect(Collectors.toSet());
|
|
|
+ usefulIds.addAll(dbIds);
|
|
|
+ String errorIdStr = ids.stream().filter(a -> !dbIds.contains(a)).collect(Collectors.joining(","));
|
|
|
+ log.info("错误的排班修改数据{}", errorIdStr);
|
|
|
+ }
|
|
|
+ scheduleVOS.stream().filter(usefulIds::contains).forEach(a -> workSchedules.forEach(b -> {
|
|
|
+ if (a.getId().equals(b.getId())) {
|
|
|
+ b.setWorkTimeType(a.getWorkTimeType());
|
|
|
+ b.setDay(a.getDay());
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ workSchedules.forEach(workScheduleMapper::updateById);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+}
|