Selaa lähdekoodia

插入表 ctop_ai_kuaishou_project_auto_video 数据

zhaoxian 1 vuosi sitten
vanhempi
commit
544267c92a

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -77,4 +77,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<Long> getAccountListByProjectId(@Param("projectId") Long projectId);
 
     JSONObject getProductInfo(@Param("accountId") Long accountId);
+
+    List<JSONObject> getAccountInfoByProjectId(@Param("projectId") Long projectId);
 }

+ 12 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -362,5 +362,17 @@ ORDER BY
 
     </select>
 
+    <select id="getAccountInfoByProjectId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            t1.account_id as 'accountId',
+            t1.auth_name as 'accountName',
+            t1.project_id as 'projectId',
+            t2.project_name as 'projectName'
+        FROM ctop_user_allocation t1
+                 LEFT JOIN ctop_project t2 ON t1.project_id=t2.id
+        WHERE t1.project_id = #{projectId}
+        AND t1.account_status = 0
+    </select>
+
 
 </mapper>

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -78,4 +78,6 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     List<Long> getAccountListByProjectId(Long projectId);
 
     JSONObject getProductInfo(Long accountId);
+
+    List<JSONObject> getAccountInfoByProjectId(Long projectId);
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -350,5 +350,10 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         return userAllocationMapper.getProductInfo(accountId);
     }
 
+    @Override
+    public List<JSONObject> getAccountInfoByProjectId(Long projectId) {
+        return userAllocationMapper.getAccountInfoByProjectId(projectId);
+    }
+
 
 }

+ 16 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouAccountAutoVideoController.java

@@ -96,6 +96,22 @@ public class AiKuaishouAccountAutoVideoController {
     }
 
     /**
+     * 通过项目ID获取视频素材
+     */
+    @GetMapping(value = "/insertAutoVideoByProjectId")
+    public Result<Object> insertAutoVideoByProjectId(Long projectId) {
+        Result<Object> result = new Result<>();
+        try {
+            aiKuaishouAccountAutoVideoService.insertAutoVideoByProjectId(projectId);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
      * 添加
      *
      * @param aiKuaishouAccountAutoVideo

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/AiKuaishouAccountAutoVideoMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.ai.mapper;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoVideo;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -33,4 +34,6 @@ public interface AiKuaishouAccountAutoVideoMapper extends BaseMapper<AiKuaishouA
     void updateAutoVideoUsed(@Param("accountId") Long accountId, @Param("signature") String signature, @Param("videoType") Integer videoType, @Param("createType") String createType, @Param("usageTimes") Integer usageTimes, @Param("date") String date);
 
     List<String> selectBatchByPhotoIds(@Param("details") JSONArray details, @Param("statDate") String statDate, @Param("accountId") Long accountId);
+
+    void insertBatchAiKuaishouProjectAutoVideo(@Param("list") List<JSONObject> list);
 }

+ 24 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouAccountAutoVideoMapper.xml

@@ -205,4 +205,28 @@
         </if>
     </select>
 
+    <insert id="insertBatchAiKuaishouProjectAutoVideo">
+        replace into ctop_ai_kuaishou_project_auto_video(
+        project_id,
+        project_name,
+        account_id,
+        account_name,
+        photo_id,
+        photo_name,
+        signature
+        )
+        values
+        <foreach collection="list" item="video" separator=",">
+            (
+            #{video.projectId},
+            #{video.projectName},
+            #{video.accountId},
+            #{video.accountName},
+            #{video.photo_id},
+            #{video.photo_name},
+            #{video.signature}
+            )
+        </foreach>
+    </insert>
+
 </mapper>

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouAccountAutoVideoService.java

@@ -30,4 +30,6 @@ public interface IAiKuaishouAccountAutoVideoService extends IService<AiKuaishouA
 
     //自动投放重构——记录(高质量,历史打捞)使用次数
     void saveOrUpdateAutoVideoUsedCount(Long accountId, String signature, Integer videoType, String createType);
+
+    void insertAutoVideoByProjectId(Long projectId);
 }

+ 82 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoVideoServiceImpl.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.ai.service.impl;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
@@ -12,7 +13,6 @@ import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouAccountAutoVideoMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountAutoVideoService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -24,6 +24,8 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 自动投放账户——素材
@@ -42,6 +44,9 @@ public class AiKuaishouAccountAutoVideoServiceImpl extends ServiceImpl<AiKuaisho
     @Autowired
     private ICtopOauthTokenService tokenService;
 
+    @Autowired
+    private IUserAllocationService userAllocationService;
+
     @Override
     public List<AiKuaishouAccountAutoVideo> getUpNewVideos(Long accountId, Integer channelType, List<String> keyword, Integer videoCnt, String statDate, String createType) {
         return autoVideoMapper.getUpNewVideos(accountId, channelType, keyword, videoCnt, statDate, createType);
@@ -179,4 +184,80 @@ public class AiKuaishouAccountAutoVideoServiceImpl extends ServiceImpl<AiKuaisho
             e.printStackTrace();
         }
     }
+
+    static ExecutorService autoVideoService = Executors.newFixedThreadPool(6);
+
+    @Override
+    public void insertAutoVideoByProjectId(Long projectId) {
+        List<JSONObject> accounts = userAllocationService.getAccountInfoByProjectId(projectId);
+        if (!Check.isNull(accounts)) {
+            accounts.forEach(acc -> autoVideoService.submit(() -> {
+                try {
+                    getVideoListByProjectId(acc, 1);
+                } catch (Exception e) {
+                    log.error("通过项目ID获取视频素材失败", e);
+                }
+            }));
+
+
+        }
+    }
+
+    private void getVideoListByProjectId(JSONObject acc, int page) {
+        Long accountId = acc.getLong("accountId");
+        Long projectId = acc.getLong("projectId");
+        String accountName = acc.getString("accountName");
+        String projectName = acc.getString("projectName");
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        try {
+            int pageSize = 500;
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_LIST;
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Content-Type", "application/json");
+            headers.put("Access-Token", token.getAccessToken());
+            Map<String, Object> param = new HashMap<>();
+            param.put("advertiser_id", accountId);
+            param.put("page_size", 500);
+            param.put("page", page);
+            String result = HttpUtils.httpPostRequest(url, param, headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (Check.isNull(resultJson)) {
+                return;
+            }
+            Integer code = resultJson.getInteger("code");
+            String message = resultJson.getString("message");
+            if (null == code || code != 0) {
+                log.error("获取快手视频列表数据异常:{},accountId:{}", message, token.getAccountId());
+                return;
+            }
+            JSONArray videoList = resultJson.getJSONObject("data").getJSONArray("details");
+            if (null == videoList || videoList.size() <= 0) {
+                log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
+                return;
+            }
+            Boolean doGet = true;
+            if (videoList.size() < pageSize) {
+                doGet = false;
+            }
+            List<JSONObject> list = new ArrayList<>();
+            for (int i = 0; i < videoList.size(); i++) {
+                JSONObject video = videoList.getJSONObject(i);
+                if (video != null && video.getInteger("new_status") == 1) {
+                    video.put("accountId",accountId);
+                    video.put("accountName",accountName);
+                    video.put("projectId",projectId);
+                    video.put("projectName",projectName);
+                    list.add(video);
+                }
+            }
+            if (!Check.isNull(list)) {
+                autoVideoMapper.insertBatchAiKuaishouProjectAutoVideo(list);
+            }
+            if (doGet) {
+                getVideoListByPage(token, page + 1);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }