ソースを参照

Merge branch 'feature_20260210_zhaohaipeng_add_content_profile' of Server/supply-demand-engine into master

zhaohaipeng 3 週間 前
コミット
7b9539af83

+ 34 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/common/enums/ContentProfileStageEnum.java

@@ -0,0 +1,34 @@
+package com.tzld.piaoquan.sde.common.enums;
+
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@Getter
+public enum ContentProfileStageEnum {
+
+    DECONSTRUCTION_SELECT_TOPIC(1, "解构-选题"),
+    DECONSTRUCTION_CREATION(2, "解构-创作"),
+    DECONSTRUCTION_MAKE(3, "解构-制作"),
+    ;
+
+    private final int value;
+
+    private final String desc;
+
+    ContentProfileStageEnum(int value, String desc) {
+        this.value = value;
+        this.desc = desc;
+    }
+
+    private static final Map<Integer, ContentProfileStageEnum> VALUE_MAP = Arrays.stream(ContentProfileStageEnum.values())
+            .collect(Collectors.toMap(ContentProfileStageEnum::getValue, Function.identity()));
+
+    public static ContentProfileStageEnum getByValue(int value) {
+        return VALUE_MAP.get(value);
+    }
+
+}

+ 9 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/mapper/ContentProfileMapper.java

@@ -0,0 +1,9 @@
+package com.tzld.piaoquan.sde.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.tzld.piaoquan.sde.model.entity.ContentProfile;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ContentProfileMapper extends BaseMapper<ContentProfile> {
+}

+ 76 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/model/entity/ContentProfile.java

@@ -0,0 +1,76 @@
+package com.tzld.piaoquan.sde.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 内容库
+ */
+@Data
+@TableName("content_profile")
+public class ContentProfile {
+
+    /**
+     * 主键ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 业务唯一标识 (Business ID)
+     */
+    private String contentId;
+
+    /**
+     * 内容类型:1文本 2图片 3视频'
+     *
+     * @see com.tzld.piaoquan.sde.common.enums.ContentTypeEnum
+     */
+    private Integer contentType;
+
+    /**
+     * 内容主体:Prompt原文/长文本/摘要
+     */
+    private String metadata;
+
+    /**
+     * 步骤/阶段:1 解构-选题 2 解构-创作 3 解构-制作
+     *
+     * @see com.tzld.piaoquan.sde.common.enums.ContentProfileStageEnum
+     */
+    private Integer stage;
+
+    /**
+     * 原始结果数据:JSON
+     */
+    private String rawResult;
+
+    /**
+     * 原始结果URL:JSON
+     */
+    private String rawUrl;
+
+    /**
+     * 执行版本号
+     */
+    private String version;
+
+    /**
+     * 记录创建时间,由数据库自动生成
+     */
+    private Date createTime;
+
+    /**
+     * 记录最后更新时间,由数据库自动维护
+     */
+    private Date updateTime;
+
+    /**
+     * 逻辑删除标记:0-正常状态,1-已删除
+     */
+    private Integer isDeleted;
+}

+ 22 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/service/ContentProfileService.java

@@ -0,0 +1,22 @@
+package com.tzld.piaoquan.sde.service;
+
+import com.tzld.piaoquan.sde.common.enums.ContentProfileStageEnum;
+import com.tzld.piaoquan.sde.model.dto.deconstruction.QueryResponseDataDTO;
+import com.tzld.piaoquan.sde.model.entity.ContentProfile;
+import com.tzld.piaoquan.sde.model.entity.SdExecutionTask;
+
+public interface ContentProfileService {
+
+    /**
+     * 根据内容ID和步骤查找内容库数据
+     *
+     * @param contentId 内容ID
+     * @param stageEnum 步骤
+     * @return 内容库数据库
+     */
+    ContentProfile findContentProfileByIdAndStage(String contentId, ContentProfileStageEnum stageEnum);
+
+    void insertOrUpdate(ContentProfile contentProfile);
+
+    void deconstructSelectTopicResultSync(SdExecutionTask sdExecutionTask, QueryResponseDataDTO queryResponseDataDTO);
+}

+ 3 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/service/ExecutionTaskService.java

@@ -53,4 +53,7 @@ public interface ExecutionTaskService {
      * 聚类
      */
     void manualClusterExecutionTaskCreateHandler(String params);
+
+    void batchCreateDeconstructTask(String dtList, String contentScope);
+
 }

+ 93 - 0
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/service/impl/ContentProfileServiceImpl.java

@@ -0,0 +1,93 @@
+package com.tzld.piaoquan.sde.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.tzld.piaoquan.sde.common.enums.ContentProfileStageEnum;
+import com.tzld.piaoquan.sde.common.enums.ContentTypeEnum;
+import com.tzld.piaoquan.sde.common.enums.IsDeleteEnum;
+import com.tzld.piaoquan.sde.mapper.ContentProfileMapper;
+import com.tzld.piaoquan.sde.mapper.SdExecutionTaskContentMapper;
+import com.tzld.piaoquan.sde.model.dto.deconstruction.QueryResponseDataDTO;
+import com.tzld.piaoquan.sde.model.entity.ContentProfile;
+import com.tzld.piaoquan.sde.model.entity.SdExecutionTask;
+import com.tzld.piaoquan.sde.model.entity.SdExecutionTaskContent;
+import com.tzld.piaoquan.sde.service.ContentProfileService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+
+@Slf4j
+@Service
+public class ContentProfileServiceImpl implements ContentProfileService {
+
+    @Autowired
+    private ContentProfileMapper contentProfileMapper;
+    @Autowired
+    private SdExecutionTaskContentMapper sdExecutionTaskContentMapper;
+
+    @Override
+    public ContentProfile findContentProfileByIdAndStage(String contentId, ContentProfileStageEnum stageEnum) {
+        if (StringUtils.isEmpty(contentId) || Objects.isNull(stageEnum)) {
+            throw new RuntimeException("contentId and stageEnum must not null");
+        }
+
+        LambdaQueryWrapper<ContentProfile> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(ContentProfile::getContentId, contentId);
+        wrapper.eq(ContentProfile::getStage, stageEnum.getValue());
+        wrapper.eq(ContentProfile::getIsDeleted, IsDeleteEnum.NORMAL.getValue());
+        return contentProfileMapper.selectOne(wrapper);
+    }
+
+    @Override
+    public void insertOrUpdate(ContentProfile contentProfile) {
+        if (StringUtils.isEmpty(contentProfile.getContentId()) || Objects.isNull(contentProfile.getStage())) {
+            throw new RuntimeException("contentId and stageEnum must not null");
+        }
+        ContentProfile profile = this.findContentProfileByIdAndStage(contentProfile.getContentId(), ContentProfileStageEnum.getByValue(contentProfile.getStage()));
+        if (Objects.isNull(profile)) {
+            contentProfile.setIsDeleted(IsDeleteEnum.NORMAL.getValue());
+            contentProfileMapper.insert(contentProfile);
+        } else {
+            contentProfile.setId(profile.getId());
+            contentProfile.setIsDeleted(IsDeleteEnum.NORMAL.getValue());
+            contentProfileMapper.updateById(contentProfile);
+        }
+    }
+
+    @Override
+    public void deconstructSelectTopicResultSync(SdExecutionTask sdExecutionTask, QueryResponseDataDTO queryResponseDataDTO) {
+        try {
+
+            if (Objects.isNull(sdExecutionTask) || Objects.isNull(queryResponseDataDTO)) {
+                return;
+            }
+            SdExecutionTaskContent content = this.findByExecutionTaskId(sdExecutionTask.getId());
+            if (Objects.isNull(content)) {
+                return;
+            }
+
+            ContentProfile contentProfile = new ContentProfile();
+            contentProfile.setContentId(content.getContentId());
+            contentProfile.setContentType(content.getContentType());
+            contentProfile.setStage(ContentProfileStageEnum.DECONSTRUCTION_SELECT_TOPIC.getValue());
+            contentProfile.setRawResult(queryResponseDataDTO.getResult());
+            contentProfile.setRawUrl(queryResponseDataDTO.getUrl());
+
+            this.insertOrUpdate(contentProfile);
+        } catch (Exception e) {
+            log.error("解构任务状态同步异常: ", e);
+        }
+    }
+
+    private SdExecutionTaskContent findByExecutionTaskId(Long executionTaskId) {
+        if (Objects.isNull(executionTaskId)) {
+            return null;
+        }
+        LambdaQueryWrapper<SdExecutionTaskContent> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SdExecutionTaskContent::getExecutionTaskId, executionTaskId);
+        wrapper.eq(SdExecutionTaskContent::getContentType, ContentTypeEnum.VIDEO.getValue());
+        return sdExecutionTaskContentMapper.selectOne(wrapper);
+    }
+}

+ 28 - 2
supply-demand-engine-core/src/main/java/com/tzld/piaoquan/sde/service/impl/ExecutionTaskServiceImpl.java

@@ -16,12 +16,14 @@ import com.tzld.piaoquan.sde.model.dto.ContentInputParamsDTO;
 import com.tzld.piaoquan.sde.model.dto.SdExecutionTaskPropertiesDTO;
 import com.tzld.piaoquan.sde.model.dto.cluster.ManualClusterExecutionConfigDTO;
 import com.tzld.piaoquan.sde.model.dto.deconstruction.QueryResponseDataDTO;
+import com.tzld.piaoquan.sde.model.entity.ContentProfile;
 import com.tzld.piaoquan.sde.model.entity.SdExecutionTask;
 import com.tzld.piaoquan.sde.model.entity.SdExecutionTaskContent;
 import com.tzld.piaoquan.sde.model.entity.SdExecutionTaskRawResult;
 import com.tzld.piaoquan.sde.model.request.ExecutionTaskGetParam;
 import com.tzld.piaoquan.sde.model.request.ExecutionTaskListParam;
 import com.tzld.piaoquan.sde.model.vo.SdExecutionTaskVO;
+import com.tzld.piaoquan.sde.service.ContentProfileService;
 import com.tzld.piaoquan.sde.service.ExecutionTaskCreateService;
 import com.tzld.piaoquan.sde.service.ExecutionTaskService;
 import com.tzld.piaoquan.sde.util.DateUtil;
@@ -59,6 +61,8 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
     private SdWorkflowTaskMapper sdWorkflowTaskMapper;
     @Autowired
     private SdExecutionTaskContentMapper sdExecutionTaskContentMapper;
+    @Autowired
+    private ContentProfileService contentProfileService;
 
     private static final String YESTERDAY_RETURN_TOP10_VIDEO_SCOPE = "yesterday_return_top10_video_scope";
     private static final String MANUAL_SELECT_VIDEO_SCOPE = "manual_select_video_scope";
@@ -275,6 +279,8 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
                     sdExecutionTaskRawResult.setUrlInfo(urlInfo);
                     int insertRows = sdExecutionTaskRawResultMapper.insert(sdExecutionTaskRawResult);
                     log.info("executionTask result insertRows success, id:{} rows = {}", sdExecutionTask.getId(), insertRows);
+
+                    contentProfileService.deconstructSelectTopicResultSync(sdExecutionTask, queryResponseDataDTO);
                 }
             } catch (Exception e) {
                 log.error("executionTask sync error {}", sdExecutionTask, e);
@@ -399,10 +405,16 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
                 continue;
             }
             String videoId = record.getString("videoid");
-            int count = sdExecutionTaskContentMapper.countByContentId(ContentTypeEnum.VIDEO.getValue(), videoId);
-            if (count > 0) {
+            // int count = sdExecutionTaskContentMapper.countByContentId(ContentTypeEnum.VIDEO.getValue(), videoId);
+            // if (count > 0) {
+            //     continue;
+            // }
+
+            ContentProfile contentProfile = contentProfileService.findContentProfileByIdAndStage(videoId, ContentProfileStageEnum.DECONSTRUCTION_SELECT_TOPIC);
+            if (Objects.nonNull(contentProfile)) {
                 continue;
             }
+
             findRecords.add(record);
         }
         if (findRecords.isEmpty()) {
@@ -522,4 +534,18 @@ public class ExecutionTaskServiceImpl implements ExecutionTaskService {
         log.info("manualClusterExecutionTaskCreateHandler finish cost = {}ms", costMs);
     }
 
+    @Override
+    public void batchCreateDeconstructTask(String dtList, String contentScope) {
+        if (StringUtils.isEmpty(dtList)) {
+            return;
+        }
+        for (String dt : dtList.split(",")) {
+            JSONObject paramJson = new JSONObject();
+            paramJson.put("table", "loghubods.supply_demand_task_video_collect_exp_top");
+            paramJson.put("contentScope", contentScope);
+            paramJson.put("dt", dt);
+            this.videoExecutionTaskCreateHandler(paramJson.toJSONString());
+        }
+    }
+
 }

+ 8 - 4
supply-demand-engine-service/src/main/java/com/tzld/piaoquan/sde/controller/ExecutionTaskController.java

@@ -11,10 +11,7 @@ import com.tzld.piaoquan.sde.service.ExecutionTaskService;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author supeng
@@ -44,4 +41,11 @@ public class ExecutionTaskController {
     public CommonResponse<SdExecutionTask> get(@RequestBody CommonRequest<ExecutionTaskGetParam> request) {
         return CommonResponse.create(executionTaskService.get(request));
     }
+
+    @Operation(summary = "批量创建解构任务")
+    @GetMapping("/batchCreateDeconstructTask")
+    public CommonResponse<Void> batchCreateDeconstructTask(@RequestParam(value = "dtList") String dtList, @RequestParam(value = "contentScope") String contentScope) {
+        executionTaskService.batchCreateDeconstructTask(dtList, contentScope);
+        return CommonResponse.create();
+    }
 }