yumeng 5 年之前
父節點
當前提交
1602d93c13

+ 36 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouMaterialUploadController.java

@@ -3,7 +3,11 @@ package cn.com.ctop.kuaishou.modules.batch.controller;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 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.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -37,15 +41,41 @@ public class KuaiShouMaterialUploadController {
 
 
 
 
     @PostMapping(value = "/image", consumes = "multipart/form-data;charset=utf-8")
     @PostMapping(value = "/image", consumes = "multipart/form-data;charset=utf-8")
-    public Map<String, Object> image(@RequestParam("multipartFile") MultipartFile multipartFile, String type, Long accountId, String code, HttpServletRequest request) throws Exception {
+    public Result<JSONObject> image(@RequestParam("requestJson") JSONObject requestJson) throws Exception {
+        Result<JSONObject> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
 
 
-        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
-        if (Check.isNull(oauthToken)) {
-            throw new Exception("未获取到账户信息");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            JSONArray imageArr = requestJson.getJSONArray("uploadImageArr");
+            if (!Check.isNull(imageArr)) {
+                for (int i = 0; i < imageArr.size(); i++) {
+                    JSONObject imageJson = imageArr.getJSONObject(i);
+                    String url = imageJson.getString("url");
+                    String imageUrl;
+                    if (!url.contains("https:")) {
+                        imageUrl = KuaishouInterfaceConstant.HTTPS_PREFIX + url;
+                    } else {
+                        imageUrl = url;
+                    }
+
+
+                    String signature = imageJson.getString("signature");
+                    uploadService.kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
+                }
+
+            }
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
         }
         }
 
 
-        uploadService.video(multipartFile, type, accountId, oauthToken.getAccessToken(), code);
-        return null;
+        return result;
     }
     }
 
 
 
 

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouMaterialUploadService.java

@@ -6,4 +6,6 @@ import java.io.IOException;
 
 
 public interface IKuaiShouMaterialUploadService {
 public interface IKuaiShouMaterialUploadService {
     void video(MultipartFile multipartFile, String type, Long accountId, String accessToken, String code) throws IOException;
     void video(MultipartFile multipartFile, String type, Long accountId, String accessToken, String code) throws IOException;
+
+    String kuauiShouImageUpload(String url, String signature, Long accountId, String token);
 }
 }

+ 9 - 95
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -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;

+ 65 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouMaterialUploadServiceImpl.java

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 
+import cn.com.ctop.common.module.enums.MaterialEnum;
 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.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 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.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -26,6 +29,10 @@ import java.util.Map;
 @Slf4j
 @Slf4j
 @Service
 @Service
 public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploadService {
 public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploadService {
+
+    @Autowired
+    private IKuaiShouImageGetService iKuaiShouImageGetService;
+
     /**
     /**
      * 上传文件
      * 上传文件
      *
      *
@@ -58,6 +65,64 @@ public class KuaiShouMaterialUploadServiceImpl implements IKuaiShouMaterialUploa
     }
     }
 
 
 
 
+    @Override
+    public String kuauiShouImageUpload(String url, String signature, Long accountId, String token) {
+        try {
+            Map<String, String> headerMap = new HashMap<>();
+            headerMap.put("Content-Type", "multipart/form-data");
+            JSONObject requestJson = new JSONObject();
+            requestJson.put("signature", signature);
+            requestJson.put("url", url);
+            requestJson.put("type", 2);
+            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);
+            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;
+    }
+
+
     public String uploadFile(MultipartFile multipartFile, String dirPath) throws IOException {
     public String uploadFile(MultipartFile multipartFile, String dirPath) throws IOException {
         String fileName = multipartFile.getOriginalFilename();
         String fileName = multipartFile.getOriginalFilename();
         String fileSuffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());
         String fileSuffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());