فهرست منبع

Merge branch 'test' of http://39.106.184.70:3000/ctop/adsp-boot into test

syh 5 سال پیش
والد
کامیت
330e1d6a3d

+ 33 - 21
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/PerformanceServiceImpl2.java

@@ -99,11 +99,11 @@ public class PerformanceServiceImpl2 extends ServiceImpl<PerformanceMapper, Perf
 
         //快手有效视频(新)
         kuaishouNewEffiVideo(calcDate, effiCalcStart, effiFirstWeekCalcEnd, thisYear, thisMonth, thisQuarter, DateUtils.formatDate(friday), DateUtils.formatDate(thursday));
-        //头条有效视频
-        //toutiaoNewEffiVideo(calcDate, effiCalcStart, effiFirstWeekCalcEnd, thisYear, thisMonth, thisQuarter, DateUtils.formatDate(friday), DateUtils.formatDate(thursday));
+        //头条有效视频(新)
+        toutiaoNewEffiVideo(calcDate, effiCalcStart, effiFirstWeekCalcEnd, thisYear, thisMonth, thisQuarter, DateUtils.formatDate(friday), DateUtils.formatDate(thursday));
 
         //总视频
-        //kuaishouNewVideo( calcDate,  thisYear,  thisQuarter,  thisMonth, DateUtils.formatDate(friday),  DateUtils.formatDate(thursday));
+        kuaishouNewVideo( calcDate,  thisYear,  thisQuarter,  thisMonth, DateUtils.formatDate(friday),  DateUtils.formatDate(thursday));
     }
 
     //快手有效视频统计
@@ -2328,24 +2328,36 @@ public class PerformanceServiceImpl2 extends ServiceImpl<PerformanceMapper, Perf
     //根据userid,appType,年度,季度查询有效视频列表
     public List<MaterialInfo> getEffiWeekVideoList(Integer appType, String startDate, String endDate, String userId){
         List<MaterialInfo> materialInfoList = userEfficientVideoMapMapper.getEffiWeekVideoList(appType, startDate, endDate, userId);
-        BigDecimal cost = null;
-        if(appType == 2){
-            for(MaterialInfo materialInfo:materialInfoList){
-                cost = userEfficientVideoMapMapper.videoTotalCostInDates(materialInfo.getCode(),startDate, endDate);
-                if(cost == null){
-                    cost = BigDecimal.ZERO;
-                }
-                materialInfo.setCost(cost);
-            }
-        }else if(appType == 1){
-            for(MaterialInfo materialInfo:materialInfoList){
-                cost = userEfficientVideoMapMapper.toutiaoVideoTotalCostInDates(materialInfo.getCode(),startDate, endDate);
-                if(cost == null){
-                    cost = BigDecimal.ZERO;
-                }
-                materialInfo.setCost(cost);
-            }
-        }
+
+        //String effiCalcStart = null;
+        //String effiCalcEnd =null;
+        //try {
+        //    effiCalcStart = DateUtils.formatDate(DateUtils.addDay(startDate, -14)); //计算有效视频开始的时间
+        //    log.info("周有效视频开始时间:" + effiCalcStart);
+        //    effiCalcEnd = DateUtils.formatDate(DateUtils.addDay(startDate, -1)); //计算有效视频结束的时间
+        //    log.info("周有效视频结束时间:" + effiCalcEnd);
+        //} catch (ParseException e) {
+        //    e.printStackTrace();
+        //}
+        //
+        //BigDecimal cost = null;
+        //if(appType == 2){
+        //    for(MaterialInfo materialInfo:materialInfoList){
+        //        cost = userEfficientVideoMapMapper.videoTotalCostInDates(materialInfo.getCode(),effiCalcStart, effiCalcEnd);
+        //        if(cost == null){
+        //            cost = BigDecimal.ZERO;
+        //        }
+        //        materialInfo.setCost(cost);
+        //    }
+        //}else if(appType == 1){
+        //    for(MaterialInfo materialInfo:materialInfoList){
+        //        cost = userEfficientVideoMapMapper.toutiaoVideoTotalCostInDates(materialInfo.getCode(),effiCalcStart, effiCalcEnd);
+        //        if(cost == null){
+        //            cost = BigDecimal.ZERO;
+        //        }
+        //        materialInfo.setCost(cost);
+        //    }
+        //}
         return materialInfoList;
     }
 

+ 115 - 0
module-report/src/main/java/cn/com/ctop/bytedance/controller/KuaiShouYiCheReportController.java

@@ -0,0 +1,115 @@
+package cn.com.ctop.bytedance.controller;
+
+import cn.com.ctop.bytedance.service.IKuaiShouYiCheReportService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController
+@RequestMapping("/ctop/yiche/report/")
+public class KuaiShouYiCheReportController {
+    @Autowired
+    private IKuaiShouYiCheReportService yiCheReportService;
+
+
+    @PostMapping("hourReport")
+    public Result<JSONObject> advertiserReport(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        JSONObject hourReport = yiCheReportService.getHourReport(requestJson);
+        result.setResult(hourReport);
+        return result;
+    }
+
+
+    /**
+     * 导出报表
+     *
+     * @return
+     */
+    @RequestMapping(value = "/exportHourReport")
+    @ResponseBody
+    public void export(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
+
+        JSONObject hourReport = yiCheReportService.getHourReport(requestJson);
+        JSONArray androidArr = hourReport.getJSONArray("android");
+
+        // 安卓相关
+        List<List<Object>> androidList = new ArrayList<>();
+        if (!Check.isNull(androidArr)) {
+            for (int i = 0; i < androidArr.size(); i++) {
+                JSONObject jsonObject = androidArr.getJSONObject(i);
+
+                List<Object> android = new ArrayList();
+                android.add(jsonObject.getString("systemType"));
+                android.add(jsonObject.getString("authName"));
+                android.add(jsonObject.getBigDecimal("charge"));
+                android.add(jsonObject.getLong("activation"));
+                android.add(jsonObject.getBigDecimal("activationCost"));
+                android.add(jsonObject.getBigDecimal("estimatedCost"));
+                androidList.add(android);
+            }
+        }
+
+
+        // ios 相关
+        JSONArray iosArr = hourReport.getJSONArray("ios");
+        List<List<Object>> iosList = new ArrayList<>();
+        if (!Check.isNull(iosArr)) {
+            for (int i = 0; i < iosArr.size(); i++) {
+                JSONObject jsonObject = iosArr.getJSONObject(i);
+                List<Object> ios = new ArrayList();
+                ios.add(jsonObject.getString("systemType"));
+                ios.add(jsonObject.getString("authName"));
+                ios.add(jsonObject.getBigDecimal("charge"));
+                ios.add(jsonObject.getLong("activation"));
+                ios.add(jsonObject.getBigDecimal("activationCost"));
+                ios.add(jsonObject.getBigDecimal("estimatedCost"));
+                iosList.add(ios);
+            }
+        }
+
+
+        String[] androidHeaders = {"投放设备", "分类", "现金花费", "账户激活量", "激活成本", "预估成本"};
+        String[] iosHeaders = {"投放设备", "分类", "现金花费", "账户激活量", "激活成本", "预估成本"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "安卓时报统计", androidHeaders, androidList);
+        eeu.exportExcel(workbook, 1, "ios时报统计", iosHeaders, iosList);
+        this.setResponseHeader(response, "易车时报.xls");
+        workbook.write(os);
+        os.flush();
+        os.close();
+    }
+
+    //发送响应流方法
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+
+}

+ 15 - 0
module-report/src/main/java/cn/com/ctop/bytedance/mapper/KuaiShouYiCheReportMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.bytedance.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+public interface KuaiShouYiCheReportMapper {
+    Integer getMaxHourByProjectIdAndStatDate(@Param("statDate") String statDate, @Param("projectId") Long projectId);
+
+    List<JSONObject> selectReportByMap(Map<String, Object> requestMap);
+
+    JSONObject selectSumReportByMap(Map<String, Object> requestMap);
+}

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

@@ -0,0 +1,114 @@
+<?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.bytedance.mapper.KuaiShouYiCheReportMapper">
+
+    <select id="getMaxHourByProjectIdAndStatDate" resultType="java.lang.Integer">
+    SELECT
+	max(t2.stat_hour)
+    FROM
+	ctop_user_allocation t1
+    LEFT JOIN ctop_kuaishou_report_hourly_account t2 ON t1.account_id = t2.account_id
+    WHERE
+	t1.project_id = #{projectId}
+    AND t2.stat_date = #{statDate}
+    </select>
+
+
+    <select id="selectReportByMap" parameterType="java.util.Map" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.system_type systemType,
+        t1.auth_name authName,
+        ROUND(sum(t2.charge) / #{disCount},3) charge,
+        sum(t2.charge) charge,
+        sum(t2.activation) activation,
+        (
+        case
+        when sum(t2.activation) != 0
+        then
+        ROUND((sum(t2.charge) / sum(t2.activation))/ #{disCount},3)
+        else
+        0
+        end
+        ) activationCost,
+
+        (
+        case
+        when t1.system_type = 'android'
+        then 16
+        when t1.system_type = 'IOS'
+        then 23
+        else 0
+        end
+        ) estimatedCost
+
+        FROM
+        ctop_user_allocation t1
+        LEFT JOIN ctop_kuaishou_report_hourly_account t2 ON t1.account_id = t2.account_id
+        where 1 = 1
+        <if test="projectId != null">
+            and t1.project_id = #{projectId}
+        </if>
+
+        <if test="statDate != null">
+            and t2.stat_date = #{statDate}
+        </if>
+
+        <if test="statHour != null">
+            and t2.stat_hour &lt;= #{statHour}
+        </if>
+        <if test="systemType != null">
+            and t1.system_type = #{systemType}
+        </if>
+        group by t1.account_id
+
+    </select>
+
+
+    <select id="selectSumReportByMap" parameterType="java.util.Map" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.system_type systemType,
+        #{dateDesc} authName,
+        ROUND(sum(t2.charge) / #{disCount},3) charge,
+        sum(t2.charge) charge,
+        sum(t2.activation) activation,
+        (
+        case
+        when sum(t2.activation) != 0
+        then
+        ROUND((sum(t2.charge) / sum(t2.activation))/ #{disCount},3)
+        else
+        0
+        end
+        ) activationCost,
+
+        (
+        case
+        when t1.system_type = 'android'
+        then 16
+        when t1.system_type = 'IOS'
+        then 23
+        else 0
+        end
+        ) estimatedCost
+        FROM
+        ctop_user_allocation t1
+        LEFT JOIN ctop_kuaishou_report_hourly_account t2 ON t1.account_id = t2.account_id
+        where 1 = 1
+        <if test="projectId != null">
+            and t1.project_id = #{projectId}
+        </if>
+
+        <if test="statDate != null">
+            and t2.stat_date = #{statDate}
+        </if>
+
+        <if test="statHour != null">
+            and t2.stat_hour &lt;= #{statHour}
+        </if>
+        <if test="systemType != null">
+            and t1.system_type = #{systemType}
+        </if>
+    </select>
+
+
+</mapper>

+ 7 - 0
module-report/src/main/java/cn/com/ctop/bytedance/service/IKuaiShouYiCheReportService.java

@@ -0,0 +1,7 @@
+package cn.com.ctop.bytedance.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IKuaiShouYiCheReportService {
+    JSONObject getHourReport(JSONObject requestJson);
+}

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

@@ -0,0 +1,95 @@
+package cn.com.ctop.bytedance.service.impl;
+
+import cn.com.ctop.bytedance.mapper.KuaiShouYiCheReportMapper;
+import cn.com.ctop.bytedance.service.IKuaiShouYiCheReportService;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class KuaiShouYiCheReportServiceImpl implements IKuaiShouYiCheReportService {
+    @Autowired
+    private KuaiShouYiCheReportMapper kuaiShouYiCheReportMapper;
+
+    @Override
+    public JSONObject getHourReport(JSONObject requestJson) {
+        Long projectId = requestJson.getLong("projectId");
+        BigDecimal disCount = requestJson.getBigDecimal("disCount");
+        String statDate = DateUtils.getNowDate("yyyy-MM-dd");
+
+        JSONObject returnJson = new JSONObject();
+        Integer maxHour = kuaiShouYiCheReportMapper.getMaxHourByProjectIdAndStatDate(statDate, projectId);
+        if (maxHour != null) {
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("projectId", projectId);
+            requestMap.put("disCount", disCount);
+            requestMap.put("statDate", statDate);
+            requestMap.put("statHour", maxHour);
+
+
+            String yesterday = DateUtils.getAnotherDay("yyyy-MM-dd", statDate, -1);
+            String weekAgoDay = DateUtils.getAnotherDay("yyyy-MM-dd", statDate, -6);
+
+
+            // 安卓
+            requestMap.put("systemType", "android");
+            // 账号
+            List<JSONObject> androidReportArr = kuaiShouYiCheReportMapper.selectReportByMap(requestMap);
+
+            // 今日
+            requestMap.put("statDate", statDate);
+            requestMap.put("dateDesc", statDate + "整体数据");
+            JSONObject nowJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            androidReportArr.add(nowJson);
+
+            // 昨日
+            requestMap.put("statDate", yesterday);
+            requestMap.put("dateDesc",  "昨日整体数据");
+            JSONObject yesterdayJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            androidReportArr.add(yesterdayJson);
+            // 七日
+            requestMap.put("statDate", weekAgoDay);
+            requestMap.put("dateDesc",  "上周同期整体数据");
+
+            JSONObject weekAgoJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            androidReportArr.add(weekAgoJson);
+
+
+            // ios
+            requestMap.put("systemType", "IOS");
+            // 账号
+            List<JSONObject> iosReportArr = kuaiShouYiCheReportMapper.selectReportByMap(requestMap);
+
+            // 今日
+            requestMap.put("statDate", statDate);
+            requestMap.put("dateDesc", statDate + "整体数据");
+            JSONObject iosNowJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            iosReportArr.add(iosNowJson);
+
+
+            // 昨日
+            requestMap.put("statDate", yesterday);
+            requestMap.put("dateDesc",  "昨日整体数据");
+            JSONObject iosYesterdayJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            iosReportArr.add(iosYesterdayJson);
+            // 七日
+            requestMap.put("statDate", weekAgoDay);
+            requestMap.put("dateDesc",  "上周同期整体数据");
+            JSONObject iosWeekAgoJson = kuaiShouYiCheReportMapper.selectSumReportByMap(requestMap);
+            iosReportArr.add(iosWeekAgoJson);
+
+            returnJson.put("android", androidReportArr);
+            returnJson.put("ios", iosReportArr);
+        }
+
+
+        System.err.println(returnJson);
+        return returnJson;
+    }
+}