phpcjl
2024-11-26 d66f9e8e853c3c4a2314ce9d0a20b85da5a8c67e
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
@@ -1,6 +1,8 @@
package com.ruoyi.other.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.security.utils.SecurityUtils;
@@ -41,20 +43,21 @@
    @Transactional(rollbackFor = Exception.class)
    public void subscribe(TechnicianSubscribe technicianSubscribe) {
        Long technicianId = technicianSubscribe.getTechnicianId();
        Technician technician = technicianMapper.selectOne(new LambdaQueryWrapper<Technician>()
                .eq(Technician::getId, technicianId)
                .eq(Technician::getStatus, 1)
                .eq(Technician::getSubscribeStatus, 1));
        if (null == technician) {
            throw new ServiceException("不满足预约条件");
        }
        Long userId = SecurityUtils.getUserId();
        TechnicianSubscribe subscribe = new TechnicianSubscribe();
        subscribe.setAppUserId(userId);
        subscribe.setDelFlag(0);
        subscribe.setCreateTime(LocalDateTime.now());
        technicianSubscribeMapper.insert(subscribe);
        technician.setSubscribeStatus(2);
        technicianMapper.updateById(technician);
        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("改技师已预约");
        }
    }
}