From ca8a3cff66f9820aeac841a85b118935fdb3e990 Mon Sep 17 00:00:00 2001 From: phpcjl <phpcjl@gmail.com> Date: 星期二, 26 十一月 2024 18:09:01 +0800 Subject: [PATCH] 1.完成技师预约接口开发 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/GoodsStatus.java | 14 +++++--------- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianErrorCode.java | 18 ++++++++++++++++++ ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java | 9 +++++---- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/PhoneType.java | 4 ++-- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/GoodsStatus.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/GoodsStatus.java index c17d2e1..1a6702b 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/GoodsStatus.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/GoodsStatus.java @@ -1,22 +1,18 @@ package com.ruoyi.other.enums; +import lombok.Getter; + +@Getter public enum GoodsStatus { DOWN(0, "下架"), UP(1, "上架"); - private Integer code; - private String desc; + private final Integer code; + private final String desc; GoodsStatus(Integer code, String desc) { this.code = code; this.desc = desc; } - public Integer getCode() { - return code; - } - - public String getDesc() { - return desc; - } } diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/PhoneType.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/PhoneType.java index 830d7dd..a840880 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/PhoneType.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/PhoneType.java @@ -4,8 +4,8 @@ PLATFORM(1, "平台"), SHOP(2, "门店"); - private Integer code; - private String desc; + private final Integer code; + private final String desc; PhoneType(Integer code, String desc) { this.code = code; diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianErrorCode.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianErrorCode.java new file mode 100644 index 0000000..50ab4e6 --- /dev/null +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianErrorCode.java @@ -0,0 +1,18 @@ +package com.ruoyi.other.enums; + +import lombok.Getter; + +@Getter +public enum TechnicianErrorCode { + TECHNICIAN_ALREADY_SUBSCRIBED(1001, "该技师已被预约"), + ; + + private final int code; + private final String message; + + TechnicianErrorCode(int code, String message) { + this.code = code; + this.message = message; + } + +} 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 9ad9a10..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,15 +1,14 @@ 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; 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; @@ -42,6 +41,7 @@ @Override @Transactional(rollbackFor = Exception.class) public void subscribe(TechnicianSubscribe technicianSubscribe) { + // 创建技师预约单 Long technicianId = technicianSubscribe.getTechnicianId(); Long userId = SecurityUtils.getUserId(); TechnicianSubscribe subscribe = new TechnicianSubscribe(); @@ -49,6 +49,7 @@ subscribe.setDelFlag(0); subscribe.setCreateTime(LocalDateTime.now()); technicianSubscribeMapper.insert(subscribe); + // 更新技师状态 UpdateWrapper<Technician> updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("id", technicianId); updateWrapper.eq("subscribe_status", 1); @@ -57,7 +58,7 @@ updateWrapper.set("create_time", LocalDateTime.now()); int update = technicianMapper.update(null, updateWrapper); if (update == 0){ - throw new ServiceException("改技师已预约"); + throw new ServiceException("该技师已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode()); } } } -- Gitblit v1.7.1