Sfoglia il codice sorgente

素材按消耗排序

yumeng 4 anni fa
parent
commit
e70abd06df

+ 72 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouVideoGetController.java

@@ -1,13 +1,20 @@
 package cn.com.ctop.kuaishou.modules.batch.controller;
 
 import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.StringUtils;
 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.service.IKuaiShouReportDailyMaterialService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -30,9 +37,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Description: 快手-获取视频接口
@@ -47,6 +52,8 @@ import java.util.Map;
 public class KuaiShouVideoGetController {
     @Autowired
     private IKuaiShouVideoGetService kuaiShouVideoGetService;
+    @Autowired
+    private IKuaiShouReportDailyMaterialService kuaiShouReportDailyMaterialService;
 
     /**
      * 分页列表查询
@@ -73,6 +80,68 @@ public class KuaiShouVideoGetController {
         return result;
     }
 
+
+    @GetMapping(value = "/getVideoList")
+    public PageInfo<KuaiShouVideoGetVo> getVideoList(Long accountId,
+                                                     String startDate,
+                                                     String endDate,
+                                                     String materialType,
+                                                     String channelType,
+                                                     String orderBy,
+                                                     @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                     HttpServletRequest req) {
+
+
+        List<KuaiShouVideoGetVo> list = new ArrayList<>();
+        PageHelper.startPage(pageNo, pageSize);
+        Map<String, Object> requestMap = new HashMap<>();
+        requestMap.put("accountId", accountId);
+        requestMap.put("orderBy", orderBy);
+        requestMap.put("materialType", materialType);
+        requestMap.put("channelType", channelType);
+        if (orderBy.equals("time")) {
+            if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
+                requestMap.put("startDate", startDate + " 00:00:00");
+                requestMap.put("endDate", endDate + " 59:59:59");
+            }
+
+            list = kuaiShouVideoGetService.getVideoList(requestMap);
+
+        } else if (orderBy.equals("cost")) {
+            if (!Check.isNull(startDate) && !Check.isNull(endDate)) {
+                requestMap.put("startDate", startDate);
+                requestMap.put("endDate", endDate);
+            }
+            list = kuaiShouReportDailyMaterialService.getVideoList(requestMap);
+        }
+        PageInfo<KuaiShouVideoGetVo> pageInfo = new PageInfo<>(list);
+        return pageInfo;
+
+    }
+
+
+    public static Map<String, Object> parseJSON2Map(String jsonStr) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        JSONObject json = JSONObject.parseObject(jsonStr);
+        for (Object k : json.keySet()) {
+            Object v = json.get(k);
+            if (v instanceof JSONArray) {
+                List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+                Iterator<Object> it = ((JSONArray) v).iterator();
+                while (it.hasNext()) {
+                    JSONObject json2 = (JSONObject) it.next();
+                    list.add(parseJSON2Map(json2.toString()));
+                }
+                map.put(k.toString(), list);
+            } else {
+                map.put(k.toString(), v);
+            }
+        }
+        return map;
+    }
+
+
     /**
      * 添加
      *

+ 47 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/vo/KuaiShouVideoGetVo.java

@@ -0,0 +1,47 @@
+package cn.com.ctop.kuaishou.modules.batch.entity.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description: 快手-获取视频接口
+ * @Author: jeecg-boot
+ * @Date: 2019-07-25
+ * @Version: V1.0
+ */
+
+public class KuaiShouVideoGetVo {
+
+    private BigDecimal charge;
+    private String statDate;
+
+    /**
+     * 视频id
+     */
+    @Excel(name = "视频id", width = 15)
+    @ApiModelProperty(value = "视频id")
+    private String photoId;
+
+    /**
+     * 视频预览链接
+     */
+    @Excel(name = "视频预览链接", width = 15)
+    @ApiModelProperty(value = "视频预览链接")
+    private String url;
+    /**
+     * 视频首帧图片链接
+     */
+    @Excel(name = "视频首帧图片链接", width = 15)
+    @ApiModelProperty(value = "视频首帧图片链接")
+    private String coverUrl;
+    /**
+     * 视频首帧图片链接
+     */
+    private String signature;
+
+    private Integer materialType;
+
+
+}

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

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.mapper;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouReportDailyMaterial;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouReportDailyMaterialVo;
 import cn.com.ctop.kuaishou.modules.report.entity.VideoGetvo;
@@ -7,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 素材
@@ -24,4 +26,5 @@ public interface KuaiShouReportDailyMaterialMapper extends BaseMapper<KuaiShouRe
 
     List<KuaiShouReportDailyMaterialVo> getPhotoListByDate(@Param("statDate") String statDate);
 
+    List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 }

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

@@ -1,10 +1,12 @@
 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.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 快手-获取视频接口
@@ -15,4 +17,6 @@ import java.util.List;
 public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
 
     void replaceBatch(@Param(value = "videos") List<KuaiShouVideoGet> videoGets);
+
+    List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 }

+ 33 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouReportDailyMaterialMapper.xml

@@ -143,4 +143,37 @@
       limit 1
     </select>
 
+
+    <select id="getVideoList" parameterType="java.util.Map"
+            resultType="cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo">
+
+    SELECT
+    sum(t1.charge) as charge,
+	t1.photo_id AS photoId,
+	t1.photo_url AS url,
+	t1.cover_url AS coverUrl,
+	t1.signature AS signature,
+	t2.material_type AS materialType
+    FROM
+	ctop_kuaishou_report_daily_material t1
+    LEFT JOIN (
+	SELECT
+		material_type,
+		signature
+	FROM
+		ctop_kuaishou_video_get
+	WHERE
+		account_id = #{accountId} group by signature) t2
+		ON t1.signature = t2.signature
+	WHERE
+		t1.account_id = #{accountId}
+	AND t1.channel_type = #{channelType}
+	AND t2.material_type = #{materialType}
+	GROUP BY
+		signature
+	ORDER BY
+		sum(t1.charge) DESC
+    </select>
+
+
 </mapper>

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

@@ -13,7 +13,7 @@
         material_type,
         signature,
         update_time
-       )
+        )
         values
         <foreach collection="videos" item="video" separator=",">
             (
@@ -31,4 +31,29 @@
             )
         </foreach>
     </insert>
+
+
+    <select id="getVideoList" parameterType="java.util.Map"
+            resultType="cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo">
+        select
+        stat_date as statDate,
+        photo_id as photoId,
+        url as url,
+        cover_url as coverUrl,
+        signature as signature,
+        material_type as materialType
+        from ctop_kuaishou_video_get
+        where account_id = #{accountId}
+        and channel_type = #{channelType}
+        and material_type = ${materialType}
+        <if test="startDate != null and startDate != '' ">
+            and stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and stat_date &lt;= #{endDate}
+        </if>
+        group by signature
+        order by stat_date desc
+    </select>
+
 </mapper>

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

@@ -1,10 +1,11 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouReportDailyMaterial;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 素材
@@ -14,4 +15,5 @@ import java.util.List;
  */
 public interface IKuaiShouReportDailyMaterialService extends IService<KuaiShouReportDailyMaterial> {
 
+    List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
 }

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

@@ -1,9 +1,11 @@
 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 com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 快手-获取视频接口
@@ -15,4 +17,6 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
 
     void getKeyFrame(String token, Long accountId, String md5, String photoId);
+
+    List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> stringObjectMap);
 }

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

@@ -1,11 +1,16 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouReportDailyMaterialMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouReportDailyMaterialService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouReportDailyMaterial;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 素材
  *
@@ -15,5 +20,11 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class KuaiShouReportDailyMaterialServiceImpl extends ServiceImpl<KuaiShouReportDailyMaterialMapper, KuaiShouReportDailyMaterial> implements IKuaiShouReportDailyMaterialService {
+    @Autowired
+    private KuaiShouReportDailyMaterialMapper dailyMaterialMapper;
 
+    @Override
+    public List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap) {
+        return dailyMaterialMapper.getVideoList(requestMap);
+    }
 }

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

@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
 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 cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import com.alibaba.fastjson.JSONArray;
@@ -117,4 +118,9 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
         }
 
     }
+
+    @Override
+    public List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap) {
+        return videoGetMapper.getVideoList(requestMap);
+    }
 }

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

@@ -1289,12 +1289,16 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     @Override
     public void getCreativeList(CtopOauthToken token, Date startDate, Date endDate) {
+
         getCreativeListByPage(token.getAccessToken(), token.getAccountId(), startDate, endDate, 1);
     }
 
 
     public void getCreativeListByPage(String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page) {
         try {
+
+
+            Thread.sleep(1500);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
             Map<String, String> headers = new HashMap<>();
             headers.put("Content-Type", " application/json");