From 3a2f3beb47ba2ffc6862c9d089e35e1dda9040ff Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期一, 02 十二月 2024 14:54:12 +0800
Subject: [PATCH] 1.t_app_user_shop表的实现

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java               |   12 +++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TechnicianSubscribeService.java          |    3 +
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java            |    6 ++-
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianStatus.java                      |   26 +++++++++++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java |   31 +++++++--------
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java |    5 ++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianSubscribeController.java    |   36 +++++++++++++----
 7 files changed, 89 insertions(+), 30 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java
index 11c9cc9..3fc2995 100644
--- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java
@@ -13,6 +13,11 @@
             public R<Technician> shopdetail(Integer techId) {
                 return R.fail("根据省市区获取地区价格配置失败:" + cause.getMessage());
             }
+
+            @Override
+            public R<Void> updateStatus(Integer status, Integer subscribeId) {
+                return R.fail("跟新技师预约状态失败:" + cause.getMessage());
+            }
         };
     }
 }
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java
index 5095d9b..d340d35 100644
--- a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java
@@ -3,11 +3,10 @@
 import com.ruoyi.common.core.constant.ServiceNameConstants;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.other.api.domain.Technician;
-import com.ruoyi.other.api.factory.SystemConfigClientFallbackFactory;
 import com.ruoyi.other.api.factory.TechnicianClientFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
 @FeignClient(contextId = "TechnicianClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = TechnicianClientFallbackFactory.class)
@@ -15,4 +14,7 @@
 
     @PostMapping("/technician/shop/detail")
     R<Technician> shopdetail(@RequestParam Integer techId);
+
+    @PutMapping("/technician-subscribe/updateStatus")
+    R<Void> updateStatus(@RequestParam Integer status, @RequestParam Integer subscribeId);
 }
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index 9155cbc..a59f576 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -22,6 +22,7 @@
 import com.ruoyi.other.api.domain.Goods;
 import com.ruoyi.other.api.domain.OrderActivityInfo;
 import com.ruoyi.other.api.domain.Technician;
+import com.ruoyi.other.api.feignClient.TechnicianClient;
 import com.ruoyi.system.api.model.LoginUser;
 import model.Order;
 import model.OrderGood;
@@ -52,7 +53,7 @@
     @Resource
     private TokenService tokenService;
     @Resource
-    private Technician
+    private TechnicianClient technicianClient;
 
     @Override
     public List<OrderVO> selectOrderListByUserId(Integer status, Long userId) {
@@ -172,6 +173,15 @@
         orderMapper.updateById(order);
         Integer orderType = order.getOrderType();
         if (orderType.equals(OrderType.SERVICE.getCode())){
+            R<Technician> shopdetail = technicianClient.shopdetail(order.getTechnicianId());
+            if (shopdetail.getCode() != R.SUCCESS){
+                throw new ServiceException("获取技师信息失败");
+            }
+            Technician technician = shopdetail.getData();
+            R<Void> r = technicianClient.updateStatus(2, technician.getId());
+            if (r.getCode() != R.SUCCESS){
+                throw new ServiceException("修改技师状态失败");
+            }
         }
     }
 }
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianSubscribeController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianSubscribeController.java
index 9b6010f..fb1ef6c 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianSubscribeController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianSubscribeController.java
@@ -2,6 +2,7 @@
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.page.TableDataInfo;
@@ -19,7 +20,7 @@
 
 /**
  * <p>
- *  前端控制器
+ * 前端控制器
  * </p>
  *
  * @author luodangjia
@@ -38,10 +39,10 @@
     @GetMapping("/list")
     @ApiOperation(value = "预约列表", notes = "预约列表", tags = {"小程序-个人中心-门店管理-预约列表"})
     public TableDataInfo list(@ApiParam(value = "状态") @RequestParam Integer status,
-                              @ApiParam(value = "门店id") @RequestParam Long shopId){
+                              @ApiParam(value = "门店id") @RequestParam Long shopId) {
         startPage();
         List<TechnicianSubscribeVO> list = technicianSubscribeService
-                .getTechnicianSubscribeByUserAndShop(SecurityUtils.getUserId(),shopId);
+                .getTechnicianSubscribeByUserAndShop(SecurityUtils.getUserId(), shopId);
         return getDataTable(list);
     }
 
@@ -50,8 +51,8 @@
      */
     @PostMapping("/subscribe")
     @ApiOperation(value = "预约技师", notes = "预约技师", tags = {"小程序-个人中心-门店管理-预约列表-预约技师"})
-    public R<Void> subscribe(@RequestBody TechnicianSubscribe technicianSubscribe){
-        technicianSubscribeService.subscribe(technicianSubscribe);
+    public R<Void> subscribe(@RequestBody TechnicianSubscribe technicianSubscribe) {
+        technicianSubscribeService.subscribe(technicianSubscribe, technicianSubscribe.getTechnicianId());
         return R.ok();
     }
 
@@ -60,12 +61,12 @@
      */
     @GetMapping("/cancel")
     @ApiOperation(value = "取消服务", notes = "取消服务", tags = {"小程序-个人中心-门店管理-预约列表-取消服务"})
-    public R<Void> cancel(@ApiParam(value = "预约id") @RequestParam Long id){
+    public R<Void> cancel(@ApiParam(value = "预约id") @RequestParam Long id) {
 
         TechnicianSubscribe subscribe = technicianSubscribeService.getOne(new LambdaQueryWrapper<TechnicianSubscribe>()
                 .eq(TechnicianSubscribe::getId, id)
                 .eq(TechnicianSubscribe::getStatus, 0));
-        if (null == subscribe){
+        if (null == subscribe) {
             return R.fail("不满足取消条件");
         }
         subscribe.setStatus(2);
@@ -73,13 +74,30 @@
         return R.ok();
     }
 
+    /**
+     * 跟新技师预约状态
+     *
+     * @param status
+     */
+    @PutMapping("/updateStatus")
+    @ApiOperation(value = "跟新技师预约状态", notes = "跟新技师预约状态", tags = {"后台-技师预约管理-跟新技师预约状态"})
+    public R<Void> updateStatus(@ApiParam @RequestParam Integer status, @ApiParam @RequestParam Long subscribeId) {
+        boolean update = technicianSubscribeService.update(new LambdaUpdateWrapper<TechnicianSubscribe>()
+                .eq(TechnicianSubscribe::getId, subscribeId)
+                .set(TechnicianSubscribe::getStatus, status));
+        if (!update) {
+            return R.fail("更新失败");
+        }
+        return R.ok();
+    }
+
 
     @GetMapping("/home/list")
     @ApiOperation(value = "列表", notes = "列表", tags = {"小程序-个人中心-我的预约"})
-    public TableDataInfo homelist(@ApiParam(value = "状态 0=待服务,1=已服务,2=已取消 4 已到期") @RequestParam Integer status){
+    public TableDataInfo homelist(@ApiParam(value = "状态 0=待服务,1=已服务,2=已取消 4 已到期") @RequestParam Integer status) {
         startPage();
         List<TechnicianSubscribeVO> list = technicianSubscribeService
-                .getTechnicianSubscribeByUser(SecurityUtils.getUserId(),status);
+                .getTechnicianSubscribeByUser(SecurityUtils.getUserId(), status);
         return getDataTable(list);
     }
 
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianStatus.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianStatus.java
new file mode 100644
index 0000000..3edfa0c
--- /dev/null
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/enums/TechnicianStatus.java
@@ -0,0 +1,26 @@
+package com.ruoyi.other.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum TechnicianStatus {
+    UNSUBSCRIBE(0, "待服务"),
+    SERVE(1, "已服务"),
+    CANCEL(2, "已取消");
+    private final Integer code;
+    private final String message;
+
+    TechnicianStatus(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public static String getMessage(Integer code) {
+        for (TechnicianStatus value : TechnicianStatus.values()) {
+            if (value.getCode().equals(code)) {
+                return value.getMessage();
+            }
+        }
+        return null;
+    }
+}
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TechnicianSubscribeService.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TechnicianSubscribeService.java
index b31e9a0..d3796aa 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TechnicianSubscribeService.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/TechnicianSubscribeService.java
@@ -20,7 +20,8 @@
      * 查询用于指定门店的相关预约记录
      */
     List<TechnicianSubscribeVO> getTechnicianSubscribeByUserAndShop(Long userId, Long shopId);
+
     List<TechnicianSubscribeVO> getTechnicianSubscribeByUser(Long userId, Integer status);
 
-    void subscribe(TechnicianSubscribe technicianSubscribe);
+    void subscribe(TechnicianSubscribe technicianSubscribe, Long technicianId);
 }
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 37f50fb..4c042e0 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,18 +1,18 @@
 package com.ruoyi.other.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.redis.annotation.DistributedLock;
 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.enums.TechnicianStatus;
 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.time.LocalDateTime;
@@ -43,25 +43,22 @@
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void subscribe(TechnicianSubscribe subscribe) {
+    @DistributedLock(lockNamePre = "#technician_subscribe_lock", lockNamePost = "#technicianId")
+    public void subscribe(TechnicianSubscribe subscribe, Long technicianId) {
+        Long count = technicianSubscribeMapper.selectCount(new LambdaQueryWrapper<TechnicianSubscribe>()
+                .eq(TechnicianSubscribe::getTechnicianId, technicianId)
+                .eq(TechnicianSubscribe::getSubscribeTime, subscribe.getSubscribeTime())
+                .eq(TechnicianSubscribe::getStatus, TechnicianStatus.UNSUBSCRIBE.getCode()));
+        if (count > 0) {
+            throw new ServiceException("当前时间段已被预约", TechnicianErrorCode.TECHNICIAN_ALREADY_SUBSCRIBED.getCode());
+        }
         // 创建技师预约单
-        Long technicianId = subscribe.getTechnicianId();
         Long userId = SecurityUtils.getUserId();
         subscribe.setAppUserId(userId);
+        subscribe.setStatus(TechnicianStatus.UNSUBSCRIBE.getCode());
         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());
-        }
+
     }
 }

--
Gitblit v1.7.1