소스 검색

代码提交

wangzhijun 1 주 전
부모
커밋
f646943f68

+ 4 - 4
nightFragrance-massage/src/main/java/com/ylx/lottery/service/impl/LotteryCountServiceImpl.java

@@ -46,20 +46,20 @@ public class LotteryCountServiceImpl implements LotteryCountService {
         List<LotteryCountDTO> dtoList = new ArrayList<>();
         // 1. 获取广誉源用户本地未同步抽奖次数
         LambdaQueryWrapper<LotteryCountLog> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(LotteryCountLog::getUserId, dto.getSourceUserId());
+        queryWrapper.eq(LotteryCountLog::getUserId, dto.getTargetUserId());
         queryWrapper.eq(LotteryCountLog::getStatus, 0);
         queryWrapper.eq(LotteryCountLog::getIsDelete, 0);
         List<LotteryStatVO> resultList = lotteryCountLogService.selectSumByGroup(queryWrapper);
 
         if (CollUtil.isEmpty(resultList)) {
-            log.info("用户[{}]没有待同步的抽奖记录", dto.getSourceUserId());
+            log.info("用户[{}]没有待同步的抽奖记录", dto.getTargetUserId());
             return true;
         }
 
         // 2. 构建请求参数
         for (LotteryStatVO statVO : resultList) {
             LotteryCountDTO countDTO = new LotteryCountDTO();
-            countDTO.setAppUserId(dto.getTargetUserId());
+            countDTO.setAppUserId(dto.getSourceUserId());
             countDTO.setCount(statVO.getTotalNum());
             countDTO.setActivityId(statVO.getLocalActivityTableId());
             dtoList.add(countDTO);
@@ -95,7 +95,7 @@ public class LotteryCountServiceImpl implements LotteryCountService {
             }
 
             // 5. 更新本地数据库状态
-            updateSyncStatus(dto.getSourceUserId());
+            updateSyncStatus(dto.getTargetUserId());
 
             return true;
 

+ 35 - 5
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/TCommentUserServiceImpl.java

@@ -2,7 +2,6 @@ package com.ylx.massage.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ylx.common.core.domain.model.WxLoginUser;
 import com.ylx.common.exception.ServiceException;
@@ -10,23 +9,23 @@ import com.ylx.common.utils.StringUtils;
 import com.ylx.lottery.domain.LotteryCountLog;
 import com.ylx.lottery.domain.vo.LocalActivityTableVO;
 import com.ylx.lottery.domain.vo.LotteryActivityVO;
-import com.ylx.lottery.domain.vo.LotteryStatVO;
 import com.ylx.lottery.service.LotteryCountLogService;
 import com.ylx.lottery.service.LotteryCountService;
 import com.ylx.massage.domain.CommentUserAudit;
-import com.ylx.massage.domain.TComment;
+import com.ylx.massage.domain.TCommentUser;
 import com.ylx.massage.domain.TOrder;
 import com.ylx.massage.enums.OrderStatusEnum;
 import com.ylx.massage.mapper.TCommentUserMapper;
-import com.ylx.massage.domain.TCommentUser;
 import com.ylx.massage.service.TCommentUserAuditService;
 import com.ylx.massage.service.TCommentUserService;
 import com.ylx.massage.service.TOrderService;
+import com.ylx.usercenter.domain.dto.UnifiedUserCenterDTO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.List;
 
@@ -36,6 +35,7 @@ import java.util.List;
  * @author makejava
  * @since 2024-08-08 10:32:08
  */
+@Slf4j
 @Service("tCommentUserService")
 public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCommentUser> implements TCommentUserService {
 
@@ -100,6 +100,8 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
         boolean bool = orderService.updateById(order);
         if (bool) {
 
+            Integer isBind = wxLoginUser.getIsBind();
+            String localLiveUserId = wxLoginUser.getLocalLiveUserId();
             // 评价有礼
             List<LotteryActivityVO> lotteryActivityVOS = lotteryCountService.queryActivityRules();
             if (CollUtil.isNotEmpty(lotteryActivityVOS)) {
@@ -159,6 +161,15 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
                     }
                 }
             }
+
+            // todo  事务问题 当前用户绑定一账通
+            if (ObjectUtil.isNotNull(isBind) && (ObjectUtil.equals(isBind, 1) && ObjectUtil.isNotNull(localLiveUserId))) {
+                // 同步抽奖次数(异步处理)
+                UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();
+                dto.setTargetUserId(localLiveUserId);
+                dto.setSourceUserId(wxLoginUser.getId());
+                syncLotteryCount(dto);
+            }
         }
         return bool;
     }
@@ -168,5 +179,24 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
     public List<TCommentUser> selectAll(TCommentUser tCommentUser) {
         return tCommentUserMapper.selectAll(tCommentUser);
     }
+
+    // 异步同步抽奖次数
+    @Async
+    public void syncLotteryCount(UnifiedUserCenterDTO dto) {
+        try {
+            boolean lotteryCountBool = this.lotteryCountService.batchAdd(dto);
+            if (lotteryCountBool) {
+                log.info("同步用户抽奖次数到本地生活服务成功, userId:{}", dto.getTargetUserId());
+            } else {
+                log.warn("同步用户抽奖次数到本地生活服务失败, userId:{}", dto.getTargetUserId());
+                // 同步失败,记录告警日志
+                log.error("【告警】同步用户抽奖次数到本地生活服务失败,需要人工处理, userId:{}", dto.getTargetUserId());
+            }
+        } catch (Exception e) {
+            log.error("同步用户抽奖次数到本地生活服务异常, userId:{}", dto.getTargetUserId(), e);
+            // 异常情况,记录告警日志
+            log.error("【告警】同步用户抽奖次数到本地生活服务异常,需要人工处理, userId:{}", dto.getTargetUserId(), e);
+        }
+    }
 }
 

+ 7 - 8
nightFragrance-massage/src/main/java/com/ylx/usercenter/service/impl/UnifiedUserCenterServiceImpl.java

@@ -63,9 +63,9 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
             validateDto(dto);
 
             // 2.获取用户信息
-            TWxUser wxUser = this.wxUserService.getById(dto.getSourceUserId());
+            TWxUser wxUser = this.wxUserService.getById(dto.getTargetUserId());
             if (ObjUtil.isEmpty(wxUser)) {
-                log.error("用户信息不存在, userId: {}", dto.getSourceUserId());
+                log.error("用户信息不存在, userId: {}", dto.getTargetUserId());
                 throw new ServiceException("用户信息不存在");
             }
 
@@ -74,12 +74,12 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
 
             // 4. 判断绑定成功
             if (ObjUtil.notEqual(remoteResult.getCode(), 200)) {
-                log.error("远程绑定失败, userId: {}, msg: {}", dto.getSourceUserId(), remoteResult.getMsg());
+                log.error("远程绑定失败, userId: {}, msg: {}", dto.getTargetUserId(), remoteResult.getMsg());
                 return R.fail("用户绑定失败:" + remoteResult.getMsg());
             }
 
             // 5. 更新本地数据库(独立事务)
-            updateUserBindStatus(dto);
+            updateUserBindStatus(dto,wxUser);
 
             // 6. 同步抽奖次数(异步处理)
             syncLotteryCount(dto);
@@ -87,10 +87,10 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
             return R.ok(remoteResult.getData(), "用户绑定成功");
 
         } catch (ServiceException e) {
-            log.error("用户绑定业务异常, userId:{}", dto.getSourceUserId(), e);
+            log.error("用户绑定业务异常, userId:{}", dto.getTargetUserId(), e);
             throw e;
         } catch (Exception e) {
-            log.error("用户绑定系统异常, userId:{}", dto.getSourceUserId(), e);
+            log.error("用户绑定系统异常, userId:{}", dto.getTargetUserId(), e);
             throw new ServiceException("系统异常,请稍后重试");
         }
     }
@@ -197,9 +197,8 @@ public class UnifiedUserCenterServiceImpl implements UnifiedUserCenterService {
 
     // 独立事务方法
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void updateUserBindStatus(UnifiedUserCenterDTO dto) {
+    public void updateUserBindStatus(UnifiedUserCenterDTO dto, TWxUser wxUser) {
         try {
-            TWxUser wxUser = this.wxUserService.getById(dto.getTargetUserId());
             wxUser.setIsBind(1);
             wxUser.setLocalLiveUserId(dto.getSourceUserId());
             boolean wxUserBool = this.wxUserService.updateById(wxUser);