|
@@ -1,22 +1,20 @@
|
|
|
package cn.com.ctop.manage.modules.material.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.common.module.entity.MaterialImageInfo;
|
|
|
import cn.com.ctop.common.module.enums.MaterialEnum;
|
|
|
import cn.com.ctop.common.module.service.IMaterialImageInfoService;
|
|
|
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.KuaiShouImageGet;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
|
|
|
+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;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
@@ -26,7 +24,6 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -36,7 +33,7 @@ import java.util.concurrent.Executors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class MaterialUploadImageServiceImpl implements IMaterialUploadImageService {
|
|
|
- static ExecutorService executorService = Executors.newFixedThreadPool(4);
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(8);
|
|
|
@Value("${oss.replace.replace-value}")
|
|
|
private String replaceValue;
|
|
|
@Value("${oss.replace.replace-old-value}")
|
|
@@ -55,63 +52,65 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
|
|
|
@Override
|
|
|
public void uploadImage(String videoId, Long accountId, String accessToken) {
|
|
|
try {
|
|
|
- QueryWrapper<MaterialImageInfo> imageInfoQueryWrapper = new QueryWrapper<>();
|
|
|
- imageInfoQueryWrapper.eq("video_id", videoId);
|
|
|
- imageInfoQueryWrapper.eq("status", 0);
|
|
|
- List<MaterialImageInfo> imageList = materialImageInfoService.list(imageInfoQueryWrapper);
|
|
|
+ List<JSONObject> imageList = materialImageInfoService.getUrlList(videoId);
|
|
|
if (!Check.isNull(imageList)) {
|
|
|
- for (MaterialImageInfo imageInfo : imageList) {
|
|
|
- QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
|
|
|
- imageQueryWrapper.eq("account_id", accountId);
|
|
|
- imageQueryWrapper.eq("signature", imageInfo.getCode());
|
|
|
- List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
|
|
|
- if (!Check.isNull(imageGetList)) {
|
|
|
- log.info("此封面已上传");
|
|
|
+ for (int i = 0; i < imageList.size(); i++) {
|
|
|
+ JSONObject imageInfo = imageList.get(i);
|
|
|
+ if (Check.isNull(imageInfo)) {
|
|
|
continue;
|
|
|
}
|
|
|
- String url = String.valueOf(imageInfo.getUrl());
|
|
|
- String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
|
|
|
- FileSystemResource resource = new FileSystemResource(new File(localUrl));
|
|
|
- Map<String, String> headerMap = new HashMap<>();
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
- requestJson.put("advertiser_id", accountId);
|
|
|
- headerMap.put("Access-Token", accessToken);
|
|
|
- headerMap.put("Content-Type", "multipart/form-data");
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
|
|
|
+ imageQueryWrapper.eq("account_id", accountId);
|
|
|
+ imageQueryWrapper.eq("signature", imageInfo.getString("signature"));
|
|
|
+ List<KuaiShouImageGet> imageGetList = imageGetService.list(imageQueryWrapper);
|
|
|
+ if (Check.isNull(imageGetList)) {
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", accountId);
|
|
|
+ headerMap.put("Access-Token", accessToken);
|
|
|
+ headerMap.put("Content-Type", "multipart/form-data");
|
|
|
|
|
|
- requestJson.put("file", resource);
|
|
|
- requestJson.put("signature", imageInfo.getCode());
|
|
|
- requestJson.put("type", "2");
|
|
|
- requestJson.put("upload_type", "1");
|
|
|
- String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
|
|
|
- String result = exceptInfoForRestTemplate(requestUrl, 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)) {
|
|
|
- String signature = dataJson.getString("signature");
|
|
|
- String image_token = dataJson.getString("image_token");
|
|
|
- KuaiShouImageGet imageGet = new KuaiShouImageGet();
|
|
|
- imageGet.setId(accountId + image_token);
|
|
|
- imageGet.setAccountId(accountId);
|
|
|
- imageGet.setUrl(dataJson.getString("url"));
|
|
|
- imageGet.setWidth(dataJson.getInteger("width"));
|
|
|
- imageGet.setHeight(dataJson.getInteger("height"));
|
|
|
- imageGet.setSize(dataJson.getInteger("size"));
|
|
|
- imageGet.setFormat(dataJson.getString("format"));
|
|
|
- Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
|
|
|
- if (!Check.isNull(type)) {
|
|
|
- imageGet.setMaterialType(type);
|
|
|
+ requestJson.put("url", imageInfo.getString("imageUrl"));
|
|
|
+ requestJson.put("signature", imageInfo.getString("signature"));
|
|
|
+ requestJson.put("type", "2");
|
|
|
+ requestJson.put("upload_type", "2");
|
|
|
+ String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
|
|
|
+ String result = exceptInfoForRestTemplate(requestUrl, 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)) {
|
|
|
+ String signature = dataJson.getString("signature");
|
|
|
+ String image_token = dataJson.getString("image_token");
|
|
|
+ KuaiShouImageGet imageGet = new KuaiShouImageGet();
|
|
|
+ imageGet.setId(accountId + image_token);
|
|
|
+ imageGet.setAccountId(accountId);
|
|
|
+ imageGet.setUrl(dataJson.getString("url"));
|
|
|
+ imageGet.setWidth(dataJson.getInteger("width"));
|
|
|
+ imageGet.setHeight(dataJson.getInteger("height"));
|
|
|
+ imageGet.setSize(dataJson.getInteger("size"));
|
|
|
+ imageGet.setFormat(dataJson.getString("format"));
|
|
|
+ Integer type = MaterialEnum.getTypeBySize(dataJson.getInteger("width"), dataJson.getInteger("height"));
|
|
|
+ if (!Check.isNull(type)) {
|
|
|
+ imageGet.setMaterialType(type);
|
|
|
+ }
|
|
|
+ imageGet.setSignature(signature);
|
|
|
+ imageGet.setImageToken(image_token);
|
|
|
+ imageGetService.saveOrUpdate(imageGet);
|
|
|
+ }
|
|
|
+ log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
|
|
|
+ } else {
|
|
|
+ log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
+ }
|
|
|
}
|
|
|
- imageGet.setSignature(signature);
|
|
|
- imageGet.setImageToken(image_token);
|
|
|
- imageGetService.saveOrUpdate(imageGet);
|
|
|
}
|
|
|
- log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getCode(), resultJson);
|
|
|
- } else {
|
|
|
- log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|