|
|
@@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
@@ -66,8 +67,11 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
|
|
|
private SdExecutionTaskContentMapper sdExecutionTaskContentMapper;
|
|
|
@Autowired
|
|
|
private ContentProfileService contentProfileService;
|
|
|
+ @Autowired
|
|
|
+ private ContentProfileMapper contentProfileMapper;
|
|
|
|
|
|
private static final String YESTERDAY_RETURN_TOP10_VIDEO_SCOPE = "yesterday_return_top10_video_scope";
|
|
|
+ private static final String HISTORY_RETURN_TOP50_VIDEO_SCOPE = "hostory_return_top50_video_scope";
|
|
|
private static final String MANUAL_SELECT_VIDEO_SCOPE = "manual_select_video_scope";
|
|
|
|
|
|
@Value("${yesterday.return.video.table:loghubods.lastday_return}")
|
|
|
@@ -375,6 +379,106 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
|
|
|
log.info("yesterdayTopReturnVideoExecutionTaskCreateHandler recordSize = {} count = {} finish cost = {}ms", records.size(), count, costMs);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void historyTopReturnVideoExecutionTaskCreateHandler(String params) {
|
|
|
+ long start = System.nanoTime();
|
|
|
+ log.info("historyTopReturnVideoExecutionTaskCreateHandler start");
|
|
|
+ String dt = null;
|
|
|
+ LocalDate current = LocalDate.now();
|
|
|
+ Integer maxDay = null;
|
|
|
+ Integer topN = null;
|
|
|
+ Integer maxCount = null;
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+ if (Objects.nonNull(params) && !params.trim().isEmpty()) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(params);
|
|
|
+ dt = jsonObject.getString("dt");
|
|
|
+ maxDay = jsonObject.getInteger("maxDay");
|
|
|
+ topN = jsonObject.getInteger("topN");
|
|
|
+ maxCount = jsonObject.getInteger("maxCount");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(dt) || dt.isEmpty()) {
|
|
|
+ current = current.minusDays(1);
|
|
|
+ dt = DateUtil.formatLocalDate(current, "yyyyMMdd");
|
|
|
+ } else {
|
|
|
+ current = LocalDate.parse(dt, formatter);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(maxDay) || maxDay <= 0) {
|
|
|
+ maxDay = 1;
|
|
|
+ }
|
|
|
+ if (Objects.isNull(topN) || topN <= 0) {
|
|
|
+ topN = 50;
|
|
|
+ }
|
|
|
+ if (Objects.isNull(maxCount) || maxCount <= 0) {
|
|
|
+ maxCount = 10500;
|
|
|
+ }
|
|
|
+ XxlJobLogger.log("current = {} dt = {} maxDay = {} topN = {} maxCount = {}", current, dt, maxDay, topN, maxCount);
|
|
|
+ for (int i = 0; i < maxDay; i++) {
|
|
|
+ XxlJobLogger.log("i= {} current = {} dt = {} maxDay = {} topN = {} maxCount = {}", i, current, dt, maxDay, topN, maxCount);
|
|
|
+ String sql = "select * from " + yesterdayReturnVideoTable + " where dt='" + dt + "' ORDER BY 回流人数 DESC LIMIT " + topN + ";";
|
|
|
+ List<Record> records = odpsManager.query(sql);
|
|
|
+ if (Objects.isNull(records) || records.isEmpty()) {
|
|
|
+ log.info("historyTopReturnVideoExecutionTaskCreateHandler records is empty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ XxlJobLogger.log("historyTopReturnVideoExecutionTaskCreateHandler records size={}", records.size());
|
|
|
+ long topCostMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
|
|
+ log.info("historyTopReturnVideoExecutionTaskCreateHandler get top video cost={}ms", topCostMs);
|
|
|
+ // 创建解构任务
|
|
|
+// for (Record record : records) {
|
|
|
+// try {
|
|
|
+// if (Objects.isNull(record)) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// String videoId = record.getString("videoid");
|
|
|
+// ContentProfile contentProfile = contentProfileService.findContentProfileByIdAndStage(videoId, ContentProfileStageEnum.DECONSTRUCTION_SELECT_TOPIC);
|
|
|
+// if (Objects.nonNull(contentProfile)) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// SdExecutionTask sdExecutionTask = new SdExecutionTask();
|
|
|
+// sdExecutionTask.setTaskNo(IdGeneratorUtil.generateExecutionTaskNo());
|
|
|
+// sdExecutionTask.setTaskType(TaskTypeEnum.DECONSTRUCT.getValue());
|
|
|
+// sdExecutionTask.setTaskStatus(ExecutionTaskStatusEnum.INIT.getValue());
|
|
|
+// sdExecutionTask.setContentType(ContentTypeEnum.VIDEO.getValue());
|
|
|
+// // 属性设置
|
|
|
+// SdExecutionTaskPropertiesDTO propertiesDTO = new SdExecutionTaskPropertiesDTO();
|
|
|
+// propertiesDTO.setContentScope(HISTORY_RETURN_TOP50_VIDEO_SCOPE);
|
|
|
+// sdExecutionTask.setProperties(JSONObject.toJSONString(propertiesDTO));
|
|
|
+// // 关联内容
|
|
|
+// SdExecutionTaskContent sdExecutionTaskContent = new SdExecutionTaskContent();
|
|
|
+// sdExecutionTaskContent.setContentType(ContentTypeEnum.VIDEO.getValue());
|
|
|
+// sdExecutionTaskContent.setContentId(videoId);
|
|
|
+// sdExecutionTaskContent.setContent(null);
|
|
|
+// List<SdExecutionTaskContent> contentList = new ArrayList<>();
|
|
|
+// contentList.add(sdExecutionTaskContent);
|
|
|
+// boolean createResult = executionTaskCreateService.create(sdExecutionTask, contentList);
|
|
|
+// log.info("historyTopReturnVideoExecutionTaskCreateHandler sdExecutionTask create videoId = {} result={}", videoId, createResult);
|
|
|
+// // 内容库添加数据
|
|
|
+// ContentProfile insertContentProfile = new ContentProfile();
|
|
|
+// insertContentProfile.setContentId(videoId);
|
|
|
+// insertContentProfile.setContentType(ContentTypeEnum.VIDEO.getValue());
|
|
|
+// insertContentProfile.setStage(ContentProfileStageEnum.DECONSTRUCTION_SELECT_TOPIC.getValue());
|
|
|
+// contentProfileService.insertOrUpdate(insertContentProfile);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("historyTopReturnVideoExecutionTaskCreateHandler error {}", record, e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// LambdaQueryWrapper<ContentProfile> wrapper = new LambdaQueryWrapper<>();
|
|
|
+// wrapper.eq(ContentProfile::getStage, ContentProfileStageEnum.DECONSTRUCTION_SELECT_TOPIC.getValue());
|
|
|
+// wrapper.eq(ContentProfile::getContentType, ContentTypeEnum.VIDEO.getValue());
|
|
|
+// wrapper.eq(ContentProfile::getIsDeleted, IsDeleteEnum.NORMAL.getValue());
|
|
|
+// long count = contentProfileMapper.selectCount(wrapper);
|
|
|
+// if (count > maxCount) {
|
|
|
+// log.info("historyTopReturnVideoExecutionTaskCreateHandler count = {} maxCount = {}", count, maxCount);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+ //向前找数据
|
|
|
+ current = current.minusDays(1);
|
|
|
+ dt = DateUtil.formatLocalDate(current, "yyyyMMdd");
|
|
|
+ }
|
|
|
+ long costMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
|
|
+ log.info("historyTopReturnVideoExecutionTaskCreateHandler finish cost = {}ms", costMs);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void videoExecutionTaskCreateHandler(String params) {
|
|
|
XxlJobParamDto paramJson = JSONObject.parseObject(params, XxlJobParamDto.class);
|