|
@@ -272,6 +272,7 @@ public class CallbackController {
|
|
|
String advertiserId = json.getString("advertiserId");
|
|
|
// 媒体类型: 1 头条 2 快手
|
|
|
String mediaId = json.getString("mediaId");
|
|
|
+
|
|
|
// 广告主名称
|
|
|
String advertiserName = json.getString("advertiser_name");
|
|
|
//创建人
|
|
@@ -282,12 +283,16 @@ public class CallbackController {
|
|
|
String projectName = json.getString("projectName");
|
|
|
BigDecimal warningProportion = json.getBigDecimal("WarningProportion");
|
|
|
BigDecimal warningAmount = json.getBigDecimal("WarningAmount");
|
|
|
+
|
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
|
+
|
|
|
if (Check.isNull(data)) {
|
|
|
returnMap.put("code", -1);
|
|
|
returnMap.put("desc", "返回信息为空");
|
|
|
return returnMap;
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
data.remove("advertiser_id");
|
|
|
JSONArray advertiser_ids = data.getJSONArray("advertiser_ids");
|
|
|
if (Check.isNull(advertiser_ids)) {
|
|
@@ -297,76 +302,126 @@ public class CallbackController {
|
|
|
|
|
|
}
|
|
|
data.remove("advertiser_ids");
|
|
|
-
|
|
|
- String access_token = data.getString("access_token");
|
|
|
- String refresh_token = data.getString("refresh_token");
|
|
|
-
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
for (int i = 0; i < advertiser_ids.size(); i++) {
|
|
|
- String advertiser_id = advertiser_ids.get(i)+"";
|
|
|
- data.put("advertiser_id", advertiser_id);
|
|
|
- CtopOauthToken token = new CtopOauthToken(advertiser_id, data);
|
|
|
- ctopOauthTokenService.saveOrUpdate(token);
|
|
|
- //获取广告主信息
|
|
|
- Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(advertiser_id + "", data.getString("access_token"));
|
|
|
- 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("账户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();
|
|
|
- }
|
|
|
- JSONArray jsonArray = advertiserDataService.advertiserList(access_token);
|
|
|
- if (!Check.isNull(jsonArray)) {
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject dataJson = jsonArray.getJSONObject(i);
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
- CtopOauthToken token = new CtopOauthToken();
|
|
|
- token.setAccessToken(access_token);
|
|
|
- token.setRefreshToken(refresh_token);
|
|
|
- token.setId(dataJson.getString("advertiser_id"));
|
|
|
- ctopOauthTokenService.updateById(token);
|
|
|
+ Long advertiser_id = advertiser_ids.getLong(i);
|
|
|
+ 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(advertiser_id1 + "", data.getString("access_token"));
|
|
|
+ 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("账户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();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ data.put("advertiser_id", advertiser_id);
|
|
|
+ CtopOauthToken token = new CtopOauthToken(advertiserId, data);
|
|
|
+ ctopOauthTokenService.saveOrUpdate(token);
|
|
|
+ //获取广告主信息
|
|
|
+ Map<String, Object> advertiserDataMap = advertiserDataService.getAdvertiserInfo(advertiser_id + "", data.getString("access_token"));
|
|
|
+ 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("账户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();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
returnMap.put("code", 0);
|
|
|
returnMap.put("desc", text.toString());
|
|
|
|