package com.gkhy.safePlatform.account.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gkhy.safePlatform.account.entity.schedule.*; import com.gkhy.safePlatform.account.enums.CrossSkyEnum; import com.gkhy.safePlatform.account.enums.ScheduleStatusEnum; import com.gkhy.safePlatform.account.model.dto.req.DeleteDTO; import com.gkhy.safePlatform.account.model.dto.req.WorkTimeGroupReqDTO; import com.gkhy.safePlatform.account.model.dto.req.WorkTimePeriodReqDTO; import com.gkhy.safePlatform.account.model.dto.resp.*; import com.gkhy.safePlatform.account.service.WorkTimeService; import com.gkhy.safePlatform.account.service.baseService.TimeStrategyInfoSerive; import com.gkhy.safePlatform.account.service.baseService.WorkTimeGroupAndPeriodRelationInfoService; import com.gkhy.safePlatform.account.service.baseService.WorkTimeGroupInfoService; import com.gkhy.safePlatform.account.service.baseService.WorkTimePeriodInfoService; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.E; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.exception.AusinessException; import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.commons.vo.SearchResultVO; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.lang.Long; import java.util.stream.Collectors; @Service public class WorkTimeServiceImpl implements WorkTimeService { @Autowired private WorkTimePeriodInfoService workTimePeriodInfoService; @Autowired private WorkTimeGroupInfoService workTimeGroupInfoService; @Autowired private WorkTimeGroupAndPeriodRelationInfoService workTimeGroupAndPeriodRelationInfoService; @Autowired private TimeStrategyInfoSerive timeStrategyInfoSerive; /** * 新增工作时间组 */ @Transactional public ResultVO addWorkTimeGroup(ContextCacheUser currentUser,WorkTimeGroupReqDTO workTimeGroupReqDTO){ ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("添加成功!"); boolean flag = true; WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); //复制 BeanUtils.copyProperties(workTimeGroupReqDTO,workTimeGroupInfo); workTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); workTimeGroupInfo.setCreateUid(currentUser.getUid()); workTimeGroupInfo.setGmtCreate(new Date()); workTimeGroupInfo.setCreateBy(currentUser.getRealName()); //新增工作时间组 int count = workTimeGroupInfoService.saveWorkTimeGroupInfo(workTimeGroupInfo); //获取所有时间段 ResultVO workTimePeriod = this.getWorkTimePeriod(new WorkTimePeriodReqDTO()); List workTimePeriodRespDTOS = (List)workTimePeriod.getData(); List workTimePeriods = workTimeGroupReqDTO.getWorkTimePeriodIds(); List listRelation = new ArrayList<>(); workTimePeriods.forEach(item -> { List selectList = workTimePeriodRespDTOS.stream().filter(timePeriod -> item.equals(timePeriod.getId())).collect(Collectors.toList()); if(selectList.size() == 0){ throw new AusinessException(E.DATA_PARAM_NULL, "工作时间段不存在!"); } WorkTimeGroupAndPeriodRelationInfo workTimeGroupAndPeriodRelationInfo = new WorkTimeGroupAndPeriodRelationInfo(); workTimeGroupAndPeriodRelationInfo.setWorkTimePeriodId(item); workTimeGroupAndPeriodRelationInfo.setWorkTimeGroupId(workTimeGroupInfo.getId()); listRelation.add(workTimeGroupAndPeriodRelationInfo); }); //批量绑定到关系表中 flag = workTimeGroupAndPeriodRelationInfoService.saveBatch(listRelation); if (flag){ return resultVO; } return new ResultVO<>(ResultCodes.SERVER_ADD_ERROR); } /** * 修改工作时间组 */ @Transactional public ResultVO updateWorkTimeGroup(ContextCacheUser currentUser,WorkTimeGroupReqDTO workTimeGroupReqDTO){ ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("更新成功!"); boolean flag = true; WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); //复制 BeanUtils.copyProperties(workTimeGroupReqDTO,workTimeGroupInfo); //判断关键字是否为空 if(null == workTimeGroupReqDTO.getId()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } workTimeGroupInfo.setEditUid(currentUser.getUid()); workTimeGroupInfo.setGmtModified(new Date()); workTimeGroupInfo.setEditBy(currentUser.getRealName()); //修改工作时间组 int count = workTimeGroupInfoService.updateWorkTimeGroup(workTimeGroupInfo); //防止重复绑定 - 避免过滤复杂,直接删除重新绑定关系 workTimeGroupAndPeriodRelationInfoService.deleteWtgAprByWorkTimeGroupId(workTimeGroupInfo.getId()); //获取所有时间段 ResultVO workTimePeriod = this.getWorkTimePeriod(new WorkTimePeriodReqDTO()); List workTimePeriodRespDTOS = (List)workTimePeriod.getData(); List workTimePeriods = workTimeGroupReqDTO.getWorkTimePeriodIds(); List listRelation = new ArrayList<>(); workTimePeriods.forEach(item -> { List selectList = workTimePeriodRespDTOS.stream().filter(timePeriod -> item.equals(timePeriod.getId())).collect(Collectors.toList()); if(selectList.size() == 0){ throw new AusinessException(E.DATA_PARAM_NULL, "工作时间段不存在!"); } WorkTimeGroupAndPeriodRelationInfo workTimeGroupAndPeriodRelationInfo = new WorkTimeGroupAndPeriodRelationInfo(); workTimeGroupAndPeriodRelationInfo.setWorkTimePeriodId(item); workTimeGroupAndPeriodRelationInfo.setWorkTimeGroupId(workTimeGroupInfo.getId()); listRelation.add(workTimeGroupAndPeriodRelationInfo); }); //批量绑定到关系表中 flag = workTimeGroupAndPeriodRelationInfoService.saveBatch(listRelation); if (flag){ return resultVO; } return new ResultVO<>(ResultCodes.SERVER_UPDATE_ERROR); } /** * 逻辑删除工作时间组 * @param id * @return */ @Override @Transactional public ResultVO deleteWorkTimeGroupById(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //判断是否绑定时间策略 TimeStrategyInfo timeStrategyInfo = new TimeStrategyInfo(); timeStrategyInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); timeStrategyInfo.setWorkTimeGroupId(id); List timeStrategyInfos = this.timeStrategyInfoSerive.getAllTimeStrategyInfo(timeStrategyInfo); if(timeStrategyInfos.size()>0){ throw new AusinessException(E.DATA_PARAM_NULL, "已绑定时间策略不可删除!"); } WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); workTimeGroupInfo.setId(id); workTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); //逻辑删除 workTimeGroupInfoService.deleteWorkTimeGroup(workTimeGroupInfo); //删除关系表中数据 workTimeGroupAndPeriodRelationInfoService.deleteWtgAprByWorkTimeGroupId(id); return resultVO; } @Override @Transactional public ResultVO deletBatchWorkTimeGroup(DeleteDTO deleteDTO) { if(null == deleteDTO.getIds()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } List list = new ArrayList<>(); //获取时间策略绑定关系 List timeStrategyInfos = timeStrategyInfoSerive.getAllTimeStrategyInfo(new TimeStrategyInfo()); //获取关系表数据 List listRelation = workTimeGroupAndPeriodRelationInfoService.getWorkTimeGroupAndPeriodRelation(null); List deleteBatchlist = new ArrayList<>(); deleteDTO.getIds().stream().forEach(item ->{ WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); workTimeGroupInfo.setId(item); workTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); list.add(workTimeGroupInfo); //过滤绑定的时间段关系 List selectList = listRelation.stream().filter(relation -> relation.getWorkTimeGroupId().equals(item)).collect(Collectors.toList()); deleteBatchlist.addAll(selectList); //过滤已绑定时间策略时间组 List collect = timeStrategyInfos.stream().filter(ts -> ts.getWorkTimeGroupId().equals(item)).collect(Collectors.toList()); if(collect.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定时间策略不可删除!"); } }); //逻辑删除 workTimeGroupInfoService.updateBatchById(list); //删除关系表中数据 workTimeGroupAndPeriodRelationInfoService.removeBatchByIds(deleteBatchlist); return new ResultVO<>("200","删除成功!"); } /** * 查询工作时间 * @param workTimeGroupReqDTO * @return */ @Override public ResultVO getWorkTimeGroup(WorkTimeGroupReqDTO workTimeGroupReqDTO) { ResultVO resultVO = new ResultVO<>(); WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); //复制 BeanUtils.copyProperties(workTimeGroupReqDTO,workTimeGroupInfo); workTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); //获取所有工作时间组数据 List workTimeGroupList = workTimeGroupInfoService.getWorkTimeGroupInfo(workTimeGroupInfo); //转换数据 List list = new ArrayList<>(); workTimeGroupList.stream().forEach(item ->{ WorkTimeGroupRespDTO workTimeGroupRespDTO = new WorkTimeGroupRespDTO(); BeanUtils.copyProperties(item,workTimeGroupRespDTO); list.add(workTimeGroupRespDTO); }); //获取工作时间关系表和时间段关联的信息 List workTimePeriodRelationDOS = workTimeGroupAndPeriodRelationInfoService.getWorkTimePeriodRelation(null); //数据转换 List workTimePeriodRelationRespDTOList = new ArrayList<>(); workTimePeriodRelationDOS.stream().forEach(item -> { WorkTimePeriodRelationRespDTO workTimePeriodRelationRespDTO = new WorkTimePeriodRelationRespDTO(); BeanUtils.copyProperties(item,workTimePeriodRelationRespDTO); workTimePeriodRelationRespDTOList.add(workTimePeriodRelationRespDTO); }); list.stream().forEach(item ->{ List selectList = workTimePeriodRelationRespDTOList.stream().filter(workTimePeriodRlation -> item.getId().equals(workTimePeriodRlation.getWorkTimeGroupId())).collect(Collectors.toList()); if(selectList.size() > 0){ item.setList(selectList); } }); resultVO.setCode("200"); resultVO.setMsg("查询成功!"); resultVO.setData(list); return resultVO; } /** * 根据id获取时间组信息 * @param id * @return */ @Override public ResultVO getWorkTimeGroupById(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("查询成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //获取工作时间组信息 WorkTimeGroupInfo workTimeGroupInfo = workTimeGroupInfoService.getWorkTimeGroupById(id); if(null == workTimeGroupInfo){ resultVO.setData(null); return resultVO; } //对象转换 WorkTimeGroupRespDTO workTimeGroupRespDTO = new WorkTimeGroupRespDTO(); BeanUtils.copyProperties(workTimeGroupInfo,workTimeGroupRespDTO); //根据工作时间组id获取 WorkTimeGroupAndPeriodRelationInfo workTimeGroupAndPeriodRelationInfo = new WorkTimeGroupAndPeriodRelationInfo(); workTimeGroupAndPeriodRelationInfo.setWorkTimeGroupId(id); List relationList = workTimeGroupAndPeriodRelationInfoService.getWorkTimePeriodRelation(workTimeGroupAndPeriodRelationInfo); //数据转换 List workTimePeriodRelationRespDTOList = new ArrayList<>(); relationList.stream().forEach(item -> { WorkTimePeriodRelationRespDTO workTimePeriodRelationRespDTO = new WorkTimePeriodRelationRespDTO(); BeanUtils.copyProperties(item,workTimePeriodRelationRespDTO); workTimePeriodRelationRespDTOList.add(workTimePeriodRelationRespDTO); }); workTimeGroupRespDTO.setList(workTimePeriodRelationRespDTOList); resultVO.setData(workTimeGroupRespDTO); return resultVO; } /***********************************************工作时间段****************************************************************/ /** * 新增工作时间段 * @param workTimePeriodReqDTO * @return */ @Override public ResultVO addWorkTimePeriod(ContextCacheUser currentUser, WorkTimePeriodReqDTO workTimePeriodReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("添加成功!"); WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); //复制数据 BeanUtils.copyProperties(workTimePeriodReqDTO,workTimePeriodInfo); //工作时长 double workhours = 0.0; double startHours = workTimePeriodReqDTO.getStartHour() + new BigDecimal((float)workTimePeriodReqDTO.getStartMin()/60).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); double endHours = workTimePeriodReqDTO.getEndHour() + new BigDecimal((float)workTimePeriodReqDTO.getEndMin()/60).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); if(workTimePeriodReqDTO.getStartHour()> workTimePeriodReqDTO.getEndHour()){//开始时间大于结束时间 workTimePeriodInfo.setEnableAcrossDay(CrossSkyEnum.ENABLE_CROSS_DAY.getStatus()); workhours = 24 - startHours + endHours; }else{//开始时间小于结束时间 workTimePeriodInfo.setEnableAcrossDay(CrossSkyEnum.UNENABLE_CROSS_DAY.getStatus()); workhours = endHours - startHours; } workTimePeriodInfo.setWorkHours(workhours); workTimePeriodInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); workTimePeriodInfo.setCreateUid(currentUser.getUid()); workTimePeriodInfo.setGmtCreate(new Date()); workTimePeriodInfo.setCreateBy(currentUser.getRealName()); Integer flag = workTimePeriodInfoService.saveWorkTimePeriodInfo(workTimePeriodInfo); if (flag != 1){ return new ResultVO<>(ResultCodes.SERVER_ADD_ERROR); } return resultVO; } /** * 工作时间段更新 * @param currentUser * @param workTimePeriodReqDTO * @return */ @Override public ResultVO updateWorkTimePeriod(ContextCacheUser currentUser,WorkTimePeriodReqDTO workTimePeriodReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("更新成功!"); WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); //复制数据 BeanUtils.copyProperties(workTimePeriodReqDTO,workTimePeriodInfo); if (null == workTimePeriodInfo.getId()) { throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //工作时长 double workhours = 0.0; double startHours = workTimePeriodReqDTO.getStartHour() + new BigDecimal((float)workTimePeriodReqDTO.getStartMin()/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); double endHours = workTimePeriodReqDTO.getEndHour() + new BigDecimal((float)workTimePeriodReqDTO.getEndMin()/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); if(workTimePeriodReqDTO.getStartHour()> workTimePeriodReqDTO.getEndHour()){//开始时间大于结束时间 workTimePeriodInfo.setEnableAcrossDay(CrossSkyEnum.ENABLE_CROSS_DAY.getStatus()); workhours = 24 - startHours + endHours; }else{//开始时间小于结束时间 workTimePeriodInfo.setEnableAcrossDay(CrossSkyEnum.UNENABLE_CROSS_DAY.getStatus()); workhours = endHours - startHours; } workTimePeriodInfo.setWorkHours(workhours); workTimePeriodInfo.setEditBy(currentUser.getRealName()); workTimePeriodInfo.setGmtModified(new Date()); workTimePeriodInfo.setEditUid(currentUser.getUid()); Integer count = workTimePeriodInfoService.updateWorkTimePeriodInfo(workTimePeriodInfo); if (count != 1){ return new ResultVO<>(ResultCodes.SERVER_UPDATE_ERROR); } return resultVO; } /** * 逻辑删除工作时间段 * @param id * @return */ @Override public ResultVO deleteWorkTimePeriod(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //判断是否存在绑定关系 WorkTimeGroupAndPeriodRelationInfo relation = new WorkTimeGroupAndPeriodRelationInfo(); relation.setWorkTimePeriodId(id); List relationInfos = workTimeGroupAndPeriodRelationInfoService.getWorkTimeGroupAndPeriodRelation(relation); if(relationInfos.size() > 0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定工作时间组不可删除!"); } WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); workTimePeriodInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); workTimePeriodInfo.setId(id); Integer count = workTimePeriodInfoService.updateWorkTimePeriodInfo(workTimePeriodInfo); if(0 == count){ return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } return resultVO; } @Override public ResultVO deleteBatchWorkTimePeriod(DeleteDTO deleteDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == deleteDTO.getIds()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //判断是否存在绑定关系 List relationInfos = workTimeGroupAndPeriodRelationInfoService.getWorkTimeGroupAndPeriodRelation(null); List list = new ArrayList<>(); deleteDTO.getIds().stream().forEach(item ->{ WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); workTimePeriodInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); workTimePeriodInfo.setId(item); list.add(workTimePeriodInfo); List selectList = relationInfos.stream().filter(relationInfo -> relationInfo.getWorkTimePeriodId().equals(item)).collect(Collectors.toList()); if(selectList.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定工作时间组不可删除!"); } }); boolean flag = workTimePeriodInfoService.updateBatchById(list); if(flag){ return resultVO; } return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } /** * 查询所有工作时间段 * @param workTimePeriodReqDTO * @return */ @Override public ResultVO getWorkTimePeriod(WorkTimePeriodReqDTO workTimePeriodReqDTO) { ResultVO resultVO = new ResultVO<>(); WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); //复制数据 BeanUtils.copyProperties(workTimePeriodReqDTO,workTimePeriodInfo); workTimePeriodInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List list = workTimePeriodInfoService.getWorkTimePeriod(workTimePeriodInfo); //数据转换 List workTimePeriodRespDTOS = new ArrayList<>(); list.stream().forEach(item -> { WorkTimePeriodRespDTO workTimePeriodRespDTO = new WorkTimePeriodRespDTO(); BeanUtils.copyProperties(item,workTimePeriodRespDTO); workTimePeriodRespDTOS.add(workTimePeriodRespDTO); }); resultVO.setCode("200"); resultVO.setMsg("查询成功"); resultVO.setData(workTimePeriodRespDTOS); return resultVO; } /** * 根据id查询时间段信息 * @param * @param id * @return */ @Override public ResultVO getWorkTimePeriodById(Long id) { ResultVO resultVO = new ResultVO<>(); resultVO.setCode("200"); resultVO.setMsg("查询成功"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } WorkTimePeriodInfo workTimePeriodInfo = workTimePeriodInfoService.getById(id); if(null == workTimePeriodInfo){ resultVO.setData(null); return resultVO; } //转换 WorkTimePeriodRespDTO workTimePeriodRespDTO = new WorkTimePeriodRespDTO(); BeanUtils.copyProperties(workTimePeriodInfo,workTimePeriodRespDTO); resultVO.setData(workTimePeriodRespDTO); return resultVO; } /** * 物理删除 * 删除工作时间组和时间段关系 * @param id * @return */ @Override public ResultVO deleteWorkTimeGroupAndPeriodRelationById(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } Integer count = workTimeGroupAndPeriodRelationInfoService.deleteWorkTimeGroupAndPeriodRelationById(id); if(0 == count){ return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } return resultVO; } @Override public SearchResultVO> getWorkTimePeriodByPage(PageQuery pageQuery) { if(null == pageQuery.getPageIndex() || null == pageQuery.getPageSize()){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "当前页或者页数量不能为空"); } Page page = new Page(pageQuery.getPageIndex(),pageQuery.getPageSize()); WorkTimePeriodInfo workTimePeriodInfo = new WorkTimePeriodInfo(); WorkTimePeriodReqDTO searchParams = pageQuery.getSearchParams(); if(null != searchParams){ //复制数据 BeanUtils.copyProperties(pageQuery.getSearchParams(),workTimePeriodInfo); } workTimePeriodInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List list = this.workTimePeriodInfoService.getWorkTimePeriodByPage(page, workTimePeriodInfo); //数据转换 List workTimePeriodRespDTOS = new ArrayList<>(); list.stream().forEach(item -> { WorkTimePeriodRespDTO workTimePeriodRespDTO = new WorkTimePeriodRespDTO(); BeanUtils.copyProperties(item,workTimePeriodRespDTO); workTimePeriodRespDTOS.add(workTimePeriodRespDTO); }); return new SearchResultVO<>( true, page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), workTimePeriodRespDTOS, ResultCodes.OK); } @Override public SearchResultVO> getWorkTimeGroupByPage(PageQuery query) { if(null == query.getPageIndex() || null == query.getPageSize()){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "当前页或者页数量不能为空"); } Page page = new Page(query.getPageIndex(),query.getPageSize()); WorkTimeGroupInfo workTimeGroupInfo = new WorkTimeGroupInfo(); if(null != query.getSearchParams()){ //复制数据 BeanUtils.copyProperties(query.getSearchParams(),workTimeGroupInfo); } workTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List list = this.workTimeGroupInfoService.getWorkTimeGroupByPage(page, workTimeGroupInfo); //数据转换 List workTimeGroupRespDTOS = new ArrayList<>(); list.stream().forEach(item -> { WorkTimeGroupRespDTO workTimeGroupRespDTO = new WorkTimeGroupRespDTO(); BeanUtils.copyProperties(item,workTimeGroupRespDTO); workTimeGroupRespDTOS.add(workTimeGroupRespDTO); }); //获取工作时间关系表和时间段关联的信息 List workTimePeriodRelationDOS = workTimeGroupAndPeriodRelationInfoService.getWorkTimePeriodRelation(null); //数据转换 List workTimePeriodRelationRespDTOList = new ArrayList<>(); workTimePeriodRelationDOS.stream().forEach(item -> { WorkTimePeriodRelationRespDTO workTimePeriodRelationRespDTO = new WorkTimePeriodRelationRespDTO(); BeanUtils.copyProperties(item,workTimePeriodRelationRespDTO); workTimePeriodRelationRespDTOList.add(workTimePeriodRelationRespDTO); }); workTimeGroupRespDTOS.stream().forEach(item ->{ List selectList = workTimePeriodRelationRespDTOList.stream().filter(workTimePeriodRlation -> item.getId().equals(workTimePeriodRlation.getWorkTimeGroupId())).collect(Collectors.toList()); if(selectList.size() > 0){ item.setList(selectList); } }); return new SearchResultVO<>( true, page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), workTimeGroupRespDTOS, ResultCodes.OK); } }