From 1901fceb6ddaa56a57f3131191454554c3e77e68 Mon Sep 17 00:00:00 2001 From: guohongjin <guohongjin@test.com> Date: 星期三, 01 五月 2024 13:56:51 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/PsychologicalCounseling --- rest/src/main/java/cn/stylefeng/rest/modular/user/controller/CounsellingInfoController.java | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 39 insertions(+), 18 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 34c63c4..5642909 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; @@ -582,6 +588,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 +624,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 +690,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 +710,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 +783,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