yaozc2021
2025-04-21 b3176719f4e73bd5ea67ac6b6835d74fd607e102
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/conferenceRoom/service/impl/MeetingRoomReservationServiceImpl.java
@@ -1,50 +1,40 @@
/*
*  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.OpaiDingTalkService;
import me.zhengjie.modules.system.domain.CustomerResources;
import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.conferenceRoom.repository.MeetingRoomReservationRepository;
import me.zhengjie.modules.conferenceRoom.service.MeetingRoomReservationService;
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 org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.SecurityUtils;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -53,11 +43,11 @@
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 {
@@ -65,14 +55,14 @@
    private final MeetingRoomReservationRepository meetingRoomReservationRepository;
    private final MeetingRoomReservationMapper meetingRoomReservationMapper;
    private final MeetingRoomRepository meetingRoomRepository;
    private final OpaiDingTalkService opaiDingTalkService;
    private final WeComServiceImpl weComService;
    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
@@ -87,15 +77,15 @@
    }
    @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);
    }
@@ -106,15 +96,15 @@
        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{
            //调用钉钉公共方法
            setDingding(resources);
        } else {
            // 发送通知
            sendNotice(resources);
        }
        return meetingRoomReservationMapper.toDto(meetingRoomReservationRepository.save(resources));
    }
@@ -123,7 +113,7 @@
    @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());
@@ -132,48 +122,52 @@
        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{
            setDingding(resources);
        } else {
            // 发送通知
            sendNotice(resources);
        }
        meetingRoomReservationRepository.save(meetingRoomReservation);
    }
    /**
     * 发送钉钉公共方法
     * 向其他应用发送通知公共方法
     *
     * @param resources
     * @return
     * @throws Exception
     */
    public void setDingding(MeetingRoomReservation resources) throws Exception {
        // 获取存储用户钉钉号
        List<String> dingDingList = new ArrayList<>();
    public void sendNotice(MeetingRoomReservation resources) {
        // 获取存储用户企微ID
        List<String> weComList = new ArrayList<>();
        // 查询用户
        List<User> userList = userRepository.findAll();
        for(User user : userList){
        for (User user : userList) {
            Role role = user.getRoles().iterator().next();
            // 获取项目组长级以上的用户的钉钉id
            if(Long.valueOf(role.getLevel()) <= Constant.ROLE_LEVEL_LEADER){
                if(ObjectUtils.isNotEmpty(user.getDingding())){
                    dingDingList.add(user.getDingding());
            // 获取项目组长级以上的用户的企微ID
            if (Long.valueOf(role.getLevel()) <= Constant.ROLE_LEVEL_LEADER) {
                if (StringUtils.isNotBlank(user.getWeComId())) {
                    weComList.add(user.getWeComId());
                }
            }
        }
        // 查询会议室
        MeetingRoom meetingRoom = meetingRoomRepository.findById(resources.getMeetingId()).orElseGet(MeetingRoom::new);
        // 发送内容至钉钉
        opaiDingTalkService.sendNotice(dingDingList, "会议室预约提示", "### 会议室预约提示  \n  >" +
                "  \n  会议主题:"   + resources.getMeetingTheme() +
                "  \n 预订者:"  + SecurityUtils.getCurrentUsername() +
                "  \n  会议室:"   + meetingRoom.getConferenceRoomName() +
                "  \n  开始时间: " + resources.getStartTime().toString().substring(0,19) +
                "  \n  结束时间: " + resources.getEndTime().toString().substring(0,19) +
                "  \n  会议室预约有变更,请登录PMS系统查看。", "card");
        // 发送内容至企微
        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);
    }
    @Override
@@ -189,7 +183,7 @@
        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());