|
@@ -11,6 +11,7 @@ import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
|
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
|
import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
|
|
|
import cn.com.ctop.toutiao.modules.report.service.IReportService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -24,7 +25,10 @@ import org.jeecg.modules.system.entity.SysUser;
|
|
|
import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
import org.jeecg.modules.system.service.ISysUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -55,6 +59,8 @@ public class CallbackController {
|
|
|
private ICtopOauthTokenService ctopOauthTokenService;
|
|
|
@Autowired
|
|
|
private IByteDanceAdvertiserDataService advertiserDataService;
|
|
|
+ @Autowired
|
|
|
+ private IReportService reportService;
|
|
|
|
|
|
|
|
|
@GetMapping("/qywexin")
|
|
@@ -101,7 +107,6 @@ public class CallbackController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @param authCode
|
|
@@ -232,10 +237,6 @@ public class CallbackController {
|
|
|
|
|
|
if (StringUtils.isNotBlank(authCode)) {
|
|
|
Map<String, Object> map = this.getByteDanceAccessToken(authCode, state);
|
|
|
- Integer code = (Integer) map.get("code");
|
|
|
- if (code == 0) {
|
|
|
- return "授权绑定成功";
|
|
|
- }
|
|
|
log.info("返回信息:{}", map.toString());
|
|
|
return (String) map.get("desc");
|
|
|
}
|
|
@@ -282,59 +283,79 @@ public class CallbackController {
|
|
|
BigDecimal warningAmount = json.getBigDecimal("WarningAmount");
|
|
|
|
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
|
- 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"));
|
|
|
- throw new Exception("获取广告主信息失败");
|
|
|
+
|
|
|
+ if (Check.isNull(data)) {
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("desc", "返回信息为空");
|
|
|
+ return returnMap;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- 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)) {
|
|
|
+ data.remove("advertiser_id");
|
|
|
+ JSONArray advertiser_ids = data.getJSONArray("advertiser_ids");
|
|
|
+ if (Check.isNull(advertiser_ids)) {
|
|
|
returnMap.put("code", -1);
|
|
|
- returnMap.put("desc", "授权失败,账号已被:" + checkUserAllocation.getUserName() + "绑定");
|
|
|
+ returnMap.put("desc", "请选择需要授权的账号");
|
|
|
return returnMap;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- 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());
|
|
|
- allocationMapper.deleteById(userAllocation.getId());
|
|
|
- Map<String, Object> deleteUserMap = new HashMap<>();
|
|
|
- deleteUserMap.put("advertiser_id", advertiserId);
|
|
|
- deleteUserMap.put("account_id", token.getAccountId());
|
|
|
- allocationMapper.deleteByMap(deleteUserMap);
|
|
|
- int i = allocationMapper.insert(userAllocation);
|
|
|
- if (i > 0) {
|
|
|
- log.info("同步分配用户表完成,task_id:{},accountId:{}", state, token.getAccountId());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ //账号绑定
|
|
|
+ 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", "success");
|
|
|
+ returnMap.put("desc", text);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
returnMap.put("code", -1);
|
|
@@ -343,7 +364,5 @@ public class CallbackController {
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private IReportService reportService;
|
|
|
|
|
|
}
|