From 339d15eb99805ce78fdd07005d64faacb57d649d Mon Sep 17 00:00:00 2001
From: guohongjin <guohongjin@test.com>
Date: 星期三, 08 五月 2024 16:37:56 +0800
Subject: [PATCH] 修改最低价显示

---
 rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java |   62 +++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java b/rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java
index 36f16bf..309c5b3 100644
--- a/rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java
+++ b/rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java
@@ -48,6 +48,8 @@
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -60,6 +62,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.stream.Collectors;
 
@@ -125,6 +128,9 @@
     private String refundAlipayUrl;
     @Value("${refund.wxpay-url}")
     private String refundWxpayUrl;
+
+    @Resource
+    private RedissonClient redissonClient;
 
 
 
@@ -302,7 +308,8 @@
             List<Customer> customerList = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId,Customer::getNickName).in(Customer::getCustomerId,custommerIds));
             //查询套餐最低价
             List<Map<String,Object>> lowMapList = this.counsellingSetMealService.listMaps(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().in(CounsellingSetMeal::getCounsellingInfoId,counseIds)
-                    .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0));
+                    .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0)
+                    .groupBy(CounsellingSetMeal::getCounsellingInfoId));
 
             List<CounsellinginfoResponseDTO> counsellinginfoResponseDTOS = BeanUtil.copyToList(page.getRecords(),CounsellinginfoResponseDTO.class, CopyOptions.create());
             counsellinginfoResponseDTOS.stream().forEach(counsellinginfoResponseDTO -> {
@@ -329,7 +336,7 @@
 
                 if (CollectionUtil.isNotEmpty(lowMapList)){
                     lowMapList.stream().forEach(stringObjectMap -> {
-                        if (stringObjectMap.get("counsellingInfoId") != null){
+                        if (stringObjectMap.get("counsellingInfoId") != null && stringObjectMap.get("counsellingInfoId").toString().equals(counsellinginfoResponseDTO.getId().toString()) ){
                             counsellinginfoResponseDTO.setLowPrice(new BigDecimal(stringObjectMap.get("price").toString()));
                         }
                     });
@@ -582,6 +589,7 @@
     @ApiOperation("咨询订单预约")
     @PostResource(name = "咨询订单预约", path = "/counsellingOrderReservation/saveCounsellingOrderReservation")
     public ResponseData<CounsellingOrderReservation> saveCounsellingOrderReservation(@RequestBody CounsellingReservationRequest counsellingReservationRequest) throws ParseException {
+
         //查询咨询师当天是否取消预约
         CounsellingSpecialTimeConfig specialTimeConfig = this.counsellingSpecialTimeConfigService.getOne(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
                 .eq(CounsellingSpecialTimeConfig::getSpecialDay,counsellingReservationRequest.getDayTime()).eq(CounsellingSpecialTimeConfig::getIsCancelDay,1));
@@ -617,6 +625,15 @@
         if (counsellingOrder == null){
             throw new ServiceException("没有在咨询的订单,无法进行预约!");
         }
+        String key = "counsel:" + counsellingReservationRequest.getCounsellingId()+"_"+counsellingReservationRequest.getDayTime()+"_"+counsellingReservationRequest.getTimePoint();
+        RLock lock = redissonClient.getLock(key);
+        boolean tryLock = false;
+        try {
+            log.info("咨询key:"+key+",userId:"+counsellingOrder.getUserId());
+            tryLock = lock.tryLock(20, TimeUnit.SECONDS);
+            if (!tryLock) {
+                throw new ServiceException("当前时间段已预约,请选择其他时间段!");
+            }
 
         //验证未支付的首次咨询订单
         long counselllingCount = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getFirstAppointmentDate,counsellingReservationRequest.getDayTime())
@@ -674,10 +691,7 @@
             this.counsellingOrderService.updateById(counsellingOrder);
             this.counsellingUserService.updateById(counsellingUserOld);
 
-
-
             CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
-
 
             //将此条消息加入到可聊天的表中t_mental_appointment
             MentalAppointment mentalAppointment = MentalAppointment.builder()
@@ -697,8 +711,8 @@
 
             // 发送IM消息
             ImPushDataDTO pushData1 = ImPushDataDTO.builder()
-                    .type(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT.getCode())
-                    .title(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT.getName())
+                    .type(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT_FIRST.getCode())
+                    .title(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT_FIRST.getName())
                     .content("预约成功"+",请注意预约时间:"+counsellingReservationRequest.getDayTime()+counsellingReservationRequest.getTimePoint())
 //                    .content("预约成功!")
                     .objId(ObjUtil.toString(counsellingInfo.getId()))
@@ -770,24 +784,32 @@
             customerService.updateCustomerRemoveCache(customer);
         }
 
-        try {
+            try {
 
-        CustomerUpdateRequest customerUpdateRequest = counsellingReservationRequest.getCustomerUpdateRequest();
-        Customer customer = new Customer();
-        BeanUtil.copyProperties(customerUpdateRequest,customer);
-            LoginUser loginUser = LoginContext.me().getLoginUser();
-            customer.setCustomerId(loginUser.getUserId());
-        customerService.updateById(customer);
-        }catch (Exception e){
-            e.printStackTrace();
-            log.info("编辑用户报错");
+            CustomerUpdateRequest customerUpdateRequest = counsellingReservationRequest.getCustomerUpdateRequest();
+            Customer customer = new Customer();
+            BeanUtil.copyProperties(customerUpdateRequest,customer);
+                LoginUser loginUser = LoginContext.me().getLoginUser();
+                customer.setCustomerId(loginUser.getUserId());
+            customerService.updateById(customer);
+            }catch (Exception e){
+                e.printStackTrace();
+                log.info("编辑用户报错");
+            }
+            return new SuccessResponseData<>(counsellingOrderReservation);
+        }catch (Exception ex){
+            log.error("咨询预约服务异常",ex.getStackTrace());
+            throw new ServiceException("当前时间段已在进行预约,请稍后再试!");
+        }finally {
+            if(tryLock){
+                lock.unlock();
+            }
         }
 
-        return new SuccessResponseData<>(counsellingOrderReservation);
-    }
+  }
 
 
-    @ApiOperation("根据咨询订单id查询咨询信息")
+   @ApiOperation("根据咨询订单id查询咨询信息")
     @GetResource(name = "根据咨询订单id查询咨询信息", path = {"/counsellingOrder/getCounsellingOrderInfoById","/worker/counsellingOrder/getCounsellingOrderInfoById"})
     public ResponseData<CounsellingOrderResponseDTO> getCounsellingOrderInfoById(Long counsellingOrderId){
         CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(counsellingOrderId);

--
Gitblit v1.7.1