|
@@ -0,0 +1,161 @@
|
|
|
|
+package cn.com.ctop.kuaishou.modules.ai.controller;
|
|
|
|
+
|
|
|
|
+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.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+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.RestController;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Api(tags = "快手-批量工具")
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/kuaishou/Ai")
|
|
|
|
+public class KuaiShouMaterialControer {
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaishouInterfaceService iKuaishouInterfaceService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouVideoLastTimeService lastTimeService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouVideoGetService videoGetService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询上新素材
|
|
|
|
+ *
|
|
|
|
+ * @param requestJson
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @PostMapping(value = "/getNewVideoList")
|
|
|
|
+ public JSONObject getNewVideo(@RequestBody JSONObject requestJson) {
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
|
+ try {
|
|
|
|
+ if (Check.isNull(requestJson)) {
|
|
|
|
+ throw new Exception("入参不能为空");
|
|
|
|
+ }
|
|
|
|
+ Long accountId = requestJson.getLong("accountId");
|
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
|
+ throw new Exception("账户id不能为空");
|
|
|
|
+ }
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(token)) {
|
|
|
|
+ throw new Exception("未获取账号授权信息");
|
|
|
|
+ }
|
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
+ iKuaishouInterfaceService.getVideoList(token, nowDate, nowDate);
|
|
|
|
+ iKuaishouInterfaceService.getSuZaoList(token.getAccessToken(), accountId, 1, nowDate, nowDate);
|
|
|
|
+ KuaiShouVideoLastTime videoLastTime = lastTimeService.getById(accountId);
|
|
|
|
+ Date startTime;
|
|
|
|
+ Date endDate = new Date();
|
|
|
|
+ if (!Check.isNull(videoLastTime)) {
|
|
|
|
+ startTime = videoLastTime.getLastTime();
|
|
|
|
+ } else {
|
|
|
|
+ startTime = DateUtils.addTime(endDate, 5);
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
|
+ requestMap.put("startTime", DateUtils.formatDate(startTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ requestMap.put("endTime", DateUtils.formatDate(endDate, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ requestMap.put("accountId", accountId);
|
|
|
|
+ List<JSONObject> materialList = videoGetService.getVideoListByMap(requestMap);
|
|
|
|
+ if (!Check.isNull(materialList)) {
|
|
|
|
+ for (int i = 0; i < materialList.size(); i++) {
|
|
|
|
+ JSONObject materialJson = materialList.get(i);
|
|
|
|
+ String signature = materialJson.getString("signature");
|
|
|
|
+ List<String> imageList = lastTimeService.getImageListByMd5(signature);
|
|
|
|
+ materialJson.put("imageList", imageList);
|
|
|
|
+ }
|
|
|
|
+ KuaiShouVideoLastTime lastTime = new KuaiShouVideoLastTime();
|
|
|
|
+ lastTime.setId(accountId);
|
|
|
|
+ lastTime.setLastTime(endDate);
|
|
|
|
+ lastTimeService.saveOrUpdate(lastTime);
|
|
|
|
+ returnJson.put("code", 0);
|
|
|
|
+ returnJson.put("message", "SUCCESS");
|
|
|
|
+ returnJson.put("data", materialList);
|
|
|
|
+ } else {
|
|
|
|
+ returnJson.put("code", -1);
|
|
|
|
+ returnJson.put("message", "暂未新上素材");
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ returnJson.put("code", -1);
|
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @PostMapping(value = "/getHistoryVideoList")
|
|
|
|
+ public JSONObject getHistoryVideoList(@RequestBody JSONObject requestJson) {
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
|
+ try {
|
|
|
|
+ if (Check.isNull(requestJson)) {
|
|
|
|
+ throw new Exception("入参不能为空");
|
|
|
|
+ }
|
|
|
|
+ Long accountId = requestJson.getLong("accountId");
|
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
|
+ throw new Exception("账户id不能为空");
|
|
|
|
+ }
|
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(token)) {
|
|
|
|
+ throw new Exception("未获取账号授权信息");
|
|
|
|
+ }
|
|
|
|
+ String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
|
+ iKuaishouInterfaceService.getVideoList(token, nowDate, nowDate);
|
|
|
|
+ iKuaishouInterfaceService.getSuZaoList(token.getAccessToken(), accountId, 1, nowDate, nowDate);
|
|
|
|
+ KuaiShouVideoLastTime videoLastTime = lastTimeService.getById(accountId);
|
|
|
|
+ Date startTime;
|
|
|
|
+ Date endDate = new Date();
|
|
|
|
+ if (!Check.isNull(videoLastTime)) {
|
|
|
|
+ startTime = videoLastTime.getLastTime();
|
|
|
|
+ } else {
|
|
|
|
+ startTime = DateUtils.addTime(endDate, 5);
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
|
+ requestMap.put("startTime", DateUtils.formatDate(startTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ requestMap.put("endTime", DateUtils.formatDate(endDate, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ requestMap.put("accountId", accountId);
|
|
|
|
+ List<JSONObject> materialList = videoGetService.getVideoListByMap(requestMap);
|
|
|
|
+ if (!Check.isNull(materialList)) {
|
|
|
|
+ for (int i = 0; i < materialList.size(); i++) {
|
|
|
|
+ JSONObject materialJson = materialList.get(i);
|
|
|
|
+ String signature = materialJson.getString("signature");
|
|
|
|
+ List<String> imageList = lastTimeService.getImageListByMd5(signature);
|
|
|
|
+ materialJson.put("imageList", imageList);
|
|
|
|
+ }
|
|
|
|
+ KuaiShouVideoLastTime lastTime = new KuaiShouVideoLastTime();
|
|
|
|
+ lastTime.setId(accountId);
|
|
|
|
+ lastTime.setLastTime(endDate);
|
|
|
|
+ lastTimeService.saveOrUpdate(lastTime);
|
|
|
|
+ returnJson.put("code", 0);
|
|
|
|
+ returnJson.put("message", "SUCCESS");
|
|
|
|
+ returnJson.put("data", materialList);
|
|
|
|
+ } else {
|
|
|
|
+ returnJson.put("code", -1);
|
|
|
|
+ returnJson.put("message", "暂未新上素材");
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ returnJson.put("code", -1);
|
|
|
|
+ returnJson.put("message", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return returnJson;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|