Prechádzať zdrojové kódy

一户多开账户调整

yumeng 5 rokov pred
rodič
commit
b5dfc57a5c

+ 15 - 7
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -7,13 +7,12 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
-import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
 import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadService;
 import com.alibaba.fastjson.JSONArray;
@@ -61,10 +60,6 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     @Autowired
     private IMaterialParameterService materialParameterService;
     @Autowired
-    private MaterialParameterMapper parameterMapper;
-    @Autowired
-    private IKuaiShouVideoGetService kuaiShouVideoGetService;
-    @Autowired
     private IMaterialUploadImageService materialUploadImageService;
     @Autowired
     private ISendMessageService sendMessageService;
@@ -72,6 +67,8 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     private IMessageTemplate messageTemplate;
     @Autowired
     private IUserAllocationService userAllocationService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
 
 
     /**
@@ -175,7 +172,6 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                     Long accountId = accountArray.getLong(i);
                     QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
                     tokenQueryWrapper.eq("account_id", accountId);
-                   // tokenQueryWrapper.eq("media_id", mediaId);
                     tokenQueryWrapper.orderByDesc("create_time");
                     tokenQueryWrapper.last("limit 1");
                     CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
@@ -228,6 +224,18 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
                                             kuaiShouVideoGetService.saveOrUpdate(videoGet);*/
                                             materialUploadImageService.uploadImage(signature, accountId, ctopOauthToken.getAccessToken());
 
+                                            Thread thread = new Thread() {
+                                                @Override
+                                                public void run() {
+                                                    try {
+                                                        Thread.sleep(2 * 1000L);
+                                                        kuaishouInterfaceService.getVideoInfo(ctopOauthToken.getAccessToken(), ctopOauthToken.getAccountId(), dataJson.getString("photo_id"));
+                                                    } catch (InterruptedException e) {
+                                                        e.printStackTrace();
+                                                    }
+                                                }
+                                            };
+                                            thread.start();
                                         }
                                         log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
                                     } else {

+ 18 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -84,6 +84,10 @@ public class BatchController {
     private IKuaishouPopulationService populationService;
     @Autowired
     private KuaiShouGroupMapper groupMapper;
+    @Autowired
+    private ISyncPullMaterialService syncPullMaterialService;
+    @Autowired
+    private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
 
 
     /**
@@ -151,7 +155,7 @@ public class BatchController {
             Thread thread2 = new Thread() {
                 @Override
                 public void run() {
-                    iKuaishouInterfaceService.getVideoList(oauthToken, startDate, nowDate);
+                    syncPullMaterialService.getSyncVideoList(accountId, nowDate, nowDate);
 
                 }
             };
@@ -160,8 +164,7 @@ public class BatchController {
             Thread thread3 = new Thread() {
                 @Override
                 public void run() {
-
-                    iKuaishouInterfaceService.getSuZaoList(oauthToken.getAccessToken(), oauthToken.getAccountId(), 1, startDate, endDate);
+                    syncPullMaterialService.getSyncSuZaoList(accountId, nowDate, endDate);
                 }
             };
             thread3.start();
@@ -1113,7 +1116,19 @@ public class BatchController {
                                                         @RequestParam(name = "endDate", defaultValue = "") String endDate, HttpServletRequest req) {
         Result<IPage<KuaiShouVideoGet>> result = new Result<>();
         try {
+
+            Long accountId = kuaiShouVideoGet.getAccountId();
+            kuaiShouVideoGet.setAccountId(null);
+            if (Check.isNull(accountId)) {
+                throw new Exception("账户id不能为空");
+            }
             QueryWrapper<KuaiShouVideoGet> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouVideoGet, req.getParameterMap());
+            KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(accountId);
+            if (!Check.isNull(baseInfo)) {
+                queryWrapper.eq("user_id", baseInfo.getUserId());
+            } else {
+                queryWrapper.eq("account_id", accountId);
+            }
             if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
                 queryWrapper.between("stat_date", startDate, endDate);
             }

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouVideoGet.java

@@ -97,4 +97,5 @@ public class KuaiShouVideoGet {
 
     private Integer channelType;
     private Integer status;
+    private Long userId;
 }

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouAdvertiserBaseInfoService.java

@@ -3,6 +3,8 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAdvertiserBaseInfo;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * 快手-广告主基本信息
  *
@@ -12,4 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaiShouAdvertiserBaseInfoService extends IService<KuaiShouAdvertiserBaseInfo> {
 
+    KuaiShouAdvertiserBaseInfo getBaseInfo(Long accountId);
+
+    List<KuaiShouAdvertiserBaseInfo> getAccountIdList(String userId);
 }

+ 7 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/ISyncPullMaterialService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+public interface ISyncPullMaterialService {
+    void getSyncVideoList(Long accountId, String startDate, String endDate);
+
+    void getSyncSuZaoList(Long accountId, String nowDate, String endDate);
+}

+ 33 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouAdvertiserBaseInfoServiceImpl.java

@@ -3,11 +3,13 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAdvertiserBaseInfo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAdvertiserBaseInfoMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAdvertiserBaseInfoService;
-
-
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 快手-广告主基本信息
  *
@@ -17,5 +19,34 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class KuaiShouAdvertiserBaseInfoServiceImpl extends ServiceImpl<KuaiShouAdvertiserBaseInfoMapper, KuaiShouAdvertiserBaseInfo> implements IKuaiShouAdvertiserBaseInfoService {
+    @Autowired
+    private KuaiShouAdvertiserBaseInfoMapper advertiserBaseInfoMapper;
+
+    /**
+     * 根据accountId获取对象
+     *
+     * @param accountId
+     * @return
+     */
+    @Override
+    public KuaiShouAdvertiserBaseInfo getBaseInfo(Long accountId) {
+        QueryWrapper<KuaiShouAdvertiserBaseInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("account_id", accountId);
+        queryWrapper.last("limit 1");
+        return advertiserBaseInfoMapper.selectOne(queryWrapper);
+    }
 
+    /**
+     * 获取账户列表
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    public List<KuaiShouAdvertiserBaseInfo> getAccountIdList(String userId) {
+        QueryWrapper<KuaiShouAdvertiserBaseInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", userId);
+        queryWrapper.groupBy("account_id");
+        return advertiserBaseInfoMapper.selectList(queryWrapper);
+    }
 }

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

@@ -89,7 +89,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                 log.error("修改广告计划预算返回结果为空,advertiserId:{},campaignId:{}", advertiserId, campaignId);
                 returnMap.put("code", -1);
                 returnMap.put("success", false);
-                returnMap.put("message", "修改广告预算返回结果为空");
+                returnMap.put("message", "修改广告计划预算返回结果为空");
             }
 
         } catch (Exception e) {

+ 54 - 14
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -132,6 +132,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaishouPopulationService populationService;
     @Autowired
     private IKuaiShouGroupService getKuaiShouGroupService;
+    @Autowired
+    private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
 
 
     @Override
@@ -186,6 +188,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         getVideoListByPage(token, startDate, endDate, 1);
     }
 
+
+
+
     private void getVideoListByPage(CtopOauthToken token, String startDate, String endDate, int page) {
         try {
             log.info("获取视频数据,accountId:{}", token.getAccountId());
@@ -214,6 +219,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 log.info("快手视频列表信息为空=》accountId:{}", token.getAccountId());
                 return;
             }
+            KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(token.getAccountId());
+            Long userId = null;
+            if (!Check.isNull(baseInfo)) {
+                userId = Long.valueOf(baseInfo.getUserId());
+            }
             for (int i = 0; i < details.size(); i++) {
                 var detailJson = details.getJSONObject(i);
                 KuaiShouVideoGet byId = kuaiShouVideoGetService.getById(token.getAccountId() + detailJson.getString("photo_id"));
@@ -230,6 +240,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (!Check.isNull(type)) {
                     kuaiShouVideoGet.setMaterialType(type);
                 }
+
+                kuaiShouVideoGet.setUserId(userId);
                 kuaiShouVideoGetService.saveOrUpdate(kuaiShouVideoGet);
 
                 Thread thread = new Thread() {
@@ -1380,17 +1392,17 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      * 获取视频信息数据
      *
      * @param accessToken
-     * @param advertiserId
+     * @param accountId
      * @param photoId
      */
     @Override
-    public void getVideoInfo(String accessToken, Long advertiserId, String photoId) {
+    public void getVideoInfo(String accessToken, Long accountId, String photoId) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_GET;
         Map<String, String> headers = new HashMap<String, String>();
         headers.put("Content-Type", " application/json");
         headers.put("Access-Token", accessToken);
         JSONObject param = new JSONObject();
-        param.put("advertiser_id", advertiserId);
+        param.put("advertiser_id", accountId);
         JSONArray photosArray = new JSONArray();
         photosArray.add(photoId);
         param.put("photo_ids", photosArray);
@@ -1402,27 +1414,49 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONArray dataArray = resultJson.getJSONArray("data");
                     if (!Check.isNull(dataArray)) {
+                        KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(accountId);
+                        Long userId = null;
+                        if (!Check.isNull(baseInfo)) {
+                            userId = Long.valueOf(baseInfo.getUserId());
+                        }
                         for (int i = 0; i < dataArray.size(); i++) {
                             JSONObject detailJson = dataArray.getJSONObject(i);
                             if (!Check.isNull(detailJson)) {
-                                KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
-                                videoGet.setId(detailJson.getString("photo_id"));
-                                videoGet.setAccountId(advertiserId);
-                                videoGet.setWidth(detailJson.getInteger("width"));
-                                videoGet.setHeight(detailJson.getInteger("height"));
-                                videoGet.setUrl(detailJson.getString("url"));
-                                videoGet.setCoverUrl(detailJson.getString("creative_name"));
-                                videoGet.setPhotoId(detailJson.getString("photo_id"));
-                                kuaiShouVideoGetService.saveOrUpdate(videoGet);
+
+                                KuaiShouVideoGet byId = kuaiShouVideoGetService.getById(accountId + photoId);
+                                if (!Check.isNull(byId)) {
+                                    continue;
+                                }
+                                var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
+                                kuaiShouVideoGet.setId(accountId + photoId);
+
+                                kuaiShouVideoGet.setAccountId(accountId);
+                                kuaiShouVideoGet.setStatDate(detailJson.getDate("upload_time"));
+                                kuaiShouVideoGet.setUpdateTime(new Date());
+                                Integer type = MaterialEnum.getTypeBySize(kuaiShouVideoGet.getWidth(), kuaiShouVideoGet.getHeight());
+                                if (!Check.isNull(type)) {
+                                    kuaiShouVideoGet.setMaterialType(type);
+                                }
+
+                                kuaiShouVideoGet.setUserId(userId);
+                                kuaiShouVideoGetService.saveOrUpdate(kuaiShouVideoGet);
+
+                                Thread thread = new Thread() {
+                                    @Override
+                                    public void run() {
+                                        videoGetService.getKeyFrame(accessToken, accountId, kuaiShouVideoGet.getSignature(), kuaiShouVideoGet.getPhotoId());
+                                    }
+                                };
+                                thread.start();
                             }
                         }
                     }
                 } else {
-                    log.error("获取广告视频信息返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
+                    log.error("获取广告视频信息返回结果异常,advertiserId:{},异常信息:{}", accountId, resultJson);
                 }
 
             } else {
-                log.error("获取广告视频信息返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
+                log.error("获取广告视频信息返回结果异常,advertiserId:{},异常信息:{}", accountId, resultJson);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -2888,6 +2922,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             if (Check.isNull(details)) {
                 return;
             }
+            KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(accountId);
+            Long userId = null;
+            if (!Check.isNull(baseInfo)) {
+                userId = Long.valueOf(baseInfo.getUserId());
+            }
             for (int i = 0; i < details.size(); i++) {
                 JSONObject jsonObject = details.getJSONObject(i);
                 if (!Check.isNull(jsonObject)) {
@@ -2904,6 +2943,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     kuaiShouVideoGet.setSignature(md5);
                     kuaiShouVideoGet.setStatDate(jsonObject.getDate("sync_date"));
                     kuaiShouVideoGet.setChannelType(1);
+                    kuaiShouVideoGet.setUserId(userId);
                     Integer type = MaterialEnum.getTypeBySize(kuaiShouVideoGet.getWidth(), kuaiShouVideoGet.getHeight());
                     if (!Check.isNull(type)) {
                         kuaiShouVideoGet.setMaterialType(type);

+ 90 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/SyncPullMaterialServiceImpl.java

@@ -0,0 +1,90 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAdvertiserBaseInfo;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAdvertiserBaseInfoService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.ISyncPullMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 异步获取素材信息
+ */
+
+@Service
+public class SyncPullMaterialServiceImpl implements ISyncPullMaterialService {
+    @Autowired
+    private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IKuaishouInterfaceService iKuaishouInterfaceService;
+    static ExecutorService videoExecutorService = Executors.newFixedThreadPool(10);
+    static ExecutorService suZhaoExecutorService = Executors.newFixedThreadPool(10);
+
+
+    /**
+     * 获取一户多开所有视频信息
+     *
+     * @param accountId
+     * @param startDate
+     * @param endDate
+     */
+    @Override
+    public void getSyncVideoList(Long accountId, String startDate, String endDate) {
+        KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(accountId);
+        if (!Check.isNull(baseInfo)) {
+            List<KuaiShouAdvertiserBaseInfo> baseInfoList = KuaiShouAdvertiserBaseInfoService.getAccountIdList(baseInfo.getUserId());
+            if (!Check.isNull(baseInfoList)) {
+                for (KuaiShouAdvertiserBaseInfo advertiserBaseInfo : baseInfoList) {
+                    CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserBaseInfo.getAccountId());
+                    if (!Check.isNull(token)) {
+                        videoExecutorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                iKuaishouInterfaceService.getVideoList(token, startDate, endDate);
+                            }
+                        });
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 获取素造素材
+     *
+     * @param accountId
+     * @param startDate
+     * @param endDate
+     */
+    @Override
+    public void getSyncSuZaoList(Long accountId, String startDate, String endDate) {
+
+        KuaiShouAdvertiserBaseInfo baseInfo = KuaiShouAdvertiserBaseInfoService.getBaseInfo(accountId);
+        if (!Check.isNull(baseInfo)) {
+            List<KuaiShouAdvertiserBaseInfo> baseInfoList = KuaiShouAdvertiserBaseInfoService.getAccountIdList(baseInfo.getUserId());
+            if (!Check.isNull(baseInfoList)) {
+                for (KuaiShouAdvertiserBaseInfo advertiserBaseInfo : baseInfoList) {
+                    CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserBaseInfo.getAccountId());
+                    if (!Check.isNull(token)) {
+                        suZhaoExecutorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                iKuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startDate, endDate);
+                            }
+                        });
+                    }
+                }
+            }
+        }
+
+    }
+}