|
@@ -1,8 +1,10 @@
|
|
|
package cn.com.ctop.kuaishou.modules.batch.controller;
|
|
|
|
|
|
+import cn.com.ctop.common.module.constant.CosConstant;
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.common.module.utils.CosUtils;
|
|
|
import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
@@ -12,14 +14,22 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
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.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/kusiShouUpload")
|
|
|
public class KuaiShouMaterialUploadController {
|
|
@@ -176,4 +186,47 @@ public class KuaiShouMaterialUploadController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @PostMapping(value = "/uploadImage")
|
|
|
+ public Result<Object> uploadImage(@RequestParam("file") MultipartFile file, Long accountId, String signature) throws Exception {
|
|
|
+ try {
|
|
|
+ QueryWrapper<KuaiShouImageGet> imageGetQueryWrapper = new QueryWrapper<>();
|
|
|
+ imageGetQueryWrapper.eq("signature", signature);
|
|
|
+ imageGetQueryWrapper.eq("account_id", accountId);
|
|
|
+ imageGetQueryWrapper.last("limit 1");
|
|
|
+ KuaiShouImageGet imageGet = iKuaiShouImageGetService.getOne(imageGetQueryWrapper);
|
|
|
+ if (Check.isNull(imageGet)) {
|
|
|
+ CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
+ if (Check.isNull(oauthToken)) {
|
|
|
+ return Result.error("未获取到账户信息");
|
|
|
+ }
|
|
|
+ String fileName = accountId + "_" + System.currentTimeMillis() + "_" + file.getOriginalFilename();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("图片上传异常");
|
|
|
+ }
|
|
|
+ String splashPath = "splash/image/" + DateUtils.date2Str() + "/";
|
|
|
+ String md5 = CosUtils.uploadFileByInputStream(inputStream, splashPath, fileName);
|
|
|
+ Thread.sleep(100);
|
|
|
+ String imageUrl = CosConstant.URL_COS_ADDRESS + splashPath + fileName;
|
|
|
+ String imageToken = uploadService.kuauiShouImageUpload(imageUrl, md5, accountId, oauthToken.getAccessToken());
|
|
|
+ if (!Check.isNull(imageToken)) {
|
|
|
+ imageGetQueryWrapper = new QueryWrapper<>();
|
|
|
+ imageGetQueryWrapper.eq("image_token", imageToken);
|
|
|
+ imageGetQueryWrapper.eq("account_id", accountId);
|
|
|
+ imageGetQueryWrapper.last("limit 1");
|
|
|
+ KuaiShouImageGet one = iKuaiShouImageGetService.getOne(imageGetQueryWrapper);
|
|
|
+ return Result.ok(one);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result.ok(imageGet);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.error("查询失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|