|
@@ -2,9 +2,13 @@ package org.jeecg.modules.ctop.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.utils.PropertiesUtils;
|
|
import cn.com.ctop.common.utils.PropertiesUtils;
|
|
import cn.com.ctop.toutiao.common.BytedanceInterfaceConstant;
|
|
import cn.com.ctop.toutiao.common.BytedanceInterfaceConstant;
|
|
|
|
+import com.alibaba.druid.support.spring.stat.annotation.Stat;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import constant.KuaishouInterfaceConstant;
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.client.ClientProtocolException;
|
|
import org.apache.http.client.ClientProtocolException;
|
|
@@ -17,23 +21,29 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
|
|
import org.apache.http.entity.mime.content.FileBody;
|
|
import org.apache.http.entity.mime.content.FileBody;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
-import org.jeecg.modules.ctop.entity.ByteDanceImageInfo;
|
|
|
|
-import org.jeecg.modules.ctop.entity.ByteDanceVideoInfo;
|
|
|
|
-import org.jeecg.modules.ctop.entity.CTopOauthToken;
|
|
|
|
-import org.jeecg.modules.ctop.entity.FileInfo;
|
|
|
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
+import org.jeecg.common.util.ResultMapUtils;
|
|
|
|
+import org.jeecg.common.util.StatusCode;
|
|
|
|
+import org.jeecg.modules.ctop.entity.*;
|
|
import org.jeecg.modules.ctop.mapper.ByteDanceImageInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.ByteDanceImageInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.ByteDanceVideoInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.ByteDanceVideoInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.FileInfoMapper;
|
|
import org.jeecg.modules.ctop.mapper.FileInfoMapper;
|
|
import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
|
|
import org.jeecg.modules.ctop.service.ICTopOauthTokenService;
|
|
import org.jeecg.modules.ctop.service.IFileInfoService;
|
|
import org.jeecg.modules.ctop.service.IFileInfoService;
|
|
|
|
+import org.jeecg.modules.system.entity.SysCategory;
|
|
|
|
+import org.jeecg.modules.system.mapper.SysCategoryMapper;
|
|
|
|
+import org.jeecg.modules.system.service.ISysCategoryService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,7 +57,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
private static final Logger logger = LoggerFactory.getLogger(FileInfoServiceImpl.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(FileInfoServiceImpl.class);
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> uploadVideoToTemplate(String accountId, String videoUrl, String templatename) {
|
|
|
|
|
|
+ public Map<String, Object> uploadVideoToBytedance(String accountId, String videoUrl) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
//TODO查询是否已经上传过头条平台
|
|
//TODO查询是否已经上传过头条平台
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
@@ -57,15 +67,44 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
String message = resultObject.getString("message");
|
|
String message = resultObject.getString("message");
|
|
if (null == code || code != 0) {
|
|
if (null == code || code != 0) {
|
|
logger.info("视频文件上传失败,accountId:{},message:{}", accountId, message);
|
|
logger.info("视频文件上传失败,accountId:{},message:{}", accountId, message);
|
|
- resultMap.put("code", -1);
|
|
|
|
- resultMap.put("message", "视频文件上传失败");
|
|
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_VIDEO_UPLOAD_FAIL.getCode());
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
ByteDanceVideoInfo videoInfo = new ByteDanceVideoInfo(data, token);
|
|
ByteDanceVideoInfo videoInfo = new ByteDanceVideoInfo(data, token);
|
|
videoInfoMapper.insert(videoInfo);
|
|
videoInfoMapper.insert(videoInfo);
|
|
- resultMap.put("code", 0);
|
|
|
|
- resultMap.put("message", "视频文件上传成功");
|
|
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
|
+ resultMap.put("videoId", videoInfo.getId());
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> upload3ImagesToBytedance(String accountId, String imageFileUrls) {
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ String[] imageUrls = imageFileUrls.split(",");
|
|
|
|
+ if (null == imageUrls || imageUrls.length < 3) {
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.IMAGE_NUMBER_SHORTAGE.getCode());
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
|
|
+ JSONArray imageIds = new JSONArray();
|
|
|
|
+ for (int i = 0; i < imageUrls.length; i++) {
|
|
|
|
+ JSONObject resultObject = uploadAdImage(token.getAccessToken(), imageUrls[i], token.getAccountId() + "");
|
|
|
|
+ System.out.println(resultObject);
|
|
|
|
+ Integer code = resultObject.getInteger("code");
|
|
|
|
+ String message = resultObject.getString("message");
|
|
|
|
+ if (null == code || code != 0) {
|
|
|
|
+ logger.info("图片文件上传失败,accountId:{},message:{}", accountId, message);
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_VIDEO_UPLOAD_FAIL.getCode());
|
|
|
|
+ return resultMap;
|
|
|
|
+ }
|
|
|
|
+ JSONObject data = resultObject.getJSONObject("data");
|
|
|
|
+ ByteDanceVideoInfo videoInfo = new ByteDanceVideoInfo(data, token);
|
|
|
|
+ videoInfoMapper.insert(videoInfo);
|
|
|
|
+ imageIds.add(videoInfo.getId());
|
|
|
|
+ }
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
|
+ resultMap.put("imageIds", imageIds);
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -75,42 +114,99 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
private ByteDanceImageInfoMapper imageInfoMapper;
|
|
private ByteDanceImageInfoMapper imageInfoMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> uploadImageToTemplate(String accountId, String imageUrl, String templatename) {
|
|
|
|
|
|
+ public Map<String, Object> uploadImageToBytedance(String accountId, String imageUrl) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
JSONObject resultObject = uploadAdImage(token.getAccessToken(), imageUrl, token.getAccountId() + "");
|
|
JSONObject resultObject = uploadAdImage(token.getAccessToken(), imageUrl, token.getAccountId() + "");
|
|
- System.out.println(resultObject);
|
|
|
|
Integer code = resultObject.getInteger("code");
|
|
Integer code = resultObject.getInteger("code");
|
|
String message = resultObject.getString("message");
|
|
String message = resultObject.getString("message");
|
|
if (null == code || code != 0) {
|
|
if (null == code || code != 0) {
|
|
logger.info("图片文件上传失败,accountId:{},message:{}", accountId, message);
|
|
logger.info("图片文件上传失败,accountId:{},message:{}", accountId, message);
|
|
- resultMap.put("code", -1);
|
|
|
|
- resultMap.put("message", "图片文件上传失败");
|
|
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.BYTEDANCE_IMAGE_UPLOAD_FAIL.getCode());
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
JSONObject data = resultObject.getJSONObject("data");
|
|
ByteDanceImageInfo imageInfo = new ByteDanceImageInfo(data, token);
|
|
ByteDanceImageInfo imageInfo = new ByteDanceImageInfo(data, token);
|
|
imageInfoMapper.insert(imageInfo);
|
|
imageInfoMapper.insert(imageInfo);
|
|
- resultMap.put("code", 0);
|
|
|
|
- resultMap.put("message", "图片文件上传成功");
|
|
|
|
|
|
+ ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
|
+ array.add(imageInfo.getId());
|
|
|
|
+ resultMap.put("imageIds", array);
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> getIndustryList(String accountId) {
|
|
|
|
|
|
+ public Map<String, Object> getIndustryList(String accountId, Integer level) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
CTopOauthToken token = tokenService.getOAuthTokenByAccountId(accountId);
|
|
- JSONObject result = searchIndustry(token);
|
|
|
|
|
|
+ JSONObject result = searchIndustry(token, level);
|
|
|
|
+ JSONArray list = result.getJSONObject("data").getJSONArray("list");
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ JSONObject object = list.getJSONObject(i);
|
|
|
|
+ SysCategory category = new SysCategory();
|
|
|
|
+ String firstCode = object.getInteger("second_industry_id") + "";
|
|
|
|
+ QueryWrapper<SysCategory> wrapper = new QueryWrapper();
|
|
|
|
+ wrapper.eq("code", firstCode);
|
|
|
|
+ SysCategory parent = sysCategoryMapper.selectOne(wrapper);
|
|
|
|
+ category.setPid(parent.getId());
|
|
|
|
+ category.setName(object.getString("third_industry_name"));
|
|
|
|
+ category.setCode(object.getInteger("third_industry_id") + "");
|
|
|
|
+ category.setCreateBy("admin");
|
|
|
|
+ category.setCreateTime(new Date());
|
|
|
|
+ category.setSysOrgCode("A01");
|
|
|
|
+ sysCategoryMapper.insert(category);
|
|
|
|
+ }
|
|
resultMap.put("code", 0);
|
|
resultMap.put("code", 0);
|
|
resultMap.put("message", "数据获取成功");
|
|
resultMap.put("message", "数据获取成功");
|
|
resultMap.put("data", result);
|
|
resultMap.put("data", result);
|
|
return resultMap;
|
|
return resultMap;
|
|
}
|
|
}
|
|
|
|
|
|
- public JSONObject searchIndustry(CTopOauthToken token) {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public JSONArray getByteDanceIndustryList(HttpServletRequest req) {
|
|
|
|
+ JSONArray result = new JSONArray();
|
|
|
|
+ String pid = "6c6b0ad4f49b65f3943528e8a35d74fc";
|
|
|
|
+ List<SysCategory> categories = categoryService.getListByPid(pid);
|
|
|
|
+ for (SysCategory category : categories) {
|
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
|
+ object.put("value", category.getCode());
|
|
|
|
+ object.put("label", category.getName());
|
|
|
|
+ JSONArray childListArray = new JSONArray();
|
|
|
|
+ List<SysCategory> childList = categoryService.getListByPid(category.getId());
|
|
|
|
+ for (SysCategory child : childList) {
|
|
|
|
+ JSONObject childObject = new JSONObject();
|
|
|
|
+ childObject.put("value", child.getCode());
|
|
|
|
+ childObject.put("label", child.getName());
|
|
|
|
+ JSONArray secendChildListArray = new JSONArray();
|
|
|
|
+ List<SysCategory> secendChildList = categoryService.getListByPid(child.getId());
|
|
|
|
+ for (SysCategory secendChild : secendChildList) {
|
|
|
|
+ JSONObject secendChildObject = new JSONObject();
|
|
|
|
+ secendChildObject.put("value", secendChild.getCode());
|
|
|
|
+ secendChildObject.put("label", secendChild.getName());
|
|
|
|
+ secendChildListArray.add(secendChildObject);
|
|
|
|
+ }
|
|
|
|
+ childObject.put("children", secendChildListArray);
|
|
|
|
+ childListArray.add(childObject);
|
|
|
|
+ }
|
|
|
|
+ object.put("children", childListArray);
|
|
|
|
+ result.add(object);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysCategoryService categoryService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysCategoryMapper sysCategoryMapper;
|
|
|
|
+
|
|
|
|
+ public JSONObject searchIndustry(CTopOauthToken token, Integer level) {
|
|
// 请求地址
|
|
// 请求地址
|
|
String url = "https://ad.toutiao.com/open_api/2/tools/industry/get/";
|
|
String url = "https://ad.toutiao.com/open_api/2/tools/industry/get/";
|
|
-
|
|
|
|
|
|
+ if (null != level) {
|
|
|
|
+ url += "?level=" + level;
|
|
|
|
+ }
|
|
// 构造请求
|
|
// 构造请求
|
|
HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
HttpEntityEnclosingRequestBase httpEntity = new HttpEntityEnclosingRequestBase() {
|
|
@Override
|
|
@Override
|
|
@@ -163,7 +259,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
// 其他参数
|
|
// 其他参数
|
|
entityBuilder.addTextBody("advertiser_id", advertiserId);
|
|
entityBuilder.addTextBody("advertiser_id", advertiserId);
|
|
entityBuilder.addTextBody("upload_type", BytedanceInterfaceConstant.UPLOAD_TYPE_BY_URL);
|
|
entityBuilder.addTextBody("upload_type", BytedanceInterfaceConstant.UPLOAD_TYPE_BY_URL);
|
|
- entityBuilder.addTextBody("image_url", imageUrl);
|
|
|
|
|
|
+ entityBuilder.addTextBody("image_url", "https:" + imageUrl);
|
|
|
|
|
|
HttpEntity entity = entityBuilder.build();
|
|
HttpEntity entity = entityBuilder.build();
|
|
CloseableHttpResponse response = null;
|
|
CloseableHttpResponse response = null;
|
|
@@ -210,6 +306,7 @@ public class FileInfoServiceImpl extends ServiceImpl<FileInfoMapper, FileInfo> i
|
|
httpPost.setHeader("Access-Token", accessToken);
|
|
httpPost.setHeader("Access-Token", accessToken);
|
|
// 文件参数
|
|
// 文件参数
|
|
try {
|
|
try {
|
|
|
|
+ videoUrl = "https:" + videoUrl;
|
|
URI uri = new URI(videoUrl);
|
|
URI uri = new URI(videoUrl);
|
|
FileBody file = new FileBody(new File(uri));
|
|
FileBody file = new FileBody(new File(uri));
|
|
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().addPart("video_file", file);
|
|
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create().addPart("video_file", file);
|