| | |
| | | /* |
| | | * Copyright 2019-2020 Zheng Jie |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | * Copyright 2019-2020 Zheng Jie |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package me.zhengjie.modules.conferenceRoom.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.assetManagement.domain.AssetManagement; |
| | | import me.zhengjie.modules.assetManagement.domain.AssetUseManagement; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceGoOut; |
| | | import me.zhengjie.modules.conferenceRoom.domain.MeetingRoom; |
| | | import me.zhengjie.modules.conferenceRoom.domain.MeetingRoomReservation; |
| | | import me.zhengjie.modules.conferenceRoom.repository.MeetingRoomRepository; |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.system.domain.CustomerResources; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomReservationDto; |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomReservationQueryCriteria; |
| | | import me.zhengjie.modules.conferenceRoom.service.mapstruct.MeetingRoomReservationMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @author wcd |
| | | * @date 2023-02-09 |
| | | **/ |
| | | * @author wcd |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @date 2023-02-09 |
| | | **/ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MeetingRoomReservationServiceImpl implements MeetingRoomReservationService { |
| | |
| | | private final UserRepository userRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(MeetingRoomReservationQueryCriteria criteria, Pageable pageable){ |
| | | Page<MeetingRoomReservation> page = meetingRoomReservationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | public Map<String, Object> queryAll(MeetingRoomReservationQueryCriteria criteria, Pageable pageable) { |
| | | Page<MeetingRoomReservation> page = meetingRoomReservationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); |
| | | //将实体转换为Dto(重写) |
| | | Function<MeetingRoomReservation, MeetingRoomReservationDto> func = new Function<MeetingRoomReservation, MeetingRoomReservationDto>(){ |
| | | Function<MeetingRoomReservation, MeetingRoomReservationDto> func = new Function<MeetingRoomReservation, MeetingRoomReservationDto>() { |
| | | @Override |
| | | public MeetingRoomReservationDto apply(MeetingRoomReservation meetingRoomReservation) { |
| | | // 将实体类转换成DTO |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MeetingRoomReservationDto> queryAll(MeetingRoomReservationQueryCriteria criteria){ |
| | | return meetingRoomReservationMapper.toDto(meetingRoomReservationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | public List<MeetingRoomReservationDto> queryAll(MeetingRoomReservationQueryCriteria criteria) { |
| | | return meetingRoomReservationMapper.toDto(meetingRoomReservationRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public MeetingRoomReservationDto findById(Long id) { |
| | | MeetingRoomReservation meetingRoomReservation = meetingRoomReservationRepository.findById(id).orElseGet(MeetingRoomReservation::new); |
| | | ValidationUtil.isNull(meetingRoomReservation.getId(),"MeetingRoomReservation","id",id); |
| | | ValidationUtil.isNull(meetingRoomReservation.getId(), "MeetingRoomReservation", "id", id); |
| | | return meetingRoomReservationMapper.toDto(meetingRoomReservation); |
| | | } |
| | | |
| | |
| | | String startTime = df.format(resources.getStartTime()); |
| | | String endTime = df.format(resources.getEndTime()); |
| | | //验证约时间是否冲突 |
| | | List<MeetingRoomReservation> meetingRoomReservations = meetingRoomReservationRepository.checkReservationTime(startTime,endTime,resources.getMeetingId()); |
| | | if(meetingRoomReservations.size() > 0){ |
| | | List<MeetingRoomReservation> meetingRoomReservations = meetingRoomReservationRepository.checkReservationTime(startTime, endTime, resources.getMeetingId()); |
| | | if (meetingRoomReservations.size() > 0) { |
| | | MeetingRoomReservation errorMeetingRoomReservation = meetingRoomReservations.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | throw new BadRequestException("预约时间冲突," + errorFormat.format(errorMeetingRoomReservation.getStartTime()) + "至" + errorFormat.format(errorMeetingRoomReservation.getEndTime()) |
| | | + "已经存在会议室预约,请调整时间"); |
| | | }else{ |
| | | } else { |
| | | // 发送通知 |
| | | sendNotice(resources); |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(MeetingRoomReservation resources) throws Exception { |
| | | MeetingRoomReservation meetingRoomReservation = meetingRoomReservationRepository.findById(resources.getId()).orElseGet(MeetingRoomReservation::new); |
| | | ValidationUtil.isNull( meetingRoomReservation.getId(),"MeetingRoomReservation","id",resources.getId()); |
| | | ValidationUtil.isNull(meetingRoomReservation.getId(), "MeetingRoomReservation", "id", resources.getId()); |
| | | meetingRoomReservation.copy(resources); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String startTime = df.format(resources.getStartTime()); |
| | |
| | | Set<Long> ids = new HashSet<>(); |
| | | ids.add(meetingRoomReservation.getId()); |
| | | //验证时间是否冲突 |
| | | List<MeetingRoomReservation> meetingRoomReservations = meetingRoomReservationRepository.checkReservationTimeEdit(startTime,endTime, resources.getMeetingId(), ids); |
| | | if(meetingRoomReservations.size() > 0){ |
| | | List<MeetingRoomReservation> meetingRoomReservations = meetingRoomReservationRepository.checkReservationTimeEdit(startTime, endTime, resources.getMeetingId(), ids); |
| | | if (meetingRoomReservations.size() > 0) { |
| | | MeetingRoomReservation errorMeetingRoomReservation = meetingRoomReservations.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | throw new BadRequestException("预约时间冲突," + errorFormat.format(errorMeetingRoomReservation.getStartTime()) + "至" + errorFormat.format(errorMeetingRoomReservation.getEndTime()) |
| | | + "已经存在会议室预约,请调整时间"); |
| | | }else{ |
| | | } else { |
| | | // 发送通知 |
| | | sendNotice(resources); |
| | | } |
| | |
| | | MeetingRoom meetingRoom = meetingRoomRepository.findById(resources.getMeetingId()).orElseGet(MeetingRoom::new); |
| | | // 发送内容至企微 |
| | | weComService.sendNotice(weComList, "会议室预约提示", String.format("<div class=\"normal\">会议主题:%s</div>" + |
| | | "<div class=\"normal\">预订者:%s</div>" + |
| | | "<div class=\"normal\">会议室:%s</div>" + |
| | | "<div class=\"normal\">开始时间:%s</div>" + |
| | | "<div class=\"normal\">结束时间:%s</div>" + |
| | | "<div class=\"highlight\">会议室预约有变更,请登录PMS系统查看。</div>", |
| | | resources.getMeetingTheme(), |
| | | SecurityUtils.getCurrentUsername(), |
| | | meetingRoom.getConferenceRoomName(), |
| | | resources.getStartTime().toString().substring(0,19), |
| | | resources.getEndTime().toString().substring(0,19)), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | "<div class=\"normal\">预订者:%s</div>" + |
| | | "<div class=\"normal\">会议室:%s</div>" + |
| | | "<div class=\"normal\">开始时间:%s</div>" + |
| | | "<div class=\"normal\">结束时间:%s</div>" + |
| | | "<div class=\"highlight\">会议室预约有变更,请登录PMS系统查看。</div>", |
| | | resources.getMeetingTheme(), |
| | | SecurityUtils.getCurrentUsername(), |
| | | meetingRoom.getConferenceRoomName(), |
| | | resources.getStartTime().toString().substring(0, 19), |
| | | resources.getEndTime().toString().substring(0, 19)), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | |
| | | @Override |
| | |
| | | for (MeetingRoomReservationDto meetingRoomReservation : all) { |
| | | // 查询会议室 |
| | | MeetingRoom meetingRoom = meetingRoomRepository.findById(meetingRoomReservation.getMeetingId()).orElseGet(MeetingRoom::new); |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("会议室", meetingRoom.getConferenceRoomName()); |
| | | map.put("会议主题", meetingRoomReservation.getMeetingTheme()); |
| | | map.put("开始时间", meetingRoomReservation.getStartTime()); |