|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.citu.framework.security.core.LoginUser;
|
|
|
import com.citu.module.menduner.common.dto.TimeRangeBaseReqVO;
|
|
|
+import com.citu.module.menduner.common.enums.PointBizTypeEnum;
|
|
|
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.config.TaskReqVO;
|
|
@@ -25,7 +26,6 @@ import com.citu.module.menduner.reward.service.config.PointRuleConfigService;
|
|
|
import com.citu.module.menduner.system.api.url.MendunerSystemUrlApi;
|
|
|
import com.citu.module.menduner.system.api.url.UrlInfoRespVO;
|
|
|
import com.citu.module.menduner.system.enums.MathOperationEnum;
|
|
|
-import com.citu.module.menduner.system.enums.account.PointBizTypeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeasy.rules.api.Facts;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -110,13 +110,13 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
@Override
|
|
|
public List<TaskRespVO> getMarkTask(TaskReqVO reqVO) {
|
|
|
LocalDateTime[] timeRange = null;
|
|
|
- if(TaskReqVO.TYPE_RECOMMEND.equals(reqVO.getType())) {
|
|
|
- timeRange =generateDateTimeRange(TimeRangeBaseReqVO.builder().type(TimeRangeBaseReqVO.ALL).build());
|
|
|
- }else {
|
|
|
+ if (TaskReqVO.TYPE_RECOMMEND.equals(reqVO.getType())) {
|
|
|
+ timeRange = generateDateTimeRange(TimeRangeBaseReqVO.builder().type(TimeRangeBaseReqVO.ALL).build());
|
|
|
+ } else {
|
|
|
LocalDate today = LocalDate.now();
|
|
|
LocalDateTime startOfDay = today.atStartOfDay(); // 当天的开始时间
|
|
|
LocalDateTime endOfDay = today.atTime(23, 59, 59); // 当天的结束时间
|
|
|
- timeRange =generateDateTimeRange(TimeRangeBaseReqVO.builder()
|
|
|
+ timeRange = generateDateTimeRange(TimeRangeBaseReqVO.builder()
|
|
|
.type(TimeRangeBaseReqVO.TYPE_CUSTOM)
|
|
|
// time 是数组,第一个元素是开始时间,第二个元素是结束时间,改为当天的起始和结束
|
|
|
.time(new LocalDateTime[]{startOfDay, endOfDay})
|
|
@@ -142,39 +142,53 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
return Collections.singletonList(EventTrackPointRespVO.builder().build());
|
|
|
}
|
|
|
|
|
|
- // 获取指定URL的积分规则配置列表
|
|
|
+ Long userId = loginUser.getId();
|
|
|
+
|
|
|
+ trigger(userId, url, null,null);
|
|
|
+ return respVOList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @DSTransactional
|
|
|
+ public List<EventTrackPointRespVO> trigger(Long userId, String url, String scene, PointBizTypeEnum bizType) {
|
|
|
+ List<EventTrackPointRespVO> respVOList = new ArrayList<>();
|
|
|
+ // 获取指定URL的积分规则配置列表,因为是查询地址的配置,所以不需要带上动态的场景
|
|
|
List<PointRuleConfigDO> configList = ruleConfigService.getByUrlList(url);
|
|
|
|
|
|
if (CollectionUtil.isEmpty(configList)) {
|
|
|
// 若未找到该URL的配置规则,同样返回一个空的响应对象
|
|
|
return Collections.singletonList(EventTrackPointRespVO.builder().build());
|
|
|
}
|
|
|
+ // 搜索出配置后,带入场景去判断处理
|
|
|
+ url = url + "?" + scene;
|
|
|
|
|
|
// 遍历处理每个积分规则配置
|
|
|
for (PointRuleConfigDO config : configList) {
|
|
|
// 处理单个积分规则
|
|
|
- EventTrackPointRespVO respVO = processPointRule(config, loginUser, url);
|
|
|
+ EventTrackPointRespVO respVO = processPointRule(config, userId, url,bizType);
|
|
|
// 将处理结果添加到响应列表中
|
|
|
respVOList.add(respVO);
|
|
|
}
|
|
|
// 调用服务记录事件访问
|
|
|
- eventRecordService.createEventRecord(loginUser.getId(), url);
|
|
|
+ eventRecordService.createEventRecord(userId, url);
|
|
|
return respVOList;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 处理单个积分规则
|
|
|
*
|
|
|
- * @param config 规则配置
|
|
|
- * @param loginUser 操作用户
|
|
|
- * @param url 事件地址
|
|
|
+ * @param config 规则配置
|
|
|
+ * @param userId 操作用户
|
|
|
+ * @param url 事件地址
|
|
|
+ * @param bizType 事件类型
|
|
|
* @return EventTrackPointRespVO
|
|
|
**/
|
|
|
- private EventTrackPointRespVO processPointRule(PointRuleConfigDO config, LoginUser loginUser, String url) {
|
|
|
+ private EventTrackPointRespVO processPointRule(PointRuleConfigDO config,
|
|
|
+ Long userId, String url, PointBizTypeEnum bizType) {
|
|
|
EventTrackPointRespVO respVO = new EventTrackPointRespVO();
|
|
|
// 获取触发规则的执行上下文信息
|
|
|
- Map<String, Object> triggerMap = getRuleContextMap(loginUser.getId(), config.getUrl(), config.getTriggerRule());
|
|
|
+ Map<String, Object> triggerMap = getRuleContextMap(userId, config.getUrl(), config.getTriggerRule());
|
|
|
// 创建积分规则对象
|
|
|
PointRule pointRule = createPointRule(config, triggerMap, null);
|
|
|
|
|
@@ -185,7 +199,7 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
respVO.setPoint(pointRule.getPoint());
|
|
|
|
|
|
// 执行规则匹配和相关操作
|
|
|
- execute(pointRule, loginUser, config, url, respVO);
|
|
|
+ execute(pointRule, userId, config, url, bizType, respVO);
|
|
|
return respVO;
|
|
|
}
|
|
|
|
|
@@ -193,16 +207,17 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
* 执行规则匹配和相关操作
|
|
|
*
|
|
|
* @param pointRule 规则对象
|
|
|
- * @param loginUser 操作用户
|
|
|
+ * @param userId 操作用户
|
|
|
* @param config 规则配置
|
|
|
* @param url 事件地址
|
|
|
+ * @param bizType 事件类型
|
|
|
* @param respVO 响应对象
|
|
|
**/
|
|
|
- private void execute(PointRule pointRule, LoginUser loginUser, PointRuleConfigDO config,
|
|
|
- String url, EventTrackPointRespVO respVO) {
|
|
|
+ private void execute(PointRule pointRule, Long userId, PointRuleConfigDO config,
|
|
|
+ String url, PointBizTypeEnum bizType, EventTrackPointRespVO respVO) {
|
|
|
DynamicRuleAction<PointRule> action = (t) -> {
|
|
|
// 发送用户积分变更消息
|
|
|
- userPointProducer.send(buildUserPointSendMessage(loginUser, config, t, url));
|
|
|
+ userPointProducer.send(buildUserPointSendMessage(userId, config, t, url, bizType));
|
|
|
// 标记规则匹配成功
|
|
|
respVO.match();
|
|
|
};
|
|
@@ -214,20 +229,24 @@ public class EventTrackServiceImpl implements EventTrackService {
|
|
|
/**
|
|
|
* 构建用户积分变更消息对象
|
|
|
*
|
|
|
- * @param loginUser 操作用户
|
|
|
+ * @param userId 操作用户
|
|
|
* @param config 规则配置
|
|
|
* @param pointRule 规则对象
|
|
|
* @param url 事件地址
|
|
|
+ * @param bizType 事件类型
|
|
|
* @return UserPointSendMessage
|
|
|
**/
|
|
|
- private UserPointSendMessage buildUserPointSendMessage(LoginUser loginUser, PointRuleConfigDO config,
|
|
|
- PointRule pointRule, String url) {
|
|
|
- PointBizTypeEnum bizType = PointBizTypeEnum.EVENT;
|
|
|
+ private UserPointSendMessage buildUserPointSendMessage(Long userId, PointRuleConfigDO config,
|
|
|
+ PointRule pointRule, String url, PointBizTypeEnum bizType) {
|
|
|
+ PointBizTypeEnum defaultBizType = PointBizTypeEnum.EVENT;
|
|
|
if (PointRuleConfigTypeEnum.MARK.getType().equals(config.getType())) {
|
|
|
- bizType = PointBizTypeEnum.RECOMMEND_TASK;
|
|
|
+ defaultBizType = PointBizTypeEnum.RECOMMEND_TASK;
|
|
|
+ }
|
|
|
+ if (null == bizType) {
|
|
|
+ bizType = defaultBizType;
|
|
|
}
|
|
|
return UserPointSendMessage.builder()
|
|
|
- .userId(loginUser.getId())
|
|
|
+ .userId(userId)
|
|
|
.url(url)
|
|
|
.title(config.getTitle())
|
|
|
.operation(MathOperationEnum.ADD.getOperator().equals(config.getOperation())
|