|
@@ -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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|