| | |
| | | package com.ruoyi.other.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.other.mapper.TechnicianSubscribeMapper; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | 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.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.util.Collections; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author luodangjia |
| | |
| | | public class TechnicianSubscribeServiceImpl extends ServiceImpl<TechnicianSubscribeMapper, TechnicianSubscribe> implements TechnicianSubscribeService { |
| | | @Resource |
| | | private TechnicianSubscribeMapper technicianSubscribeMapper; |
| | | @Resource |
| | | private TechnicianMapper technicianMapper; |
| | | |
| | | @Override |
| | | public List<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop(Long userId, Long shopId) { |
| | |
| | | public List<TechnicianSubscribeVO> getTechnicianSubscribeByUser(Long userId, Integer status) { |
| | | return technicianSubscribeMapper.getTechnicianSubscribeByUser(userId, status); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void subscribe(TechnicianSubscribe technicianSubscribe) { |
| | | // 创建技师预约单 |
| | | Long technicianId = technicianSubscribe.getTechnicianId(); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | TechnicianSubscribe subscribe = new TechnicianSubscribe(); |
| | | subscribe.setAppUserId(userId); |
| | | 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()); |
| | | } |
| | | } |
| | | } |