|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
@@ -19,6 +20,7 @@ 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;
|
|
|
import org.jeasy.rules.api.Facts;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -28,6 +30,7 @@ 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.*;
|
|
@@ -37,6 +40,7 @@ import static com.citu.module.menduner.reward.enums.EasyRulesConstants.*;
|
|
|
*
|
|
|
* @author rayson
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@Validated
|
|
|
public class EventTrackServiceImpl implements EventTrackService {
|
|
@@ -88,7 +92,7 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
|
|
|
@Override
|
|
|
public List<EventTrackUrlRespVO> getEventTrackList() {
|
|
|
- List<PointRuleConfigDO> list = ruleConfigService.getList();
|
|
|
+ List<PointRuleConfigDO> list = ruleConfigService.selectDistinctUrlList();
|
|
|
return PointRuleConfigConvert.INSTANCE.convertList(list);
|
|
|
}
|
|
|
|
|
@@ -99,51 +103,72 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public EventTrackPointRespVO click(String url) {
|
|
|
+ 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 null;
|
|
|
- }
|
|
|
-
|
|
|
- // 根据URL获取积分规则配置信息
|
|
|
- PointRuleConfigDO config = ruleConfigService.getByUrl(url);
|
|
|
- if (null == config) {
|
|
|
- // 如果配置信息不存在,返回空
|
|
|
- return null;
|
|
|
- }
|
|
|
+ // 获取当前登录用户信息
|
|
|
+ LoginUser loginUser = LoginUserContext.get2();
|
|
|
+ if (null == loginUser) {
|
|
|
+ // 如果用户未登录,返回空
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
|
|
|
- // 获取触发参数映射
|
|
|
- Map<String, Object> triggerMap =
|
|
|
- getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
|
-
|
|
|
- // 创建积分规则对象
|
|
|
- PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
|
-
|
|
|
- // 设置响应对象的基本信息
|
|
|
- respVO.setTitle(pointRule.getRuleName());
|
|
|
- respVO.setOperation(pointRule.getOperation());
|
|
|
- respVO.setType(config.getType());
|
|
|
- respVO.setPoint(pointRule.getPoint());
|
|
|
-
|
|
|
- // 执行规则匹配和响应处理
|
|
|
- DynamicRuleAction<PointRule> action = (t) -> {
|
|
|
- pointRecordService.createPointRecord(
|
|
|
- loginUser.getId(),
|
|
|
- url,
|
|
|
- MathOperationEnum.ADD,
|
|
|
- t.getPoint(),
|
|
|
- PointBizTypeEnum.EVENT,
|
|
|
- String.valueOf(config.getId()));
|
|
|
- respVO.match();
|
|
|
- };
|
|
|
-
|
|
|
- match(pointRule, action);
|
|
|
+ // 根据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) -> {
|
|
|
+ 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;
|
|
|
}
|