|
|
@@ -1,29 +1,43 @@
|
|
|
package com.tzld.supply.job;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.supply.api.DeepSeekApiService;
|
|
|
+import com.tzld.supply.common.enums.ArticleAnalyseStrategyEnum;
|
|
|
import com.tzld.supply.common.enums.SpiderContentScreenStatusEnum;
|
|
|
import com.tzld.supply.common.enums.SpiderContentStatusEnum;
|
|
|
+import com.tzld.supply.common.enums.TitleAnalyseStrategyEnum;
|
|
|
import com.tzld.supply.dao.mapper.supply.spider.SpiderContentMapper;
|
|
|
import com.tzld.supply.dao.mapper.supply.spider.ext.SpiderMapperExt;
|
|
|
+import com.tzld.supply.model.dto.ArticleAnalyseConfigDTO;
|
|
|
+import com.tzld.supply.model.dto.TitleAnalyseConfigDTO;
|
|
|
import com.tzld.supply.model.entity.DeepSeekResult;
|
|
|
import com.tzld.supply.model.entity.PrecisionScreenEntity;
|
|
|
import com.tzld.supply.model.entity.RoughScreenEntity;
|
|
|
import com.tzld.supply.model.po.supply.spider.SpiderContent;
|
|
|
import com.tzld.supply.model.po.supply.spider.SpiderContentExample;
|
|
|
+import com.tzld.supply.service.strategy.ArticleAnalyseStrategy;
|
|
|
+import com.tzld.supply.service.strategy.TitleAnalyseStrategy;
|
|
|
import com.tzld.supply.util.DateUtils;
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import com.xxl.job.core.log.XxlJobLogger;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -45,8 +59,20 @@ public class ContentScreenJob {
|
|
|
@Value("${deepseek.pq-improve-narration-script-prompt}")
|
|
|
private String pqNarrationScriptPrompt;
|
|
|
|
|
|
+ @ApolloJsonValue("${title.analyse.config:{}}")
|
|
|
+ private TitleAnalyseConfigDTO titleAnalyseConfigDTO;
|
|
|
+
|
|
|
+ @ApolloJsonValue("${article.analyse.config:{}}")
|
|
|
+ private ArticleAnalyseConfigDTO articleAnalyseConfigDTO;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Map<TitleAnalyseStrategyEnum, TitleAnalyseStrategy> titleAnalyseStrategyMap;
|
|
|
+ @Autowired
|
|
|
+ private Map<ArticleAnalyseStrategyEnum, ArticleAnalyseStrategy> articleAnalyseStrategyMap;
|
|
|
+
|
|
|
/**
|
|
|
* 粗筛
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -106,6 +132,32 @@ public class ContentScreenJob {
|
|
|
return SpiderContentScreenStatusEnum.PASSED.getCode();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 规则判断:hardcode
|
|
|
+ */
|
|
|
+ private Integer judgeRoughScreenStatus(JSONObject jsonObject, List<TitleAnalyseConfigDTO.StrategyConfig> strategyConfigs) {
|
|
|
+ if (Objects.isNull(jsonObject) || jsonObject.isEmpty() || Objects.isNull(strategyConfigs) || strategyConfigs.isEmpty()) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ //全部满足
|
|
|
+ for (TitleAnalyseConfigDTO.StrategyConfig strategyConfig : strategyConfigs) {
|
|
|
+ String strategyName = strategyConfig.getStrategyName();
|
|
|
+ Double minScore = strategyConfig.getMinScore();
|
|
|
+ if (Objects.isNull(strategyName) || strategyName.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject resultJson = jsonObject.getJSONObject(strategyName);
|
|
|
+ if (Objects.isNull(resultJson) || resultJson.isEmpty()) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ Double score = resultJson.getDouble("最终综合得分");
|
|
|
+ if (Objects.isNull(score) || score < minScore) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return SpiderContentScreenStatusEnum.PASSED.getCode();
|
|
|
+ }
|
|
|
+
|
|
|
private List<SpiderContent> getRoughScreenSpiderContent() {
|
|
|
SpiderContentExample example = new SpiderContentExample();
|
|
|
example.createCriteria().andStatusEqualTo(0).andAiRoughStatusEqualTo(0);
|
|
|
@@ -114,6 +166,7 @@ public class ContentScreenJob {
|
|
|
|
|
|
/**
|
|
|
* 精筛
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -179,8 +232,38 @@ public class ContentScreenJob {
|
|
|
return SpiderContentScreenStatusEnum.PASSED.getCode();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 文章规则判断:hardcode
|
|
|
+ */
|
|
|
+ private Integer judgePrecisionScreenStatus(JSONObject jsonObject, List<ArticleAnalyseConfigDTO.StrategyConfig> strategyConfigs) {
|
|
|
+ if (Objects.isNull(jsonObject) || jsonObject.isEmpty() || Objects.isNull(strategyConfigs) || strategyConfigs.isEmpty()) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ for (ArticleAnalyseConfigDTO.StrategyConfig strategyConfig : strategyConfigs) {
|
|
|
+ String strategyName = strategyConfig.getStrategyName();
|
|
|
+ Double minScore = strategyConfig.getMinScore();
|
|
|
+ if (Objects.isNull(strategyName) || strategyName.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(strategyName);
|
|
|
+ if (Objects.isNull(resultJson) || resultJson.isEmpty()) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ JSONObject finalJson = resultJson.getJSONObject("综合判定");
|
|
|
+ if (Objects.isNull(finalJson) || finalJson.isEmpty()) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ Double score = finalJson.getDouble("最终综合得分");
|
|
|
+ if (Objects.isNull(score) || score < minScore) {
|
|
|
+ return SpiderContentScreenStatusEnum.ABANDONED.getCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return SpiderContentScreenStatusEnum.PASSED.getCode();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 票圈标题改写生成
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -224,6 +307,7 @@ public class ContentScreenJob {
|
|
|
|
|
|
/**
|
|
|
* 口播生成
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -265,4 +349,150 @@ public class ContentScreenJob {
|
|
|
return ReturnT.SUCCESS;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 标题分析 任务
|
|
|
+ */
|
|
|
+ @XxlJob("titleAnalyseHandler")
|
|
|
+ public ReturnT<String> titleAnalyseHandler(String param) {
|
|
|
+ if (StringUtils.isNotBlank(param)) {
|
|
|
+ titleAnalyseConfigDTO = JSON.parseObject(param, TitleAnalyseConfigDTO.class);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(titleAnalyseConfigDTO) || Objects.isNull(titleAnalyseConfigDTO.getStrategies())
|
|
|
+ || titleAnalyseConfigDTO.getStrategies().isEmpty()) {
|
|
|
+ XxlJobLogger.log("titleAnalyseConfigDTO config is null or empty");
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ Integer lastDays = titleAnalyseConfigDTO.getLastDays();
|
|
|
+ Long lastTime = LocalDateTime.now().minusDays(lastDays).atZone(ZoneId.systemDefault())
|
|
|
+ .toInstant()
|
|
|
+ .toEpochMilli();
|
|
|
+ XxlJobLogger.log("titleAnalyseConfigDTO config is " + titleAnalyseConfigDTO);
|
|
|
+ List<TitleAnalyseConfigDTO.StrategyConfig> strategies = titleAnalyseConfigDTO.getStrategies();
|
|
|
+ if (Objects.isNull(strategies) || strategies.isEmpty()) {
|
|
|
+ XxlJobLogger.log("strategies is null or empty");
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ List<SpiderContent> contentList = getRoughScreenSpiderContent();
|
|
|
+ if (contentList.isEmpty()) {
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ for (SpiderContent content : contentList) {
|
|
|
+ if (content.getCreateTime() < lastTime) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiRoughStatus(SpiderContentScreenStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiRoughResult("长时间未完成,自动放弃");
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ }
|
|
|
+ //执行策略
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ for (TitleAnalyseConfigDTO.StrategyConfig strategyConfig : strategies) {
|
|
|
+ String strategyName = strategyConfig.getStrategyName();
|
|
|
+ if (StringUtils.isBlank(strategyName)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ TitleAnalyseStrategy titleAnalyseStrategy = titleAnalyseStrategyMap.get(strategyName);
|
|
|
+ if (Objects.isNull(titleAnalyseStrategy)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String result = titleAnalyseStrategy.execute();
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ jsonObject.put(strategyName, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (jsonObject.isEmpty()) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiRoughStatus(SpiderContentScreenStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ } else {
|
|
|
+ Integer aiRoughStatus = judgeRoughScreenStatus(jsonObject, strategies);
|
|
|
+ content.setAiRoughStatus(aiRoughStatus);
|
|
|
+ content.setAiRoughResult(jsonObject.toJSONString());
|
|
|
+ if (aiRoughStatus == SpiderContentScreenStatusEnum.PASSED.getCode()) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.FILTERING.getCode());
|
|
|
+ } else {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ }
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文章分析 任务
|
|
|
+ */
|
|
|
+ @XxlJob("articleAnalyseHandler")
|
|
|
+ public ReturnT<String> articleAnalyseHandler(String param) {
|
|
|
+ if (StringUtils.isNotBlank(param)) {
|
|
|
+ articleAnalyseConfigDTO = JSON.parseObject(param, ArticleAnalyseConfigDTO.class);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(articleAnalyseConfigDTO) || Objects.isNull(articleAnalyseConfigDTO.getStrategies())
|
|
|
+ || articleAnalyseConfigDTO.getStrategies().isEmpty()) {
|
|
|
+ XxlJobLogger.log("articleAnalyseConfigDTO config is null or empty");
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ Integer lastDays = titleAnalyseConfigDTO.getLastDays();
|
|
|
+ Long lastTime = LocalDateTime.now().minusDays(lastDays).atZone(ZoneId.systemDefault())
|
|
|
+ .toInstant()
|
|
|
+ .toEpochMilli();
|
|
|
+ XxlJobLogger.log("articleAnalyseConfigDTO config is " + articleAnalyseConfigDTO);
|
|
|
+ List<ArticleAnalyseConfigDTO.StrategyConfig> strategies = articleAnalyseConfigDTO.getStrategies();
|
|
|
+ if (Objects.isNull(strategies) || strategies.isEmpty()) {
|
|
|
+ XxlJobLogger.log("strategies is null or empty");
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ List<SpiderContent> contentList = spiderMapperExt.getRoughScreenSpiderContentHasContent();
|
|
|
+ if (contentList.isEmpty()) {
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+ for (SpiderContent content : contentList) {
|
|
|
+ if (content.getCreateTime() < lastTime) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiRoughStatus(SpiderContentScreenStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiRoughResult("长时间未完成,自动放弃");
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ }
|
|
|
+ //执行策略
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ for (ArticleAnalyseConfigDTO.StrategyConfig strategyConfig : strategies) {
|
|
|
+ String strategyName = strategyConfig.getStrategyName();
|
|
|
+ if (StringUtils.isBlank(strategyName)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ArticleAnalyseStrategy articleAnalyseStrategy = articleAnalyseStrategyMap.get(strategyName);
|
|
|
+ if (Objects.isNull(articleAnalyseStrategy)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String result = articleAnalyseStrategy.execute();
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ jsonObject.put(strategyName, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jsonObject.isEmpty()) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setAiPrecisionStatus(SpiderContentScreenStatusEnum.ABANDONED.getCode());
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ } else {
|
|
|
+ Integer aiPrecisionStatus = judgePrecisionScreenStatus(jsonObject, strategies);
|
|
|
+ content.setAiPrecisionStatus(aiPrecisionStatus);
|
|
|
+ content.setAiPrecisionResult(jsonObject.toJSONString());
|
|
|
+ if (aiPrecisionStatus == SpiderContentScreenStatusEnum.PASSED.getCode()) {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.PASSED.getCode());
|
|
|
+ } else {
|
|
|
+ content.setStatus(SpiderContentStatusEnum.ABANDONED.getCode());
|
|
|
+ }
|
|
|
+ content.setUpdateTime(System.currentTimeMillis());
|
|
|
+ spiderContentMapper.updateByPrimaryKeySelective(content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ReturnT.SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
}
|