|
@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
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.IKuaiShouAdvertiserBaseInfoService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
import cn.com.ctop.manage.modules.material.service.IMaterialUploadImageService;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -35,7 +36,7 @@ import java.util.concurrent.Executors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class MaterialUploadImageServiceImpl implements IMaterialUploadImageService {
|
|
|
- static ExecutorService executorService = Executors.newFixedThreadPool(8);
|
|
|
+ static ExecutorService executorService = Executors.newFixedThreadPool(15);
|
|
|
|
|
|
@Value("${oss.replace.download}")
|
|
|
private String downloadUrl;
|
|
@@ -44,6 +45,8 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
|
|
|
private IMaterialImageInfoService materialImageInfoService;
|
|
|
@Autowired
|
|
|
private IKuaiShouImageGetService imageGetService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouAdvertiserBaseInfoService baseInfoService;
|
|
|
|
|
|
/**
|
|
|
* 同步素材到账号下
|
|
@@ -58,63 +61,75 @@ public class MaterialUploadImageServiceImpl implements IMaterialUploadImageServi
|
|
|
if (Check.isNull(imageInfo)) {
|
|
|
continue;
|
|
|
}
|
|
|
- executorService.submit(new Runnable() {
|
|
|
- @SneakyThrows
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- synchronized (this) {
|
|
|
- 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("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);
|
|
|
+ List<Long> accountList = baseInfoService.getAccountListByAccountId(accountId);
|
|
|
+ if (Check.isNull(accountList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int j = 0; j < accountList.size(); j++) {
|
|
|
+ Long imageAccountId = accountList.get(j);
|
|
|
+ if (Check.isNull(imageAccountId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ executorService.submit(new Runnable() {
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ synchronized (this) {
|
|
|
+ QueryWrapper<KuaiShouImageGet> imageQueryWrapper = new QueryWrapper<>();
|
|
|
+ imageQueryWrapper.eq("account_id", imageAccountId);
|
|
|
+ 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", imageAccountId);
|
|
|
+ headerMap.put("Access-Token", accessToken);
|
|
|
+ headerMap.put("Content-Type", "multipart/form-data");
|
|
|
+
|
|
|
+ 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(imageAccountId + image_token);
|
|
|
+ imageGet.setAccountId(imageAccountId);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
+ imageGet.setStatDate(DateUtils.parseDate(nowDate, "yyyy-MM-dd"));
|
|
|
+ imageGet.setSignature(signature);
|
|
|
+ imageGet.setImageToken(image_token);
|
|
|
+ imageGetService.saveOrUpdate(imageGet);
|
|
|
}
|
|
|
- String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
- imageGet.setStatDate(DateUtils.parseDate(nowDate, "yyyy-MM-dd"));
|
|
|
- imageGet.setSignature(signature);
|
|
|
- imageGet.setImageToken(image_token);
|
|
|
- imageGetService.saveOrUpdate(imageGet);
|
|
|
+ log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", imageAccountId, imageInfo.getString("signature"), resultJson);
|
|
|
+ } else {
|
|
|
+ log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
}
|
|
|
- log.info("快手封面素材素材同步完成,accountId:{},code:{},返回信息:{}", accountId, imageInfo.getString("signature"), resultJson);
|
|
|
- } else {
|
|
|
- log.error("快手同步封面素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|