|
@@ -2,20 +2,14 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
|
|
|
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.UserAllocation;
|
|
import cn.com.ctop.common.module.entity.UserAllocation;
|
|
-import cn.com.ctop.common.module.enums.MaterialEnum;
|
|
|
|
import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
-import cn.com.ctop.common.module.service.IMaterialParameterService;
|
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
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.LoadFileUtil;
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
import cn.com.ctop.common.module.utils.PropertiesUtils;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.*;
|
|
import cn.com.ctop.kuaishou.modules.batch.mapper.*;
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
|
|
|
|
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.*;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
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.conditions.query.QueryWrapper;
|
|
@@ -36,7 +30,6 @@ import org.springframework.web.client.RestTemplate;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
-import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -59,6 +52,12 @@ public class BatchServiceImpl implements IBatchService {
|
|
private UserAllocationMapper userAllocationMapper;
|
|
private UserAllocationMapper userAllocationMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private IKuaiShouUpdateService updateService;
|
|
private IKuaiShouUpdateService updateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouMaterialUploadService uploadService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaiShouGroupMapper groupMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaiShouCreativeMapper creativeMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -788,8 +787,7 @@ public class BatchServiceImpl implements IBatchService {
|
|
* @param unitId
|
|
* @param unitId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- @Autowired
|
|
|
|
- private KuaiShouGroupMapper groupMapper;
|
|
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public KuaiShouGroup getUnitInfo(Long accountId, Long unitId) {
|
|
public KuaiShouGroup getUnitInfo(Long accountId, Long unitId) {
|
|
@@ -878,7 +876,7 @@ public class BatchServiceImpl implements IBatchService {
|
|
imageToken = imageGet.getImageToken();
|
|
imageToken = imageGet.getImageToken();
|
|
} else {
|
|
} else {
|
|
String url = imageGetService.getUrlByCode(signature);
|
|
String url = imageGetService.getUrlByCode(signature);
|
|
- imageToken = this.kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
|
|
|
|
|
|
+ imageToken = uploadService.kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
|
|
}
|
|
}
|
|
if (Check.isNull(imageToken)) {
|
|
if (Check.isNull(imageToken)) {
|
|
JSONObject failJson = new JSONObject();
|
|
JSONObject failJson = new JSONObject();
|
|
@@ -915,9 +913,6 @@ public class BatchServiceImpl implements IBatchService {
|
|
return returnJson;
|
|
return returnJson;
|
|
}
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private KuaiShouCreativeMapper creativeMapper;
|
|
|
|
-
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取创意信息
|
|
* 获取创意信息
|
|
@@ -1253,87 +1248,6 @@ public class BatchServiceImpl implements IBatchService {
|
|
return returnJson;
|
|
return returnJson;
|
|
}
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
|
- private IMaterialParameterService materialParameterService;
|
|
|
|
-
|
|
|
|
- public String kuauiShouImageUpload(String url, String signature, Long accountId, String token) {
|
|
|
|
- System.err.println(url);
|
|
|
|
- System.err.println(signature);
|
|
|
|
- try {
|
|
|
|
- // String replaceUrl = url.replace(replaceOldValue, replaceValue);
|
|
|
|
- // log.info("replaceUrl:{}", replaceUrl);
|
|
|
|
- /* String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
|
|
|
|
- FileSystemResource resource = new FileSystemResource(new File(localUrl));*/
|
|
|
|
- Map<String, String> headerMap = new HashMap<>();
|
|
|
|
- headerMap.put("Content-Type", "multipart/form-data");
|
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
|
- // requestJson.put("file", resource);
|
|
|
|
- requestJson.put("signature", signature);
|
|
|
|
- requestJson.put("url", url);
|
|
|
|
- requestJson.put("type", 2);
|
|
|
|
- /* QueryWrapper<MaterialParameter> parameterQueryWrapper = new QueryWrapper<>();
|
|
|
|
- parameterQueryWrapper.eq("material_id", signature);
|
|
|
|
- parameterQueryWrapper.orderByDesc("create_time").last("limit 1");
|
|
|
|
- MaterialParameter materialParameter = materialParameterService.getOne(parameterQueryWrapper);
|
|
|
|
- if (!Check.isNull(materialParameter)) {
|
|
|
|
- Integer type = MaterialEnum.getTypeBySize(Integer.valueOf(materialParameter.getWidth()), Integer.valueOf(materialParameter.getHeight()));
|
|
|
|
- if (!Check.isNull(type) && type != 0) {
|
|
|
|
- requestJson.put("type", type);
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
- requestJson.put("advertiser_id", accountId);
|
|
|
|
- headerMap.put("Access-Token", token);
|
|
|
|
- String requestUrl = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
|
|
|
|
- requestJson.put("upload_type", "2");
|
|
|
|
- String result = exceptInfoForRestTemplate(requestUrl, requestJson, headerMap);
|
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
|
- System.err.println(resultJson);
|
|
|
|
- if (!Check.isNull(resultJson)) {
|
|
|
|
- if (resultJson.getInteger("code") == 0) {
|
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
|
- 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);
|
|
|
|
- iKuaiShouImageGetService.saveOrUpdate(imageGet);
|
|
|
|
- return dataJson.getString("image_token");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- log.error("上传图片失败,accountId:{},code:{},data:{}", accountId, signature, resultJson);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- log.error("上传图片,返回结果为空,accountId:{},code:{},data:{}", accountId, signature, resultJson);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return null;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RestTemplate rest;
|
|
private RestTemplate rest;
|