|
|
@@ -20,10 +20,12 @@ 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 com.ylx.usercenter.service.UnifiedUserCenterService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronization;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronizationManager;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
|
@@ -51,6 +53,8 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
private LotteryCountService lotteryCountService;
|
|
|
@Resource
|
|
|
private LotteryCountLogService lotteryCountLogService;
|
|
|
+ @Resource
|
|
|
+ private UnifiedUserCenterService unifiedUserCenterService;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -97,112 +101,103 @@ public class TCommentUserServiceImpl extends ServiceImpl<TCommentUserMapper, TCo
|
|
|
//修改订单状态(已完成)
|
|
|
order.setnStatus(OrderStatusEnum.COMPLETE.getCode());
|
|
|
order.setcId(comment.getOrderId());
|
|
|
- boolean bool = orderService.updateById(order);
|
|
|
- if (bool) {
|
|
|
-
|
|
|
- Integer isBind = wxLoginUser.getIsBind();
|
|
|
- String localLiveUserId = wxLoginUser.getLocalLiveUserId();
|
|
|
- // 评价有礼
|
|
|
- List<LotteryActivityVO> lotteryActivityVOS = lotteryCountService.queryActivityRules();
|
|
|
- if (CollUtil.isNotEmpty(lotteryActivityVOS)) {
|
|
|
- for (LotteryActivityVO activity : lotteryActivityVOS) {
|
|
|
-
|
|
|
- List<LocalActivityTableVO> gyyPointTables = activity.getGyyPointTables();
|
|
|
- if (CollUtil.isNotEmpty(gyyPointTables)) {
|
|
|
- for (LocalActivityTableVO localActivityTable : gyyPointTables) {
|
|
|
-
|
|
|
- LotteryCountLog lotteryCountLog = new LotteryCountLog();
|
|
|
- lotteryCountLog.setOpenId(wxLoginUser.getCOpenid());
|
|
|
- lotteryCountLog.setUserId(wxLoginUser.getId());
|
|
|
- lotteryCountLog.setUserPhone(wxLoginUser.getCPhone());
|
|
|
- // 活动类型:2.任务奖励
|
|
|
- lotteryCountLog.setActivityType(2);
|
|
|
- lotteryCountLog.setLocalActivityTableId(localActivityTable.getId());
|
|
|
- lotteryCountLog.setLotteryNum(localActivityTable.getPointNumber());
|
|
|
- lotteryCountLog.setReceiveTime(new Date());
|
|
|
- lotteryCountLog.setIsDelete("0");
|
|
|
- // 同步状态 0-未同步到本地生活
|
|
|
- lotteryCountLog.setStatus(0);
|
|
|
-
|
|
|
- lotteryCountLog.setIsLottery(0);
|
|
|
- lotteryCountLog.setType(3);
|
|
|
- lotteryCountLogService.save(lotteryCountLog);
|
|
|
- }
|
|
|
- } else {
|
|
|
+ boolean updateOrderSuccess = orderService.updateById(order);
|
|
|
+ if (!updateOrderSuccess) {
|
|
|
+ throw new ServiceException("订单状态更新失败");
|
|
|
+ }
|
|
|
|
|
|
- // 非任务奖励活动
|
|
|
- if (ObjectUtil.isNull(activity.getParticipationRules()) || ObjectUtil.notEqual(activity.getParticipationRules(), 3)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 评价有礼 —— 发放抽奖次数日志
|
|
|
+ grantLotteryCountForComment(wxLoginUser);
|
|
|
|
|
|
- List<LocalActivityTableVO> localActivityTables = activity.getLocalActivityTables();
|
|
|
- if (CollUtil.isEmpty(localActivityTables)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 已绑定一账通 → 异步同步抽奖次数
|
|
|
+ syncLotteryCountIfNeeded(wxLoginUser);
|
|
|
|
|
|
- for (LocalActivityTableVO localActivityTable : localActivityTables) {
|
|
|
-
|
|
|
- // 判断是否评价有礼
|
|
|
- if (ObjectUtil.isNull(localActivityTable.getType()) || ObjectUtil.notEqual(localActivityTable.getType(), 4)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- LotteryCountLog lotteryCountLog = new LotteryCountLog();
|
|
|
- lotteryCountLog.setOpenId(wxLoginUser.getCOpenid());
|
|
|
- lotteryCountLog.setUserId(wxLoginUser.getId());
|
|
|
- lotteryCountLog.setUserPhone(wxLoginUser.getCPhone());
|
|
|
- // 活动类型:2.任务奖励
|
|
|
- lotteryCountLog.setActivityType(2);
|
|
|
- lotteryCountLog.setLocalActivityTableId(localActivityTable.getId());
|
|
|
- lotteryCountLog.setLotteryNum(1);
|
|
|
- lotteryCountLog.setReceiveTime(new Date());
|
|
|
- lotteryCountLog.setIsDelete("0");
|
|
|
- // 同步状态 0-未同步到本地生活
|
|
|
- lotteryCountLog.setStatus(0);
|
|
|
-
|
|
|
- lotteryCountLog.setIsLottery(0);
|
|
|
- lotteryCountLog.setType(3);
|
|
|
- lotteryCountLogService.save(lotteryCountLog);
|
|
|
- }
|
|
|
- }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TCommentUser> selectAll(TCommentUser tCommentUser) {
|
|
|
+ return tCommentUserMapper.selectAll(tCommentUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评价有礼发放抽奖次数
|
|
|
+ */
|
|
|
+ private void grantLotteryCountForComment(WxLoginUser wxLoginUser) {
|
|
|
+ List<LotteryActivityVO> activityList = lotteryCountService.queryActivityRules();
|
|
|
+ if (CollUtil.isEmpty(activityList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (LotteryActivityVO activity : activityList) {
|
|
|
+ // 处理积分表
|
|
|
+ List<LocalActivityTableVO> pointTables = activity.getGyyPointTables();
|
|
|
+ if (CollUtil.isNotEmpty(pointTables)) {
|
|
|
+ for (LocalActivityTableVO table : pointTables) {
|
|
|
+ saveLotteryLog(wxLoginUser, table, table.getPointNumber());
|
|
|
}
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 非积分表、任务奖励类型(参与规则=3)
|
|
|
+ if (ObjectUtil.notEqual(activity.getParticipationRules(), 3)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<LocalActivityTableVO> localTables = activity.getLocalActivityTables();
|
|
|
+ if (CollUtil.isEmpty(localTables)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- // 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);
|
|
|
+ // 类型=4 → 评价有礼
|
|
|
+ for (LocalActivityTableVO table : localTables) {
|
|
|
+ if (ObjectUtil.equals(table.getType(), 4)) {
|
|
|
+ saveLotteryLog(wxLoginUser, table, 1);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return bool;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<TCommentUser> selectAll(TCommentUser tCommentUser) {
|
|
|
- return tCommentUserMapper.selectAll(tCommentUser);
|
|
|
+ /**
|
|
|
+ * 统一保存抽奖次数日志
|
|
|
+ */
|
|
|
+ private void saveLotteryLog(WxLoginUser wxLoginUser, LocalActivityTableVO table, Integer lotteryNum) {
|
|
|
+ LotteryCountLog log = new LotteryCountLog();
|
|
|
+ log.setOpenId(wxLoginUser.getCOpenid());
|
|
|
+ log.setUserId(wxLoginUser.getId());
|
|
|
+ log.setUserPhone(wxLoginUser.getCPhone());
|
|
|
+ log.setActivityType(2); // 任务奖励
|
|
|
+ log.setLocalActivityTableId(table.getId());
|
|
|
+ log.setLotteryNum(lotteryNum);
|
|
|
+ log.setReceiveTime(new Date());
|
|
|
+ log.setIsDelete("0");
|
|
|
+ log.setStatus(0); // 未同步
|
|
|
+ log.setIsLottery(0);
|
|
|
+ log.setType(3);
|
|
|
+ lotteryCountLogService.save(log);
|
|
|
}
|
|
|
|
|
|
- // 异步同步抽奖次数
|
|
|
- @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);
|
|
|
+ private void syncLotteryCountIfNeeded(WxLoginUser wxLoginUser) {
|
|
|
+ if (ObjectUtil.equals(wxLoginUser.getIsBind(), 1)
|
|
|
+ && StringUtils.isNotBlank(wxLoginUser.getLocalLiveUserId())) {
|
|
|
+
|
|
|
+ UnifiedUserCenterDTO dto = new UnifiedUserCenterDTO();
|
|
|
+ dto.setTargetUserId(wxLoginUser.getLocalLiveUserId());
|
|
|
+ dto.setSourceUserId(wxLoginUser.getId());
|
|
|
+
|
|
|
+ // 👇 事务提交后再执行异步
|
|
|
+ TransactionSynchronizationManager.registerSynchronization(
|
|
|
+ new TransactionSynchronization() {
|
|
|
+ @Override
|
|
|
+ public void afterCommit() {
|
|
|
+ // 事务提交完成!现在调用异步,一定能查到数据
|
|
|
+ unifiedUserCenterService.syncLotteryCount(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|