|
@@ -62,6 +62,7 @@ public class MaterialUploadTaskServiceImpl
|
|
|
// private static String downloadUrl = "D:\\file";
|
|
|
private static ExecutorService kuaishouExecutorService = Executors.newFixedThreadPool(5);
|
|
|
private static ExecutorService bytedanceExecutorService = Executors.newFixedThreadPool(5);
|
|
|
+ private static ExecutorService bytedanceExecutorAgent = Executors.newFixedThreadPool(5);
|
|
|
private static ExecutorService submitExecutorService = Executors.newFixedThreadPool(5);
|
|
|
private static ExecutorService bindExecutorService = Executors.newFixedThreadPool(20);
|
|
|
|
|
@@ -107,7 +108,20 @@ public class MaterialUploadTaskServiceImpl
|
|
|
if (task.getMediaId() == 2 || task.getMediaId() == 4) {
|
|
|
uploadKuaiShou(task, resource, materialType);
|
|
|
} else if (task.getMediaId() == 1 || task.getMediaId() == 3) {
|
|
|
+ int count = materialUploadTaskMapper.checkBytedance(task.getSignature());
|
|
|
+ if (count == 0) {
|
|
|
+ try {
|
|
|
+ materialUploadTaskMapper.saveInfo(task.getSignature(), task.getMaterialName(), 1, "待同步", 73970348172L, new Date());
|
|
|
+ uploadBytedanceAgent(fileBody, task);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("代理商上传素材验证失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
uploadBytedance(fileBody, task);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -294,6 +308,88 @@ public class MaterialUploadTaskServiceImpl
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public void uploadBytedanceAgent(FileBody fileBody, MaterialUploadTask task) {
|
|
|
+ bytedanceExecutorAgent.submit(
|
|
|
+ new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String token = materialUploadTaskMapper.getTAgentToken(73970348172L);
|
|
|
+ if (Check.isNull(token)) {
|
|
|
+ log.error("此账户id未获取到代理商token");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ String url = HttpConstant.BYTEDANCE_VIDEO_UPLOAD_AGENT;
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ CloseableHttpClient client = null;
|
|
|
+ // 构造请求
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.setHeader("Access-Token", token);
|
|
|
+ // 文件参数
|
|
|
+ try {
|
|
|
+ MultipartEntityBuilder entityBuilder =
|
|
|
+ MultipartEntityBuilder.create().addPart("video_file", fileBody);
|
|
|
+ // 其他参数
|
|
|
+ entityBuilder.addTextBody("agent_id", "73970348172");
|
|
|
+ entityBuilder.addTextBody("video_signature", task.getSignature());
|
|
|
+ entityBuilder.addTextBody("is_need_auth", "true");
|
|
|
+ entityBuilder.addTextBody(
|
|
|
+ "file_name",
|
|
|
+ task.getMaterialName(),
|
|
|
+ ContentType.create("text/plain", Charset.forName("UTF-8")));
|
|
|
+ org.apache.http.HttpEntity entity = entityBuilder.build();
|
|
|
+ client = HttpClientBuilder.create().build();
|
|
|
+ httpPost.setURI(URI.create(url));
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ response = client.execute(httpPost);
|
|
|
+ if (response != null && response.getStatusLine().getStatusCode() == 200) {
|
|
|
+ BufferedReader bufferedReader =
|
|
|
+ new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ String line = "";
|
|
|
+ while ((line = bufferedReader.readLine()) != null) {
|
|
|
+ result.append(line);
|
|
|
+ }
|
|
|
+ bufferedReader.close();
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result.toString());
|
|
|
+ System.err.println(resultJson);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ if (resultJson.getInteger("code") == 0) {
|
|
|
+ JSONObject data = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONObject videoInfo = data.getJSONObject("video_info");
|
|
|
+ materialUploadTaskMapper.updateAgentStatus(task.getSignature(), videoInfo.getString("video_id"), videoInfo.getLong("material_id"), 2, "同步成功");
|
|
|
+ log.error("头条同步步素材到代理商成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ String message = resultJson.getString("message");
|
|
|
+ materialUploadTaskMapper.updateAgentStatus(task.getSignature(), null, null, 3, message);
|
|
|
+ log.error("头条同步步素材到代理商失败,返回信息:{}", resultJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ materialUploadTaskMapper.updateStatusById(task.getId(), 0, "接口异常,待重试", new Date());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (response != null) {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ if (null != client) {
|
|
|
+ client.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void syncBytedance(Long accountId, Integer mediaId, String signature, JSONArray accountArray, String loginId, String userName, String materialName, String materialUrl, String videoId) {
|
|
|
bindExecutorService.submit(
|
|
|
new Runnable() {
|