Forráskód Böngészése

Merge remote-tracking branch 'ctop/master'

hcst_sunzhen 5 éve
szülő
commit
20b8332ffc

+ 115 - 47
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -298,64 +298,132 @@ public class CallbackController {
                 return returnMap;
 
             }
-
             data.remove("advertiser_ids");
             StringBuilder text = new StringBuilder();
             for (int i = 0; i < advertiser_ids.size(); i++) {
                 Long advertiser_id = advertiser_ids.getLong(i);
-                data.put("advertiser_id", advertiser_id);
-                CtopOauthToken token = new CtopOauthToken(advertiserId, data);
-                ctopOauthTokenService.saveOrUpdate(token);
-                //获取广告主信息
-                Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(token.getAccountId() + "");
-                Boolean getSuccess = (Boolean) advertiserDataMap.get("success");
-                if (null == getSuccess || !getSuccess) {
-                    log.info("获取广告主信息失败,accountId:{},message:{}", token.getAccountId(), (String) advertiserDataMap.get("message"));
-                    continue;
-                }
+                JSONObject adJson = advertiserDataService.getAdvertiserList(data.getString("access_token"), advertiser_id);
+                Integer returnCode = adJson.getInteger("code");
+                if (returnCode == 0) {
+                    JSONArray dataArr = adJson.getJSONArray("data");
+                    if (!Check.isNull(dataArr)) {
+                        for (int j = 0; j < dataArr.size(); j++) {
+                            JSONObject dataJson = dataArr.getJSONObject(j);
+                            Long advertiser_id1 = dataJson.getLong("advertiser_id");
+                            data.put("advertiser_id", advertiser_id1);
+                            CtopOauthToken token = new CtopOauthToken(advertiserId, data);
+                            ctopOauthTokenService.saveOrUpdate(token);
+                            //获取广告主信息
+                            Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(token.getAccountId() + "");
+                            Boolean getSuccess = (Boolean) advertiserDataMap.get("success");
+                            if (null == getSuccess || !getSuccess) {
+                                log.info("获取广告主信息失败,accountId:{},message:{}", token.getAccountId(), (String) advertiserDataMap.get("message"));
+                                text.append("账户id:" + advertiser_id + "暂未获取数据权限,请检查账户")
+                                        .append("<br/>");
+                                continue;
+                            }
 
-                Long accountId = token.getAccountId();
-                QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
-                userAllocationQueryWrapper.eq("account_id", accountId);
-                userAllocationQueryWrapper.eq("media_id", 1);
-                userAllocationQueryWrapper.orderByDesc("create_time");
-                userAllocationQueryWrapper.last("limit 1");
-                UserAllocation checkUserAllocation = allocationMapper.selectOne(userAllocationQueryWrapper);
-                if (!Check.isNull(checkUserAllocation)) {
-                    text.append("accountId:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定失败,失败原因:已被" + checkUserAllocation.getUserName() + "绑定。")
-                            .append("<br/>");
-                    continue;
-                }
-                text.append("accountId:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定成功。").append("<br/>");
-                String systemType = json.getString("systemType");
-                UserAllocation userAllocation = new UserAllocation();
-                userAllocation.setUserId(userId);
-                userAllocation.setUserName(userName);
-                userAllocation.setAccountId(token.getAccountId());
-                userAllocation.setAdvertiserName(advertiserName);
-                userAllocation.setMediaId(mediaId);
-                userAllocation.setProjectId(projectId);
-                userAllocation.setProjectName(projectName);
-                userAllocation.setSystemType(systemType);
-                userAllocation.setAuthName((String) advertiserDataMap.get("name"));
-                userAllocation.setAdvertiserId(advertiserId);
-                userAllocation.setWarningProportion(warningProportion);
-                userAllocation.setWarningAmount(warningAmount);
-                userAllocation.setCreateTime(new Date());
-                userAllocation.setUpdateTime(new Date());
-                int j = allocationMapper.insert(userAllocation);
-                if (j > 0) {
-                    log.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
+                            Long accountId = token.getAccountId();
+                            QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+                            userAllocationQueryWrapper.eq("account_id", accountId);
+                            userAllocationQueryWrapper.eq("media_id", 1);
+                            userAllocationQueryWrapper.orderByDesc("create_time");
+                            userAllocationQueryWrapper.last("limit 1");
+                            UserAllocation checkUserAllocation = allocationMapper.selectOne(userAllocationQueryWrapper);
+                            if (!Check.isNull(checkUserAllocation)) {
+                                text.append("账户id:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定失败,失败原因:已被" + checkUserAllocation.getUserName() + "绑定。")
+                                        .append("<br/>");
+                                continue;
+                            }
+                            text.append("accountId:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定成功。").append("<br/>");
+                            String systemType = json.getString("systemType");
+                            UserAllocation userAllocation = new UserAllocation();
+                            userAllocation.setUserId(userId);
+                            userAllocation.setUserName(userName);
+                            userAllocation.setAccountId(token.getAccountId());
+                            userAllocation.setAdvertiserName(advertiserName);
+                            userAllocation.setMediaId(mediaId);
+                            userAllocation.setProjectId(projectId);
+                            userAllocation.setProjectName(projectName);
+                            userAllocation.setSystemType(systemType);
+                            userAllocation.setAuthName((String) advertiserDataMap.get("name"));
+                            userAllocation.setAdvertiserId(advertiserId);
+                            userAllocation.setWarningProportion(warningProportion);
+                            userAllocation.setWarningAmount(warningAmount);
+                            userAllocation.setCreateTime(new Date());
+                            userAllocation.setUpdateTime(new Date());
+                            int g = allocationMapper.insert(userAllocation);
+                            if (g > 0) {
+                                log.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
+                            }
+                            //账号绑定
+                            bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
+                            new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
+                        }
+
+                    }
+
+                } else {
+                    data.put("advertiser_id", advertiser_id);
+                    CtopOauthToken token = new CtopOauthToken(advertiserId, data);
+                    ctopOauthTokenService.saveOrUpdate(token);
+                    //获取广告主信息
+                    Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(token.getAccountId() + "");
+                    Boolean getSuccess = (Boolean) advertiserDataMap.get("success");
+                    if (null == getSuccess || !getSuccess) {
+                        log.info("获取广告主信息失败,accountId:{},message:{}", token.getAccountId(), (String) advertiserDataMap.get("message"));
+                        text.append("accountId:" + advertiser_id + "暂未获取数据权限,请检查账户")
+                                .append("<br/>");
+                        continue;
+                    }
+
+                    Long accountId = token.getAccountId();
+                    QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+                    userAllocationQueryWrapper.eq("account_id", accountId);
+                    userAllocationQueryWrapper.eq("media_id", 1);
+                    userAllocationQueryWrapper.orderByDesc("create_time");
+                    userAllocationQueryWrapper.last("limit 1");
+                    UserAllocation checkUserAllocation = allocationMapper.selectOne(userAllocationQueryWrapper);
+                    if (!Check.isNull(checkUserAllocation)) {
+                        text.append("账户id:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定失败,失败原因:已被" + checkUserAllocation.getUserName() + "绑定。")
+                                .append("<br/>");
+                        continue;
+                    }
+                    text.append("账户id:" + accountId + ",授权名称为:" + (String) advertiserDataMap.get("name") + ",绑定成功。").append("<br/>");
+                    String systemType = json.getString("systemType");
+                    UserAllocation userAllocation = new UserAllocation();
+                    userAllocation.setUserId(userId);
+                    userAllocation.setUserName(userName);
+                    userAllocation.setAccountId(token.getAccountId());
+                    userAllocation.setAdvertiserName(advertiserName);
+                    userAllocation.setMediaId(mediaId);
+                    userAllocation.setProjectId(projectId);
+                    userAllocation.setProjectName(projectName);
+                    userAllocation.setSystemType(systemType);
+                    userAllocation.setAuthName((String) advertiserDataMap.get("name"));
+                    userAllocation.setAdvertiserId(advertiserId);
+                    userAllocation.setWarningProportion(warningProportion);
+                    userAllocation.setWarningAmount(warningAmount);
+                    userAllocation.setCreateTime(new Date());
+                    userAllocation.setUpdateTime(new Date());
+                    int g = allocationMapper.insert(userAllocation);
+                    if (g > 0) {
+                        log.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
+                    }
+                    //账号绑定
+                    bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
+                    new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
                 }
-                //账号绑定
-                bindAccountAuthService.addBindAccount(token.getAccountId(), KuaishouInterfaceConstant.LOGIN_TYPE_BYTEDANCE, advertiserId);
-                new Thread(() -> reportService.loadBytedanceHistoryData(token)).start();
+
+
             }
 
+
             returnMap.put("code", 0);
             returnMap.put("desc", text.toString());
 
-        } catch (Exception e) {
+        } catch (
+                Exception e) {
             e.printStackTrace();
             returnMap.put("code", -1);
             returnMap.put("desc", "回调token异常");

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

@@ -952,14 +952,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     returnMap.put("campaignId", campaignId);
                     returnMap.put("success", true);
                     // 创建成功 拉取广告组信息
-                    Thread thread = new Thread() {
-                        @Override
-                        public void run() {
-                            getCampaign(accessToken, advertiserId, campaignId);
-                        }
-
-                    };
-                    thread.start();
+                    getCampaign(accessToken, advertiserId, campaignId);
                 } else {
                     log.error("创建广告计划失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
                     returnMap.put("code", -1);

+ 3 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceAdvertiserDataService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.toutiao.modules.material.service;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import com.alibaba.fastjson.JSONObject;
 
 import java.util.Map;
 
@@ -8,6 +9,8 @@ import java.util.Map;
  * @author jeecg-boot
  */
 public interface IByteDanceAdvertiserDataService {
+    JSONObject getAdvertiserList(String token, Long accountId);
+
     Map<String, Object> getAdvertiserInfo(String accountId);
 
     Map<String, Object> getAdvertiserPlan(CtopOauthToken token, String ids, String date, String updateDate);

+ 49 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -37,6 +37,55 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     private IByteDanceVideoInfoService videoInfoService;
 
     @Override
+    public JSONObject getAdvertiserList(String token, Long accountId) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            String url = "https://ad.oceanengine.com/open_api/2/majordomo/advertiser/select/";
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Content-Type", "application/json");
+            headers.put("Access-Token", token);
+            TreeMap<String, Object> params = new TreeMap<>();
+            params.put("advertiser_id", accountId);
+            String result = HttpUtils.httpGetRequest(url, headers, params);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (Check.isNull(jsonObject)) {
+                throw new Exception("返回结果为空");
+
+            }
+
+            Integer code = jsonObject.getInteger("code");
+            if (code == 0) {
+                JSONObject data = jsonObject.getJSONObject("data");
+                if (Check.isNull(data)) {
+                    throw new Exception("data为空");
+                }
+                JSONArray list = data.getJSONArray("list");
+                if (Check.isNull(list)) {
+                    throw new Exception("账户列表为空");
+
+                }
+                returnJson.put("code", 0);
+                returnJson.put("data", list);
+
+            } else {
+                returnJson.put("code", -1);
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+
+        }
+
+
+        return returnJson;
+
+
+    }
+
+    @Override
     public Map<String, Object> getAdvertiserInfo(String accountId) {
         Map<String, Object> resultMap = new HashMap<>();
         CtopOauthToken cTopOauthToken = tokenService.getOauthTokenByAccountId(accountId);