From 34ec63ac94b2b61bbdbc4b6a98a577efedbafda8 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 28 十一月 2024 13:41:23 +0800 Subject: [PATCH] 开发购物车列表 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java index 6fb0962..e1434cb 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java @@ -1,13 +1,14 @@ package com.ruoyi.other.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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; 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.api.domain.TechnicianSubscribe; import com.ruoyi.other.service.TechnicianSubscribeService; import com.ruoyi.other.vo.TechnicianSubscribeVO; import org.springframework.stereotype.Service; @@ -40,21 +41,24 @@ @Override @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("该技师已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode()); + } } } -- Gitblit v1.7.1