|
@@ -1,6 +1,5 @@
|
|
|
package com.citu.module.menduner.reward.service.event;
|
|
|
|
|
|
-import com.baomidou.dynamic.datasource.tx.LocalTxUtil;
|
|
|
import com.citu.framework.security.core.LoginUser;
|
|
|
import com.citu.module.menduner.common.util.LoginUserContext;
|
|
|
import com.citu.module.menduner.reward.controller.base.common.TreeRespVO;
|
|
@@ -14,10 +13,11 @@ import com.citu.module.menduner.reward.dal.dataobject.config.Condition;
|
|
|
import com.citu.module.menduner.reward.dal.dataobject.config.PointRuleConfigDO;
|
|
|
import com.citu.module.menduner.reward.enums.MathOperationEnum;
|
|
|
import com.citu.module.menduner.reward.enums.record.PointBizTypeEnum;
|
|
|
+import com.citu.module.menduner.reward.mq.message.UserPointSendMessage;
|
|
|
+import com.citu.module.menduner.reward.mq.producer.UserPointProducer;
|
|
|
import com.citu.module.menduner.reward.rule.DynamicPointRule;
|
|
|
import com.citu.module.menduner.reward.rule.DynamicRuleAction;
|
|
|
import com.citu.module.menduner.reward.service.config.PointRuleConfigService;
|
|
|
-import com.citu.module.menduner.reward.service.record.PointRecordService;
|
|
|
import com.citu.module.menduner.system.api.url.MendunerSystemUrlApi;
|
|
|
import com.citu.module.menduner.system.api.url.UrlInfoRespVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -30,7 +30,6 @@ import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.citu.module.menduner.reward.enums.EasyRulesConstants.*;
|
|
@@ -52,12 +51,13 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
@Resource
|
|
|
private EventRecordService eventRecordService;
|
|
|
|
|
|
- @Resource
|
|
|
- private PointRecordService pointRecordService;
|
|
|
|
|
|
@Resource
|
|
|
private MendunerSystemUrlApi mendunerSystemUrlApi;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserPointProducer userPointProducer;
|
|
|
+
|
|
|
public static List<TreeRespVO<List<TreeRespVO<List<UrlInfoRespVO>>>>> convertUrlInfoListToTree(List<UrlInfoRespVO> urlInfoList) {
|
|
|
// 首先按client分组,然后在每个client分组内部按module分组
|
|
|
Map<String, Map<String, List<UrlInfoRespVO>>> groupedByClientAndModule = urlInfoList.stream()
|
|
@@ -104,71 +104,57 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
|
|
|
@Override
|
|
|
public EventTrackPointRespVO click(String url) throws Exception {
|
|
|
- AtomicBoolean state = new AtomicBoolean(true);
|
|
|
- String xid = LocalTxUtil.startTransaction();
|
|
|
+
|
|
|
// 初始化响应对象
|
|
|
EventTrackPointRespVO respVO = new EventTrackPointRespVO();
|
|
|
- try {
|
|
|
+ // 获取当前登录用户信息
|
|
|
+ LoginUser loginUser = LoginUserContext.get2();
|
|
|
+ if (null == loginUser) {
|
|
|
+ // 如果用户未登录,返回空
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
|
|
|
- // 获取当前登录用户信息
|
|
|
- LoginUser loginUser = LoginUserContext.get2();
|
|
|
- if (null == loginUser) {
|
|
|
- // 如果用户未登录,返回空
|
|
|
- return respVO;
|
|
|
- }
|
|
|
+ // 根据URL获取积分规则配置信息
|
|
|
+ PointRuleConfigDO config = ruleConfigService.getByUrl(url);
|
|
|
+ if (null == config) {
|
|
|
+ // 如果配置信息不存在,返回空
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
|
|
|
- // 根据URL获取积分规则配置信息
|
|
|
- PointRuleConfigDO config = ruleConfigService.getByUrl(url);
|
|
|
- if (null == config) {
|
|
|
- // 如果配置信息不存在,返回空
|
|
|
- return respVO;
|
|
|
- }
|
|
|
+ // 获取触发参数映射
|
|
|
+ Map<String, Object> triggerMap =
|
|
|
+ getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
|
+
|
|
|
+ // 创建积分规则对象
|
|
|
+ PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
|
+
|
|
|
+ // 设置响应对象的基本信息
|
|
|
+ respVO.setTitle(config.getTitle());
|
|
|
+ respVO.setOperation(pointRule.getOperation());
|
|
|
+ respVO.setType(config.getType());
|
|
|
+ respVO.setPoint(pointRule.getPoint());
|
|
|
+
|
|
|
+ // 执行规则匹配和响应处理
|
|
|
+ DynamicRuleAction<PointRule> action = (t) -> {
|
|
|
+ // 发送消息
|
|
|
+ userPointProducer.send(UserPointSendMessage.builder()
|
|
|
+ .userId(loginUser.getId())
|
|
|
+ .url(url)
|
|
|
+ .title(config.getTitle())
|
|
|
+ .operation(MathOperationEnum.ADD.getOperator().equals(config.getOperation())
|
|
|
+ ? MathOperationEnum.ADD : MathOperationEnum.SUBTRACT)
|
|
|
+ .point(t.getPoint())
|
|
|
+ .bizType(PointBizTypeEnum.EVENT)
|
|
|
+ .bizId(String.valueOf(config.getId()))
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ // 标记匹配成功
|
|
|
+ respVO.match();
|
|
|
+
|
|
|
+ };
|
|
|
+ // 匹配
|
|
|
+ match(pointRule, action);
|
|
|
|
|
|
- // 获取触发参数映射
|
|
|
- Map<String, Object> triggerMap =
|
|
|
- getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
|
-
|
|
|
- // 创建积分规则对象
|
|
|
- PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
|
-
|
|
|
- // 设置响应对象的基本信息
|
|
|
- respVO.setTitle(config.getTitle());
|
|
|
- respVO.setOperation(pointRule.getOperation());
|
|
|
- respVO.setType(config.getType());
|
|
|
- respVO.setPoint(pointRule.getPoint());
|
|
|
-
|
|
|
- // 执行规则匹配和响应处理
|
|
|
-
|
|
|
- DynamicRuleAction<PointRule> action = (t) -> {
|
|
|
- try {
|
|
|
- // 增加积分
|
|
|
- pointRecordService.createPointRecord(
|
|
|
- loginUser.getId(),
|
|
|
- url,
|
|
|
- config.getTitle(),
|
|
|
- MathOperationEnum.ADD.getOperator().equals(config.getOperation())
|
|
|
- ? MathOperationEnum.ADD : MathOperationEnum.SUBTRACT,
|
|
|
- t.getPoint(),
|
|
|
- PointBizTypeEnum.EVENT,
|
|
|
- String.valueOf(config.getId()));
|
|
|
- // 增加点击数
|
|
|
- eventRecordService.createEventRecord(loginUser.getId(), url);
|
|
|
- respVO.match();
|
|
|
- }catch (Exception ex) {
|
|
|
- state.set(false);
|
|
|
- throw ex;
|
|
|
- }
|
|
|
- };
|
|
|
- match(pointRule, action);
|
|
|
- }catch (Exception ex) {
|
|
|
- state.set(false);
|
|
|
- }finally {
|
|
|
- if (state.get()) {
|
|
|
- LocalTxUtil.commit(xid);
|
|
|
- } else {
|
|
|
- LocalTxUtil.rollback(xid);
|
|
|
- }
|
|
|
- }
|
|
|
// 返回响应对象
|
|
|
return respVO;
|
|
|
}
|