luodangjia
2024-12-04 a981c07d34edd0975b9d556d97c1f851ce79974c
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
@@ -1,18 +1,18 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.Technician;
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;
import com.ruoyi.other.service.TechnicianSubscribeService;
import com.ruoyi.other.vo.TechnicianSubscribeVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
@@ -43,26 +43,22 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void subscribe(TechnicianSubscribe technicianSubscribe) {
//    @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 technicianId = technicianSubscribe.getTechnicianId();
        Long userId = SecurityUtils.getUserId();
        TechnicianSubscribe subscribe = new TechnicianSubscribe();
        subscribe.setAppUserId(userId);
        subscribe.setStatus(TechnicianStatus.UNSUBSCRIBE.getCode());
        subscribe.setDelFlag(0);
        subscribe.setCreateTime(LocalDateTime.now());
        technicianSubscribeMapper.insert(subscribe);
        // 更新技师状态
        UpdateWrapper<Technician> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", technicianId);
        updateWrapper.eq("subscribe_status", 1);
        updateWrapper.eq("status", 2);
        updateWrapper.set("subscribe_status", 2);
        updateWrapper.set("create_time", LocalDateTime.now());
        int update = technicianMapper.update(null, updateWrapper);
        if (update == 0){
            throw new ServiceException("该技师已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode());
        }
    }
}