phpcjl
2024-12-05 095021e559ebf541e46d4bee6337d70d8147cb6c
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
@@ -1,12 +1,8 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.redis.annotation.DistributedLock;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.other.api.domain.TechnicianSubscribe;
import com.ruoyi.other.enums.TechnicianErrorCode;
import com.ruoyi.other.enums.TechnicianStatus;
import com.ruoyi.other.mapper.TechnicianMapper;
import com.ruoyi.other.mapper.TechnicianSubscribeMapper;
@@ -43,15 +39,15 @@
    }
    @Override
    @DistributedLock(lockNamePre = "#technician_subscribe_lock", lockNamePost = "#technicianId")
//    @DistributedLock(lockNamePre = "#technician_subscribe_lock", lockNamePost = "#technicianId")
    public void subscribe(TechnicianSubscribe subscribe, Long technicianId) {
        Long count = technicianSubscribeMapper.selectCount(new LambdaQueryWrapper<TechnicianSubscribe>()
                .eq(TechnicianSubscribe::getTechnicianId, technicianId)
                .eq(TechnicianSubscribe::getSubscribeTime, subscribe.getSubscribeTime())
                .eq(TechnicianSubscribe::getStatus, TechnicianStatus.UNSUBSCRIBE.getCode()));
        if (count > 0) {
            throw new ServiceException("当前时间段已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode());
        }
//        Long count = technicianSubscribeMapper.selectCount(new LambdaQueryWrapper<TechnicianSubscribe>()
//                .eq(TechnicianSubscribe::getTechnicianId, technicianId)
//                .eq(TechnicianSubscribe::getSubscribeTime, subscribe.getSubscribeTime())
//                .eq(TechnicianSubscribe::getStatus, TechnicianStatus.UNSUBSCRIBE.getCode()));
//        if (count > 0) {
//            throw new ServiceException("当前时间段已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode());
//        }
        // 创建技师预约单
        Long userId = SecurityUtils.getUserId();
        subscribe.setAppUserId(userId);