MrShi
2025-05-21 f5ab83dfad01c87828232af8cd18c676e69fd917
server/meeting/meeting_service/src/main/java/com/doumee/service/business/impl/BookingsServiceImpl.java
@@ -374,6 +374,7 @@
        userAction.setRemark(info);
        userAction.setMemberId(id+"");
        userActionMapper.insert(userAction);
    }
    @Override
@@ -538,6 +539,7 @@
        IPage<Bookings> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Bookings> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        Integer minute =getNearStartMinut();
        queryWrapper.selectAll(Bookings.class);
        queryWrapper.selectAs(Rooms::getName, Bookings::getRoomName);
@@ -575,22 +577,25 @@
        queryWrapper.eq(pageWrap.getModel().getStatus() != null, Bookings::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getRealName()), SystemUser::getRealname, pageWrap.getModel().getRealName());
        queryWrapper.eq(pageWrap.getModel().getDepartmentId() != null, Company::getId, pageWrap.getModel().getDepartmentId());
        //status 状态 0已预约 1已撤销 2已结束
        //会议状态: 1=未开始;2=进行中;3=已结束 ; 4=即将开始; 5=已撤销
        queryWrapper.apply(Objects.nonNull(pageWrap.getModel().getMeetingStatus())
                        &&Constants.equalsInteger(pageWrap.getModel().getMeetingStatus(),Constants.ONE),
                " ( now() < t.START_TIME and t.status = 0 ) "
                " ( now() < t.START_TIME and t.status = 0  AND SUBDATE( now(), INTERVAL -"+minute+" MINUTE ) <  t.START_TIME ) "
        )
        .apply(Objects.nonNull(pageWrap.getModel().getMeetingStatus())
                        &&Constants.equalsInteger(pageWrap.getModel().getMeetingStatus(),Constants.TWO),
                " ( now() >= t.START_TIME and t.END_TIME >= now() and t.status = 0 ) "
                " ( t.status = 0 and t.START_TIME_REAL is not null  ) "
        )
        .apply(Objects.nonNull(pageWrap.getModel().getMeetingStatus())
                        &&Constants.equalsInteger(pageWrap.getModel().getMeetingStatus(),Constants.THREE),
                " ( ( now() > t.END_TIME  and  t.`STATUS` = 0  ) or   t.`STATUS` = 2  )  "
                " (   t.`STATUS` = 2  )  "
                //" ( ( now() > t.END_TIME  and  t.`STATUS` = 0  ) or   t.`STATUS` = 2  )  "
        )
        .apply(Objects.nonNull(pageWrap.getModel().getMeetingStatus())
                        &&Constants.equalsInteger(pageWrap.getModel().getMeetingStatus(),Constants.FOUR),
                " now() < t.START_TIME  AND SUBDATE( t.START_TIME, INTERVAL 120 MINUTE ) < NOW() "
                " (t.status = 0  AND SUBDATE( now(), INTERVAL -"+minute+" MINUTE ) >  t.START_TIME and t.START_TIME_REAL is null ) "
                //" now() < t.START_TIME  AND SUBDATE( t.START_TIME, INTERVAL "+minute+" MINUTE ) < NOW() "
        )
        .apply(Objects.nonNull(pageWrap.getModel().getMeetingStatus())
                        &&Constants.equalsInteger(pageWrap.getModel().getMeetingStatus(),Constants.FIVE),
@@ -611,7 +616,6 @@
        SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
        SimpleDateFormat format1 = new SimpleDateFormat("HH:mm");
        IPage<Bookings> result = bookingsJoinMapper.selectJoinPage(page, Bookings.class, queryWrapper);
        Integer minute =getNearStartMinut();
        result.getRecords().stream().forEach(s -> {
            dealMeetingStatusByModel(s,minute);
            MPJLambdaWrapper<Multifile> bookquery = new MPJLambdaWrapper<>();
@@ -640,16 +644,16 @@
            s.setSysList(userrelList);
            //会议室管理员
            MPJLambdaWrapper<UserRel> param = new MPJLambdaWrapper<>();
            urquery.selectAll(UserRel.class);
            urquery.eq(UserRel::getObjType, MeetConstants.ZERO);
            urquery.eq(UserRel::getIsdeleted, MeetConstants.ZERO);
            urquery.eq(UserRel::getObjId, s.getRoomId());
            List<UserRel> adminList = userRelJoinMapper.selectJoinList(UserRel.class, urquery);
            param.selectAll(UserRel.class);
            param.eq(UserRel::getObjType, MeetConstants.ZERO);
            param.eq(UserRel::getIsdeleted, MeetConstants.ZERO);
            param.eq(UserRel::getObjId, s.getRoomId());
            List<UserRel> adminList = userRelJoinMapper.selectJoinList(UserRel.class, param);
            s.setAdminList(adminList);
            //查询是否有权限
            s.setHasRole(getHasRoleByParam(s,userInfo,adminList));
          /*  //服务项
            /*  //服务项
            MPJLambdaWrapper<ProjectRel> prquery = new MPJLambdaWrapper<>();
            prquery.selectAll(ProjectRel.class);
            prquery.eq(ProjectRel::getIsdeleted, MeetConstants.ZERO);
@@ -670,7 +674,7 @@
        if(Constants.equalsInteger(userInfo.getId(),s.getCreator())  ){
              return 1;
        }
        if(adminList!=null){
        if(adminList!=null && userInfo!=null){
            for(UserRel u : adminList){
                if(Constants.equalsInteger(userInfo.getId(),u.getUserId())  ){
                    return 1;
@@ -1091,7 +1095,8 @@
    @Override
    public MeetingDetailResponse getMeetingDetail(Integer id,Integer sysUserId) {
        MeetingDetailResponse meetingDetailResponse = bookingsMapper.meetingDetail(id);
        if (Objects.isNull(meetingDetailResponse)) {
        if (Objects.isNull(meetingDetailResponse)
                || Constants.equalsInteger(meetingDetailResponse.getIsdeleted(),Constants.ONE) ) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "未查询到会议详情");
        }
        //预约人
@@ -1184,6 +1189,7 @@
    public Integer reservationMeeting(BookingsRequest bookingsRequest) {
        Bookings bookings = new Bookings();
        BeanUtils.copyProperties(bookingsRequest, bookings);
        bookings.setJoinNotice(bookingsRequest.getJoinNotice());
        if (Objects.isNull(bookingsRequest.getId())) {
            this.create(bookings);
            return bookings.getId();
@@ -1204,8 +1210,20 @@
        if (Objects.isNull(bookings)) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "未查询到预约记录");
        }
        if (!bookings.getCreator().equals(businessOverDTO.getUserId())) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "非你的预约记录,无法进行取消");
//        LoginUserInfo user =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        //会议室管理员
        MPJLambdaWrapper<UserRel> param = new MPJLambdaWrapper<>();
        param.selectAll(UserRel.class);
        param.eq(UserRel::getObjType, MeetConstants.ZERO);
        param.eq(UserRel::getIsdeleted, MeetConstants.ZERO);
        param.eq(UserRel::getObjId, bookings.getRoomId());
        List<UserRel> adminList = userRelJoinMapper.selectJoinList(UserRel.class, param);
        Integer hasRole =getHasRoleByParam(bookings,businessOverDTO.getLoginUser(),adminList);
//        if (!bookings.getCreator().equals(businessOverDTO.getUserId())) {
        if (!Constants.equalsInteger(hasRole,Constants.ONE)) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,只有会议室管理员和申请人才能进行该操作哦!");
        }
        if (Objects.nonNull(bookings.getStartTimeReal()) && System.currentTimeMillis() > bookings.getStartTimeReal().getTime()) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "会议已开始,无法进行取消");
@@ -1302,6 +1320,37 @@
    }
    /**
     * 自动开始会议
     */
    @Override
    public void autoStart(){
        List<Rooms> roomList = roomsMapper.selectList(new QueryWrapper<Rooms>().lambda().eq(Rooms::getIsdeleted,Constants.ZERO).eq(Rooms::getStatus,Constants.ZERO));
        for (Rooms rooms:roomList) {
            //查询当前会议室是否存在进行中的会议
            if(bookingsMapper.selectCount(new QueryWrapper<Bookings>().lambda().eq(Bookings::getIsdeleted,Constants.ZERO)
                    .eq(Bookings::getStatus,Constants.ZERO).eq(Bookings::getRoomId,rooms.getId()).isNotNull(Bookings::getStartTimeReal).
                    apply(" DATE_FORMAT(NOW(), '%Y-%m-%d') = DATE_FORMAT(START_TIME, '%Y-%m-%d') ")
            )<=Constants.ZERO){
                //根据会议室获取可以开启的会议记录(第一条记录)
                Bookings bookings = bookingsMapper.selectOne(new QueryWrapper<Bookings>().lambda()
                        .eq(Bookings::getIsdeleted,Constants.ZERO)
                        .eq(Bookings::getStatus,Constants.ZERO)
                        .eq(Bookings::getRoomId,rooms.getId())
                        .apply(" now() > START_TIME and now() < END_TIME ")
                        .isNull(Bookings::getStartTimeReal)
                        .orderByAsc(Bookings::getStartTime)
                        .last(" limit 1 ")
                );
                if(Objects.nonNull(bookings)){
                    bookings.setStartTimeReal(new Date());
                    bookings.setEditDate(bookings.getStartTimeReal());
                    bookingsMapper.updateById(bookings);
                }
            }
        }
    }
    /**
     * 提前开始
     * @param businessOverDTO
     */
@@ -1355,7 +1404,7 @@
                    .ne(Bookings::getId,bookings.getId())
            )>Constants.ZERO){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在未开启会议,无法开始会议");
            };
            }
            if(bookingsMapper.selectCount(new QueryWrapper<Bookings>()
                    .lambda() 
@@ -1366,7 +1415,7 @@
                    .eq(Bookings::getRoomId,bookings.getRoomId())
            )>Constants.ZERO){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前开启时间与其他会议存在冲突,无法开始会议");
            };
            }
        }else{
            if(bookings.getStartTime().getTime() > System.currentTimeMillis()){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未到会议申请开始时间,无法开始");
@@ -1384,6 +1433,7 @@
                .set(Bookings::getDoneInfo,"其他会议开始,自动关闭")
                .apply(" ( END_TIME < now() or ( END_TIME > now() and START_TIME < now() and START_TIME_REAL is null  ) )")
                .eq(Bookings::getStatus,Constants.ZERO)
                .ne(Bookings::getId,bookings.getId())
                .eq(Bookings::getRoomId,bookings.getRoomId())
        );
@@ -1431,7 +1481,10 @@
                 .eq(Bookings::getIsdeleted, MeetConstants.ZERO)
                 .eq(Bookings::getStatus, MeetConstants.ZERO)
                 .eq(Rooms::getId, rooms.getId())
                 .apply("to_days(t.start_time) = to_days(now()) and t.end_time > now()")//子查询当天的
                 .apply(" (  " +
                         " to_days(t.start_time) = to_days(now()) " +
                         " and ( t.START_TIME_REAL is not null or ( t.end_time > now()  and  t.START_TIME_REAL is  null ) ) " +
                         " ) ")//子查询当天的
                 .orderByAsc(Bookings::getStartTime);
        Integer minute =getNearStartMinut();
        List<Bookings> meetingList =bookingsMapper.selectJoinList(Bookings.class,queryWrapper);
@@ -1578,7 +1631,8 @@
                            .replace("{参会人员姓名}",StringUtils.defaultString(i.getRealName(),""))
                            .replace("{会议主题}",StringUtils.defaultString(bookings.getName(),""))
                            .replace("{会议室名称}",StringUtils.defaultString(bookings.getRoomName(),""))
                            .replace("{会议时间段}",StringUtils.defaultString(timeInfo,"")));
                            .replace("{会议时间段}",StringUtils.defaultString(timeInfo,""))
                            .replace("{会议备注}",StringUtils.defaultString(bookings.getRemark(),"无")));
                    smsEmailList.add(smsEmail);
                }
            }
@@ -1604,6 +1658,7 @@
                            .replace("{参会人员姓名}",StringUtils.defaultString(systemUser.getRealname(),""))
                            .replace("{会议主题}",StringUtils.defaultString(bookings.getName(),""))
                            .replace("{会议室名称}",StringUtils.defaultString(bookings.getRoomName(),""))
                            .replace("{会议备注}",StringUtils.defaultString(bookings.getRemark(),"无"))
                            .replace("{会议时间段}",StringUtils.defaultString(timeInfo,"")));
                    smsEmailList.add(smsEmail);
                }