| | |
| | | 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; |
| | |
| | | @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); |
| | | int update = technicianMapper.update(null, updateWrapper); |
| | | if (update == 0){ |
| | | throw new ServiceException("改技师已预约"); |
| | | } |
| | | } |
| | | } |