|
@@ -1,10 +1,15 @@
|
|
package com.pig4cloud.pig.marketing.service.impl;
|
|
package com.pig4cloud.pig.marketing.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.pig4cloud.pig.marketing.api.dto.MktMgmtPushRecordQueryDTO;
|
|
import com.pig4cloud.pig.marketing.api.dto.MktMgmtPushRecordQueryDTO;
|
|
import com.pig4cloud.pig.marketing.api.dto.MktMgmtPushRecordSaveDTO;
|
|
import com.pig4cloud.pig.marketing.api.dto.MktMgmtPushRecordSaveDTO;
|
|
import com.pig4cloud.pig.marketing.api.entity.*;
|
|
import com.pig4cloud.pig.marketing.api.entity.*;
|
|
|
|
+import com.pig4cloud.pig.marketing.api.vo.rule.StatKeywordVO;
|
|
import com.pig4cloud.pig.marketing.mapper.*;
|
|
import com.pig4cloud.pig.marketing.mapper.*;
|
|
import com.pig4cloud.pig.marketing.service.MktMgmtPushRecordService;
|
|
import com.pig4cloud.pig.marketing.service.MktMgmtPushRecordService;
|
|
import com.pig4cloud.pig.marketing.util.PushFrequencyUtil;
|
|
import com.pig4cloud.pig.marketing.util.PushFrequencyUtil;
|
|
@@ -15,6 +20,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -152,6 +158,68 @@ public class MktMgmtPushRecordServiceImpl implements MktMgmtPushRecordService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 统计关键词
|
|
|
|
+ * @param days 统计天数
|
|
|
|
+ * @return 统计结果
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<StatKeywordVO> statKeyword(Integer days) {
|
|
|
|
+ log.info("开始统计关键词频率,统计天数:{}", days);
|
|
|
|
+
|
|
|
|
+ // 计算开始时间(days天前)
|
|
|
|
+ LocalDateTime startTime = LocalDateTime.now().minusDays(days);
|
|
|
|
+
|
|
|
|
+ // 查询指定天数内的推送记录
|
|
|
|
+ List<MktMgmtPushRecord> mktMgmtPushRecords = mktMgmtPushRecordMapper.selectList(
|
|
|
|
+ Wrappers.<MktMgmtPushRecord>lambdaQuery()
|
|
|
|
+ .ge(MktMgmtPushRecord::getCreateTime, startTime)
|
|
|
|
+ .select(MktMgmtPushRecord::getTriggerCondition)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ log.info("查询到{}条推送记录", mktMgmtPushRecords.size());
|
|
|
|
+
|
|
|
|
+ // 统计关键字出现次数
|
|
|
|
+ Map<String, Integer> keywordCountMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ for (MktMgmtPushRecord record : mktMgmtPushRecords) {
|
|
|
|
+ String triggerCondition = record.getTriggerCondition();
|
|
|
|
+ if (StringUtils.hasText(triggerCondition)) {
|
|
|
|
+ try {
|
|
|
|
+ // 解析JSON格式的triggerCondition
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(triggerCondition);
|
|
|
|
+ JSONArray keywordsArray = jsonObject.getJSONArray("keywords");
|
|
|
|
+
|
|
|
|
+ if (keywordsArray != null) {
|
|
|
|
+ for (int i = 0; i < keywordsArray.size(); i++) {
|
|
|
|
+ String keyword = keywordsArray.getString(i);
|
|
|
|
+ if (StringUtils.hasText(keyword)) {
|
|
|
|
+ keywordCountMap.put(keyword, keywordCountMap.getOrDefault(keyword, 0) + 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.warn("解析triggerCondition失败,记录ID:{},内容:{},错误:{}",
|
|
|
|
+ record.getId(), triggerCondition, e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 转换为StatKeywordVO列表并按出现次数降序排列
|
|
|
|
+ List<StatKeywordVO> result = keywordCountMap.entrySet().stream()
|
|
|
|
+ .sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue()))
|
|
|
|
+ .map(entry -> {
|
|
|
|
+ StatKeywordVO vo = new StatKeywordVO();
|
|
|
|
+ vo.setKeyword(entry.getKey());
|
|
|
|
+ vo.setCount(entry.getValue());
|
|
|
|
+ return vo;
|
|
|
|
+ })
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ log.info("统计完成,共统计到{}个不同的关键字", result.size());
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
@NotNull
|
|
@NotNull
|
|
private static MktMgmtPushRecord getMktMgmtPushRecord(MktMgmtPushRecordSaveDTO saveDTO, String triggerCondition, MktMgmtRule selectedRule) {
|
|
private static MktMgmtPushRecord getMktMgmtPushRecord(MktMgmtPushRecordSaveDTO saveDTO, String triggerCondition, MktMgmtRule selectedRule) {
|
|
// 构建推送详情的JSON格式
|
|
// 构建推送详情的JSON格式
|