Explorar el Código

账户维度-盯盘素材数据接口

zhaoxian hace 4 años
padre
commit
995be06c23

+ 12 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouVideoEtlInfoController.java

@@ -8,6 +8,7 @@ import cn.com.ctop.kuaishou.modules.report.service.IKuaishouVideoEtlInfoService;
 import com.alibaba.excel.EasyExcelFactory;
 import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.metadata.Sheet;
+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;
@@ -98,6 +99,17 @@ public class KuaishouVideoEtlInfoController {
 		return result;
 	}
 
+	 @PostMapping(value = "/queryPageList")
+	 public Result<Object> queryPageList(@RequestBody JSONObject request) {
+		 try {
+			 return kuaishouVideoEtlInfoService.queryPageList(request);
+		 } catch (Exception e) {
+			 log.error("查询异常,", e.getMessage());
+			 e.printStackTrace();
+		 }
+		 return Result.error("查询失败");
+	 }
+
 	/**
 	  *   添加
 	 * @param kuaishouVideoEtlInfo

+ 10 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouVideoEtlInfoMapper.java

@@ -1,15 +1,24 @@
 package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouVideoEtlInfo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 快手视频信息清洗表(有效,爆款)
+ *
  * @author: jeecg-boot
- * @date:   2020-12-17
+ * @date: 2020-12-17
  * @cersion: V1.0
  */
 public interface KuaishouVideoEtlInfoMapper extends BaseMapper<KuaishouVideoEtlInfo> {
 
     String getCompanyNameByUserId(String planId);
+
+    Long getTotal(@Param("accountId") Long accountId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<JSONObject> queryPageList(@Param("accountId") Long accountId, @Param("sortCode") String sortCode, @Param("sortType") String sortType, @Param("startTime") String startTime, @Param("endTime") String endTime);
 }

+ 44 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouVideoEtlInfoMapper.xml

@@ -3,6 +3,49 @@
 <mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouVideoEtlInfoMapper">
 
     <select id="getCompanyNameByUserId" resultType="java.lang.String">
-        select company_name from user_company where user_id = #{planId} limit 1
+        select company_name
+        from user_company
+        where user_id = #{planId} limit 1
     </select>
+
+    <select id="getTotal" resultType="java.lang.Long">
+        SELECT count(1)
+        FROM ctop_etl_kuaishou_account_material_report_daily t1
+        WHERE t1.account_id = #{accountId}
+          AND t1.stat_date &gt;= #{startTime}
+          AND t1.stat_date &lt;= #{endTime}
+        GROUP BY t1.signature
+    </select>
+
+    <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.signature,
+               SUM(t1.charge) as 'charge',
+               SUM(t1.activation) as 'activation',
+               SUM(t1.photo_show) as 'phototShow',
+               ROUND(SUM(t1.charge) / SUM(t1.activation), 2) as 'activationCost',
+               t2.url,
+               t2.cover_url as 'coverUrl',
+               t2.state_date as 'stateDate'
+        FROM ctop_etl_kuaishou_account_material_report_daily t1
+                 INNER JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
+        WHERE t1.account_id = #{accountId}
+          AND t1.stat_date &gt;= #{startTime}
+          AND t1.stat_date &lt;= #{endTime}
+        GROUP BY t1.signature
+        <if test="sortCode == 'charge' ">
+            ORDER BY  SUM(t1.charge)
+        </if>
+        <if test="sortCode == 'activationCost' ">
+            ORDER BY SUM(t1.charge) / SUM(t1.activation)
+        </if>
+        <if test="sortCode == 'phototShow' ">
+            ORDER BY SUM(t1.photo_show)
+        </if>
+        <if test="sortCode == 'activation' ">
+            ORDER BY SUM(t1.activation)
+        </if>
+        ${sortType}
+    </select>
+
+
 </mapper>

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouVideoEtlInfoService.java

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.report.service;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouVideoEtlInfo;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
 
+import java.text.ParseException;
 import java.util.Date;
 
 /**
@@ -17,4 +20,6 @@ public interface IKuaishouVideoEtlInfoService extends IService<KuaishouVideoEtlI
     void etlKuaishouVideoInfoGroupByProjectId(Date date);
 
     KuaishouVideoEtlInfo getBySignature(String signature);
+
+    Result<Object> queryPageList(JSONObject request) throws ParseException;
 }

+ 113 - 69
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouVideoEtlInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.report.service.impl;
 
 import cn.com.ctop.common.module.service.IMaterialAscriptionService;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouReportDailyMaterialService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouReportDailyMaterial;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouProjectVideoEtlInfo;
@@ -11,13 +12,17 @@ import cn.com.ctop.kuaishou.modules.report.service.IKuaishouVideoEtlInfoService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 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.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -26,9 +31,10 @@ import java.util.concurrent.Executors;
 
 /**
  * 快手视频信息清洗表(有效,爆款)
+ *
  * @author jeecg-boot
- * @date   2020-12-17
  * @version V1.0
+ * @date 2020-12-17
  */
 @Slf4j
 @Service
@@ -38,80 +44,81 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
     @Autowired
     private IKuaiShouReportDailyMaterialService dailyMaterialService;
     static ExecutorService executorService = Executors.newFixedThreadPool(100);
+
     @Override
     public void etlKuaishouVideoInfo(Date getDate) {
         String date = DateUtils.formatDate(getDate);
         //1:查询单当日视频信息
         List<KuaiShouReportDailyMaterial> materials = dailyMaterialService.getSignatureByDate(date);
-        if(null!=materials&&!materials.isEmpty()){
-            CountDownLatch countDownLatch= new CountDownLatch(materials.size());
-            materials.forEach(material->{
-                executorService.submit(()->{
+        if (null != materials && !materials.isEmpty()) {
+            CountDownLatch countDownLatch = new CountDownLatch(materials.size());
+            materials.forEach(material -> {
+                executorService.submit(() -> {
                     try {
-                        if(null == material.getSignature()||material.getSignature().trim().equals("")){
+                        if (null == material.getSignature() || material.getSignature().trim().equals("")) {
                             return;
                         }
 
                         String signature = material.getSignature();
                         KuaishouVideoEtlInfo etlInfo = this.getBySignature(signature);
-                        KuaiShouReportDailyMaterial nowData = dailyMaterialService.getEtlDataByParams(signature,date,null);
+                        KuaiShouReportDailyMaterial nowData = dailyMaterialService.getEtlDataByParams(signature, date, null);
                         String minDate = nowData.getStatDate();
-                        Integer days = DateUtils.getdaysOfTwoDate(minDate,date);
-                        if(null == etlInfo){
+                        Integer days = DateUtils.getdaysOfTwoDate(minDate, date);
+                        if (null == etlInfo) {
                             //第一次查询的数据
                             etlInfo = new KuaishouVideoEtlInfo(nowData);
                             BigDecimal totalCost = etlInfo.getTotalCost();
-                            JSONObject ascription =  materialAscriptionService.getDetailByCode(signature);
+                            JSONObject ascription = materialAscriptionService.getDetailByCode(signature);
                             String planId = null;
-                            if(null!=ascription){
+                            if (null != ascription) {
                                 planId = ascription.getString("planId");
-                                if(null!=planId&&!planId.trim().equals("")){
+                                if (null != planId && !planId.trim().equals("")) {
                                     etlInfo.setPlanId(planId);
                                 }
-                                String planName =  ascription.getString("planName");
-                                if(null!=planName&&!planName.trim().equals("")){
+                                String planName = ascription.getString("planName");
+                                if (null != planName && !planName.trim().equals("")) {
                                     etlInfo.setPlanName(planName);
                                 }
                                 String clipId = ascription.getString("clipId");
-                                if(null!=clipId&&!clipId.trim().equals("")){
+                                if (null != clipId && !clipId.trim().equals("")) {
                                     etlInfo.setClipId(clipId);
                                 }
                                 String clipName = ascription.getString("clipName");
-                                if(null!=clipName&&!clipName.trim().equals("")){
+                                if (null != clipName && !clipName.trim().equals("")) {
                                     etlInfo.setClipName(clipName);
                                 }
                                 String shotId = ascription.getString("shotId");
-                                if(null!=shotId&&!shotId.trim().equals("")){
+                                if (null != shotId && !shotId.trim().equals("")) {
                                     etlInfo.setShotId(shotId);
                                 }
                                 String shotName = ascription.getString("shotName");
-                                if(null!=shotName&&!shotName.trim().equals("")){
+                                if (null != shotName && !shotName.trim().equals("")) {
                                     etlInfo.setShotName(shotName);
                                 }
                             }
-                            if(null!=planId){
+                            if (null != planId) {
                                 String companyName = kuaishouVideoEtlInfoMapper.getCompanyNameByUserId(planId);
-                                if (null!=companyName&&!companyName.trim().equals("")){
+                                if (null != companyName && !companyName.trim().equals("")) {
                                     etlInfo.setCompanyName(companyName);
                                 }
                             }
                             //计算投放总天数
-                            if(days <= 7){
+                            if (days <= 7) {
                                 etlInfo.setSingleWeekCost(nowData.getCharge());
                             }
-                            if(days <= 14){
+                            if (days <= 14) {
                                 etlInfo.setTwoWeekCost(nowData.getCharge());
                             }
-                            if(days <= 28){
+                            if (days <= 28) {
                                 etlInfo.setFourWeekCost(nowData.getCharge());
                             }
                             //计算是否有效,爆款
-                            if(totalCost.compareTo(new BigDecimal("5000"))>0){
+                            if (totalCost.compareTo(new BigDecimal("5000")) > 0) {
                                 //此刻成为有效
                                 etlInfo.setEffectDate(date);
                                 etlInfo.setEffectDayNum(days);
                             }
-                            if(totalCost.compareTo(new BigDecimal("50000"))>0){
+                            if (totalCost.compareTo(new BigDecimal("50000")) > 0) {
                                 //此刻成为爆款
                                 etlInfo.setFaddishDate(date);
                                 etlInfo.setFaddishDayNum(days);
@@ -119,7 +126,7 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
                             etlInfo.setCreateTime(new Date());
                             etlInfo.setUpdateTime(new Date());
                             this.save(etlInfo);
-                        }else{
+                        } else {
                             //只需要更新汇总数据
                             etlInfo.setTotalCost(nowData.getCharge());
                             etlInfo.setAclick(nowData.getAclick());
@@ -129,24 +136,24 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
                             etlInfo.setUpdateTime(new Date());
                             BigDecimal totalCost = etlInfo.getTotalCost();
                             //计算投放总天数
-                            if(days <= 7){
+                            if (days <= 7) {
                                 etlInfo.setSingleWeekCost(nowData.getCharge());
                             }
-                            if(days <= 14){
+                            if (days <= 14) {
                                 etlInfo.setTwoWeekCost(nowData.getCharge());
                             }
-                            if(days <= 28){
+                            if (days <= 28) {
                                 etlInfo.setFourWeekCost(nowData.getCharge());
                             }
-                            if(null == etlInfo.getEffectDayNum()){
-                                if(totalCost.compareTo(new BigDecimal("5000"))>0){
+                            if (null == etlInfo.getEffectDayNum()) {
+                                if (totalCost.compareTo(new BigDecimal("5000")) > 0) {
                                     //此刻成为有效
                                     etlInfo.setEffectDate(date);
                                     etlInfo.setEffectDayNum(days);
                                 }
                             }
-                            if(null == etlInfo.getFaddishDayNum()){
-                                if(totalCost.compareTo(new BigDecimal("50000"))>0){
+                            if (null == etlInfo.getFaddishDayNum()) {
+                                if (totalCost.compareTo(new BigDecimal("50000")) > 0) {
                                     //此刻成为爆款
                                     etlInfo.setFaddishDate(date);
                                     etlInfo.setFaddishDayNum(days);
@@ -154,9 +161,9 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
                             }
                             this.updateById(etlInfo);
                         }
-                    }catch (Exception e){
+                    } catch (Exception e) {
 
-                    }finally {
+                    } finally {
                         countDownLatch.countDown();
                     }
                 });
@@ -167,86 +174,87 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
-            log.info("{}数据获取完成",date);
+            log.info("{}数据获取完成", date);
         }
     }
 
     @Autowired
     private IKuaishouProjectVideoEtlInfoService kuaishouProjectVideoEtlInfoService;
+
     @Override
     public void etlKuaishouVideoInfoGroupByProjectId(Date getDate) {
         String date = DateUtils.formatDate(getDate);
         //1:查询单当日视频信息--以项目汇总
         List<KuaiShouReportDailyMaterial> materials = dailyMaterialService.getSignatureByDateGroupByProjectId(date);
-        if(null!=materials&&!materials.isEmpty()){
-            CountDownLatch countDownLatch= new CountDownLatch(materials.size());
-            materials.forEach(material->{
-                executorService.submit(()->{
+        if (null != materials && !materials.isEmpty()) {
+            CountDownLatch countDownLatch = new CountDownLatch(materials.size());
+            materials.forEach(material -> {
+                executorService.submit(() -> {
                     try {
-                        if(null == material.getSignature()||material.getSignature().trim().equals("")){
+                        if (null == material.getSignature() || material.getSignature().trim().equals("")) {
                             return;
                         }
-                        if(null == material.getProjectId()||material.getProjectId() == 0){
+                        if (null == material.getProjectId() || material.getProjectId() == 0) {
                             return;
                         }
 
                         String signature = material.getSignature();
                         Long projectId = material.getProjectId();
-                        KuaishouProjectVideoEtlInfo etlInfo = kuaishouProjectVideoEtlInfoService.getByProjectVideoEtlInfoByParams(signature,projectId);
-                        KuaiShouReportDailyMaterial nowData = dailyMaterialService.getEtlDataByParams(signature,date,projectId);
+                        KuaishouProjectVideoEtlInfo etlInfo = kuaishouProjectVideoEtlInfoService.getByProjectVideoEtlInfoByParams(signature, projectId);
+                        KuaiShouReportDailyMaterial nowData = dailyMaterialService.getEtlDataByParams(signature, date, projectId);
                         String minDate = nowData.getStatDate();
-                        Integer days = DateUtils.getdaysOfTwoDate(minDate,date);
-                        if(null == etlInfo){
+                        Integer days = DateUtils.getdaysOfTwoDate(minDate, date);
+                        if (null == etlInfo) {
                             //第一次查询的数据
-                            etlInfo = new KuaishouProjectVideoEtlInfo(nowData,projectId);
-                            JSONObject ascription =  materialAscriptionService.getDetailByCode(signature);
+                            etlInfo = new KuaishouProjectVideoEtlInfo(nowData, projectId);
+                            JSONObject ascription = materialAscriptionService.getDetailByCode(signature);
                             String planId = null;
-                            if(null!=ascription){
+                            if (null != ascription) {
                                 planId = ascription.getString("planId");
-                                if(null!=planId&&!planId.trim().equals("")){
+                                if (null != planId && !planId.trim().equals("")) {
                                     etlInfo.setPlanId(planId);
                                 }
-                                String planName =  ascription.getString("planName");
-                                if(null!=planName&&!planName.trim().equals("")){
+                                String planName = ascription.getString("planName");
+                                if (null != planName && !planName.trim().equals("")) {
                                     etlInfo.setPlanName(planName);
                                 }
                                 String clipId = ascription.getString("clipId");
-                                if(null!=clipId&&!clipId.trim().equals("")){
+                                if (null != clipId && !clipId.trim().equals("")) {
                                     etlInfo.setClipId(clipId);
                                 }
                                 String clipName = ascription.getString("clipName");
-                                if(null!=clipName&&!clipName.trim().equals("")){
+                                if (null != clipName && !clipName.trim().equals("")) {
                                     etlInfo.setClipName(clipName);
                                 }
                                 String shotId = ascription.getString("shotId");
-                                if(null!=shotId&&!shotId.trim().equals("")){
+                                if (null != shotId && !shotId.trim().equals("")) {
                                     etlInfo.setShotId(shotId);
                                 }
                                 String shotName = ascription.getString("shotName");
-                                if(null!=shotName&&!shotName.trim().equals("")){
+                                if (null != shotName && !shotName.trim().equals("")) {
                                     etlInfo.setShotName(shotName);
                                 }
                             }
-                            if(null!=planId){
+                            if (null != planId) {
                                 String companyName = kuaishouVideoEtlInfoMapper.getCompanyNameByUserId(planId);
-                                if (null!=companyName&&!companyName.trim().equals("")){
+                                if (null != companyName && !companyName.trim().equals("")) {
                                     etlInfo.setCompanyName(companyName);
                                 }
                             }
                             //计算投放总天数
-                            if(days <= 7){
+                            if (days <= 7) {
                                 etlInfo.setSingleWeekCost(nowData.getCharge());
                             }
-                            if(days <= 14){
+                            if (days <= 14) {
                                 etlInfo.setTwoWeekCost(nowData.getCharge());
                             }
-                            if(days <= 28){
+                            if (days <= 28) {
                                 etlInfo.setFourWeekCost(nowData.getCharge());
                             }
                             etlInfo.setCreateTime(new Date());
                             etlInfo.setUpdateTime(new Date());
                             kuaishouProjectVideoEtlInfoService.save(etlInfo);
-                        }else{
+                        } else {
                             //只需要更新汇总数据
                             etlInfo.setTotalCost(nowData.getCharge());
                             etlInfo.setAclick(nowData.getAclick());
@@ -255,20 +263,20 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
                             etlInfo.setPhotoShow(nowData.getPhotoShow());
                             etlInfo.setUpdateTime(new Date());
                             //计算投放总天数
-                            if(days <= 7){
+                            if (days <= 7) {
                                 etlInfo.setSingleWeekCost(nowData.getCharge());
                             }
-                            if(days <= 14){
+                            if (days <= 14) {
                                 etlInfo.setTwoWeekCost(nowData.getCharge());
                             }
-                            if(days <= 28){
+                            if (days <= 28) {
                                 etlInfo.setFourWeekCost(nowData.getCharge());
                             }
                             kuaishouProjectVideoEtlInfoService.updateById(etlInfo);
                         }
-                    }catch (Exception e){
+                    } catch (Exception e) {
 
-                    }finally {
+                    } finally {
                         countDownLatch.countDown();
                     }
                 });
@@ -279,16 +287,52 @@ public class KuaishouVideoEtlInfoServiceImpl extends ServiceImpl<KuaishouVideoEt
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
-            log.info("{}数据获取完成",date);
+            log.info("{}数据获取完成", date);
         }
     }
 
     @Autowired
     private IMaterialAscriptionService materialAscriptionService;
+
     @Override
     public KuaishouVideoEtlInfo getBySignature(String signature) {
         QueryWrapper<KuaishouVideoEtlInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("video_code",signature).last("limit 1");
+        queryWrapper.eq("video_code", signature).last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public Result<Object> queryPageList(JSONObject request) throws ParseException {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        Long accountId = request.getLong("accountId");
+        if (Check.isNull(accountId)) {
+            return Result.error("未选择账户");
+        }
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        if (Check.isNull(startTime) || Check.isNull(endTime)) {
+            startTime = DateUtils.getNowDate("yyyy-MM-dd");
+            endTime = startTime;
+        }
+        String sortCode = request.getString("sortCode");
+        String sortType = request.getString("sortType");
+        if (Check.isNull(sortCode)) {
+            sortCode = "charge";
+        }
+        if (Check.isNull(sortType)) {
+            sortType = "DESC";
+        }
+        Long total = kuaishouVideoEtlInfoMapper.getTotal(accountId,startTime,endTime);
+        PageHelper.startPage(pageNo, pageSize, false);
+        PageInfo pageInfo = new PageInfo(kuaishouVideoEtlInfoMapper.queryPageList(accountId, sortCode, sortType,startTime,endTime));
+        pageInfo.setTotal(total);
+        return Result.ok(pageInfo);
+    }
 }