Bladeren bron

Merge branch 'master' into test

yumeng 5 jaren geleden
bovenliggende
commit
22e12def9d

+ 22 - 0
module-report/src/main/java/cn/com/ctop/bytedance/controller/MaterialReportController.java

@@ -2,6 +2,8 @@ package cn.com.ctop.bytedance.controller;
 
 
 import cn.com.ctop.bytedance.service.IMaterialReportService;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,4 +36,24 @@ public class MaterialReportController {
 
     }
 
+
+    @PostMapping(value = "/getMaterialAccount")
+    public List<UserAllocation> getKuaiShouChainRatio(@RequestBody String userId) {
+        if (Check.isNull(userId)) {
+            return null;
+        }
+        List<UserAllocation> accountIdList = materialReportService.selectAccountIds(userId);
+        return accountIdList;
+
+    }
+
+
+    @PostMapping(value = "/getMaterialReportByAccount")
+    public List<JSONObject> getMaterialReportByAccount(@RequestBody JSONObject json) {
+
+        List<JSONObject> reportList = materialReportService.selectReportByAccountIds(json);
+        return reportList;
+
+    }
+
 }

+ 4 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/MaterialReportMapper.java

@@ -18,4 +18,8 @@ public interface MaterialReportMapper {
     List<JSONObject> selectDailyByMap(Map<String, Object> paramsMap);
 
     JSONObject selectDailyChainRatioByMap(Map<String, Object> paramsMap);
+
+    List<JSONObject> selectHourMaterialList(Map<String, Object> paramsMap);
+
+    List<JSONObject> selectDayMaterialList(Map<String, Object> paramsMap);
 }

+ 186 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/MaterialReportMapper.xml

@@ -195,6 +195,10 @@
             <if test="signature != null">
                 and signature = #{signature}
             </if>
+            <if test="accountId != null">
+                and account_id = #{accountId}
+            </if>
+
         </where>
         group by signature
 
@@ -364,9 +368,191 @@
             <if test="endDate != null">
                 and stat_date &lt;= #{endDate}
             </if>
+
+            <if test="accountId != null">
+                and account_id = #{accountId}
+            </if>
         </where>
         group by signature
     </select>
 
 
+    <select id="selectHourMaterialList" parameterType="Map" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        sum(t2.charge) cost, -- 花费
+        sum(t2.photo_show) photoShow, -- 封面曝光数
+        sum(t2.photo_click) photoClick, -- 封面点击数
+        sum(t2.aclick) aclick, -- 素材曝光数
+        sum(t2.bclick) bclick, -- 行为数
+        (case
+        when sum(photo_show) != 0
+        then (sum(t2.photo_click) / sum(photo_show))
+        else 0
+        end
+        ) photoClickRatio, -- 封面点击率
+
+        (case
+        when sum(aclick) != 0
+        then (sum(t2.bclick) / sum(aclick))
+        else 0
+        end
+        ) actionRatio, -- 行为率
+
+        (case
+        when sum(t2.photo_show) != 0
+        then ((sum(t2.charge) / sum(t2.photo_show)) * 1000)
+        else 0
+        end
+        ) impression1kCost, -- 均千次封面曝光花费
+
+        (case
+        when sum(t2.photo_click) != 0
+        then (sum(t2.charge) / sum(t2.photo_click))
+        else 0
+        end
+        ) photoClickCost, -- 平均封面点击单价
+
+        (CASE
+        WHEN sum(t2.photo_click) != 0
+        THEN (sum(t2.charge) / sum(t2.photo_click))
+        ELSE 0
+        end
+        ) actionCost, -- 平均行为单价
+
+        (case
+        WHEN sum(t2.form_count) != 0
+        THEN sum(t2.form_count)
+        WHEN sum(t2.activation) != 0
+        THEN sum(t2.activation)
+        ELSE 0
+        END
+        ) conversions, -- 转化数
+
+        (
+        CASE
+        WHEN sum(t2.form_count) != 0
+        THEN (sum(t2.charge) / sum(t2.form_count))
+        WHEN sum(t2.activation) != 0
+        THEN (sum(t2.charge) / sum(t2.activation))
+        ELSE 0
+        END
+        ) conversionPrice, -- 转化单价
+
+        t2.url url, -- 视频url
+        t2.signature signature, -- 视频md5
+        t2.account_id accountId
+        from
+        ctop_oauth_token t1
+        left join
+        ctop_kuaishou_report_hourly_creative_statistic t2
+        on t1.id = t2.account_id
+        where t1.id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and t1.media_id = '2'
+        <if test="statHour != null">
+            and t2.stat_hour &lt;= #{statHour}
+        </if>
+        <if test="statDate != null">
+            and t2.stat_date = #{statDate}
+        </if>
+        and t2.signature != ''
+        GROUP BY t2.signature
+        order by sum(t2.charge) desc
+        limit 100
+    </select>
+
+
+    <select id="selectDayMaterialList" parameterType="Map" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        sum(t2.charge) cost, -- 花费
+        sum(t2.photo_show) photoShow, -- 封面曝光数
+        sum(t2.photo_click) photoClick, -- 封面点击数
+        sum(t2.aclick) aclick, -- 素材曝光数
+        sum(t2.bclick) bclick, -- 行为数
+        (case
+        when sum(photo_show) != 0
+        then (sum(t2.photo_click) / sum(photo_show))
+        else 0
+        end
+        ) photoClickRatio, -- 封面点击率
+
+        (case
+        when sum(aclick) != 0
+        then (sum(t2.bclick) / sum(aclick))
+        else 0
+        end
+        ) actionRatio, -- 行为率
+
+        (case
+        when sum(t2.photo_show) != 0
+        then ((sum(t2.charge) / sum(t2.photo_show)) * 1000)
+        else 0
+        end
+        ) impression1kCost, -- 均千次封面曝光花费
+
+        (case
+        when sum(t2.photo_click) != 0
+        then (sum(t2.charge) / sum(t2.photo_click))
+        else 0
+        end
+        ) photoClickCost, -- 平均封面点击单价
+
+        (CASE
+        WHEN sum(t2.photo_click) != 0
+        THEN (sum(t2.charge) / sum(t2.photo_click))
+        ELSE 0
+        end
+        ) actionCost, -- 平均行为单价
+
+        (case
+        WHEN sum(t2.form_count) != 0
+        THEN sum(t2.form_count)
+        WHEN sum(t2.activation) != 0
+        THEN sum(t2.activation)
+        ELSE 0
+        END
+        ) conversions, -- 转化数
+
+        (
+        CASE
+        WHEN sum(t2.form_count) != 0
+        THEN (sum(t2.charge) / sum(t2.form_count))
+        WHEN sum(t2.activation) != 0
+        THEN (sum(t2.charge) / sum(t2.activation))
+        ELSE 0
+        END
+        ) conversionPrice, -- 转化单价
+
+        t2.url url, -- 视频url
+        t2.signature signature, -- 视频md5
+        t2.account_id accountId
+        from
+        ctop_oauth_token t1
+        left join
+        ctop_kuaishou_report_daily_creative_statistic t2
+        on t1.id = t2.account_id
+        where t1.id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and t1.media_id = '2'
+
+        <if test="startDate != null">
+            and t2.stat_date &gt;= #{startDate}
+        </if>
+
+        <if test="endDate != null">
+            and t2.stat_date &lt;= #{endDate}
+        </if>
+        and t2.signature != ''
+        GROUP BY t2.signature
+        order by sum(t2.charge) desc
+        limit 100
+    </select>
+
+
 </mapper>

+ 17 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IMaterialReportService.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.bytedance.service;
 
+import cn.com.ctop.common.module.entity.UserAllocation;
 import com.alibaba.fastjson.JSONObject;
 
 import java.util.List;
@@ -23,4 +24,20 @@ public interface IMaterialReportService {
      * @return
      */
     JSONObject getKuaiShouChainRatio(JSONObject json);
+
+    /**
+     * 查询账号accountId
+     *
+     * @param userId
+     * @return
+     */
+    List<UserAllocation> selectAccountIds(String userId);
+
+    /**
+     * 根据账号 查新素材报表
+     *
+     * @param json
+     * @return
+     */
+    List<JSONObject> selectReportByAccountIds(JSONObject json);
 }

+ 126 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/MaterialReportServiceImpl.java

@@ -2,8 +2,12 @@ package cn.com.ctop.bytedance.service.impl;
 
 import cn.com.ctop.bytedance.mapper.MaterialReportMapper;
 import cn.com.ctop.bytedance.service.IMaterialReportService;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +25,9 @@ public class MaterialReportServiceImpl implements IMaterialReportService {
     @Autowired
     private MaterialReportMapper materialReportMapper;
 
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+
     @Override
     public String getRoleCodeByUserId(String userId) {
         return materialReportMapper.getRoleCodeByUserId(userId);
@@ -142,10 +149,14 @@ public class MaterialReportServiceImpl implements IMaterialReportService {
                 return null;
             }
             Integer type = json.getInteger("type");
+            String accountId = json.getString("accountId");
             String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
             String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
             Map<String, Object> paramsMap = new HashMap<>();
             paramsMap.put("signature", signature);
+            if (!Check.isNull(accountId)) {
+                paramsMap.put("accountId", accountId);
+            }
             String beContrastDate = "";
             String contrastStartDate = "";
             String beContrastStartDate = "";
@@ -430,4 +441,119 @@ public class MaterialReportServiceImpl implements IMaterialReportService {
     }
 
 
+    /**
+     * 查询 所有绑定账号
+     *
+     * @param userId
+     * @return
+     */
+
+
+    @Override
+    public List<UserAllocation> selectAccountIds(String userId) {
+        String roleCode = materialReportMapper.getRoleCodeByUserId(userId);
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("media_id", 2);
+        if ("operator".equals(roleCode)) {
+            queryWrapper.eq("userId", userId);
+        }
+        queryWrapper.isNotNull("account_id");
+        queryWrapper.groupBy("account_id");
+        queryWrapper.orderByAsc("advertiser_name");
+
+        List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
+        return userAllocations;
+    }
+
+    /**
+     * 根据账号 查询素材报表
+     *
+     * @param json
+     * @return
+     */
+    @Override
+    public List<JSONObject> selectReportByAccountIds(JSONObject json) {
+
+
+        long startTime = System.currentTimeMillis();
+
+        List<JSONObject> marketJsonList = new ArrayList<>();
+        try {
+            if (Check.isNull(json)) {
+                return marketJsonList;
+            }
+
+            JSONArray accountIds = json.getJSONArray("accountIds");
+            if (Check.isNull(accountIds)) {
+                return marketJsonList;
+            }
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+            Integer type = json.getInteger("type");
+
+            Map<String, Object> paramsMap = new HashMap<>();
+            paramsMap.put("accountIds", accountIds);
+            if (type == 1) { // 今天分时数据
+                Integer maxHour = materialReportMapper.selectMaxHourByDate(nowDate);
+                if (Check.isNull(maxHour) || maxHour == 0) {
+                    return marketJsonList;
+                }
+                Integer statHour = maxHour - 1;
+                paramsMap.put("statHour", statHour);
+                paramsMap.put("statDate", nowDate);
+                marketJsonList = materialReportMapper.selectHourMaterialList(paramsMap);
+
+            } else if (type == 2) {
+                paramsMap.put("startDate", anotherDay);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 3) {
+                String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 4) {
+                String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -15);
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 5) {// 近一个月
+                String startDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -1);
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 6) {// 近三个月
+                String startDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 7) {// 近六个月
+                String startDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -6);
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", anotherDay);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            } else if (type == 9) {  // 自定义查询日期
+                String startDate = json.getString("startDate");
+                String endDate = json.getString("endDate");
+                paramsMap.put("startDate", startDate);
+                paramsMap.put("endDate", endDate);
+                marketJsonList = materialReportMapper.selectDayMaterialList(paramsMap);
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        log.info("账户维度素材数据请求所用时长------------->: {} ms", System.currentTimeMillis() - startTime);
+        return marketJsonList;
+    }
+
+
 }