|
@@ -1,5 +1,7 @@
|
|
package com.citu.module.menduner.reward.service.event;
|
|
package com.citu.module.menduner.reward.service.event;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.citu.framework.security.core.LoginUser;
|
|
import com.citu.framework.security.core.LoginUser;
|
|
import com.citu.module.menduner.common.util.LoginUserContext;
|
|
import com.citu.module.menduner.common.util.LoginUserContext;
|
|
import com.citu.module.menduner.reward.controller.base.common.TreeRespVO;
|
|
import com.citu.module.menduner.reward.controller.base.common.TreeRespVO;
|
|
@@ -26,10 +28,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.citu.module.menduner.reward.enums.EasyRulesConstants.*;
|
|
import static com.citu.module.menduner.reward.enums.EasyRulesConstants.*;
|
|
@@ -51,7 +50,6 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
@Resource
|
|
@Resource
|
|
private EventRecordService eventRecordService;
|
|
private EventRecordService eventRecordService;
|
|
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private MendunerSystemUrlApi mendunerSystemUrlApi;
|
|
private MendunerSystemUrlApi mendunerSystemUrlApi;
|
|
|
|
|
|
@@ -103,60 +101,108 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public EventTrackPointRespVO click(String url) throws Exception {
|
|
|
|
-
|
|
|
|
- // 初始化响应对象
|
|
|
|
- EventTrackPointRespVO respVO = new EventTrackPointRespVO();
|
|
|
|
|
|
+ @DSTransactional
|
|
|
|
+ public List<EventTrackPointRespVO> click(String url) {
|
|
|
|
+ List<EventTrackPointRespVO> respVOList = new ArrayList<>();
|
|
// 获取当前登录用户信息
|
|
// 获取当前登录用户信息
|
|
LoginUser loginUser = LoginUserContext.get2();
|
|
LoginUser loginUser = LoginUserContext.get2();
|
|
- if (null == loginUser) {
|
|
|
|
- // 如果用户未登录,返回空
|
|
|
|
- return respVO;
|
|
|
|
|
|
+
|
|
|
|
+ if (loginUser == null) {
|
|
|
|
+ // 若用户未登录,返回一个空的响应对象
|
|
|
|
+ return Collections.singletonList(EventTrackPointRespVO.builder().build());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取指定URL的积分规则配置列表
|
|
|
|
+ List<PointRuleConfigDO> configList = ruleConfigService.getByUrlList(url);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtil.isEmpty(configList)) {
|
|
|
|
+ // 若未找到该URL的配置规则,同样返回一个空的响应对象
|
|
|
|
+ return Collections.singletonList(EventTrackPointRespVO.builder().build());
|
|
}
|
|
}
|
|
|
|
|
|
- // 根据URL获取积分规则配置信息
|
|
|
|
- PointRuleConfigDO config = ruleConfigService.getByUrl(url);
|
|
|
|
- if (null == config) {
|
|
|
|
- // 如果配置信息不存在,返回空
|
|
|
|
- return respVO;
|
|
|
|
|
|
+ // 遍历处理每个积分规则配置
|
|
|
|
+ for (PointRuleConfigDO config : configList) {
|
|
|
|
+ // 处理单个积分规则
|
|
|
|
+ EventTrackPointRespVO respVO = processPointRule(config, loginUser, url);
|
|
|
|
+ // 将处理结果添加到响应列表中
|
|
|
|
+ respVOList.add(respVO);
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取触发参数映射
|
|
|
|
- Map<String, Object> triggerMap =
|
|
|
|
- getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
|
|
|
|
+ return respVOList;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 处理单个积分规则
|
|
|
|
+ *
|
|
|
|
+ * @param config 规则配置
|
|
|
|
+ * @param loginUser 操作用户
|
|
|
|
+ * @param url 事件地址
|
|
|
|
+ * @return EventTrackPointRespVO
|
|
|
|
+ **/
|
|
|
|
+ private EventTrackPointRespVO processPointRule(PointRuleConfigDO config, LoginUser loginUser, String url) {
|
|
|
|
+ EventTrackPointRespVO respVO = new EventTrackPointRespVO();
|
|
|
|
+ // 获取触发规则的执行上下文信息
|
|
|
|
+ Map<String, Object> triggerMap = getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
// 创建积分规则对象
|
|
// 创建积分规则对象
|
|
PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
|
|
|
|
- // 设置响应对象的基本信息
|
|
|
|
|
|
+ // 设置响应对象的属性
|
|
respVO.setTitle(config.getTitle());
|
|
respVO.setTitle(config.getTitle());
|
|
respVO.setOperation(pointRule.getOperation());
|
|
respVO.setOperation(pointRule.getOperation());
|
|
respVO.setType(config.getType());
|
|
respVO.setType(config.getType());
|
|
respVO.setPoint(pointRule.getPoint());
|
|
respVO.setPoint(pointRule.getPoint());
|
|
|
|
|
|
- // 执行规则匹配和响应处理
|
|
|
|
|
|
+ // 执行规则匹配和相关操作
|
|
|
|
+ execute(pointRule, loginUser, config, url, respVO);
|
|
|
|
+ // 调用服务记录事件访问
|
|
|
|
+ eventRecordService.createEventRecord(loginUser.getId(), url);
|
|
|
|
+
|
|
|
|
+ return respVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 执行规则匹配和相关操作
|
|
|
|
+ *
|
|
|
|
+ * @param pointRule 规则对象
|
|
|
|
+ * @param loginUser 操作用户
|
|
|
|
+ * @param config 规则配置
|
|
|
|
+ * @param url 事件地址
|
|
|
|
+ * @param respVO 响应对象
|
|
|
|
+ **/
|
|
|
|
+ private void execute(PointRule pointRule, LoginUser loginUser, PointRuleConfigDO config,
|
|
|
|
+ String url, EventTrackPointRespVO respVO) {
|
|
DynamicRuleAction<PointRule> action = (t) -> {
|
|
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()
|
|
|
|
- );
|
|
|
|
- // 标记匹配成功
|
|
|
|
|
|
+ // 发送用户积分变更消息
|
|
|
|
+ userPointProducer.send(buildUserPointSendMessage(loginUser, config, t, url));
|
|
|
|
+ // 标记规则匹配成功
|
|
respVO.match();
|
|
respVO.match();
|
|
-
|
|
|
|
};
|
|
};
|
|
- // 匹配
|
|
|
|
|
|
+ // 执行规则匹配
|
|
match(pointRule, action);
|
|
match(pointRule, action);
|
|
|
|
+ }
|
|
|
|
|
|
- // 返回响应对象
|
|
|
|
- return respVO;
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建用户积分变更消息对象
|
|
|
|
+ *
|
|
|
|
+ * @param loginUser 操作用户
|
|
|
|
+ * @param config 规则配置
|
|
|
|
+ * @param pointRule 规则对象
|
|
|
|
+ * @param url 事件地址
|
|
|
|
+ * @return UserPointSendMessage
|
|
|
|
+ **/
|
|
|
|
+ private UserPointSendMessage buildUserPointSendMessage(LoginUser loginUser, PointRuleConfigDO config,
|
|
|
|
+ PointRule pointRule, String url) {
|
|
|
|
+ return UserPointSendMessage.builder()
|
|
|
|
+ .userId(loginUser.getId())
|
|
|
|
+ .url(url)
|
|
|
|
+ .title(config.getTitle())
|
|
|
|
+ .operation(MathOperationEnum.ADD.getOperator().equals(config.getOperation())
|
|
|
|
+ ? MathOperationEnum.ADD : MathOperationEnum.SUBTRACT) // 确定操作类型(加法或减法)
|
|
|
|
+ .point(pointRule.getPoint())
|
|
|
|
+ .bizType(PointBizTypeEnum.EVENT)
|
|
|
|
+ .bizId(String.valueOf(config.getId()))
|
|
|
|
+ .build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -211,9 +257,7 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 执行匹配
|
|
* 执行匹配
|
|
- *
|
|
|
|
* @param pointRule 积分规则对象
|
|
* @param pointRule 积分规则对象
|
|
- * @return void
|
|
|
|
**/
|
|
**/
|
|
private void match(PointRule pointRule,
|
|
private void match(PointRule pointRule,
|
|
DynamicRuleAction<PointRule> action) {
|
|
DynamicRuleAction<PointRule> action) {
|