|
@@ -4,26 +4,21 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.entity.MaterialInfo;
|
|
|
import cn.com.ctop.common.module.entity.MaterialParameter;
|
|
|
import cn.com.ctop.common.module.enums.MaterialEnum;
|
|
|
-import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
|
|
|
-import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
|
|
|
-import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.service.IFileInfoService;
|
|
|
+import cn.com.ctop.common.module.service.IMaterialInfoService;
|
|
|
import cn.com.ctop.common.module.service.IMaterialParameterService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
|
|
|
import cn.com.ctop.manage.modules.material.service.IMaterialUploadService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.http.ParseException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
@@ -37,7 +32,6 @@ import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -56,20 +50,14 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- private CtopOauthTokenMapper oauthTokenMapper;
|
|
|
+ private ICtopOauthTokenService oauthTokenService;
|
|
|
@Autowired
|
|
|
- private MaterialInfoMapper materialInfoMapper;
|
|
|
- @Autowired
|
|
|
- private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
+ private IMaterialInfoService materialInfoService;
|
|
|
@Autowired
|
|
|
private IFileInfoService fileInfoService;
|
|
|
@Autowired
|
|
|
- private IKuaiShouImageGetService iKuaiShouImageGetService;
|
|
|
- @Autowired
|
|
|
private IMaterialParameterService materialParameterService;
|
|
|
@Autowired
|
|
|
- private MaterialParameterMapper parameterMapper;
|
|
|
- @Autowired
|
|
|
private IKuaiShouVideoGetService kuaiShouVideoGetService;
|
|
|
@Autowired
|
|
|
private IMaterialUploadImageService materialUploadImageService;
|
|
@@ -87,9 +75,9 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
public void uploadAccount(String mediaId, JSONArray materialArray, JSONArray accountArray) {
|
|
|
try {
|
|
|
if ("2".equals(mediaId)) {
|
|
|
- this.kuaiShouUpload(mediaId, materialArray, accountArray);
|
|
|
+ this.kuaiShouUpload(materialArray, accountArray);
|
|
|
} else if ("1".equals(mediaId)) {
|
|
|
- this.touTiaoUpload(mediaId, materialArray, accountArray);
|
|
|
+ this.touTiaoUpload(materialArray, accountArray);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -99,64 +87,38 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void touTiaoUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
|
|
|
+ private void touTiaoUpload(JSONArray materialArray, JSONArray accountArray) {
|
|
|
for (int j = 0; j < materialArray.size(); j++) {
|
|
|
String materialId = materialArray.getString(j);
|
|
|
- MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
|
|
|
- if (Check.isNull(materialInfo)) {
|
|
|
+ MaterialInfo materialInfo = materialInfoService.getById(materialId);
|
|
|
+ if (Check.isNull(materialInfo) || Check.isNull(materialInfo.getUrl())) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (Check.isNull(materialInfo.getUrl())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- try {
|
|
|
- String url = materialInfo.getUrl().replace(replaceOldValue, replaceValue);
|
|
|
- String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
|
|
|
-
|
|
|
- for (int i = 0; i < accountArray.size(); i++) {
|
|
|
- Long accountId = accountArray.getLong(i);
|
|
|
- if (Check.isNull(accountId)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- executorService.submit(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- log.info("头条文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
|
|
|
- if ("VIDEO".equals(materialInfo.getType())) {
|
|
|
- fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl);
|
|
|
-
|
|
|
- } else if ("IMAGE".equals(materialInfo.getType())) {
|
|
|
- fileInfoService.uploadImageToBytedance(String.valueOf(accountId), localUrl);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ String url = materialInfo.getUrl().replace(replaceOldValue, replaceValue);
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
|
|
|
+ for (int i = 0; i < accountArray.size(); i++) {
|
|
|
+ Long accountId = accountArray.getLong(i);
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ executorService.submit(() -> {
|
|
|
+ log.info("头条文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
|
|
|
+ if ("VIDEO".equals(materialInfo.getType())) {
|
|
|
+ fileInfoService.uploadVideoToBytedance(String.valueOf(accountId), localUrl);
|
|
|
+ } else if ("IMAGE".equals(materialInfo.getType())) {
|
|
|
+ fileInfoService.uploadImageToBytedance(String.valueOf(accountId), localUrl);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void kuaiShouUpload(String mediaId, JSONArray materialArray, JSONArray accountArray) {
|
|
|
+ private void kuaiShouUpload(JSONArray materialArray, JSONArray accountArray) {
|
|
|
for (int j = 0; j < materialArray.size(); j++) {
|
|
|
String materialId = materialArray.getString(j);
|
|
|
- MaterialInfo materialInfo = materialInfoMapper.selectById(materialId);
|
|
|
- if (Check.isNull(materialInfo)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (Check.isNull(materialInfo.getUrl())) {
|
|
|
+ MaterialInfo materialInfo = materialInfoService.getById(materialId);
|
|
|
+ if (Check.isNull(materialInfo) || Check.isNull(materialInfo.getUrl())) {
|
|
|
continue;
|
|
|
}
|
|
|
try {
|
|
@@ -169,10 +131,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
JSONObject requestJson = new JSONObject();
|
|
|
requestJson.put("file", resource);
|
|
|
requestJson.put("signature", materialInfo.getCode());
|
|
|
- QueryWrapper<MaterialParameter> parameterQueryWrapper = new QueryWrapper<>();
|
|
|
- parameterQueryWrapper.eq("material_id", materialInfo.getId());
|
|
|
- parameterQueryWrapper.orderByDesc("create_time").last("limit 1");
|
|
|
- MaterialParameter materialParameter = materialParameterService.getOne(parameterQueryWrapper);
|
|
|
+ MaterialParameter materialParameter = materialParameterService.getOneByMaterialId(materialInfo.getId());
|
|
|
if (!Check.isNull(materialParameter)) {
|
|
|
Integer type = MaterialEnum.getTypeBySize(Integer.valueOf(materialParameter.getWidth()), Integer.valueOf(materialParameter.getHeight()));
|
|
|
if (!Check.isNull(type) && type != 0) {
|
|
@@ -181,94 +140,58 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
}
|
|
|
for (int i = 0; i < accountArray.size(); i++) {
|
|
|
Long accountId = accountArray.getLong(i);
|
|
|
- QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
|
|
|
- tokenQueryWrapper.eq("account_id", accountId);
|
|
|
- tokenQueryWrapper.eq("media_id", mediaId);
|
|
|
- tokenQueryWrapper.orderByDesc("create_time");
|
|
|
- tokenQueryWrapper.last("limit 1");
|
|
|
- CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
|
|
|
+ CtopOauthToken ctopOauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
if (Check.isNull(ctopOauthToken)) {
|
|
|
continue;
|
|
|
}
|
|
|
requestJson.put("advertiser_id", accountId);
|
|
|
headerMap.put("Access-Token", ctopOauthToken.getAccessToken());
|
|
|
- executorService.submit(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- log.info("快手文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
|
|
|
-
|
|
|
- String result = exceptInfoForRestTemplate(url, requestJson, headerMap);
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
- if (resultJson.getInteger("code") == 0) {
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
-
|
|
|
-
|
|
|
- // kuaishouInterfaceService.videoGet(accountId, ctopOauthToken.getAccessToken(), dataJson.getString("photo_id"), dataJson.getString("signature"));
|
|
|
- String photoId = dataJson.getString("photo_id");
|
|
|
- String signature = dataJson.getString("signature");
|
|
|
- KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
|
|
|
- videoGet.setAccountId(accountId);
|
|
|
- videoGet.setId(accountId + photoId);
|
|
|
- videoGet.setUrl(materialInfo.getUrl());
|
|
|
- QueryWrapper<MaterialParameter> parameterQueryWrapper = new QueryWrapper<>();
|
|
|
- parameterQueryWrapper.eq("material_id", materialId);
|
|
|
- parameterQueryWrapper.last("limit 1");
|
|
|
-
|
|
|
- MaterialParameter materialParameter = parameterMapper.selectOne(parameterQueryWrapper);
|
|
|
- if (!Check.isNull(materialParameter)) {
|
|
|
- String width = materialParameter.getWidth();
|
|
|
- String height = materialParameter.getHeight();
|
|
|
- videoGet.setWidth(Integer.valueOf(width));
|
|
|
- videoGet.setHeight(Integer.valueOf(height));
|
|
|
- Integer type = MaterialEnum.getTypeBySize(Integer.valueOf(width), Integer.valueOf(height));
|
|
|
- if (!Check.isNull(type)) {
|
|
|
- videoGet.setMaterialType(type);
|
|
|
- }
|
|
|
- }
|
|
|
- videoGet.setPhotoId(photoId);
|
|
|
- // videoGet.setCoverUrl(dataJson.getString("cover_url"));
|
|
|
- videoGet.setSignature(signature);
|
|
|
- kuaiShouVideoGetService.saveOrUpdate(videoGet);
|
|
|
- materialUploadImageService.uploadImage(videoGet.getId(), accountId, ctopOauthToken.getAccessToken());
|
|
|
-
|
|
|
- }
|
|
|
- log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
|
|
|
- } else {
|
|
|
- log.error("快手同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
+ executorService.submit(() -> {
|
|
|
+ log.info("快手文件多线程上传:{},accountId:{}", Thread.currentThread().getName(), accountId);
|
|
|
+ String videoUploadUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
|
|
|
+ String result = exceptInfoForRestTemplate(videoUploadUrl, requestJson, headerMap);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson) && resultJson.getInteger("code") == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ String photoId = dataJson.getString("photo_id");
|
|
|
+ String signature = dataJson.getString("signature");
|
|
|
+ KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
|
|
|
+ videoGet.setAccountId(accountId);
|
|
|
+ videoGet.setId(accountId + photoId);
|
|
|
+ videoGet.setUrl(materialInfo.getUrl());
|
|
|
+
|
|
|
+ if (!Check.isNull(materialParameter)) {
|
|
|
+ String width = materialParameter.getWidth();
|
|
|
+ String height = materialParameter.getHeight();
|
|
|
+ videoGet.setWidth(Integer.valueOf(width));
|
|
|
+ videoGet.setHeight(Integer.valueOf(height));
|
|
|
+ Integer type = MaterialEnum.getTypeBySize(Integer.valueOf(width), Integer.valueOf(height));
|
|
|
+ if (!Check.isNull(type)) {
|
|
|
+ videoGet.setMaterialType(type);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ videoGet.setPhotoId(photoId);
|
|
|
+ videoGet.setSignature(signature);
|
|
|
+ kuaiShouVideoGetService.saveOrUpdate(videoGet);
|
|
|
+ materialUploadImageService.uploadImage(videoGet.getId(), accountId, ctopOauthToken.getAccessToken());
|
|
|
}
|
|
|
+ log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
|
|
|
+ } else {
|
|
|
+ log.error("快手同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
- /*boolean isTrue = LoadFileUtil.delFile(localUrl);
|
|
|
- if (isTrue) {
|
|
|
- log.info("删除本地缓存素材成功,code:{}", materialInfo.getCode());
|
|
|
- }*/
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
private RestTemplate rest;
|
|
|
|
|
|
- private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
|
|
|
+ private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) {
|
|
|
try {
|
|
|
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
|
|
|
if (!Check.isNullMap(paramMap)) {
|
|
@@ -281,7 +204,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
|
|
|
headers.add(key, headerMap.get(key));
|
|
|
}
|
|
|
}
|
|
|
- HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(param, headers);
|
|
|
ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
|
|
return responseEntity.getBody();
|
|
|
}
|