소스 검색

上新素材

yumeng 4 년 전
부모
커밋
faa585a880

+ 19 - 19
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -10,14 +10,7 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 类描述:时间操作定义类
@@ -831,21 +824,28 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
 
-    public static void main(String[] args) throws ParseException {
-        /*Date date = stampToTime(1599458521L);
-        String s = formatDate(date);
-        System.err.println(s);*/
-        Long s1 = timeToStamp("2020-09-23 21:30:00");
-        System.err.println(s1);
+    public static int getdaysOfTwoDate(String minDate, String date) {
+        Date bigDate = parseDate(date, "yyyy-MM-dd");
+        Date smallDate = parseDate(minDate, "yyyy-MM-dd");
+        int days = (int) ((bigDate.getTime() - smallDate.getTime()) / (1000 * 3600 * 24));
+        return days + 1;
     }
 
-    public static int getdaysOfTwoDate(String minDate, String date) {
-        Date bigDate = parseDate(date,"yyyy-MM-dd");
-        Date smallDate = parseDate(minDate,"yyyy-MM-dd");
-        int days = (int) ((bigDate.getTime() - smallDate.getTime()) / (1000*3600*24));
-        return days+1;
+
+    /**
+     * 当前时间前推
+     *
+     * @param endDate
+     * @param i
+     * @return
+     */
+    public static Date addTime(Date endDate, int i) {
+        Long time = Long.valueOf(i * 1000 * 60);
+        Long time1 = endDate.getTime() - time;
+        return new Date(time1);
     }
 
+
     /**
      * String类型 转换为Date, 如果参数长度为10 转换格式”yyyy-MM-dd“ 如果参数长度为19 转换格式”yyyy-MM-dd
      * HH:mm:ss“ * @param text String类型的时间值

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -181,6 +181,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/shiwan/shiwanFileUpload/*", "anon");
         filterChainDefinitionMap.put("/oa/wechatNoList/*", "anon");
         filterChainDefinitionMap.put("/ruleGroup/*", "anon");
+        filterChainDefinitionMap.put("/kuaishou/Ai/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 161 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

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

+ 56 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaiShouVideoLastTime.java

@@ -0,0 +1,56 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-01-11
+ */
+@Data
+@TableName("ctop_kuaishou_video_last_time")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_video_last_time对象", description = "ai获取素材上次截止日期")
+public class KuaiShouVideoLastTime {
+
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long Id;
+    /**
+     * 素材最后上新时间
+     */
+    @ApiModelProperty(value = "素材最后上新时间")
+    private Date lastTime;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 18 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaiShouVideoLastTimeMapper.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import java.util.List;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author: jeecg-boot
+ * @date: 2021-01-11
+ * @cersion: V1.0
+ */
+public interface KuaiShouVideoLastTimeMapper extends BaseMapper<KuaiShouVideoLastTime> {
+
+    List<String> getImageListByMd5(String signature);
+}

+ 12 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaiShouVideoLastTimeMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouVideoLastTimeMapper">
+    <select id="getImageListByMd5" resultType="java.lang.String">
+      select
+      signature
+      from ctop_material_cut_frame
+      where video_signature = #{md5}
+      limit 15
+    </select>
+
+</mapper>

+ 17 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouVideoLastTimeService.java

@@ -0,0 +1,17 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+/**
+ * @Description: ai获取素材上次截止日期
+ * @Author: jeecg-boot
+ * @Date: 2021-01-11
+ * @Version: V1.0
+ */
+public interface IKuaiShouVideoLastTimeService extends IService<KuaiShouVideoLastTime> {
+
+    List<String> getImageListByMd5(String signature);
+}

+ 28 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouVideoLastTimeServiceImpl.java

@@ -0,0 +1,28 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouVideoLastTimeMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * ai获取素材上次截止日期
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-01-11
+ */
+@Service
+public class KuaiShouVideoLastTimeServiceImpl extends ServiceImpl<KuaiShouVideoLastTimeMapper, KuaiShouVideoLastTime> implements IKuaiShouVideoLastTimeService {
+    @Autowired
+    private KuaiShouVideoLastTimeMapper videoLastTimeMapper;
+
+    @Override
+    public List<String> getImageListByMd5(String signature) {
+        return videoLastTimeMapper.getImageListByMd5(signature);
+    }
+}

+ 3 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -20,8 +21,7 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 
-    List<KuaiShouVideoGet> getHighQualityVideo(long accountId,int days,int num);
-
-
+    List<KuaiShouVideoGet> getHighQualityVideo(long accountId, int days, int num);
 
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 }

+ 22 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml

@@ -58,7 +58,6 @@
     </select>
 
 
-
     <select id="getHighQualityVideo" parameterType="java.util.Map"
             resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
         select * from ctop_kuaishou_video_get
@@ -82,5 +81,27 @@
     </select>
 
 
+    <select id="getVideoListByMap" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        photo_id as 'photo_id',
+        signature as 'signature',
+        stat_date as 'stat_date',
+        channel_type as 'channel_type',
+        url as 'video_url'
+        from ctop_kuaishou_video_get
+        where 1 = 1
+        <if test="accountId != null and accountId != '' ">
+            and account_id = #{accountId}
+        </if>
+        <if test="startTime != null and startTime != '' ">
+            and stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != '' ">
+            and stat_date &lt;= #{endTime}
+        </if>
+        group by signature
+        order by stat_date desc
+    </select>
+
 
 </mapper>

+ 3 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -2,9 +2,10 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -30,7 +31,5 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId,String startTime, String endTime);
 
-
-
-
+    List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 }

+ 25 - 20
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -19,11 +19,10 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 /**
  * @Description: 快手-获取视频接口
@@ -122,13 +121,13 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     }
 
     @Override
-    public List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer aiStatus) {
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId, Integer aiStatus) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null!=aiStatus&&aiStatus!=0){
-            queryWrapper.eq("ai_status",aiStatus);
+        if (null != aiStatus && aiStatus != 0) {
+            queryWrapper.eq("ai_status", aiStatus);
         }
         queryWrapper.orderByDesc("stat_date");
         return this.list(queryWrapper);
@@ -136,12 +135,12 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
 
 
     @Override
-    public List<KuaiShouVideoGet>getNewVideoDescDate(Long accountId,Integer newVideoCnt){
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId, Integer newVideoCnt) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null!=newVideoCnt && newVideoCnt>0){
+        if (null != newVideoCnt && newVideoCnt > 0) {
             queryWrapper.orderByDesc("stat_date");
             queryWrapper.last("limit " + newVideoCnt);
         }
@@ -150,16 +149,22 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
 
 
     @Override
-    public List<KuaiShouVideoGet>getNewVideoBetweenTime(Long accountId,String startTime, String endTime){
-        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
-        if(null!=accountId&&accountId!=0){
-            queryWrapper.eq("account_id",accountId);
+    public List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId, String startTime, String endTime) {
+        QueryWrapper<KuaiShouVideoGet> queryWrapper = new QueryWrapper<>();
+        if (null != accountId && accountId != 0) {
+            queryWrapper.eq("account_id", accountId);
         }
-        if(null != startTime && null != endTime){
-            queryWrapper.le("stat_date",endTime);
-            queryWrapper.gt("stat_date",startTime);
+        if (null != startTime && null != endTime) {
+            queryWrapper.le("stat_date", endTime);
+            queryWrapper.gt("stat_date", startTime);
         }
         return this.list(queryWrapper);
     }
 
+    @Override
+    public List<JSONObject> getVideoListByMap(Map<String, Object> requestMap) {
+        return videoGetMapper.getVideoListByMap(requestMap);
+    }
+
+
 }