Explorar el Código

运营个人 添加头条维度数据---账户维度

zhaoxian hace 1 año
padre
commit
65aa4f5092

+ 1 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialStareMapper.java

@@ -96,6 +96,7 @@ public interface MaterialStareMapper {
 
     //快手 -查询 账户 数据信息
     List<KuaiShouOperateAccountVo> getKuaiShouOperateAccountInfo(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("projectId") String projectId, @Param("accountId") Long accountId, @Param("list") Set<String> operatorUserIds);
+    List<KuaiShouOperateAccountVo> getBytedanceOperateAccountInfo(@Param("startDate") Long startDate, @Param("endDate") Long endDate, @Param("projectId") String projectId, @Param("accountId") Long accountId, @Param("list") Set<String> operatorUserIds);
 
 
     //快手 账户 余额

+ 66 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/MaterialStareMapper.xml

@@ -888,6 +888,72 @@
     </select>
 
 
+    <!-- 快手 -查询 账户 数据信息  -->
+    <select id="getBytedanceOperateAccountInfo" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo">
+        SELECT
+        SUM( d.cost ) AS totalCost,
+        d.account_id as accountId,
+        d.account_name as accountName,
+        d.project_id AS projectId,
+        d.project_name AS projectName,
+        d.user_id AS userId,
+        COUNT( DISTINCT d.user_id ) AS userNum,
+        ( SELECT u.realname FROM `jeecg-boot`.sys_user u WHERE u.id = d.user_id ) AS userName,
+        (SELECT u.warning_amount FROM `jeecg-boot`.ctop_user_allocation u where u.account_id = d.account_id) as
+        warningAmount,
+        IFNULL(SUM( d.active ),0) AS active,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.active ), 2 ),0) AS activationPrice,
+        IF(SUM( d.attribution_next_day_open_cnt ) / SUM( d.active ) > 0.0001,CONCAT(ROUND(SUM( d.attribution_next_day_open_cnt ) / SUM(
+        d.active ) * 100, 2 ),'%'),0.00) AS 'leave',
+        IFNULL(SUM( d.game_pay_count ),0) AS eventPay,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.game_pay_count ), 2 ),0) AS eventPayCost,
+        IF(SUM( d.game_pay_count ) / ( SUM( d.active ) + SUM( d.form )) > 0.0001,CONCAT(ROUND( SUM( d.game_pay_count ) /
+        ( SUM( d.active ) + SUM( d.form )) * 100, 2 ),'%'),0.00) AS eventPayRate,
+        IFNULL(SUM( d.pay_count ),0) AS eventNewUserPay,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.pay_count ), 2 ),0) AS eventNewUserPayCost,
+        IFNULL(ROUND( SUM( d.pay_count ) / ( SUM( d.active ) + SUM( d.form )), 2 ),0) AS
+        eventNewUserPayRate,
+
+        IFNULL(SUM( d.register ),0) AS eventRegister,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.register ), 2 ),0) AS eventRegisterCost,
+        IFNULL(SUM( d.game_addiction ),0) AS keyAction,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.game_addiction ), 2 ),0) AS keyActionCost,
+        IF(SUM( d.game_addiction )/ SUM( d.active ) > 0.0001,CONCAT( ROUND(SUM( d.game_addiction )/ SUM( d.active ) *
+        100 , 2 ), '%' ),0.00) AS keyActionRate,
+        IFNULL(SUM( d.stat_pay_amount ),0) AS eventPayPurchaseAmountFirstDay,
+        IFNULL(ROUND(SUM( d.stat_pay_amount )/SUM( d.cost ),2),0) AS eventPayFirstDayRoi,
+        IFNULL(SUM( d.form ),0) AS formCount,
+        IFNULL(ROUND( SUM( d.cost ) / SUM( d.form ), 2 ),0) AS formCountPrice,
+        IFNULL(SUM(d.`show`),0) as photoShow,
+        IFNULL(SUM(d.`click`),0) as photoClick
+        FROM
+        application.bytedance_advertiser_report_daily_dw d
+        WHERE
+        d.cost > 0
+        <if test="startDate != null and startDate != '' ">
+            and d.stat_datetime &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and d.stat_datetime &lt;= #{endDate}
+        </if>
+        <if test="projectId != null and projectId != '' ">
+            and d.project_id = #{projectId}
+        </if>
+        <if test="accountId != null and accountId != '' ">
+            and d.account_id = #{accountId}
+        </if>
+        <if test='list!=null and list.size()>0'>
+            AND d.user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY d.account_id
+        ORDER BY SUM( d.cost ) DESC
+    </select>
+
+
     <!-- 快手 账户 余额 -->
     <select id="getKuaiShouAccountBalance" resultType="com.alibaba.fastjson.JSONObject">
         SELECT advertiser_id as accountId,

+ 94 - 11
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/MaterialStareServiceImpl.java

@@ -1188,6 +1188,97 @@ public class MaterialStareServiceImpl implements MaterialStareService {
      */
     @Override
     public Result getKuaiShouOperateAccountInfo(Integer pageNum, int pageSize, String startTime, String endTime, String projectId, String userId) {
+        String mediaType = null;
+        //查询用户角色
+        String roleCode = materialStareMapper.getRoleCodeByUserId(userId);
+        //判断是否运营相关角色,并获取媒体类型
+        if (!Check.isNull(roleCode)) {
+            if ("touTiaoOperationManager".equals(roleCode)) {
+                mediaType = "1";
+            } else if ("kuaishouOperationManager".equals(roleCode)) {
+                mediaType = "2";
+            } else if (roleCode.toLowerCase().contains("perat")) {
+                String leaderRoleCode = materialStareMapper.getOperatLeaderRole(userId);
+                if (!Check.isNull(leaderRoleCode)) {
+                    if ("touTiaoOperationManager".equals(leaderRoleCode)) {
+                        mediaType = "1";
+                    } else if ("kuaishouOperationManager".equals(leaderRoleCode)) {
+                        mediaType = "2";
+                    }
+                }
+            } else {
+                return Result.successMsg("非运营相关角色,不显示数据", null);
+            }
+        }
+
+        if ("1".equals(mediaType)) {
+            return getBytedanceOperateAccountInfo(pageNum, pageSize, startTime, endTime, projectId, userId);
+        } else {
+            DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+            try {
+                //查询当前人员所有下级
+                Set<String> operatorUserIds = getAffiliateId(userId);
+                //2022-02-15 ==>> 20220215
+                long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+                long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+                //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
+                Map<String, String> lastTime = DateUtils.getStartEndTime(startTime, endTime);
+                long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+                long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+                Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween")) + 1;
+
+                //计算同比 时间值 只支持7天
+                long startEqually = new Long("0");
+                long endEqually = new Long("0");
+                if (daysBetween <= 7) {
+                    startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
+                    endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
+                }
+
+                PageHelper.startPage(pageNum, pageSize);
+                //查询运营数据-账户 维度
+                List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getKuaiShouOperateAccountInfo(startDate, entDate, projectId, null, operatorUserIds);
+                for (KuaiShouOperateAccountVo accountInfo : listOperate) {
+
+                    //查询 有效 上新视频 爆款视频
+                    JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null, null, String.valueOf(accountInfo.getAccountId()), startDate, entDate);
+                    accountInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
+                    accountInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
+                    accountInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
+
+                    long accountId = accountInfo.getAccountId();
+                    List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getKuaiShouOperateAccountInfo(lastTimeStart, lastTimeEnd, projectId, accountId, operatorUserIds);
+                    //环比 = (当前 - 上阶段 ) / 上阶段
+                    String yearOnYear = "0";
+                    if (!Check.isNull(accountYearOnYearInfo)) {
+                        Double yearOnYearD = (accountInfo.getTotalCost() - accountYearOnYearInfo.get(0).getTotalCost()) / accountYearOnYearInfo.get(0).getTotalCost();
+                        yearOnYear = decimalFormat.format(yearOnYearD);
+                    }
+                    accountInfo.setYearOnYear(yearOnYear);
+
+                    //同比 日期超过 7 天 则不显示
+                    String equallyRate = "-";
+                    if (daysBetween <= 7) {
+                        List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getKuaiShouOperateAccountInfo(startEqually, endEqually, projectId, accountId, operatorUserIds);
+                        if (!Check.isNull(accountEquallyInfo)) {
+                            Double equallyRateD = (accountInfo.getTotalCost() - accountEquallyInfo.get(0).getTotalCost()) / accountEquallyInfo.get(0).getTotalCost();
+                            equallyRate = decimalFormat.format(equallyRateD);
+                        }
+                    }
+                    accountInfo.setEquallyRate(equallyRate);
+                }
+
+                PageInfo<KuaiShouOperateAccountVo> pageInfo = new PageInfo<>(listOperate);
+                return Result.successMsg("运营账户列表数据查询成功。", pageInfo);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return Result.errorMsg("哎呀,查询失败了。");
+        }
+    }
+
+    public Result getBytedanceOperateAccountInfo(Integer pageNum, int pageSize, String startTime, String endTime, String projectId, String userId) {
         DecimalFormat decimalFormat = new DecimalFormat("0.00%");
         try {
             //查询当前人员所有下级
@@ -1209,20 +1300,13 @@ public class MaterialStareServiceImpl implements MaterialStareService {
                 startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
                 endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
             }
-
             PageHelper.startPage(pageNum, pageSize);
             //查询运营数据-账户 维度
-            List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getKuaiShouOperateAccountInfo(startDate, entDate, projectId, null, operatorUserIds);
+            List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getBytedanceOperateAccountInfo(startDate, entDate, projectId, null, operatorUserIds);
             for (KuaiShouOperateAccountVo accountInfo : listOperate) {
 
-                //查询 有效 上新视频 爆款视频
-                JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null, null, String.valueOf(accountInfo.getAccountId()), startDate, entDate);
-                accountInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
-                accountInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
-                accountInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
-
                 long accountId = accountInfo.getAccountId();
-                List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getKuaiShouOperateAccountInfo(lastTimeStart, lastTimeEnd, projectId, accountId, operatorUserIds);
+                List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getBytedanceOperateAccountInfo(lastTimeStart, lastTimeEnd, projectId, accountId, operatorUserIds);
                 //环比 = (当前 - 上阶段 ) / 上阶段
                 String yearOnYear = "0";
                 if (!Check.isNull(accountYearOnYearInfo)) {
@@ -1234,7 +1318,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
                 //同比 日期超过 7 天 则不显示
                 String equallyRate = "-";
                 if (daysBetween <= 7) {
-                    List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getKuaiShouOperateAccountInfo(startEqually, endEqually, projectId, accountId, operatorUserIds);
+                    List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getBytedanceOperateAccountInfo(startEqually, endEqually, projectId, accountId, operatorUserIds);
                     if (!Check.isNull(accountEquallyInfo)) {
                         Double equallyRateD = (accountInfo.getTotalCost() - accountEquallyInfo.get(0).getTotalCost()) / accountEquallyInfo.get(0).getTotalCost();
                         equallyRate = decimalFormat.format(equallyRateD);
@@ -1242,7 +1326,6 @@ public class MaterialStareServiceImpl implements MaterialStareService {
                 }
                 accountInfo.setEquallyRate(equallyRate);
             }
-
             PageInfo<KuaiShouOperateAccountVo> pageInfo = new PageInfo<>(listOperate);
             return Result.successMsg("运营账户列表数据查询成功。", pageInfo);
         } catch (Exception e) {