yumeng hace 4 años
padre
commit
94ef52b8ae

+ 50 - 46
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadImageServiceImpl.java

@@ -8,7 +8,6 @@ import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
@@ -31,14 +30,15 @@ import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+
 @Slf4j
 @Service
 public class MaterialUploadImageServiceImpl implements IMaterialUploadImageService {
     static ExecutorService executorService = Executors.newFixedThreadPool(8);
-
     @Value("${oss.replace.download}")
     private String downloadUrl;
 
+
     @Autowired
     private IMaterialImageInfoService materialImageInfoService;
     @Autowired
@@ -48,7 +48,7 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
      * 同步素材到账号下
      */
     @Override
-    public void uploadImage(String videoId, Long accountId, String accessToken) {
+    public synchronized void uploadImage(String videoId, Long accountId, String accessToken) {
         try {
             List<JSONObject> imageList = materialImageInfoService.getUrlList(videoId);
             if (!Check.isNull(imageList)) {
@@ -60,55 +60,57 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
                     executorService.submit(new Runnable() {
                         @Override
                         public void run() {
-                            QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
-                            imageQueryWrapper.eq("account_id", accountId);
-                            imageQueryWrapper.eq("signature", imageInfo.getString("signature"));
-                            List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
-                            if (Check.isNull(imageGetList)) {
-                                Map<String, String> headerMap = new HashMap<>();
-                                JSONObject requestJson = new JSONObject();
-                                requestJson.put("advertiser_id", accountId);
-                                headerMap.put("Access-Token", accessToken);
-                                headerMap.put("Content-Type", "multipart/form-data");
+                            synchronized (this) {
+                                QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
+                                imageQueryWrapper.eq("account_id", accountId);
+                                imageQueryWrapper.eq("signature", imageInfo.getString("signature"));
+                                List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
+                                if (Check.isNull(imageGetList)) {
+                                    Map<String, String> headerMap = new HashMap<>();
+                                    JSONObject requestJson = new JSONObject();
+                                    requestJson.put("advertiser_id", accountId);
+                                    headerMap.put("Access-Token", accessToken);
+                                    headerMap.put("Content-Type", "multipart/form-data");
 
-                                requestJson.put("url", imageInfo.getString("imageUrl"));
-                                requestJson.put("signature", imageInfo.getString("signature"));
-                                requestJson.put("type", "2");
-                                requestJson.put("upload_type", "2");
-                                String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
-                                String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
-                                JSONObject resultJson = JSONObject.parseObject(result);
-                                if (!Check.isNull(resultJson)) {
-                                    if (resultJson.getInteger("code") == 0) {
-                                        JSONObject dataJson = resultJson.getJSONObject("data");
-                                        if (!Check.isNull(dataJson)) {
-                                            String signature = dataJson.getString("signature");
-                                            String image_token = dataJson.getString("image_token");
-                                            KuaiShouImageGet imageGet = new KuaiShouImageGet();
-                                            imageGet.setId(accountId + image_token);
-                                            imageGet.setAccountId(accountId);
-                                            imageGet.setUrl(dataJson.getString("url"));
-                                            imageGet.setWidth(dataJson.getInteger("width"));
-                                            imageGet.setHeight(dataJson.getInteger("height"));
-                                            imageGet.setSize(dataJson.getInteger("size"));
-                                            imageGet.setFormat(dataJson.getString("format"));
-                                            Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
-                                            if (!Check.isNull(type)) {
-                                                imageGet.setMaterialType(type);
+                                    requestJson.put("url", imageInfo.getString("imageUrl"));
+                                    requestJson.put("signature", imageInfo.getString("signature"));
+                                    requestJson.put("type", "2");
+                                    requestJson.put("upload_type", "2");
+                                    String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
+                                    String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
+                                    JSONObject resultJson = JSONObject.parseObject(result);
+                                    if (!Check.isNull(resultJson)) {
+                                        if (resultJson.getInteger("code") == 0) {
+                                            JSONObject dataJson = resultJson.getJSONObject("data");
+                                            if (!Check.isNull(dataJson)) {
+                                                String signature = dataJson.getString("signature");
+                                                String image_token = dataJson.getString("image_token");
+                                                KuaiShouImageGet imageGet = new KuaiShouImageGet();
+                                                imageGet.setId(accountId + image_token);
+                                                imageGet.setAccountId(accountId);
+                                                imageGet.setUrl(dataJson.getString("url"));
+                                                imageGet.setWidth(dataJson.getInteger("width"));
+                                                imageGet.setHeight(dataJson.getInteger("height"));
+                                                imageGet.setSize(dataJson.getInteger("size"));
+                                                imageGet.setFormat(dataJson.getString("format"));
+                                                Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
+                                                if (!Check.isNull(type)) {
+                                                    imageGet.setMaterialType(type);
+                                                }
+                                                String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+                                                imageGet.setStatDate(DateUtils.parseDate(nowDate, "yyyy-MM-dd"));
+                                                imageGet.setSignature(signature);
+                                                imageGet.setImageToken(image_token);
+                                                imageGetService.saveOrUpdate(imageGet);
                                             }
-                                            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-                                            imageGet.setStatDate(DateUtils.parseDate(nowDate, "yyyy-MM-dd"));
-                                            imageGet.setSignature(signature);
-                                            imageGet.setImageToken(image_token);
-                                            imageGetService.saveOrUpdate(imageGet);
+                                            log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
+                                        } else {
+                                            log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
                                         }
-                                        log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
-                                    } else {
-                                        log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
                                     }
                                 }
-                            }
 
+                            }
                         }
                     });
                 }
@@ -144,4 +146,6 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
         }
         return null;
     }
+
+
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/MaterialRefuseController.java

@@ -74,7 +74,7 @@ public class MaterialRefuseController {
             if (Check.isNull(ctopOauthToken)) {
                 throw new Exception("未获取到授权信息");
             }
-            creativeService.syncCreative(accountId, ctopOauthToken.getAccessToken(), campaignId);
+            creativeService.syncCreative(accountId, ctopOauthToken.getAccessToken(), campaignId, 1);
             result.setSuccess(true);
         } catch (Exception e) {
             result.setSuccess(false);

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCreativeService.java

@@ -32,5 +32,5 @@ public interface IKuaiShouCreativeService extends IService<KuaiShouCreative> {
      */
     Integer checkCreativeCount(Long accountId, Long unitId);
 
-    void syncCreative(Long accountId, String accessToken, Long campaignId);
+    void syncCreative(Long accountId, String accessToken, Long campaignId, Integer page);
 }

+ 1 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -1,9 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -17,5 +14,5 @@ import java.util.List;
 public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
 
-    void getKeyFrame(String token,Long accountId, String md5, String photoId);
+    void getKeyFrame(String token, Long accountId, String md5, String photoId);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCreativeServiceImpl.java

@@ -77,7 +77,7 @@ public class KuaiShouCreativeServiceImpl extends ServiceImpl<KuaiShouCreativeMap
     }
 
     @Override
-    public void syncCreative(Long accountId, String accessToken, Long campaignId) {
+    public void syncCreative(Long accountId, String accessToken, Long campaignId, Integer page) {
 
 
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
@@ -86,7 +86,9 @@ public class KuaiShouCreativeServiceImpl extends ServiceImpl<KuaiShouCreativeMap
         headers.put("Access-Token", accessToken);
         JSONObject param = new JSONObject();
         param.put("advertiser_id", accountId);
+        param.put("campaign_id", campaignId);
         param.put("page_size", 200);
+        param.put("page", page);
 
         String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
         JSONObject resultJson = JSONObject.parseObject(result);
@@ -174,5 +176,6 @@ public class KuaiShouCreativeServiceImpl extends ServiceImpl<KuaiShouCreativeMap
             }
         }
         this.replaceBatch(creatives);
+        this.syncCreative(accountId, accessToken, campaignId, page + 1);
     }
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -54,7 +54,7 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
      * @param
      */
     @Override
-    public void getKeyFrame(String token, Long accountId, String videoMd5, String photoId) {
+    public synchronized void getKeyFrame(String token, Long accountId, String videoMd5, String photoId) {
         try {
             if (Check.isNull(videoMd5)) {
                 return;