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.LeaveTypeEnum; import com.gkhy.safePlatform.account.enums.ScheduleStatusEnum; import com.gkhy.safePlatform.account.enums.UnitOfMeaSureEnum; import com.gkhy.safePlatform.account.model.dto.req.BreakTimeGroupReqDTO; import com.gkhy.safePlatform.account.model.dto.req.BreakTimeRuleReqDTO; import com.gkhy.safePlatform.account.model.dto.req.DeleteDTO; import com.gkhy.safePlatform.account.model.dto.req.ScheduleAllYearDateReqDTO; import com.gkhy.safePlatform.account.model.dto.resp.BreakTimeGroupRespDTO; import com.gkhy.safePlatform.account.model.dto.resp.BreakTimeRuleRelationRespDTO; import com.gkhy.safePlatform.account.model.dto.resp.BreakTimeRuleRespDTO; import com.gkhy.safePlatform.account.service.BreakTimeService; import com.gkhy.safePlatform.account.service.baseService.*; 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.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Service public class BreakTimeServiceImpl implements BreakTimeService { @Autowired private BreakTimeRuleInfoService breakTimeRuleInfoService; @Autowired private BreakTimeGroupInfoService breakTimeGroupInfoService; @Autowired private BreakTimeGroupAndRuleRelationInfoService breakTimeGroupAndRuleRelationInfoService; @Autowired private ScheduleAllYearDateService scheduleAllYearDateService; @Autowired private TimeStrategyInfoSerive timeStrategyInfoSerive; /** * 新增休息规则 * @param currentUser * @param breakTimeRuleReqDTO * @return */ @Override public ResultVO addBreakTimeRule(ContextCacheUser currentUser, BreakTimeRuleReqDTO breakTimeRuleReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("添加成功!"); if(null == currentUser.getUid()){ throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } //校验休假类型 if (LeaveTypeEnum.parse(breakTimeRuleReqDTO.getType()) == null) { throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休假类型参数非法"); } //时间单位 if (UnitOfMeaSureEnum.parse(breakTimeRuleReqDTO.getRule()) == null) { throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "时间单位参数非法"); } //校验规则序号 if(breakTimeRuleReqDTO.getType().equals(LeaveTypeEnum.CUSTOM_REST_DAYS.getCode())){//自定义休息时间才需要检验是否合法 String[] str = breakTimeRuleReqDTO.getRuleNumber().split(","); if(breakTimeRuleReqDTO.getRule().equals(UnitOfMeaSureEnum.WEEK.getCode())){//周 Arrays.stream(str).forEach(item ->{ if( Integer.parseInt(item) > 8 || Integer.parseInt(item) < 1 ){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休息规则序号参数非法"); } }); } if(breakTimeRuleReqDTO.getRule().equals(UnitOfMeaSureEnum.MONTH.getCode())){//月 Arrays.stream(str).forEach(item ->{ if( Integer.parseInt(item) > 31 || Integer.parseInt(item) < 1 ){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休息规则序号参数非法"); } }); } } BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); //复制数据 BeanUtils.copyProperties(breakTimeRuleReqDTO,breakTimeRuleInfo); breakTimeRuleInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); breakTimeRuleInfo.setCreateUid(currentUser.getUid()); breakTimeRuleInfo.setGmtCreate(new Date()); breakTimeRuleInfo.setCreateBy(currentUser.getRealName()); //插入休息时间规则 int flag = breakTimeRuleInfoService.addBreakTimeRule(breakTimeRuleInfo); if(flag == 0){ return new ResultVO<>(ResultCodes.SERVER_ADD_ERROR); } return resultVO; } /** * 更新休息时间规则 * @param currentUser * @param breakTimeRuleReqDTO * @return */ @Override public ResultVO updateBreakTimeRule(ContextCacheUser currentUser, BreakTimeRuleReqDTO breakTimeRuleReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("更新成功!"); if(null == currentUser.getUid()){ throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } //校验休假类型 if (LeaveTypeEnum.parse(breakTimeRuleReqDTO.getType()) == null) { throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休假类型参数非法"); } if (UnitOfMeaSureEnum.parse(breakTimeRuleReqDTO.getRule()) == null) { throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "时间单位参数非法"); } //校验规则序号 if(breakTimeRuleReqDTO.getType().equals(LeaveTypeEnum.CUSTOM_REST_DAYS.getCode())){//自定义休息时间才需要检验是否合法 String[] str = breakTimeRuleReqDTO.getRuleNumber().split(","); if(breakTimeRuleReqDTO.getRule().equals(UnitOfMeaSureEnum.WEEK.getCode())){//周 Arrays.stream(str).forEach(item ->{ if( Integer.parseInt(item) > 8 || Integer.parseInt(item) < 1 ){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休息规则序号参数非法"); } }); } if(breakTimeRuleReqDTO.getRule().equals(UnitOfMeaSureEnum.MONTH.getCode())){//月 Arrays.stream(str).forEach(item ->{ if( Integer.parseInt(item) > 31 || Integer.parseInt(item) < 1 ){ throw new AusinessException(E.DATA_STATUS_NOT_EXIST, "休息规则序号参数非法"); } }); } } BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); //复制数据 BeanUtils.copyProperties(breakTimeRuleReqDTO,breakTimeRuleInfo); if(null == breakTimeRuleReqDTO.getId()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } breakTimeRuleInfo.setEditUid(currentUser.getUid()); breakTimeRuleInfo.setGmtModified(new Date()); breakTimeRuleInfo.setEditBy(currentUser.getRealName()); //插入休息时间规则 int flag = breakTimeRuleInfoService.updateBreakTimeRule(breakTimeRuleInfo); if(flag == 0){ return new ResultVO<>(ResultCodes.SERVER_UPDATE_ERROR); } return resultVO; } /** * 删除休息规则 -- 逻辑删除 * @param id * @return */ @Override public ResultVO deleteBreakTimeRule(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //检查是否有绑定休息时间组 BreakTimeGroupAndRuleRelationInfo breakTimeGroupAndRuleRelationInfo = new BreakTimeGroupAndRuleRelationInfo(); breakTimeGroupAndRuleRelationInfo.setBreakTimeRuleId(id); List relations = breakTimeGroupAndRuleRelationInfoService.getBreakTimeGroupAndRuleRelation(breakTimeGroupAndRuleRelationInfo); if(relations.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定休息时间组不可删除!"); } BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); breakTimeRuleInfo.setId(id); breakTimeRuleInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); int flag = breakTimeRuleInfoService.updateBreakTimeRule(breakTimeRuleInfo); if(flag == 0){ return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } return resultVO; } /** * 批量删除休息规则 * @param deleteDTO * @return */ @Override public ResultVO deleteBatchBreakTimeRule(DeleteDTO deleteDTO) { Long l = System.currentTimeMillis(); ResultVO resultVO = new ResultVO("200","删除成功!"); if(null == deleteDTO.getIds()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //获取所有规则和休息时间组绑定关系 List relations = breakTimeGroupAndRuleRelationInfoService.getBreakTimeGroupAndRuleRelation(null); List list = new ArrayList<>(); deleteDTO.getIds().stream().forEach(item -> { BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); breakTimeRuleInfo.setId(item); breakTimeRuleInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); list.add(breakTimeRuleInfo); //过滤出休息时间组和规则绑定关系 List collect = relations.stream().filter(relation -> relation.getBreakTimeRuleId().equals(item)).collect(Collectors.toList()); //如果绑定休息时间组则不可删除 if(collect.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定休息时间组不可删除!"); } }); //批量删除 boolean flag = breakTimeRuleInfoService.updateBatchById(list); if(flag){ return resultVO; } return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } /** * 查询所有数据 * @param breakTimeRuleReqDTO * @return */ @Override public ResultVO getAllBreakTimeRule(BreakTimeRuleReqDTO breakTimeRuleReqDTO) { ResultVO resultVO = new ResultVO<>(); BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); //复制数据 BeanUtils.copyProperties(breakTimeRuleReqDTO,breakTimeRuleInfo); breakTimeRuleInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List list = breakTimeRuleInfoService.getAllBreakTimeRule(breakTimeRuleInfo); //数据转换 List breakTimeRuleRespDTOS = new ArrayList<>(); list.stream().forEach(item -> { BreakTimeRuleRespDTO breakTimeRuleRespDTO = new BreakTimeRuleRespDTO(); BeanUtils.copyProperties(item,breakTimeRuleRespDTO); breakTimeRuleRespDTOS.add(breakTimeRuleRespDTO); }); resultVO.setCode("200"); resultVO.setMsg("查询成功!"); resultVO.setData(breakTimeRuleRespDTOS); return resultVO; } /** * 分页查询 * 休息规则 * @param pageQuery * @return */ @Override public SearchResultVO> getAllBreakTimeRuleByPage(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()); BreakTimeRuleInfo breakTimeRuleInfo = new BreakTimeRuleInfo(); if(null != pageQuery.getSearchParams()){ //复制数据 BeanUtils.copyProperties(pageQuery.getSearchParams(),breakTimeRuleInfo); } breakTimeRuleInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List list = breakTimeRuleInfoService.getAllBreakTimeRuleByPage(page,breakTimeRuleInfo); //数据转换 List breakTimeRuleRespDTOS = new ArrayList<>(); list.stream().forEach(item -> { BreakTimeRuleRespDTO breakTimeRuleRespDTO = new BreakTimeRuleRespDTO(); BeanUtils.copyProperties(item,breakTimeRuleRespDTO); breakTimeRuleRespDTOS.add(breakTimeRuleRespDTO); }); return new SearchResultVO<>( true, page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), breakTimeRuleRespDTOS, ResultCodes.OK); } /** * 根据id查询 * @param id * @return */ @Override public ResultVO getBreakTimeRuleById(Long id) { ResultVO resultVO = new ResultVO<>(); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } BreakTimeRuleInfo breakTimeRuleInfo = breakTimeRuleInfoService.getBreakTimeRuleById(id); if(breakTimeRuleInfo == null){ //对象转换 BreakTimeRuleRespDTO breakTimeRuleRespDTO = new BreakTimeRuleRespDTO(); //复制数据 BeanUtils.copyProperties(breakTimeRuleInfo,breakTimeRuleRespDTO); }else{ resultVO.setData(null); } resultVO.setCode("200"); resultVO.setMsg("查询成功!"); return resultVO; } /** * 新增休息时间组 * @param currentUser * @param breakTimeGroupReqDTO * @return */ @Override @Transactional public ResultVO addBreakTimeGroup(ContextCacheUser currentUser, BreakTimeGroupReqDTO breakTimeGroupReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("添加成功!"); if(null == currentUser.getUid()){ throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); //复制数据 BeanUtils.copyProperties(breakTimeGroupReqDTO,breakTimeGroupInfo); breakTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); breakTimeGroupInfo.setCreateUid(currentUser.getUid()); breakTimeGroupInfo.setGmtCreate(new Date()); breakTimeGroupInfo.setCreateBy(currentUser.getRealName()); //新增休息时间工作组 breakTimeGroupInfoService.addBreakTimeGroup(breakTimeGroupInfo); //获取休息时间规则 ResultVO ruleInfoResultVO = this.getAllBreakTimeRule(new BreakTimeRuleReqDTO()); List breakTimeRuleRespDTOS = (List)ruleInfoResultVO.getData(); List list = breakTimeGroupReqDTO.getBreakTimeRuleIds(); List listRelation = new ArrayList<>(); list.stream().forEach(item -> { List selectList = breakTimeRuleRespDTOS.stream().filter(rule -> rule.getId().equals(item)).collect(Collectors.toList()); if(selectList.size() == 0){ throw new AusinessException(E.DATA_PARAM_NULL, "休息规则不存在!"); } BreakTimeGroupAndRuleRelationInfo breakTimeGroupAndRuleRelationInfo = new BreakTimeGroupAndRuleRelationInfo(); breakTimeGroupAndRuleRelationInfo.setBreakTimeGroupId(breakTimeGroupInfo.getId()); breakTimeGroupAndRuleRelationInfo.setBreakTimeRuleId(item); listRelation.add(breakTimeGroupAndRuleRelationInfo); }); //绑定休息时间组和休息规则 breakTimeGroupAndRuleRelationInfoService.saveBatch(listRelation); return resultVO; } /** * 更新休息时间组 * @param currentUser * @param breakTimeGroupReqDTO * @return */ @Override @Transactional public ResultVO updateBreakTimeGroup(ContextCacheUser currentUser, BreakTimeGroupReqDTO breakTimeGroupReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("更新成功!"); if(null == currentUser.getUid()){ throw new BusinessException(ResultCodes.SERVER_PARAM_NULL); } BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); //复制数据 BeanUtils.copyProperties(breakTimeGroupReqDTO,breakTimeGroupInfo); breakTimeGroupInfo.setEditUid(currentUser.getUid()); breakTimeGroupInfo.setGmtModified(new Date()); breakTimeGroupInfo.setEditBy(currentUser.getRealName()); if(null == breakTimeGroupInfo.getId()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //更新休息时间工作组 breakTimeGroupInfoService.updateBreakTimeGroup(breakTimeGroupInfo); //避免重复绑定,删除原来绑定关系 breakTimeGroupAndRuleRelationInfoService.deleteBtgarrByBreakTimeGroupId(breakTimeGroupInfo.getId()); //获取休息时间规则 ResultVO ruleInfoResultVO = this.getAllBreakTimeRule(new BreakTimeRuleReqDTO()); List breakTimeRuleRespDTOS = (List)ruleInfoResultVO.getData(); List list = breakTimeGroupReqDTO.getBreakTimeRuleIds(); List listRelation = new ArrayList<>(); list.stream().forEach(item -> { List selectList = breakTimeRuleRespDTOS.stream().filter(rule -> rule.getId().equals(item)).collect(Collectors.toList()); if(selectList.size() == 0){ throw new AusinessException(E.DATA_PARAM_NULL, "休息规则不存在!"); } BreakTimeGroupAndRuleRelationInfo breakTimeGroupAndRuleRelationInfo = new BreakTimeGroupAndRuleRelationInfo(); breakTimeGroupAndRuleRelationInfo.setBreakTimeGroupId(breakTimeGroupInfo.getId()); breakTimeGroupAndRuleRelationInfo.setBreakTimeRuleId(item); listRelation.add(breakTimeGroupAndRuleRelationInfo); }); //重新绑定休息时间组和休息规则 breakTimeGroupAndRuleRelationInfoService.saveBatch(listRelation); return resultVO; } /** * 删除休息时间组 * @param id * @return */ @Override @Transactional public ResultVO deleteBreakTimeGroup(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.setBreakTimeGroupId(id); List timeStrategyInfos = this.timeStrategyInfoSerive.getAllTimeStrategyInfo(timeStrategyInfo); if(timeStrategyInfos.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定时间策略不可删除!"); } //逻辑删除休息时间组 BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); breakTimeGroupInfo.setId(id); breakTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); breakTimeGroupInfoService.updateBreakTimeGroup(breakTimeGroupInfo); //物理删除绑定关系 int flag = breakTimeGroupAndRuleRelationInfoService.deleteBtgarrByBreakTimeGroupId(id); if(0 == flag){ return new ResultVO<>(ResultCodes.SERVER_DEL_ERROR); } return resultVO; } /** * 批量删除休息时间组 * @param deleteDTO * @return */ @Override public ResultVO deleteBatchBreakTimeGroup(DeleteDTO deleteDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("删除成功!"); if(null == deleteDTO.getIds()){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //获取时间策略绑定休息时间组数据 List timeStrategyInfos = this.timeStrategyInfoSerive.getAllTimeStrategyInfo(new TimeStrategyInfo()); //获取绑定的休息规则数据 List periodRelations = breakTimeGroupAndRuleRelationInfoService.getBreakTimeGroupAndRuleRelation(null); List deleteBatchRelationInfos = new ArrayList<>(); List list = new ArrayList<>(); deleteDTO.getIds().stream().forEach(item ->{ //逻辑删除休息时间组 BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); breakTimeGroupInfo.setId(item); breakTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_NOT_ACTIVE.getStatus()); list.add(breakTimeGroupInfo); //过滤出需要删除的关系数据 List selectList = periodRelations.stream().filter(pr -> pr.getBreakTimeGroupId().equals(item)).collect(Collectors.toList()); deleteBatchRelationInfos.addAll(selectList); //过滤出绑定休息时间组数据 List collect = timeStrategyInfos.stream().filter(ts -> ts.getBreakTimeGroupId().equals(item)).collect(Collectors.toList()); if(collect.size()>0){ throw new AusinessException(E.DATA_BING_RELATION, "已绑定时间策略不可删除!"); } }); //批量删除 breakTimeGroupInfoService.updateBatchById(list); //批量删除绑定关系 breakTimeGroupAndRuleRelationInfoService.removeBatchByIds(deleteBatchRelationInfos); return resultVO; } /** * 获取所有休息时间组的信息 */ @Override public ResultVO getAllBreakTimeGroup(BreakTimeGroupReqDTO breakTimeGroupReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("查询成功!"); BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); //复制数据 BeanUtils.copyProperties(breakTimeGroupReqDTO,breakTimeGroupInfo); //获取所有休息时间组 breakTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List breakTimeGroupInfos = breakTimeGroupInfoService.getAllBreakTimeGroup(breakTimeGroupInfo); //数据转换 List list = new ArrayList<>(); breakTimeGroupInfos.stream().forEach(item ->{ BreakTimeGroupRespDTO breakTimeGroupRespDTO = new BreakTimeGroupRespDTO(); BeanUtils.copyProperties(item,breakTimeGroupRespDTO); list.add(breakTimeGroupRespDTO); }); //获取休息时间关系表和休息时间规则表关联的信息 List relationList = breakTimeGroupAndRuleRelationInfoService.getAllBreakTimeRuleRelation(null); List breakTimeRuleRelationRespDTOS = new ArrayList<>(); //数据转换 relationList.stream().forEach(item -> { BreakTimeRuleRelationRespDTO breakTimeRuleRelationRespDTO = new BreakTimeRuleRelationRespDTO(); BeanUtils.copyProperties(item,breakTimeRuleRelationRespDTO); breakTimeRuleRelationRespDTOS.add(breakTimeRuleRelationRespDTO); }); list.stream().forEach(item -> { List selectList = breakTimeRuleRelationRespDTOS.stream().filter(relation -> item.getId().equals(relation.getBreakTimeGroupId())).collect(Collectors.toList()); item.setList(selectList); }); resultVO.setData(list); return resultVO; } /** * 获取所有休息时间组的信息 */ @Override public SearchResultVO> getAllBreakTimeGroupByPage(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()); BreakTimeGroupInfo breakTimeGroupInfo = new BreakTimeGroupInfo(); if(null != pageQuery.getSearchParams()){ //复制数据 BeanUtils.copyProperties(pageQuery.getSearchParams(),breakTimeGroupInfo); } //获取所有休息时间组 breakTimeGroupInfo.setStatus(ScheduleStatusEnum.STATUS_ACTIVE.getStatus()); List breakTimeGroupInfos = breakTimeGroupInfoService.getAllBreakTimeGroupByPage(page,breakTimeGroupInfo); //数据转换 List list = new ArrayList<>(); breakTimeGroupInfos.stream().forEach(item ->{ BreakTimeGroupRespDTO breakTimeGroupRespDTO = new BreakTimeGroupRespDTO(); BeanUtils.copyProperties(item,breakTimeGroupRespDTO); list.add(breakTimeGroupRespDTO); }); //获取休息时间关系表和休息时间规则表关联的信息 List relationList = breakTimeGroupAndRuleRelationInfoService.getAllBreakTimeRuleRelation(null); List breakTimeRuleRelationRespDTOS = new ArrayList<>(); //数据转换 relationList.stream().forEach(item -> { BreakTimeRuleRelationRespDTO breakTimeRuleRelationRespDTO = new BreakTimeRuleRelationRespDTO(); BeanUtils.copyProperties(item,breakTimeRuleRelationRespDTO); breakTimeRuleRelationRespDTOS.add(breakTimeRuleRelationRespDTO); }); list.stream().forEach(item -> { List selectList = breakTimeRuleRelationRespDTOS.stream().filter(relation -> item.getId().equals(relation.getBreakTimeGroupId())).collect(Collectors.toList()); item.setList(selectList); }); return new SearchResultVO<>( true, page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), list, ResultCodes.OK); } /** *根据id获取休息时间组相关信息 * @param * @param id * @return */ @Override public ResultVO getBreakTimeGroupById(Long id) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("查询成功!"); if(null == id){ throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL); } //获取休息时间组信息 BreakTimeGroupInfo breakTimeGroupInfo = breakTimeGroupInfoService.getBreakTimeGroupById(id); if(breakTimeGroupInfo == null){ resultVO.setData(null); return resultVO; } //对象转换 BreakTimeGroupRespDTO breakTimeGroupRespDTO = new BreakTimeGroupRespDTO(); BeanUtils.copyProperties(breakTimeGroupInfo,breakTimeGroupRespDTO); //根据工作时间组id获取 BreakTimeGroupAndRuleRelationInfo breakTimeGroupAndRuleRelationInfo = new BreakTimeGroupAndRuleRelationInfo(); breakTimeGroupAndRuleRelationInfo.setBreakTimeGroupId(id); List relationList = breakTimeGroupAndRuleRelationInfoService.getAllBreakTimeRuleRelation(breakTimeGroupAndRuleRelationInfo); //数据转换 List list = new ArrayList<>(); relationList.stream().forEach(item -> { BreakTimeRuleRelationRespDTO breakTimeRuleRelationRespDTO = new BreakTimeRuleRelationRespDTO(); BeanUtils.copyProperties(item,breakTimeRuleRelationRespDTO); list.add(breakTimeRuleRelationRespDTO); }); breakTimeGroupRespDTO.setList(list); resultVO.setData(breakTimeGroupRespDTO); return resultVO; } /** * 更新日期信息 * @param scheduleAllYearDateReqDTO * @return */ @Override public ResultVO updateScheduleAllYearDate(ScheduleAllYearDateReqDTO scheduleAllYearDateReqDTO) { ResultVO resultVO = new ResultVO(); resultVO.setCode("200"); resultVO.setMsg("更新成功!"); ScheduleAllYearDateInfo scheduleAllYearDateInfo = new ScheduleAllYearDateInfo(); //复制数据 BeanUtils.copyProperties(scheduleAllYearDateReqDTO, scheduleAllYearDateInfo); int flag = scheduleAllYearDateService.updateScheduleAllYearDate(scheduleAllYearDateInfo); if( 0 != flag){ return resultVO; } return new ResultVO<>(ResultCodes.SERVER_UPDATE_ERROR); } }