فهرست منبع

投放数据,素材维度

huangxuechao 4 سال پیش
والد
کامیت
6131f76ac1

+ 5 - 1
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/mapper/BytedanceReportMaterialDailyMapper.java

@@ -2,8 +2,12 @@ package org.jeecg.modules.bytedance.report.mapper;
 
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import io.lettuce.core.dynamic.annotation.Param;
 import org.jeecg.modules.bytedance.report.entity.BytedanceReportMaterialDaily;
 
+import java.util.List;
+import java.util.Map;
+
 
 /**
  * 素材报表
@@ -12,5 +16,5 @@ import org.jeecg.modules.bytedance.report.entity.BytedanceReportMaterialDaily;
  * @cersion: V1.0
  */
 public interface BytedanceReportMaterialDailyMapper extends BaseMapper<BytedanceReportMaterialDaily> {
-
+    List<Map<String,Object>> selectMaterialDailyReportByAccountId(@Param("accountId") String accountId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 }

+ 23 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/mapper/xml/BytedanceReportMaterialDailyMapper.xml

@@ -2,5 +2,28 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.bytedance.report.mapper.BytedanceReportMaterialDailyMapper">
 
+    <!-- 查询账户花费-->
+    <select id="selectMaterialDailyReportByAccountId" resultType="java.util.HashMap">
+        SELECT
+            video.video_url as videoUrl,
+            report.material_id as materialId,
+            report.cost,
+            report.show_material as showMaterial,
+            report.click,
+            report.convert_material as convertMaterial,
+            creative.count,
+            video.material_upload_time as materialUploadTime
+        FROM
+            ctop_bytedance_report_material_daily report
+        LEFT JOIN ctop_bytedance_video_info video ON video.material_id = report.material_id AND video.account_id = report.account_id
+        LEFT JOIN (SELECT video_id,account_id,count(*) AS count FROM ctop_bytedance_creative t WHERE t.account_id = #{accountId} GROUP BY video_id,account_id) creative ON creative.video_id = video.vid
+        WHERE
+            video.account_id = #{accountId}
+        <if test="startTime!=null">and STR_TO_DATE(report.stat_datetime,'%Y-%m-%d') &gt;= STR_TO_DATE(#{startTime},'%Y-%m-%d')</if>
+        <if test="endTime!=null">and STR_TO_DATE(report.stat_datetime,'%Y-%m-%d') &lt;= STR_TO_DATE(#{endTime},'%Y-%m-%d')</if>
+        GROUP BY
+            report.material_id
+        order by report.cost desc
 
+    </select>
 </mapper>

+ 2 - 1
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/service/IBytedanceReportMaterialDailyService.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.bytedance.report.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.bytedance.report.entity.BytedanceReportMaterialDaily;
 
 /**
@@ -10,5 +11,5 @@ import org.jeecg.modules.bytedance.report.entity.BytedanceReportMaterialDaily;
  * @version V1.0
  */
 public interface IBytedanceReportMaterialDailyService extends IService<BytedanceReportMaterialDaily> {
-
+    Result getMaterialDailyReportByAccountId(String accountId, String startTime, String endTime,Integer pageNum,Integer pageSize);
 }

+ 51 - 1
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/service/impl/BytedanceReportMaterialDailyServiceImpl.java

@@ -1,12 +1,21 @@
 package org.jeecg.modules.bytedance.report.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.bytedance.report.entity.BytedanceReportMaterialDaily;
+import org.jeecg.modules.bytedance.report.entity.vo.ReportCostVo;
 import org.jeecg.modules.bytedance.report.mapper.BytedanceReportMaterialDailyMapper;
 import org.jeecg.modules.bytedance.report.service.IBytedanceReportMaterialDailyService;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 素材报表
  * @author jeecg-boot
@@ -15,8 +24,49 @@ import org.springframework.stereotype.Service;
  */
 @Service
 @Primary
-
 public class BytedanceReportMaterialDailyServiceImpl extends ServiceImpl<BytedanceReportMaterialDailyMapper, BytedanceReportMaterialDaily> implements IBytedanceReportMaterialDailyService {
 
+    @Resource
+    private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
+
+    public Result getMaterialDailyReportByAccountId(String accountId, String startTime, String endTime,Integer pageNum,Integer pageSize){
+        PageHelper.startPage(pageNum,pageSize);
+        List<Map<String, Object>> dailyReportList = bytedanceReportMaterialDailyMapper.selectMaterialDailyReportByAccountId(accountId, startTime, endTime);
+
+
+        for (Map<String, Object> dailyReportMap: dailyReportList) {
+            if(dailyReportMap == null || dailyReportMap.isEmpty()){
+                return Result.error("头条视频日报数据为空。");
+            }
+
+            if(dailyReportMap.get("count") == null){
+                dailyReportMap.put("count",0);
+            }
+
+            BigDecimal cost = new BigDecimal(dailyReportMap.get("cost").toString());
+            BigDecimal click = new BigDecimal(dailyReportMap.get("click").toString());
+            BigDecimal showMaterial = new BigDecimal(dailyReportMap.get("showMaterial").toString());
+            BigDecimal convertMaterial = new BigDecimal(dailyReportMap.get("convertMaterial").toString());
+
+            BigDecimal costPerThousandShow = cost.multiply(new BigDecimal(1000)).divide(showMaterial, 2, BigDecimal.ROUND_HALF_UP);
+            dailyReportMap.put("costPerThousandShow", costPerThousandShow);
+
+            BigDecimal costPerClick = cost.divide(click, 2, BigDecimal.ROUND_HALF_UP);
+            dailyReportMap.put("costPerClick", costPerClick);
+
+            BigDecimal clickRate = click.multiply(new BigDecimal(100)).divide(showMaterial, 2, BigDecimal.ROUND_HALF_UP);
+            dailyReportMap.put("clickRate", clickRate);
+
+            BigDecimal costConvert = cost.divide(convertMaterial, 2, BigDecimal.ROUND_HALF_UP);
+            dailyReportMap.put("costConvert", costConvert);
+
+            BigDecimal convertRate = convertMaterial.multiply(new BigDecimal(100)).divide(click,2,BigDecimal.ROUND_HALF_UP);
+            dailyReportMap.put("convertRate", convertRate);
+
+        }
+
+        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(dailyReportList);
 
+        return Result.successMsg("数据加载成功。",dailyReportList);
+    }
 }

+ 14 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/BytedanceReportController.java

@@ -191,8 +191,20 @@ public class BytedanceReportController {
 
 
 
-
-
+	@ApiOperation(value="投放数据-更新计划定向包", notes="投放数据-更新计划定向包")
+	@GetMapping(value = "/selectMaterialDailyReport")
+	public Result selectMaterialDailyReport(@RequestParam("accountId") String accountId,
+					@RequestParam("startTime") String startTime,
+					@RequestParam("endTime") String endTime,
+					@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
+					@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
+		try {
+			return bytedanceReportMaterialDailyService.getMaterialDailyReportByAccountId(accountId,startTime,endTime,pageNum,pageSize);
+		}catch (Exception e){
+			log.error("投放数据-获取花费和环比异常",e);
+			return Result.error("请求失败,请联系开发人员!");
+		}
+	}