瀏覽代碼

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-cloud

yumeng 3 年之前
父節點
當前提交
0144d20794

+ 4 - 3
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/KuaiShouMaterialStareController.java

@@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.util.Set;
 
 /**
- * 快手-运营数据盯盘-经理-end-master
+ * 快手-运营数据盯盘-经理&个人-end-master
  */
 @Slf4j
 @RestController
@@ -180,8 +180,9 @@ public class KuaiShouMaterialStareController {
     @GetMapping("/getKuaiShouAccountInfoBrokenLine")
     public Result<JSONObject> getKuaiShouAccountInfoBrokenLine(@RequestParam(name="accountId") long accountId,
                                                      @RequestParam(name="startTime") String startTime,
-                                                     @RequestParam(name="endTime") String endTime) {
-        return materialStareService.getKuaiShouAccountInfoBrokenLine(accountId,startTime,endTime);
+                                                     @RequestParam(name="endTime") String endTime,
+                                                     @RequestParam(name="type") String type) {
+        return materialStareService.getKuaiShouAccountInfoBrokenLine(accountId,startTime,endTime,type);
     }
 
 

+ 6 - 2
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialStareMapper.java

@@ -21,6 +21,7 @@ public interface MaterialStareMapper {
     String getUserCompanyByUserId(@Param("userId")String userId);
     Set<String> getAffiliateId(@Param("leaderId")String leaderId,@Param("companyId")String companyId);
     Set<String> querySubordinateRecursive(@Param("companyId")String companyId,@Param("leaderIds")Set<String> leaderIds);
+    Set<String> getKuaiShouAllOperators(@Param("companyId")String companyId,@Param("startDate")Long start, @Param("endDate")Long endDate,@Param("userIds")Set<String> userIds);
 
 
 
@@ -54,11 +55,14 @@ public interface MaterialStareMapper {
     JSONObject getKuaiShouAccountBalance(@Param("accountId")Long accountId);
     //快手 账户 消耗以及状态
     JSONObject getKuaiShouAccountTotalCost(@Param("accountId")Long accountId,@Param("statDate")Long statDate);
+    //快手-运营 月总消耗
+    JSONObject getKuaiShouAccountCostMonth(@Param("userId")String userId,@Param("statDate")Long statDate,@Param("endDate")Long endDate);
+    JSONObject getKuaiShouUserByUserId(@Param("userId")String userId);
 
     //快手 账户趋势图-时报
-    List<JSONObject> getKuaiShouAccountInfoBrokenLineHour(@Param("accountId")Long accountId,@Param("statDate")Long statDate,@Param("endDate")Long endDate);
+    List<JSONObject> getKuaiShouAccountInfoBrokenLineHour(@Param("type")String type,@Param("accountId")Long accountId,@Param("statDate")Long statDate,@Param("endDate")Long endDate);
     //快手 账户趋势图-日报
-    List<JSONObject> getKuaiShouAccountInfoBrokenLineDaily(@Param("accountId")Long accountId,@Param("startDate")Long startDate, @Param("endDate")Long endDate);
+    List<JSONObject> getKuaiShouAccountInfoBrokenLineDaily(@Param("type")String type,@Param("accountId")Long accountId,@Param("startDate")Long startDate, @Param("endDate")Long endDate);
 
     //快手 账户 素材上新-有效-爆款   searchType: 0-全部 1-上新 2-有效 3-爆款
     List<JSONObject> getKuaiShouAccountMaterialNewAndEffectAndFaddish(@Param("accountId")Long accountId,@Param("searchType")String searchType,@Param("startDate")Long startDate, @Param("endDate")Long endDate);

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

@@ -127,7 +127,7 @@
         COUNT(DISTINCT account_id) accountNum
         FROM
         application.kuaishou_account_report_daily_dw
-        where 1 = 1
+        where charge > 0
         <if test="startDate != null and startDate != '' ">
             and stat_date &gt;= #{startDate}
         </if>
@@ -160,9 +160,9 @@
         LEFT JOIN
         (
         SELECT abi.account_id ,
-        COUNT(abi.new_effect_num) as newEffectNum,
-        COUNT(abi.new_campaign_num) as newCampaignNum,
-        COUNT(abi.new_unit_num) as newUnitNum
+        SUM(abi.new_effect_num) as newEffectNum,
+        SUM(abi.new_campaign_num) as newCampaignNum,
+        SUM(abi.new_unit_num) as newUnitNum
         from application.app_kuaishou_account_base_info_d abi
             <where>
                 <if test="startDate != null and startDate != '' ">
@@ -230,9 +230,9 @@
         LEFT JOIN (
             SELECT
             abi.account_id,
-            COUNT( abi.new_effect_num ) AS newEffectNum,
-            COUNT( abi.new_video_num ) AS newVideoNum,
-            COUNT( abi.new_hot_num ) AS newHotNum
+            SUM( abi.new_effect_num ) AS newEffectNum,
+            SUM( abi.new_video_num ) AS newVideoNum,
+            SUM( abi.new_hot_num ) AS newHotNum
             FROM
             application.app_kuaishou_account_base_info_d abi
             <where>
@@ -312,9 +312,9 @@
         LEFT JOIN (
             SELECT
             abi.account_id,
-            COUNT( abi.new_effect_num ) AS newEffectNum,
-            COUNT( abi.new_video_num ) AS newVideoNum,
-            COUNT( abi.new_hot_num ) AS newHotNum
+            SUM( abi.new_effect_num ) AS newEffectNum,
+            SUM( abi.new_video_num ) AS newVideoNum,
+            SUM( abi.new_hot_num ) AS newHotNum
             FROM
             application.app_kuaishou_account_base_info_d abi
             <where>
@@ -361,7 +361,7 @@
             advertiser_id as accountId,
             balance
         FROM media_api.kuaishou_advertiser_fund_get
-        where d.account_id = #{accountId}
+        where advertiser_id = #{accountId}
 
     </select>
 
@@ -369,26 +369,52 @@
     <!-- 快手 账户 余额 以及状态 -->
     <select id="getKuaiShouAccountTotalCost" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
-        SUM(h.charge) todayCost,
-        u.account_status as accountStatus,
-        u.account_id as accountId,
-        u.auth_name as accountName
-        from
-        application.kuaishou_account_report_hourly_dw h
-        LEFT JOIN `jeecg-boot`.`ctop_user_allocation` u
-        on u.account_id = h.account_id
+            u.account_id as accountId,
+            u.auth_name as accountName,
+            u.account_status as accountStatus,
+            IFNULL((SELECT SUM( h.charge ) from application.kuaishou_account_report_hourly_dw h where u.account_id = h.account_id and h.stat_date = #{statDate}),0) as todayCost
+        FROM
+        `jeecg-boot`.`ctop_user_allocation` u
+        WHERE u.account_id = #{accountId}
+
+    </select>
+
+
+    <!-- 快手-运营 月总消耗 -->
+    <select id="getKuaiShouAccountCostMonth" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            SUM( d.charge ) cost
+        FROM
+            application.kuaishou_account_report_daily_dw d
         <where>
-            <if test="accountId != null and accountId != '' ">
-                and h.account_id = #{accountId}
+            <if test="userId != null and userId != '' ">
+                and d.user_id = #{userId}
             </if>
             <if test="statDate != null and statDate != '' ">
-                and h.stat_date = #{statDate}
+                and d.stat_date &gt;= #{statDate}
             </if>
+            <if test="endDate != null and endDate != '' ">
+                and d.stat_date &lt;= #{endDate}
+            </if>
+
         </where>
+
+    </select>
+
+
+    <!-- 用户 -->
+    <select id="getKuaiShouUserByUserId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            realname as userName
+        FROM
+            `jeecg-boot`.sys_user
+        WHERE id = #{userId}
+
     </select>
 
 
 
+
     <!-- 快手 账户趋势图-时报 -->
     <select id="getKuaiShouAccountInfoBrokenLineHour" resultType="com.alibaba.fastjson.JSONObject">
         SELECT t.*,y.*
@@ -396,10 +422,77 @@
             (
                 SELECT
                     h.`hour` as tHour,
-                    h.charge AS tCost,
-                    IFNULL( ROUND(( h.charge / h.activation ), 2 ), 0 ) AS tActivationPrice,
-                    IFNULL( ROUND(( h.charge / h.event_new_user_pay ), 2 ), 0 ) AS tEventNewUserPayCost,
-                    IFNULL( ROUND( ( h.event_next_day_stay / h.activation ), 2 ), 0 ) AS tLeave
+                    <if test='type == "cost"'>
+                        h.charge AS tData,
+                    </if>
+                    <if test='type == "activation"'>
+                        IFNULL(h.activation,0) AS tData ,
+                    </if>
+                    <if test='type == "activationPrice"'>
+                        IFNULL(ROUND( (h.charge  /  h.activation) , 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "leave"'>
+                        IF(( h.event_next_day_stay  /  h.activation ) > 0.0001,ROUND(( h.event_next_day_stay  / h.activation ) * 100, 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventPay"'>
+                        IFNULL( h.event_pay ,0) AS tData,
+                    </if>
+                    <if test='type == "eventPayCost"'>
+                        IFNULL(ROUND(  (h.charge  /  h.event_pay ), 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventPayRate"'>
+                        IF(( h.event_pay  /   h.activation  +  h.form_count ) > 0.0001,ROUND( ( h.event_pay  /  h.activation  +  h.form_count ) * 100, 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventNewUserPay"'>
+                        IFNULL( h.event_new_user_pay ,0) AS tData,
+                    </if>
+                    <if test='type == "eventNewUserPayCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_new_user_pay ), 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventNewUserPayRate"'>
+                        IFNULL(ROUND( ( h.event_new_user_pay  /   (h.activation  +  h.form_count) ) * 100, 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventAppInvoked"'>
+                        IFNULL( h.event_app_invoked ,0) AS tData,
+                    </if>
+                    <if test='type == "eventAppInvokedCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_app_invoked ), 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventRegister"'>
+                        IFNULL( h.event_register ,0) AS tData,
+                    </if>
+                    <if test='type == "eventRegisterCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_register) , 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "keyAction"'>
+                        IFNULL( h.key_action ,0) AS tData,
+                    </if>
+                    <if test='type == "keyActionCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.key_action ), 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "keyActionRate"'>
+                        IF(( h.key_action /  h.activation ) > 0.0001,CONCAT( ( h.key_action / h.activation ) * 100 , 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "eventPayPurchaseAmountFirstDay"'>
+                        IFNULL( h.event_pay_purchase_amount_first_day ,0) AS tData,
+                    </if>
+                    <if test='type == "eventPayFirstDayRoi"'>
+                        IFNULL( h.event_pay_first_day_roi ,0) AS tData,
+                    </if>
+                    <if test='type == "formCount"'>
+                        IFNULL( h.form_count ,0) AS tData,
+                    </if>
+                    <if test='type == "formCountPrice"'>
+                        IFNULL(ROUND( ( h.charge /  h.form_count ), 2 ),0) AS tData,
+                    </if>
+                    <if test='type == "photoShow"'>
+                        IFNULL(h.`show`,0) as tData,
+                    </if>
+                    <if test='type == "photoClick"'>
+                        IFNULL(h.photo_click,0) as tData,
+                    </if>
+                    h.account_id as tAccountId
+
                 FROM
                     application.kuaishou_account_report_hourly_dw h
                 <where>
@@ -416,10 +509,76 @@
             (
                 SELECT
                     h.`hour` as yHour,
-                    h.charge AS yCost,
-                    IFNULL( ROUND(( h.charge / h.activation ), 2 ), 0 ) AS yActivationPrice,
-                    IFNULL( ROUND(( h.charge / h.event_new_user_pay ), 2 ), 0 ) AS yEventNewUserPayCost,
-                    IFNULL( ROUND( ( h.event_next_day_stay / h.activation ), 2 ), 0 ) AS yLeave
+                    <if test='type == "cost"'>
+                        h.charge AS yData,
+                    </if>
+                    <if test='type == "activation"'>
+                        IFNULL(h.activation,0) AS yData ,
+                    </if>
+                    <if test='type == "activationPrice"'>
+                        IFNULL(ROUND( (h.charge  /  h.activation) , 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "leave"'>
+                        IF(( h.event_next_day_stay  /  h.activation ) > 0.0001,ROUND(( h.event_next_day_stay  / h.activation ) * 100, 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventPay"'>
+                        IFNULL( h.event_pay ,0) AS yData,
+                    </if>
+                    <if test='type == "eventPayCost"'>
+                        IFNULL(ROUND(  (h.charge  /  h.event_pay ), 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventPayRate"'>
+                        IF(( h.event_pay  /   h.activation  +  h.form_count ) > 0.0001,ROUND( ( h.event_pay  /  h.activation  +  h.form_count ) * 100, 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventNewUserPay"'>
+                        IFNULL( h.event_new_user_pay ,0) AS yData,
+                    </if>
+                    <if test='type == "eventNewUserPayCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_new_user_pay ), 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventNewUserPayRate"'>
+                        IFNULL(ROUND( ( h.event_new_user_pay  /   (h.activation  +  h.form_count) ) * 100, 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventAppInvoked"'>
+                        IFNULL( h.event_app_invoked ,0) AS yData,
+                    </if>
+                    <if test='type == "eventAppInvokedCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_app_invoked ), 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventRegister"'>
+                        IFNULL( h.event_register ,0) AS yData,
+                    </if>
+                    <if test='type == "eventRegisterCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.event_register) , 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "keyAction"'>
+                        IFNULL( h.key_action ,0) AS yData,
+                    </if>
+                    <if test='type == "keyActionCost"'>
+                        IFNULL(ROUND( ( h.charge  /  h.key_action ), 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "keyActionRate"'>
+                        IF(( h.key_action /  h.activation ) > 0.0001, ROUND(( h.key_action / h.activation ) * 100 , 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "eventPayPurchaseAmountFirstDay"'>
+                        IFNULL( h.event_pay_purchase_amount_first_day ,0) AS yData,
+                    </if>
+                    <if test='type == "eventPayFirstDayRoi"'>
+                        IFNULL( h.event_pay_first_day_roi ,0) AS yData,
+                    </if>
+                    <if test='type == "formCount"'>
+                        IFNULL( h.form_count ,0) AS yData,
+                    </if>
+                    <if test='type == "formCountPrice"'>
+                        IFNULL(ROUND( ( h.charge /  h.form_count ), 2 ),0) AS yData,
+                    </if>
+                    <if test='type == "photoShow"'>
+                        IFNULL(h.`show`,0) as yData,
+                    </if>
+                    <if test='type == "photoClick"'>
+                        IFNULL(h.photo_click,0) as yData,
+                    </if>
+                    h.account_id as yAccountId
                 FROM
                     application.kuaishou_account_report_hourly_dw h
                 <where>
@@ -441,10 +600,73 @@
     <select id="getKuaiShouAccountInfoBrokenLineDaily" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
             DATE_FORMAT(d.stat_date,'%Y-%m-%d') as dateTime,
-            SUM( d.charge ) as cost,
-            IFNULL( ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ), 0 ) AS activationPrice,
-            IFNULL( ROUND( SUM( d.charge ) / SUM( d.event_new_user_pay ), 2 ), 0 ) AS eventNewUserPayCost,
-            IFNULL( ROUND( SUM( d.event_next_day_stay ) / SUM( d.activation ), 2 ), 0 ) AS leave
+            <if test='type == "cost"'>
+                SUM( d.charge ) as data,
+            </if>
+            <if test='type == "activation"'>
+                IFNULL(SUM( d.activation ),0) AS data,
+            </if>
+            <if test='type == "activationPrice"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ),0) AS data,
+            </if>
+            <if test='type == "leave"'>
+                IF(SUM( d.event_next_day_stay ) / SUM( d.activation ) > 0.0001,ROUND(SUM( d.event_next_day_stay ) / SUM( d.activation ) * 100, 2 ),0) AS data,
+            </if>
+            <if test='type == "eventPay"'>
+                IFNULL(SUM( d.event_pay ),0) AS data,
+            </if>
+            <if test='type == "eventPayCost"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ),0) AS data,
+            </if>
+            <if test='type == "eventPayRate"'>
+                IF(SUM( d.event_pay ) / ( SUM( d.activation ) + SUM( d.form_count )) > 0.0001,ROUND( SUM( d.event_pay ) / ( SUM( d.activation ) + SUM( d.form_count )) * 100, 2 ),0) AS data,
+            </if>
+            <if test='type == "eventNewUserPay"'>
+                IFNULL(SUM( d.event_new_user_pay ),0) AS data,
+            </if>
+            <if test='type == "eventNewUserPayCost"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.event_new_user_pay ), 2 ),0) AS data,
+            </if>
+            <if test='type == "eventNewUserPayRate"'>
+                IFNULL(ROUND( (SUM( d.event_new_user_pay ) / ( SUM( d.activation ) + SUM( d.form_count ))) * 100, 2 ),0) AS data,
+            </if>
+            <if test='type == "eventAppInvoked"'>
+                IFNULL(SUM( d.event_app_invoked ),0) AS data,
+            </if>
+            <if test='type == "eventAppInvokedCost"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.event_app_invoked ), 2 ),0) AS data,
+            </if>
+            <if test='type == "eventRegister"'>
+                IFNULL(SUM( d.event_register ),0) AS data,
+            </if>
+            <if test='type == "eventRegisterCost"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.event_register ), 2 ),0) AS data,
+            </if>
+            <if test='type == "keyAction"'>
+                IFNULL(SUM( d.key_action ),0) AS data,
+            </if>
+            <if test='type == "keyActionCost"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.key_action ), 2 ),0) AS data,
+            </if>
+            <if test='type == "keyActionRate"'>
+                IF(SUM( d.key_action )/ SUM( d.activation ) > 0.0001, ROUND(SUM( d.key_action )/ SUM( d.activation ) * 100 , 2 ),0) AS data,
+            </if>
+            <if test='type == "eventPayPurchaseAmountFirstDay"'>
+                IFNULL(SUM( d.event_pay_purchase_amount_first_day ),0) AS data,
+            </if>
+            <if test='type == "eventPayFirstDayRoi"'>
+                IFNULL(SUM( d.event_pay_first_day_roi ),0) AS data,
+            </if>
+            <if test='type == "formCount"'>
+                IFNULL(SUM( d.form_count ),0) AS data,
+            </if>
+            <if test='type == "formCountPrice"'>
+                IFNULL(ROUND( SUM( d.charge ) / SUM( d.form_count ), 2 ),0) AS data,
+            </if>
+            <if test='type == "photoShow"'>
+                IFNULL(SUM(d.`show`),0) as data
+            </if>
+            d.account_id as accountId
         FROM
             application.kuaishou_account_report_daily_dw d
         <where>
@@ -521,6 +743,7 @@
     <!-- 快手 账户饼图图-分版位 -->
     <select id="getKuaiShouAccountMaterialNewAndEffectAndFaddish" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
+        m.cover_url as coverUrl,
         DATE_FORMAT(m.media_time,'%Y-%m-%d') as dateTime,
         vd.signature,
         m.material_name as videoName,
@@ -715,6 +938,29 @@
 
 
 
+    <!-- 快手 同公司所有下级运营人员 -->
+    <select id="getKuaiShouAllOperators" resultType="java.lang.String">
+        SELECT DISTINCT
+        d.user_id
+        FROM
+        application.kuaishou_account_report_daily_dw d
+        WHERE
+         d.charge > 0
+        <if test="startDate != null and startDate != '' ">
+            and d.stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and d.stat_date &lt;= #{endDate}
+        </if>
+        AND d.user_id in
+        <foreach collection="userIds" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+    </select>
+
+
+
 
 
 
@@ -727,7 +973,8 @@
         from `jeecg-boot`.sys_user a
                  left join `jeecg-boot`.sys_user_role b on a.id = b.user_id
                  left join `jeecg-boot`.sys_role c on b.role_id = c.id
-        where a.id = #{userId}
+        where
+         a.id = #{userId}
             LIMIT 1
     </select>
 
@@ -754,10 +1001,15 @@
         SELECT DISTINCT
             u.id
         FROM
-            sys_user u,
-            user_company c
+        `jeecg-boot`.sys_user u,
+        `jeecg-boot`.user_company c,
+        `jeecg-boot`.sys_user_role r,
+        `jeecg-boot`.sys_role sr
         WHERE
             u.id = c.user_id
+            and c.user_id = r.user_id
+            and r.role_id = sr.id
+            AND sr.role_name LIKE '%运营%'
         <if test="leaderId != null and leaderId != '' ">
             AND u.leader_id = #{leaderId}
         </if>
@@ -772,10 +1024,15 @@
         SELECT DISTINCT
         u.id
         FROM
-        sys_user u,
-        user_company c
+        `jeecg-boot`.sys_user u,
+        `jeecg-boot`.user_company c,
+        `jeecg-boot`.sys_user_role r,
+        `jeecg-boot`.sys_role sr
         WHERE
         u.id = c.user_id
+        and c.user_id = r.user_id
+        and r.role_id = sr.id
+        AND sr.role_name LIKE '%运营%'
         AND u.STATUS = 1
         AND u.del_flag = 0
         <if test="companyId != null and companyId != '' ">

+ 4 - 17
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/SysManagerCompanyMapper.xml

@@ -261,19 +261,12 @@
                  open="(" close=")">
             #{id}
         </foreach>
-
         ) t1
         LEFT JOIN
         (
-        SELECT SUM(new_video_num) as 'yesCount'
-        FROM application.app_kuaishou_account_base_info_d
-        WHERE project_id IN (
-        SELECT id
-        FROM `jeecg-boot`.ctop_project
-        WHERE media_id = 2
+        SELECT sum(1) as 'yesCount' FROM application.app_kuaishou_material_info
+        WHERE help_time = DATE_FORMAT(#{lastDay}, '%Y%m%d')
         and company_id = #{companyId}
-        )
-        AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
         ) t2 ON 1 = 1
     </select>
 
@@ -291,15 +284,9 @@
         ) t1
         LEFT JOIN
         (
-        SELECT SUM(new_video_num) as 'yesCount'
-        FROM application.app_bytedance_account_base_info_d
-        WHERE project_id IN (
-        SELECT id
-        FROM `jeecg-boot`.ctop_project
-        WHERE media_id = 1
+        SELECT sum(1) as 'yesCount' FROM application.app_bytedance_material_info
+        WHERE help_time = DATE_FORMAT(#{lastDay}, '%Y%m%d')
         and company_id = #{companyId}
-        )
-        AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
         ) t2 ON 1 = 1
     </select>
 

+ 1 - 1
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/MaterialStareService.java

@@ -27,7 +27,7 @@ public interface MaterialStareService {
 
     Result getKuaiShouAccountInfo(long accountId);
 
-    Result getKuaiShouAccountInfoBrokenLine(long accountId,String startTime, String endTime);
+    Result getKuaiShouAccountInfoBrokenLine(long accountId,String startTime, String endTime,String type);
 
     Result getKuaiShouAccountMaterialNewAndEffectAndFaddish(long accountId,String searchType,String startTime, String endTime,Integer pageNum,Integer pageSize);
 

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

@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.text.DecimalFormat;
 import java.text.ParseException;
@@ -188,9 +189,16 @@ public class MaterialStareServiceImpl implements MaterialStareService {
     public Result kuaiShouOperateDateTotal(String mediaType, String startTime, String endTime, String userId) {
         Map resultMap = new HashMap();
         DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+        //查询用户所属公司
+        String companyId = materialStareMapper.getUserCompanyByUserId(userId);
+        Set<String> operatorUserIds = null;
         try {
             //查询当前人员所有下级
-            Set<String> operatorUserIds = getAffiliateId(userId);
+            operatorUserIds= getAffiliateId(userId);
+
+            //有消耗的账户
+            operatorUserIds = materialStareMapper.getKuaiShouAllOperators(companyId,DateUtils.getDateInteger(startTime).longValue(),DateUtils.getDateInteger(endTime).longValue(),operatorUserIds);
+
             SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
             // ==>> 20220202
             String now = sdf.format(new Date());
@@ -218,7 +226,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
             // 人均消耗 = 时间段内 总消耗 / 人数
             Double userAveragecost = Double.valueOf(totalCost.getString("totalCost")) / operatorUserIds.size();
             DecimalFormat df = new DecimalFormat("#.000");
-            resultMap.put("userAverageAccount",df.format(userAverageAccount));
+            resultMap.put("userAverageAccount",new Double(Math.ceil(userAverageAccount)).intValue());
             resultMap.put("userAveragecost",df.format(userAveragecost));
         }catch (Exception e){
             e.printStackTrace();
@@ -261,17 +269,22 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
             //当天总消耗
             JSONObject jsonObjectNow = materialStareMapper.getKuaiShouTotalCost(nowDate,nowDate,nowHour,userSet);
-            resultMap.put("todayCost",jsonObjectNow.getString("totalCost"));
+            resultMap.put("todayCost",Check.isNull(jsonObjectNow.getString("totalCost")) ? "0" : jsonObjectNow.getString("totalCost"));
             //昨天同时段总消耗
             JSONObject jsonObjectYesterday = materialStareMapper.getKuaiShouTotalCost(time,time,nowHour,userSet);
 
             //今日同比 = (今天总消耗 - 昨天总消耗 ) / 昨天总消耗
-            Double d = (Double.valueOf(jsonObjectNow.getString("totalCost")) - Double.valueOf(jsonObjectYesterday.getString("totalCost"))) / Double.valueOf(jsonObjectYesterday.getString("totalCost"));
+            Double d = new Double("0");
+            if (!Check.isNull( jsonObjectNow.getString("totalCost")) && !Check.isNull(jsonObjectYesterday.getString("totalCost"))){
+                 d = (Double.valueOf(jsonObjectNow.getString("totalCost"))
+                        - Double.valueOf(jsonObjectYesterday.getString("totalCost")))
+                        / Double.valueOf(jsonObjectYesterday.getString("totalCost"));
+            }
             resultMap.put("todayCompare",decimalFormat.format(d));
 
             //所选时段消耗
             JSONObject timeNowCost = materialStareMapper.getKuaiShouTotalCostDaily(stratDate,endDate,userSet);
-            resultMap.put("timeCost",timeNowCost.getString("totalCost"));
+            resultMap.put("timeCost",Check.isNull(timeNowCost.getString("totalCost")) ? "0" : timeNowCost.getString("totalCost"));
             //上阶段时间
             Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
             long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
@@ -279,8 +292,12 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
             //上阶段消耗
             JSONObject timeLastCost = materialStareMapper.getKuaiShouTotalCostDaily(lastTimeStart,lastTimeEnd,userSet);
-            //同比 = (当前总消耗 - 上阶段总消耗 ) / 当前总消耗
-            Double timeCompare = (Double.valueOf(timeNowCost.getString("totalCost")) - Double.valueOf(timeLastCost.getString("totalCost"))) / Double.valueOf(timeNowCost.getString("totalCost"));
+            //环比 = (当前总消耗 - 上阶段总消耗 ) / 上阶段总消耗
+            Double timeCompare = new Double("0");
+            if (!Check.isNull(timeNowCost.getString("totalCost")) && !Check.isNull(timeLastCost.getString("totalCost"))){
+                timeCompare = (Double.valueOf(timeNowCost.getString("totalCost")) - Double.valueOf(timeLastCost.getString("totalCost"))) / Double.valueOf(timeLastCost.getString("totalCost"));
+            }
+
             resultMap.put("timeCompare",decimalFormat.format(timeCompare));
 
             //当前月份的框返 和 激励
@@ -288,8 +305,20 @@ public class MaterialStareServiceImpl implements MaterialStareService {
             long monthFirstDay = Long.valueOf(DateUtils.getFirstDayByMonth());
             //框返 激励
             JSONObject nowMonthCost = materialStareMapper.getKuaiShouAccountCharged(monthFirstDay,nowDate,userSet);
-            resultMap.put("directCharged",nowMonthCost.getString("directCharged"));//框返
-            resultMap.put("contractCharged",nowMonthCost.getString("contractCharged"));//激励
+
+
+
+            resultMap.put("directCharged",Check.isNull(nowMonthCost) ? "0" : nowMonthCost.getString("directCharged"));//框返
+            resultMap.put("contractCharged",Check.isNull(nowMonthCost) ? "0" : nowMonthCost.getString("contractCharged"));//激励
+
+            //当前月消耗
+            JSONObject monthCost = materialStareMapper.getKuaiShouAccountCostMonth(userId, monthFirstDay,nowDate);
+            resultMap.put("monthCost",Check.isNull(monthCost) ? "0" : monthCost.getString("cost"));
+
+            //用户
+            JSONObject userName = materialStareMapper.getKuaiShouUserByUserId(userId);
+            resultMap.put("userName",Check.isNull(userName) ? "-" : userName.getString("userName"));
+
 
             //公司 组内排名
             //用户所属公司id
@@ -430,7 +459,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
             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"));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"))+1;
 
             //计算同比 时间值 只支持7天
             long startEqually = new Long("0");
@@ -504,7 +533,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
             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"));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"))+1;
 
             //计算同比 时间值 只支持7天
             long startEqually = new Long("0");
@@ -565,7 +594,8 @@ public class MaterialStareServiceImpl implements MaterialStareService {
         // ==>> 20220202
         String now = sdf.format(new Date());
         long nowDate = Long.valueOf(now);
-
+        //当前月份第一天
+        long monthFirstDay = Long.valueOf(DateUtils.getFirstDayByMonth());
         //账户余额
         JSONObject balance = materialStareMapper.getKuaiShouAccountBalance(accountId);
         resultMap.put("balance",Check.isNull(balance) ? "0" : balance.getString("balance"));
@@ -578,6 +608,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
         resultMap.put("totalCost",Check.isNull(totalCost) ? "0" : totalCost.getString("todayCost"));
         //0-开 1-关
         resultMap.put("state", Check.isNull(totalCost) ? "1" : totalCost.getString("accountStatus"));
+
         return Result.successMsg("账户查询成功",resultMap);
     }
 
@@ -594,7 +625,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
      * @time: 2022/2/21
      */
     @Override
-    public Result getKuaiShouAccountInfoBrokenLine(long accountId, String startTime, String endTime) {
+    public Result getKuaiShouAccountInfoBrokenLine(long accountId, String startTime, String endTime,String type) {
 
         List<JSONObject> resultList = new ArrayList<>();
         try {
@@ -609,10 +640,10 @@ public class MaterialStareServiceImpl implements MaterialStareService {
             if (daysBetween == 0){
                 //昨天
                 long yesterday = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(entDate), -1));
-                resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineHour(accountId,startDate,yesterday);
+                resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineHour(type,accountId,startDate,yesterday);
                 return Result.successMsg("账户时报报折线图查询成功",resultList);
             }
-            resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineDaily(accountId,startDate,entDate);
+            resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineDaily(type,accountId,startDate,entDate);
             return Result.successMsg("账户日报折线图查询成功",resultList);
 
         }catch (Exception e){
@@ -696,14 +727,17 @@ public class MaterialStareServiceImpl implements MaterialStareService {
         //查询用户角色
         String roleCode = materialStareMapper.getRoleCodeByUserId(userId);
         //管理员查询公司下所有用户
-        if ("admin".equals(roleCode)) {
+       /* if ("admin".equals(roleCode)) {
             return materialStareMapper.getCompanyAllUserId(companyId);
-        }
+        }*/
 
         Set<String> result;
         //查询当前用户是否存在下级
         Set<String> subordinate = materialStareMapper.getAffiliateId(userId,companyId);
         if (subordinate.isEmpty()) {
+            if ("admin".equals(roleCode)) {
+                return materialStareMapper.getCompanyAllUserId(companyId);
+            }
             subordinate.add(userId);
             return subordinate;
         } else {