|
@@ -2,11 +2,17 @@ package cn.com.ctop.kuaishou.modules.ai.controller;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
|
+import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -15,6 +21,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+
|
|
@Slf4j
|
|
@Slf4j
|
|
@Api(tags = "快手-创意拒审重提")
|
|
@Api(tags = "快手-创意拒审重提")
|
|
@RestController
|
|
@RestController
|
|
@@ -24,6 +34,15 @@ public class KuaiShouCreativeRefusalController {
|
|
private ICtopOauthTokenService tokenService;
|
|
private ICtopOauthTokenService tokenService;
|
|
@Autowired
|
|
@Autowired
|
|
private IKuaiShouCreativeService creativeService;
|
|
private IKuaiShouCreativeService creativeService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouUpdateService updateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IMaterialCutFrameService cutFrameService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouImageGetService imageGetService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouMaterialUploadService uploadService;
|
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(50);
|
|
|
|
|
|
/**
|
|
/**
|
|
* 吃创意拒审重提
|
|
* 吃创意拒审重提
|
|
@@ -33,7 +52,7 @@ public class KuaiShouCreativeRefusalController {
|
|
*/
|
|
*/
|
|
@PostMapping(value = "again")
|
|
@PostMapping(value = "again")
|
|
public JSONObject campaignCreate(@RequestBody JSONObject requestJson) {
|
|
public JSONObject campaignCreate(@RequestBody JSONObject requestJson) {
|
|
-
|
|
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
try {
|
|
try {
|
|
if (Check.isNull(requestJson)) {
|
|
if (Check.isNull(requestJson)) {
|
|
throw new Exception("入参不能为空");
|
|
throw new Exception("入参不能为空");
|
|
@@ -52,19 +71,60 @@ public class KuaiShouCreativeRefusalController {
|
|
}
|
|
}
|
|
for (int i = 0; i < creativeIds.size(); i++) {
|
|
for (int i = 0; i < creativeIds.size(); i++) {
|
|
Long creativeId = creativeIds.getLong(i);
|
|
Long creativeId = creativeIds.getLong(i);
|
|
- // KuaiShouCreative creative = creativeService.getCreativeByCreativeId(creativeId);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ KuaiShouCreative creative = creativeService.getCreativeByCreativeId(creativeId);
|
|
|
|
+ if (!Check.isNull(creative)) {
|
|
|
|
+ JSONObject cutJson = cutFrameService.getCutFrameByVideoMd5(creative.getPhotoId(), creative.getImageToken());
|
|
|
|
+ if (!Check.isNull(cutJson)) {
|
|
|
|
+ String signature = cutJson.getString("signature");
|
|
|
|
+ String url = cutJson.getString("url");
|
|
|
|
+ String imageToken = getImageToken(signature, accountId, oauthToken.getAccessToken(), url);
|
|
|
|
+ if (!Check.isNull(imageToken)) {
|
|
|
|
+ JSONObject updateJson = new JSONObject();
|
|
|
|
+ updateJson.put("creativeId", creativeId);
|
|
|
|
+ updateJson.put("imageToken", imageToken);
|
|
|
|
+ Map<String, Object> creativeMap = updateService.updateCreative(oauthToken.getAccessToken(), accountId, requestJson);
|
|
|
|
+ Integer code = (Integer) creativeMap.get("code");
|
|
|
|
+ if (code == 0) {
|
|
|
|
+ log.info("自动投放拒审重提成功,accountId:{},creativeId:{}", accountId, creativeId);
|
|
|
|
+ } else {
|
|
|
|
+ log.info("自动投放拒审重提失败,accountId:{},creativeId:{}", accountId, creativeId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ returnJson.put("code", 0);
|
|
|
|
+ returnJson.put("message", "异步提交中");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ returnJson.put("code", 0);
|
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
}
|
|
}
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
|
|
+ private String getImageToken(String md5, Long accountId, String accessToken, String url) {
|
|
|
|
+ String imageToken = null;
|
|
|
|
+ QueryWrapper<KuaiShouImageGet> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("account_id", accountId);
|
|
|
|
+ queryWrapper.eq("signature", md5);
|
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
|
+ KuaiShouImageGet imageGet = imageGetService.getOne(queryWrapper);
|
|
|
|
+ if (!Check.isNull(imageGet)) {
|
|
|
|
+ imageToken = imageGet.getImageToken();
|
|
|
|
+ } else {
|
|
|
|
+ imageToken = uploadService.kuauiShouImageUpload(url, md5, accountId, accessToken);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+ return imageToken;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|