|
@@ -2,6 +2,7 @@ package org.jeecg.modules.ctop.controller;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.*;
|
|
|
import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
|
|
|
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
|
import cn.com.ctop.common.module.service.*;
|
|
|
import cn.com.ctop.common.module.utils.*;
|
|
|
import cn.com.ctop.common.module.vo.ResFileDTO;
|
|
@@ -11,6 +12,8 @@ import cn.com.ctop.crawler.modules.douyin.service.DouyinMusicService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.*;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
|
|
|
+import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
|
|
|
+import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
|
import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
|
|
|
import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
|
|
|
import cn.com.ctop.toutiao.modules.material.service.IBytedanceEffectVideoInfoService;
|
|
@@ -29,11 +32,15 @@ import org.quartz.JobExecutionException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -102,6 +109,123 @@ public class TestController {
|
|
|
private IBytedanceAccountReportTaskRecordService reportTaskRecordService;
|
|
|
@Resource
|
|
|
private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService ctopOauthTokenService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBindAccountAuthService bindAccountAuthService;
|
|
|
+ @Autowired
|
|
|
+ private UserAllocationMapper allocationMapper;
|
|
|
+
|
|
|
+ @GetMapping("/testKuaishou")
|
|
|
+ public String kuaishouCallback( @RequestParam("auth_code") String authCode, @RequestParam("state") String state) {
|
|
|
+ try {
|
|
|
+ JSONObject json = JSONObject.parseObject(state);
|
|
|
+ if (Check.isNull(json)) {
|
|
|
+ throw new Exception("回调信息为空");
|
|
|
+ }
|
|
|
+ log.info("快手授权返回信息:{}", json);
|
|
|
+ log.info("快手授权返回oauthCode:{}", authCode);
|
|
|
+ Integer agentType = json.getInteger("agentType");
|
|
|
+ Long appId = json.getLong("appId");
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotBlank(authCode)) {
|
|
|
+ KuaishouResultToken accessToken = kuaishouInterfaceService.getAccessToken(authCode, appId);
|
|
|
+ if (accessToken.getCode() != 0) {
|
|
|
+ throw new Exception("快手回调token返回错误");
|
|
|
+ }
|
|
|
+ KuaishouAccessToken token = accessToken.getData();
|
|
|
+ if (token != null) {
|
|
|
+ Long accountId = token.getAccountId();
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
+ return "授权绑定失败!";
|
|
|
+ }
|
|
|
+ Map<String, Object> advertiseBaseInfoMap = kuaishouInterfaceService.advertiserInfo(accountId, token.getAccessToken());
|
|
|
+ if ((Integer) advertiseBaseInfoMap.get("code") != 0) {
|
|
|
+ return "授权绑定失败,失败原因:" + advertiseBaseInfoMap.get("message");
|
|
|
+ }
|
|
|
+ String advertiserId = json.getString("advertiserId");
|
|
|
+ //指定分配人姓名
|
|
|
+ String userName = json.getString("userName");
|
|
|
+ // 媒体类型: 1 头条 2 快手
|
|
|
+ String mediaId = json.getString("mediaId");
|
|
|
+ //创建人
|
|
|
+ String userId = json.getString("userId");
|
|
|
+ Long projectId = json.getLong("projectId");
|
|
|
+ BigDecimal warningProportion = json.getBigDecimal("WarningProportion");
|
|
|
+ BigDecimal warningAmount = json.getBigDecimal("WarningAmount");
|
|
|
+ String systemType = json.getString("systemType");
|
|
|
+ CtopOauthToken topOauthToken = new CtopOauthToken();
|
|
|
+ topOauthToken.setId(String.valueOf(accountId));
|
|
|
+ topOauthToken.setAppId(json.getLong("appId"));
|
|
|
+ topOauthToken.setAccountId(accountId);
|
|
|
+ topOauthToken.setMediaId("2");
|
|
|
+ topOauthToken.setAdvertiserId(advertiserId);
|
|
|
+ topOauthToken.setAgentType(agentType);
|
|
|
+ topOauthToken.setAccessToken(token.getAccessToken());
|
|
|
+ long accessTokenExpireIn = token.getAccessTokenExpiresIn() * 1000L;
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ Date accessTokenExpireInDate = new Date(now + accessTokenExpireIn);
|
|
|
+ topOauthToken.setAccessTokenExpiresIn(accessTokenExpireInDate);
|
|
|
+ topOauthToken.setRefreshToken(token.getRefreshToken());
|
|
|
+ long refreshTokenExpireIn = token.getRefreshTokenExpiresIn() * 1000L;
|
|
|
+ Date refreshTokenExpireInDate = new Date(now + refreshTokenExpireIn);
|
|
|
+ topOauthToken.setRefreshTokenExpiresIn(refreshTokenExpireInDate);
|
|
|
+ topOauthToken.setUpdateTime(new Date());
|
|
|
+ ctopOauthTokenService.saveOrUpdate(topOauthToken);
|
|
|
+ QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
|
|
|
+ userAllocationQueryWrapper.eq("account_id", accountId);
|
|
|
+ userAllocationQueryWrapper.eq("media_id", 2);
|
|
|
+ userAllocationQueryWrapper.orderByDesc("create_time");
|
|
|
+ userAllocationQueryWrapper.last("limit 1");
|
|
|
+ UserAllocation checkUserAllocation = allocationMapper.selectOne(userAllocationQueryWrapper);
|
|
|
+ if (!Check.isNull(checkUserAllocation)) {
|
|
|
+ return "授权失败,该账号已被:" + checkUserAllocation.getUserName() + " 绑定!";
|
|
|
+ }
|
|
|
+ UserAllocation userAllocation = new UserAllocation();
|
|
|
+ userAllocation.setUserName(userName);
|
|
|
+ userAllocation.setUserId(userId);
|
|
|
+ userAllocation.setAdvertiserId(advertiserId);
|
|
|
+ userAllocation.setSystemType(systemType);
|
|
|
+ // 获取快手昵称
|
|
|
+ userAllocation.setAuthName((String) advertiseBaseInfoMap.get("userName"));
|
|
|
+ userAllocation.setMediaId(mediaId);
|
|
|
+ userAllocation.setAccountId(accountId);
|
|
|
+ userAllocation.setProjectId(projectId);
|
|
|
+ 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", accountId);
|
|
|
+ allocationMapper.deleteByMap(deleteUserMap);
|
|
|
+ int i = allocationMapper.insert(userAllocation);
|
|
|
+ if (i > 0) {
|
|
|
+ log.info("同步分配用户表完成,task_id:{},accountId:{}", state, accountId);
|
|
|
+ }
|
|
|
+ //账号绑定
|
|
|
+ bindAccountAuthService.addBindAccount(accountId, KuaishouInterfaceConstant.LOGIN_TYPE_KUAISHOU, advertiserId);
|
|
|
+ Thread t = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ kuaishouInterfaceService.loadKuaishouDataSingle(topOauthToken);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ t.start();
|
|
|
+ }
|
|
|
+ return "授权绑定成功";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return "授权绑定失败!";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@GetMapping("/getBytedanceMatReport")
|
|
|
public Map<String,Object>getData(){
|
|
@@ -710,11 +834,11 @@ public class TestController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @GetMapping(value = "/getToken")
|
|
|
+ /* @GetMapping(value = "/getToken")
|
|
|
public String getToken(Long accountId, String token, String refreshToken, Integer agentType) {
|
|
|
oauthTokenService.getKuaiShouRefreshToken(accountId, token, refreshToken, agentType);
|
|
|
return "Success";
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/getAccountReport")
|