浏览代码

盯盘2.0功能开发

zhaoxian 4 年之前
父节点
当前提交
40c687153a
共有 19 个文件被更改,包括 1512 次插入95 次删除
  1. 40 4
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 44 36
      module-common/src/main/java/cn/com/ctop/common/module/mapper/SysDepartMapper.java
  3. 1 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/SysRoleMapper.java
  4. 3 1
      module-common/src/main/java/cn/com/ctop/common/module/mapper/SysUserDepartMapper.java
  5. 33 13
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysDepartMapper.xml
  6. 18 14
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysRoleMapper.xml
  7. 16 7
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysUserDepartMapper.xml
  8. 129 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/EtlKuaishouReportAccountHourlyController.java
  9. 15 9
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/EtlKuaishouReportAccountHourly.java
  10. 94 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/enums/CheckParametersCostEnum.java
  11. 23 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountDailyMapper.java
  12. 19 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountHourlyMapper.java
  13. 4 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportHourlyAccountMapper.java
  14. 262 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountDailyMapper.xml
  15. 390 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountHourlyMapper.xml
  16. 38 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportHourlyAccountMapper.xml
  17. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IEtlKuaishouReportAccountHourlyService.java
  18. 367 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouReportAccountHourlyServiceImpl.java
  19. 2 2
      module-kuaishou/src/main/resources/json_template/kuaishou_filed_mapping.json

+ 40 - 4
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -10,7 +10,14 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * 类描述:时间操作定义类
@@ -146,8 +153,6 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
 
-
-
     // 指定模式的时间格式
     private static SimpleDateFormat getSDFormat(String pattern) {
         return new SimpleDateFormat(pattern);
@@ -1579,11 +1584,42 @@ public class DateUtils extends PropertyEditorSupport {
     }
 
     /**
-     * 获取两个日期之间的所有日期集合
+     * 根据数字查询本周对应的日期
+     * 1-7对应周一~周天
+     *
+     * @param
+     * @return java.lang.String
+     * @throws
      * @author ZHAOXA
+     */
+    public static String getdateFromWeek(int number) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        // 今天是一周中的第几天
+        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
+
+        if (c.getFirstDayOfWeek() == Calendar.SUNDAY) {
+            c.add(Calendar.DAY_OF_MONTH, 1);
+        }
+        // 计算一周开始的日期
+        c.add(Calendar.DAY_OF_MONTH, -dayOfWeek);
+
+        for (int i = 1; i <= 7; i++) {
+            c.add(Calendar.DAY_OF_MONTH, 1);
+            if (number == i) {
+                return sdf.format(c.getTime());
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 获取两个日期之间的所有日期集合
+     *
      * @param
      * @return java.util.List<java.lang.String>
      * @throws
+     * @author ZHAOXA
      */
     public static List<String> getDays(String startTime, String endTime) {
         // 返回的日期集合

+ 44 - 36
module-common/src/main/java/cn/com/ctop/common/module/mapper/SysDepartMapper.java

@@ -1,9 +1,10 @@
 package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.SysDepart;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
-import org.springframework.data.repository.query.Param;
 
 import java.util.List;
 
@@ -13,42 +14,49 @@ import java.util.List;
  * <p>
  *
  * @Author: Steve
- * @Since:   2019-01-22
+ * @Since: 2019-01-22
  */
 public interface SysDepartMapper extends BaseMapper<SysDepart> {
 
-	/**
-	 * 根据用户ID查询部门集合
-	 */
-	public List<SysDepart> queryUserDeparts(@Param("userId") String userId);
-
-	/**
-	 * 根据用户名查询部门
-	 *
-	 * @param username
-	 * @return
-	 */
-	public List<SysDepart> queryDepartsByUsername(@Param("username") String username);
-
-	@Select("select id from sys_depart where org_code=#{orgCode}")
-	public String queryDepartIdByOrgCode(@Param("orgCode") String orgCode);
-
-	@Select("select id,parent_id from sys_depart where id=#{departId}")
-	public SysDepart getParentDepartId(@Param("departId") String departId);
-
-	/**
-	 *  根据部门Id查询,当前和下级所有部门IDS
-	 * @param departId
-	 * @return
-	 */
-	List<String> getSubDepIdsByDepId(@Param("departId") String departId);
-
-	/**
-	 * 根据部门编码获取部门下所有IDS
-	 * @param orgCodes
-	 * @return
-	 */
-	List<String> getSubDepIdsByOrgCodes(@org.apache.ibatis.annotations.Param("orgCodes") String[] orgCodes);
-
-	SysDepart queryUserDepartsByDepartId(@Param("departId") String departId);
+    /**
+     * 根据用户ID查询部门集合
+     */
+    public List<SysDepart> queryUserDeparts(@Param("userId") String userId);
+
+    /**
+     * 根据用户名查询部门
+     *
+     * @param username
+     * @return
+     */
+    public List<SysDepart> queryDepartsByUsername(@Param("username") String username);
+
+    @Select("select id from sys_depart where org_code=#{orgCode}")
+    public String queryDepartIdByOrgCode(@Param("orgCode") String orgCode);
+
+    @Select("select id,parent_id from sys_depart where id=#{departId}")
+    public SysDepart getParentDepartId(@Param("departId") String departId);
+
+    /**
+     * 根据部门Id查询,当前和下级所有部门IDS
+     *
+     * @param departId
+     * @return
+     */
+    List<String> getSubDepIdsByDepId(@Param("departId") String departId);
+
+    /**
+     * 根据部门编码获取部门下所有IDS
+     *
+     * @param orgCodes
+     * @return
+     */
+    List<String> getSubDepIdsByOrgCodes(@org.apache.ibatis.annotations.Param("orgCodes") String[] orgCodes);
+
+    SysDepart queryUserDepartsByDepartId(@Param("departId") String departId);
+
+    List<JSONObject> getDepartmentIds(@Param("userId") String userId);
+
+    List<JSONObject> checkLowestLevelDepartment(@Param("departIds") List<JSONObject> departIds);
+
 }

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/SysRoleMapper.java

@@ -34,4 +34,5 @@ public interface SysRoleMapper extends BaseMapper<SysRole> {
     @Delete("delete from sys_role_permission where role_id = #{roleId}")
     void deleteRolePermissionRelation(@Param("roleId") String roleId);
 
+    SysRole queryRoleByUserId(@Param("userId") String userId);
 }

+ 3 - 1
module-common/src/main/java/cn/com/ctop/common/module/mapper/SysUserDepartMapper.java

@@ -2,7 +2,7 @@ package cn.com.ctop.common.module.mapper;
 
 import cn.com.ctop.common.module.entity.SysUserDepart;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import io.lettuce.core.dynamic.annotation.Param;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -15,4 +15,6 @@ public interface SysUserDepartMapper extends BaseMapper<SysUserDepart>{
     List<SysUserDepart> getUserDepartByUid(@Param("userId") String userId);
 
 	SysUserDepart getUserDepartByUserId(@Param("userId") String userId);
+
+    List<String> getUserIds(@Param("ids") List<String> ids);
 }

+ 33 - 13
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysDepartMapper.xml

@@ -2,9 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.common.module.mapper.SysDepartMapper">
 
-	<select id="queryUserDeparts" parameterType="String" resultType="cn.com.ctop.common.module.entity.SysDepart">
-	   select * from sys_depart where id IN ( select dep_id from sys_user_depart where user_id = #{userId} )
-	</select>
+    <select id="queryUserDeparts" parameterType="String" resultType="cn.com.ctop.common.module.entity.SysDepart">
+        select *
+        from sys_depart
+        where id IN (select dep_id from sys_user_depart where user_id = #{userId})
+    </select>
 
     <!-- 根据username查询所拥有的部门 -->
     <select id="queryDepartsByUsername" parameterType="String" resultType="cn.com.ctop.common.module.entity.SysDepart">
@@ -23,22 +25,40 @@
 
     <!-- 根据部门Id查询,当前和下级所有部门IDS -->
     <select id="getSubDepIdsByDepId" resultType="java.lang.String">
-		select id from sys_depart where del_flag = '0' and org_code like concat((select org_code from sys_depart where id=#{departId}),'%')
-	</select>
+        select id
+        from sys_depart
+        where del_flag = '0'
+          and org_code like concat((select org_code from sys_depart where id = #{departId}), '%')
+    </select>
 
     <!--根据部门编码获取我的部门下所有部门ids -->
     <select id="getSubDepIdsByOrgCodes" resultType="java.lang.String">
-		select id from sys_depart where del_flag = '0' and
-        <foreach collection="orgCodes" item="item" index="index"  open="(" separator="or" close=")">
+        select id from sys_depart where del_flag = '0' and
+        <foreach collection="orgCodes" item="item" index="index" open="(" separator="or" close=")">
             org_code LIKE CONCAT(#{item},'%')
         </foreach>
-	</select>
+    </select>
+
+    <select id="queryUserDepartsByDepartId" parameterType="String"
+            resultType="cn.com.ctop.common.module.entity.SysDepart">
+        select *
+        from sys_depart
+        where id = #{departId} limit 1
+    </select>
 
-    <select id="queryUserDepartsByDepartId" parameterType="String" resultType="cn.com.ctop.common.module.entity.SysDepart">
-		select * from sys_depart
-			where id = #{departId}
-			limit 1
-	</select>
+    <select id="getDepartmentIds" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT dep_id as 'id'
+        FROM sys_user_depart
+        WHERE user_id = #{userId}
+    </select>
+
+    <select id="checkLowestLevelDepartment" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT id,parent_id FROM sys_depart WHERE parent_id IN
+        <foreach item="item" index="index" collection="departIds"
+                 open="(" separator="," close=")">
+            #{item.id}
+        </foreach>
+    </select>
 
 
 </mapper>

+ 18 - 14
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysRoleMapper.xml

@@ -4,22 +4,26 @@
 
     <!-- 根据roleCode获取roleId -->
     <select id="getRoleIdByRoleCode" resultType="java.lang.String">
-		select
-		id
-		from sys_role
-		where role_code = #{roleCode}
-	</select>
+        select id
+        from sys_role
+        where role_code = #{roleCode}
+    </select>
 
     <!-- 根据userId获取角色code -->
     <select id="getRoleCodeByUserId" resultType="java.lang.String">
-		select
-		c.role_code
-		from
-		sys_user a
-		left join sys_user_role b on a.id = b.user_id
-		left join sys_role c on b.role_id = c.id
-        where
-        a.id = #{userId}
-	</select>
+        select c.role_code
+        from sys_user a
+                 left join sys_user_role b on a.id = b.user_id
+                 left join sys_role c on b.role_id = c.id
+        where a.id = #{userId}
+    </select>
+
+
+    <select id="queryRoleByUserId" resultType="cn.com.ctop.common.module.entity.SysRole">
+        SELECT t2.role_name,t2.role_code
+        FROM sys_user_role t1
+                 LEFT JOIN sys_role t2 ON t1.role_id = t2.id
+        WHERE t1.user_id = #{userId} LIMIT 1
+    </select>
 
 </mapper>

+ 16 - 7
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/SysUserDepartMapper.xml

@@ -2,17 +2,26 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.common.module.mapper.SysUserDepartMapper">
     <select id="getUserDepartByUid" parameterType="String" resultType="cn.com.ctop.common.module.entity.SysUserDepart">
-		SELECT *
-		FROM sys_user_depart
-		WHERE user_id = #{userId, jdbcType=VARCHAR}
+        SELECT *
+        FROM sys_user_depart
+        WHERE user_id = #{userId, jdbcType=VARCHAR}
     </select>
 
     <select id="getUserDepartByUserId" parameterType="String"
             resultType="cn.com.ctop.common.module.entity.SysUserDepart">
-		SELECT *
-		FROM sys_user_depart
-		WHERE user_id = #{userId, jdbcType=VARCHAR}
-		limit 1
+        SELECT *
+        FROM sys_user_depart
+        WHERE user_id = #{userId, jdbcType=VARCHAR} limit 1
+    </select>
+
+    <select id="getUserIds" resultType="java.lang.String">
+        SELECT user_id
+        FROM sys_user_depart
+        WHERE dep_id IN
+        <foreach item="id" index="index" collection="ids"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
     </select>
 
 </mapper>

+ 129 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/EtlKuaishouReportAccountHourlyController.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
 import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.QueryGenerator;
 import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly;
 import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouReportAccountHourlyService;
@@ -96,6 +97,134 @@ public class EtlKuaishouReportAccountHourlyController {
 
 
     /**
+     * 盯盘——运营个人绩效
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/personalAchievements")
+    public Result<Object> personalAchievements(String userId) {
+        try {
+            if (Check.isNull(userId)) {
+                return Result.error("缺少参数");
+            }
+            return etlKuaishouReportAccountHourlyService.queryPersonalAchievements(userId);
+        } catch (Exception e) {
+            log.error("error:", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("error");
+    }
+
+    /**
+     * 判断角色
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/checkRole")
+    public Result<Object> checkRole(String userId) {
+        try {
+            if (Check.isNull(userId)) {
+                return Result.error("缺少参数");
+            }
+            return etlKuaishouReportAccountHourlyService.checkRole(userId);
+        } catch (Exception e) {
+            log.error("error:", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("error");
+    }
+
+    /**
+     * 个人账户列表
+     *
+     * @param request
+     * @return
+     */
+    @PostMapping(value = "/accountPageList")
+    public Result<Object> accountPageList(@RequestBody JSONObject request) {
+        try {
+            return etlKuaishouReportAccountHourlyService.accountPageList(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+    /**
+     * 经理账户列表
+     *
+     * @param request
+     * @return
+     */
+    @PostMapping(value = "/leaderAccountPageList")
+    public Result<Object> leaderAccountPageList(@RequestBody JSONObject request) {
+        try {
+            return etlKuaishouReportAccountHourlyService.leaderAccountPageList(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+     /**
+     * 趋势图
+     *
+     * @param request
+     * @return
+     */
+    @PostMapping(value = "/queryNewlyData")
+    public Result<Object> queryNewlyData(@RequestBody JSONObject request) {
+        try {
+            return etlKuaishouReportAccountHourlyService.queryNewlyData(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+     /**
+     * 运营人员当日数据列表
+     *
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/operatingStaffDataList")
+    public Result<Object> operatingStaffDataList(@RequestBody JSONObject request) {
+        try {
+            return etlKuaishouReportAccountHourlyService.operatingStaffDataList(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+     /**
+     * 项目列表
+     *
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/projectList")
+    public Result<Object> projectList(@RequestBody JSONObject request) {
+        try {
+            return etlKuaishouReportAccountHourlyService.projectList(request);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    /**
      * 获取当日花费最大的账户
      *
      * @param

+ 15 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/EtlKuaishouReportAccountHourly.java

@@ -1,21 +1,20 @@
 package cn.com.ctop.kuaishou.modules.report.entity;
 
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.util.Date;
-
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import org.springframework.format.annotation.DateTimeFormat;
 import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * 账户维度-每小时盯盘数据
@@ -223,7 +222,8 @@ public class EtlKuaishouReportAccountHourly {
     @Excel(name = "落地页数据-落地页授信数", width = 15)
     @ApiModelProperty(value = "落地页数据-落地页授信数")
     private Long eventCreditGrantLandingPage;
-    /**Save pv the next day
+    /**
+     * Save pv the next day
      * 应用下载数据-次留数(仅支持分日查询)
      */
     @Excel(name = "应用下载数据-次留数(仅支持分日查询)", width = 15)
@@ -259,6 +259,12 @@ public class EtlKuaishouReportAccountHourly {
     private Date updateTime;
 
     @TableField(exist = false)
+    private BigDecimal totalBalance;//余额
+    @TableField(exist = false)
+    private BigDecimal budget;//预算
+    @TableField(exist = false)
+    private String authName;//账户名称
+    @TableField(exist = false)
     private BigDecimal activationCost;//激活单价
     @TableField(exist = false)
     private BigDecimal impression1kCost;//平均千次素材曝光花费 = 花费/素材曝光数*1000
@@ -318,5 +324,5 @@ public class EtlKuaishouReportAccountHourly {
     private BigDecimal formActionRatio;//表单提交点击率 =当日回传表单数/当日行为数
     @TableField(exist = false)
     private BigDecimal submitRatio;//按钮点击率 =当日按钮点击数 / 当日行为数
-    private BigDecimal grew=new BigDecimal(0);//同比 = (今日实时花费-昨日截止到此时的花费)/昨日截止到此时的花费*100%;
+    private BigDecimal grew = new BigDecimal(0);//同比 = (今日实时花费-昨日截止到此时的花费)/昨日截止到此时的花费*100%;
 }

+ 94 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/enums/CheckParametersCostEnum.java

@@ -0,0 +1,94 @@
+package cn.com.ctop.kuaishou.modules.report.enums;
+
+/**
+ * 运营盯盘 按字段排序枚举
+ *
+ * @param
+ * @author ZHAOXA
+ * @return
+ * @throws
+ */
+public enum CheckParametersCostEnum {
+    PARAMETER1("cost", "sum(t1.charge)"),
+    PARAMETER2("photoShow", "sum(t1.photo_show)"),
+    PARAMETER3("photoClick", "sum(t1.photo_click)"),
+    PARAMETER4("aClick", "sum(t1.aclick)"),
+    PARAMETER5("bClick", "sum(t1.bclick)"),
+    PARAMETER6("cpm", "sum(t1.charge) / sum(t1.photo_show)"),
+    PARAMETER7("cpc", "sum(t1.charge) / sum(t1.photo_click)"),
+    PARAMETER8("cpb", "sum(t1.charge) / sum(t1.bclick)"),
+    PARAMETER9("downloadStart", "sum(download_started)"),
+    PARAMETER10("downloadStartCost", "sum(t1.charge) / sum(t1.download_started)"),
+    PARAMETER11("downloadFinish", "sum(download_completed)"),
+    PARAMETER12("downloadFinishCost", "sum(t1.charge) / sum(t1.download_completed)"),
+    PARAMETER13("active", "sum(activation)"),
+    PARAMETER14("activeCost", "sum(t1.charge) / sum(t1.activation)"),
+    PARAMETER15("firstDayPay", "sum(t1.event_pay_first_day)"),
+    PARAMETER16("firstDayPayAmount", "sum(t1.event_pay_purchase_amount_first_day)"),
+    PARAMETER17("firstDayPayCost", "sum(t1.charge) / sum(t1.event_pay_first_day)"),
+    PARAMETER18("eventPay", "sum(t1.event_pay)"),
+    PARAMETER19("eventPayPurchaseAmount", "sum(t1.event_pay_purchase_amount)"),
+    PARAMETER20("eventPayCost", "sum(t1.charge) / sum(t1.event_pay)"),
+    PARAMETER21("register", "sum(t1.event_register)"),
+    PARAMETER22("activeRegisterCost", "sum(t1.charge)/sum(t1.event_register)"),
+    PARAMETER23("eventJinJianApp", "sum(event_jin_jian_app)"),
+    PARAMETER24("eventJinJianAppCost", "sum(t1.charge)/sum(t1.event_jin_jian_app)"),
+    PARAMETER25("eventCreditGrantApp", "sum(event_credit_grant_app)"),
+    PARAMETER26("eventCreditGrantAppCost", "sum(t1.charge)/sum(t1.event_credit_grant_app)"),
+    PARAMETER27("formCount", "sum(t1.form_count)"),
+    PARAMETER28("formCountCost", "sum(t1.charge)/sum(t1.form_count)"),
+    PARAMETER29("nextDayOpen", "sum(t1.event_next_day_stay)"),
+    PARAMETER30("nextDayOpenCost", "sum(t1.charge)/sum(t1.event_next_day_stay)"),
+    PARAMETER31("eventJinJianLandingPage", "sum(t1.event_jin_jian_landing_page)"),
+    PARAMETER32("eventJinJianLandingPageCost", "sum(t1.charge)/sum(t1.event_jin_jian_landing_page)"),
+    PARAMETER33("eventCreditGrantLandingPage", "sum(t1.event_credit_grant_landing_page)"),
+    PARAMETER34("eventCreditGrantLandingPageCost", "sum(t1.charge)/sum(t1.event_credit_grant_landing_page)"),
+    PARAMETER35("submit", "sum(t1.submit)"),
+    PARAMETER36("submitCost", "sum(t1.charge)/sum(t1.submit)"),
+    PARAMETER37("totalBalance", "balance"),
+    PARAMETER38("budget", "day_budget");
+
+    private String value;
+    private String formula;
+
+    CheckParametersCostEnum(String value, String formula) {
+        this.value = value;
+        this.formula = formula;
+    }
+
+    public static String getFormula(String value) {
+        for (CheckParametersCostEnum campaignType : CheckParametersCostEnum.values()) {
+            if (campaignType.getValue().equals(value)) {
+                return campaignType.getFormula();
+            }
+        }
+        return "";
+    }
+
+    public static boolean isInclude(String key) {
+        boolean include = false;
+        for (CheckParametersCostEnum e : CheckParametersCostEnum.values()) {
+            if (e.getValue().equals(key)) {
+                include = true;
+                break;
+            }
+        }
+        return include;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getFormula() {
+        return formula;
+    }
+
+    public void setFormula(String formula) {
+        this.formula = formula;
+    }
+}

+ 23 - 4
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountDailyMapper.java

@@ -1,12 +1,13 @@
 package cn.com.ctop.kuaishou.modules.report.mapper;
 
-import java.util.List;
-
+import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly;
 import com.alibaba.fastjson.JSONObject;
-import org.apache.ibatis.annotations.Param;
-import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountDaily;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 盯盘日数据
@@ -26,4 +27,22 @@ public interface EtlKuaishouReportAccountDailyMapper extends BaseMapper<EtlKuais
     JSONObject getMaxChargeAccountId(@Param("userId") String userId);
 
     String getNewlyUpdateTime();
+
+    JSONObject getMonthlyRank(Map<String, Object> paramsMap);
+
+    List<JSONObject> accountPageList(JSONObject request);
+
+    int accountPageListTotal(JSONObject request);
+
+    List<JSONObject> queryEveryDayCharge(JSONObject request);
+
+    List<JSONObject> queryEveryDayCount(JSONObject request);
+
+    List<JSONObject> projectPageList(JSONObject request);
+
+    int projectPageListTotal(JSONObject request);
+
+    List<JSONObject> leaderAccountPageList(JSONObject request);
+
+    int leaderAccountPageListTotal(JSONObject request);
 }

+ 19 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouReportAccountHourlyMapper.java

@@ -22,7 +22,25 @@ public interface EtlKuaishouReportAccountHourlyMapper extends BaseMapper<EtlKuai
 
     EtlKuaishouReportAccountHourly getOnedayAggregateByHour(@Param("startTime") String startTime, @Param("accountId") Long accountId);
 
-    List<JSONObject> getOnedayEtlReportList(@Param("startTime") String startTime, @Param("accountId") Long accountId,@Param("value") String value,@Param("type") String type);
+    List<JSONObject> getOnedayEtlReportList(@Param("startTime") String startTime, @Param("accountId") Long accountId, @Param("value") String value, @Param("type") String type);
 
     String getNewlyUpdateTime();
+
+    List<JSONObject> accountPageList(JSONObject request);
+
+    int accountPageListTotal(JSONObject request);
+
+    List<JSONObject> queryEveryHourlyCharge(JSONObject request);
+
+    List<JSONObject> operatingStaffDataList(JSONObject request);
+
+    Integer operatingStaffDataListTotal(JSONObject request);
+
+    List<JSONObject> projectPageList(JSONObject request);
+
+    int projectPageListTotal(JSONObject request);
+
+    List<JSONObject> leaderAccountPageList(JSONObject request);
+
+    int leaderAccountPageListTotal(JSONObject request);
 }

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportHourlyAccountMapper.java

@@ -2,11 +2,13 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportHourlyAccount;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 public interface KuaishouReportHourlyAccountMapper extends BaseMapper<KuaishouReportHourlyAccount> {
     Integer selectMaxHour(@Param("accountId") Long accountId, @Param("statDate") String statDate);
@@ -16,4 +18,6 @@ public interface KuaishouReportHourlyAccountMapper extends BaseMapper<KuaishouRe
     void replaceBatch(@Param("addList") List<KuaishouReportHourlyAccount> addList);
 
     List<EtlKuaishouReportAccountHourly> queryEveryhourlyDataForAccount();
+
+    JSONObject queryPersonalAchievements(Map<String, Object> paramsMap);
 }

+ 262 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountDailyMapper.xml

@@ -269,9 +269,270 @@
     </select>
 
     <select id="getNewlyUpdateTime" resultType="java.lang.String">
-        select DATE_FORMAT(update_time,'%Y-%m-%d %H:%i:%s')
+        select DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%s')
         FROM ctop_etl_kuaishou_report_account_daily
         ORDER BY update_time desc LIMIT 1
     </select>
 
+    <select id="getMonthlyRank" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (
+                 SELECT @rownum:=@rownum+1 as id,t.*,
+        (SELECT COUNT(1) FROM(SELECT 1 FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT  JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE t1.stat_date &gt;= #{mStartDate}
+                     AND t1.stat_date &lt;= #{today}
+                     AND media_id =2
+                     GROUP BY user_id) t) as 'totle'
+                 FROM (
+                     SELECT sum(charge) as 'charge', t2.user_id 'userId' FROM ctop_etl_kuaishou_report_account_daily t1
+                     LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+                     WHERE t1.stat_date &gt;= #{mStartDate}
+                     AND t1.stat_date &lt;= #{today}
+                     AND media_id =2
+                     GROUP BY user_id
+                     ORDER BY SUM(charge) DESC
+                     ) t, (select @rownum := 0) a
+             ) tt
+        WHERE tt.userId = #{userId}
+    </select>
+
+    <select id="accountPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        '-' as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t4.week_charge)/t4.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t1.account_id 'accountId',
+        t2.auth_name as 'authName',
+        IFNULL(ROUND(play_3s_count / aclick * 100, 2), 0) as 'play3sRatio',
+        (select realname FROM sys_user where id = #{userId}) as 'realname',
+        IFNULL(t6.balance,0) as 'totalBalance',
+        IFNULL(t6.day_budget,0) as 'budget'
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_etl_kuaishou_report_account_daily i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date &gt;= DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND stat_date &lt;= DATE_SUB(#{endTime},INTERVAL 7 DAY)
+        AND i2.user_id = #{userId}
+        GROUP BY i1.account_id
+        ) t4 ON t2.account_id = t4.account_id
+        LEFT JOIN ctop_kuaishou_account_balance_budget t6 ON t6.account_id = t2.account_id
+        where stat_date &gt;= #{startTime}
+        AND stat_date &lt;= #{endTime}
+        AND t2.user_id = #{userId}
+        GROUP BY t2.account_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="accountPageListTotal" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1), 0)
+        from (
+                 SELECT t2.account_id
+                 FROM ctop_etl_kuaishou_report_account_daily t1
+                          LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+                 where stat_date &gt;= #{startTime}
+                   AND stat_date &lt;= #{endTime}
+                   AND t2.user_id = #{userId}
+                 GROUP BY t2.account_id
+             ) t
+    </select>
+
+    <select id="leaderAccountPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        '-' as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t4.week_charge)/t4.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t1.account_id 'accountId',
+        t2.auth_name as 'authName',
+        IFNULL(ROUND(play_3s_count / aclick * 100, 2), 0) as 'play3sRatio',
+        t5.realname,
+        IFNULL(t6.balance,0) as 'totalBalance',
+        IFNULL(t6.day_budget,0) as 'budget'
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_etl_kuaishou_report_account_daily i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date &gt;= DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND stat_date &lt;= DATE_SUB(#{endTime},INTERVAL 7 DAY)
+        <if test="userIds != null">
+            AND i2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND i2.project_id = #{projectId}
+        </if>
+        GROUP BY i1.account_id
+        ) t4 ON t2.account_id = t4.account_id
+        LEFT JOIN (
+        SELECT
+        id,realname
+        FROM
+        sys_user
+        WHERE 1=1
+        <if test="userIds != null">
+            and id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        ) t5 ON t2.user_id = t5.id
+        LEFT JOIN ctop_kuaishou_account_balance_budget t6 ON t6.account_id = t2.account_id
+        where stat_date &gt;= #{startTime}
+        AND stat_date &lt;= #{endTime}
+        <if test="userIds != null">
+            AND t2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND t2.project_id = #{projectId}
+        </if>
+        GROUP BY t2.account_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="leaderAccountPageListTotal" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1), 0)
+        from (
+        SELECT t2.account_id
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where stat_date &gt;= #{startTime}
+        AND stat_date &lt;= #{endTime}
+        <if test="userIds != null">
+            AND t2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND t2.project_id = #{projectId}
+        </if>
+        GROUP BY t2.account_id
+        ) t
+    </select>
+
+    <select id="queryEveryDayCharge" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL(stat_date,'') 'time',
+        IFNULL(SUM(charge),0) 'value'
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where stat_date &lt;=#{endTime}
+        and stat_date &gt;=#{startTime}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY stat_date
+        ORDER BY stat_date
+    </select>
+
+    <select id="queryEveryDayCount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL(stat_date,'') 'time',
+        IFNULL(SUM(new_count),0) 'value'
+        FROM ctop_etl_kuaishou_newly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where stat_date &lt;=#{endTime}
+        and stat_date &gt;=#{startTime}
+        AND new_type = #{parameterCode}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY stat_date
+        ORDER BY stat_date
+    </select>
+
+
+    <select id="projectPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        '-' as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t6.week_charge)/t6.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t2.project_id 'projectId',
+        t3.project_name as 'projectName',
+        IFNULL(ROUND(SUM(play_3s_count) / SUM(aclick) * 100, 2), 0) as 'play3sRatio',
+        (SELECT count(1) FROM ctop_user_allocation where project_id = t3.id) as 'accountCount',
+        IFNULL(t4.userCount,0) as 'userCount'
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
+        LEFT JOIN (
+        SELECT project_id,COUNT(1) 'userCount'
+        FROM (
+        SELECT DISTINCT project_id,user_id
+        FROM ctop_user_allocation
+        ) t
+        GROUP BY project_id
+        ) t4 ON t4.project_id = t3.id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_etl_kuaishou_report_account_daily i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where i1.stat_date &gt;= DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND i1.stat_date &lt;= DATE_SUB(#{endTime},INTERVAL 7 DAY)
+        AND i2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY i1.account_id
+        ) t6 ON t2.account_id = t6.account_id
+        where t1.stat_date &gt;= #{startTime}
+        AND t1.stat_date &lt;= #{endTime}
+        AND t2.user_id in
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t3.id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+
+    <select id="projectPageListTotal" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1),0) from
+        (
+        SELECT
+        t3.id
+        FROM ctop_etl_kuaishou_report_account_daily t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
+        where t1.stat_date &gt;= #{startTime}
+        AND t1.stat_date &lt;= #{endTime}
+        AND t2.user_id in
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t3.id
+        ) t
+    </select>
+
+
 </mapper>

+ 390 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouReportAccountHourlyMapper.xml

@@ -221,9 +221,398 @@
     </select>
 
     <select id="getNewlyUpdateTime" resultType="java.lang.String">
-        select DATE_FORMAT(update_time,'%Y-%m-%d %H:%i:%s')
+        select DATE_FORMAT(update_time, '%Y-%m-%d %H:%i:%s')
         FROM ctop_etl_kuaishou_report_account_hourly
         ORDER BY update_time desc LIMIT 1
     </select>
 
+    <select id="accountPageListTotal" resultType="java.lang.Integer">
+        select IFNULL(SUM(1), 0)
+        from (
+                 SELECT t2.account_id
+                 FROM ctop_etl_kuaishou_report_account_hourly t1
+                          LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+                 where stat_date = #{startTime}
+                   AND t2.user_id = #{userId}
+                 GROUP BY t2.account_id
+             ) t
+    </select>
+
+    <select id="accountPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t3.y_charge)/t3.y_charge*100,3)as CHAR),'%'),'0%') as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t4.week_charge)/t4.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t1.account_id 'accountId',
+        t2.auth_name as 'authName',
+        IFNULL(ROUND(SUM(play_3s_count) / SUM(aclick) * 100, 2), 0) as 'play3sRatio',
+        (select realname FROM sys_user where id = #{userId}) as 'realname',
+        IFNULL(t6.balance,0) as 'totalBalance',
+        IFNULL(t6.day_budget,0) as 'budget'
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'y_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 1 DAY)
+        AND stat_hour &lt;= #{hours}
+        AND i2.user_id = #{userId}
+        GROUP BY i1.account_id
+        ) t3 ON t2.account_id = t3.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND stat_hour &lt;= #{hours}
+        AND i2.user_id = #{userId}
+        GROUP BY i1.account_id
+        ) t4 ON t2.account_id = t4.account_id
+        LEFT JOIN ctop_kuaishou_account_balance_budget t6 ON t6.account_id = t2.account_id
+        where stat_date = #{startTime}
+        AND t2.user_id = #{userId}
+        GROUP BY t2.account_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="leaderAccountPageListTotal" resultType="java.lang.Integer">
+        select IFNULL(SUM(1),0)
+        from (
+        SELECT
+        t2.account_id
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where stat_date = #{startTime}
+        <if test="userIds != null">
+            AND t2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND t2.project_id = #{projectId}
+        </if>
+        GROUP BY t2.account_id
+        ) t
+    </select>
+
+    <select id="leaderAccountPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t3.y_charge)/t3.y_charge*100,3)as CHAR),'%'),'0%') as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t4.week_charge)/t4.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t1.account_id 'accountId',
+        t2.auth_name as 'authName',
+        IFNULL(ROUND(SUM(play_3s_count) / SUM(aclick) * 100, 2), 0) as 'play3sRatio',
+        t5.realname,
+        IFNULL(t6.balance,0) as 'totalBalance',
+        IFNULL(t6.day_budget,0) as 'budget'
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'y_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 1 DAY)
+        AND stat_hour &lt;= #{hours}
+        <if test="userIds != null">
+            AND i2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND i2.project_id = #{projectId}
+        </if>
+        GROUP BY i1.account_id
+        ) t3 ON t2.account_id = t3.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND stat_hour &lt;= #{hours}
+        <if test="userIds != null">
+            AND i2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND i2.project_id = #{projectId}
+        </if>
+        GROUP BY i1.account_id
+        ) t4 ON t2.account_id = t4.account_id
+        LEFT JOIN (
+        SELECT
+        id,realname
+        FROM
+        sys_user
+        WHERE 1=1
+        <if test="userIds != null">
+            and id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        ) t5 ON t2.user_id = t5.id
+        LEFT JOIN ctop_kuaishou_account_balance_budget t6 ON t6.account_id = t2.account_id
+        where stat_date = #{startTime}
+        <if test="userIds != null">
+            AND t2.user_id IN
+            <foreach item="id" index="index" collection="userIds"
+                     open="(" separator="," close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test="projectId != null">
+            AND t2.project_id = #{projectId}
+        </if>
+        GROUP BY t2.account_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="queryEveryHourlyCharge" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL(stat_hour,'') 'time',
+        IFNULL(SUM(charge),0) 'value'
+        FROM ctop_kuaishou_report_hourly_account t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        where stat_date = #{startTime}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY stat_hour
+        ORDER BY stat_hour
+    </select>
+
+    <select id="operatingStaffDataListTotal" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1),0)
+        FROM (
+        SELECT 1
+        FROM ctop_kuaishou_report_hourly_account t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE stat_date = #{today}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t2.user_id
+        ) t
+    </select>
+
+    <select id="operatingStaffDataList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL(t9.realname,'') 'realName',
+        IFNULL(t3.accountCount,0) 'accountCount',
+        IFNULL(SUM(t1.charge),0) 'charge',
+        IFNULL(t4.weekCharge,0) 'weekCharge',
+        IFNULL(ROUND((t4.weekCharge-t5.lweekCharge)/t5.lweekCharge*100,2), 0)as 'grew',
+        IFNULL(t6.effectiveCount,0) 'effectiveCount',
+        IFNULL(t7.campaignCount,0) 'campaignCount',
+        IFNULL(t8.unitCount,0) 'unitCount'
+        FROM
+        ctop_kuaishou_report_hourly_account t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT user_id,COUNT(1) 'accountCount' FROM ctop_user_allocation WHERE user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY user_id
+        ) t3 ON t2.user_id = t3.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(charge) 'weekCharge',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_report_account_daily tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &lt;=#{today}
+        and tt1.stat_date &gt;=#{weekStartTime}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t4 ON t2.user_id = t4.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(charge) 'lweekCharge',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_report_account_daily tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date &lt;=#{lweekEndTime}
+        and tt1.stat_date &gt;=#{lweekStartTime}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t5 ON t2.user_id = t5.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(effective_count) 'effectiveCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_account_material_overview tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.state_date = #{yesterday}
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t6 ON t2.user_id = t6.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(new_count) 'campaignCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_newly tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date = #{yesterday}
+        AND tt1.new_type = 'campaign'
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t7 ON t2.user_id = t7.user_id
+        LEFT JOIN (
+        SELECT
+        SUM(new_count) 'unitCount',
+        tt2.user_id
+        FROM
+        ctop_etl_kuaishou_newly tt1
+        LEFT JOIN ctop_user_allocation tt2 ON tt1.account_id = tt2.account_id
+        WHERE tt1.stat_date = #{yesterday}
+        AND tt1.new_type = 'unit'
+        AND tt2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY tt2.user_id
+        ) t8 ON t2.user_id = t8.user_id
+        LEFT JOIN (
+        SELECT
+        id,realname
+        FROM
+        sys_user
+        WHERE id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        ) t9 ON t2.user_id = t9.id
+        WHERE
+        t1.stat_date = #{today}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t2.user_id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="projectPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed},
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t5.y_charge)/t5.y_charge*100,3)as CHAR),'%'),'0%') as 'grewRatio',
+        IFNULL(CONCAT(CAST(ROUND((SUM(charge)-t6.week_charge)/t6.week_charge*100,3)as CHAR),'%'),'0%') as
+        'weekGrewRatio',
+        t3.project_name as 'projectName',
+        IFNULL(ROUND(SUM(play_3s_count) / SUM(aclick) * 100, 2), 0) as 'play3sRatio',
+        (SELECT count(1) FROM ctop_user_allocation where project_id = t3.id) as 'accountCount',
+        IFNULL(t4.userCount,0) as 'userCount'
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
+        LEFT JOIN (
+        SELECT project_id,COUNT(1) 'userCount'
+        FROM (
+        SELECT DISTINCT project_id,user_id
+        FROM ctop_user_allocation
+        ) t
+        GROUP BY project_id
+        ) t4 ON t4.project_id = t3.id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'y_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 1 DAY)
+        AND stat_hour &lt;= #{hours}
+        AND i2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY i1.account_id
+        ) t5 ON t2.account_id = t5.account_id
+        LEFT JOIN(
+        SELECT i1.account_id,SUM(charge) as 'week_charge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        where stat_date = DATE_SUB(#{startTime},INTERVAL 7 DAY)
+        AND stat_hour &lt;= #{hours}
+        AND i2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY i1.account_id
+        ) t6 ON t2.account_id = t6.account_id
+        where stat_date = #{startTime}
+        AND t2.user_id IN
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t3.id
+        <if test="sortCode != '' and sortCode != null ">
+            ORDER BY ${sortCode}
+        </if>
+        ${sortType}
+    </select>
+
+    <select id="projectPageListTotal" resultType="java.lang.Integer">
+        select IFNULL(SUM(1),0) from
+        (
+        SELECT
+        t3.id
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
+        where stat_date = #{startTime}
+        AND t2.user_id in
+        <foreach item="id" index="index" collection="userIds"
+                 open="(" separator="," close=")">
+            #{id}
+        </foreach>
+        GROUP BY t3.id
+        )t
+    </select>
+
+
 </mapper>

+ 38 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportHourlyAccountMapper.xml

@@ -175,4 +175,42 @@
         GROUP BY account_id
     </select>
 
+
+    <select id="queryPersonalAchievements" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        IFNULL((SELECT realname from sys_user WHERE id = #{userId}),'') as 'realName',
+        IFNULL(SUM(charge),0) 'charge',
+        IFNULL(ROUND((SUM(charge)-t3.zcharge)/t3.zcharge*100,2),0) 'grew',
+        IFNULL(t4.weekCharge,0) 'weekCharge',
+        IFNULL(t5.lweekCharge,0) 'lweekCharge',
+        IFNULL(ROUND((t4.weekCharge-t5.lweekCharge)/t5.lweekCharge*100,2),0) 'weekGrew',
+        IFNULL((SELECT count(1) FROM ctop_user_allocation where user_id = #{userId} AND account_status = 0),0) 'accouuntCount'
+        FROM ctop_etl_kuaishou_report_account_hourly t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        LEFT JOIN(
+        SELECT SUM(charge) 'zcharge' FROM ctop_kuaishou_report_hourly_account i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        WHERE i2.user_id = #{userId}
+        AND i1.stat_date = #{today}
+        AND i1.stat_hour  &lt;= DATE_FORMAT(now(), '%H')
+        ) t3 ON 1=1
+        LEFT JOIN(
+        SELECT SUM(charge) 'weekCharge' FROM ctop_etl_kuaishou_report_account_daily i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        WHERE i2.user_id = #{userId}
+        AND i1.stat_date &gt;= #{startDate}
+        AND i1.stat_date  &lt;= #{today}
+        ) t4 ON 1=1
+        LEFT JOIN(
+        SELECT SUM(charge) 'lweekCharge' FROM ctop_etl_kuaishou_report_account_daily i1
+        LEFT JOIN ctop_user_allocation i2 ON i1.account_id = i2.account_id
+        WHERE i2.user_id = #{userId}
+        AND i1.stat_date &gt;= #{lastStartDate}
+        AND i1.stat_date  &lt;= #{lastEndDate}
+        ) t5 ON 1=1
+        WHERE t2.user_id = #{userId}
+        AND t1.stat_date = #{today}
+        AND t1.stat_hour = DATE_FORMAT(now(), '%H')
+    </select>
+
 </mapper>

+ 14 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IEtlKuaishouReportAccountHourlyService.java

@@ -25,4 +25,18 @@ public interface IEtlKuaishouReportAccountHourlyService extends IService<EtlKuai
     Result<Object> getMaxChargeAccountId(Long accountId);
 
     Result<Object> getMaxChargeAccountIdByUser(String userId);
+
+    Result<Object> queryPersonalAchievements(String userId);
+
+    Result<Object> checkRole(String userId);
+
+    Result<Object> accountPageList(JSONObject request) throws Exception;
+
+    Result<Object> queryNewlyData(JSONObject request);
+
+    Result<Object> operatingStaffDataList(JSONObject request);
+
+    Result<Object> projectList(JSONObject request) throws Exception;
+
+    Result<Object> leaderAccountPageList(JSONObject request) throws Exception;
 }

+ 367 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouReportAccountHourlyServiceImpl.java

@@ -2,13 +2,18 @@ package cn.com.ctop.kuaishou.modules.report.service.impl;
 
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.SysRole;
 import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.SysDepartMapper;
+import cn.com.ctop.common.module.mapper.SysRoleMapper;
+import cn.com.ctop.common.module.mapper.SysUserDepartMapper;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreativeMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouReportAccountHourly;
+import cn.com.ctop.kuaishou.modules.report.enums.CheckParametersCostEnum;
 import cn.com.ctop.kuaishou.modules.report.enums.CheckParametersEnum;
 import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouReportAccountDailyMapper;
 import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouReportAccountHourlyMapper;
@@ -16,11 +21,16 @@ import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyAccountMap
 import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouReportAccountHourlyService;
 import com.alibaba.fastjson.JSONObject;
 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.common.constant.AccountReportConstants;
 import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.JsonResourceUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.ParseException;
@@ -29,7 +39,9 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 账户维度-每小时盯盘数据
@@ -57,6 +69,12 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
     private EtlKuaishouReportAccountDailyMapper etlDailyAccountMapper;
     @Autowired
     private ICtopOauthTokenService oauthTokenService;
+    @Resource
+    private SysDepartMapper departMapper;
+    @Resource
+    private SysUserDepartMapper sysUserDepartMapper;
+    @Resource
+    private SysRoleMapper roleMapper;
 
     @Override
     public void queryEveryhourlyDataForAccount() {
@@ -274,10 +292,357 @@ public class EtlKuaishouReportAccountHourlyServiceImpl extends ServiceImpl<EtlKu
             result.setMessage("未获取到账户信息");
             return result;
         }
+        obj.put("totalBalance", getBalance(oauthToken));
+        return Result.ok(obj);
+    }
+
+    private BigDecimal getBalance(CtopOauthToken oauthToken) {
         JSONObject fundJson = iKuaishouInterfaceService.fundGet(oauthToken);
         if (!Check.isNull(fundJson)) {
-            obj.put("totalBalance", fundJson.getBigDecimal("balance")); // 余额
+            return fundJson.getBigDecimal("balance"); // 余额
+        }
+        return new BigDecimal(0);
+    }
+
+    /**
+     * 运营盯盘,---------个人绩效
+     */
+    @Override
+    public Result<Object> queryPersonalAchievements(String userId) {
+        SysRole role = roleMapper.queryRoleByUserId(userId);
+        //TODO
+//        if (roleName.contains("总监") || roleName.contains("经理")) {
+//
+//        }
+//        if (roleName.contains("管理员")) {
+//
+//        }
+        Map<String, Object> paramsMap = new HashMap<>();
+        //本周一
+        String monday = DateUtils.getdateFromWeek(1);
+        //当天日期
+        String today = DateUtils.formatDate(new Date());
+        //上周一日期
+        String lastStartDate = DateUtils.getLastDay(monday, 7);
+        //上周当天日期
+        String lastEndDate = DateUtils.getLastDay(today, 7);
+        paramsMap.put("lastStartDate", lastStartDate);
+        paramsMap.put("lastEndDate", lastEndDate);
+        paramsMap.put("startDate", monday);
+        paramsMap.put("today", today);
+        paramsMap.put("userId", userId);
+        JSONObject data = hourlyAccountMapper.queryPersonalAchievements(paramsMap);
+        if (!Check.isNull(data)) {
+            Integer totle = 0;
+            Integer rank = 0;
+            paramsMap.put("mStartDate", DateUtils.dateformat(DateUtils.initDateByMonth(), DateUtils.WEB_FORMAT));
+            JSONObject user = etlDailyAccountMapper.getMonthlyRank(paramsMap);
+            if (!Check.isNull(user)) {
+                totle = user.getInteger("totle");
+                rank = user.getInteger("id");
+                data.put("monthCharge", user.getBigDecimal("charge"));
+            }
+            data.put("total", totle);
+            data.put("rank", rank);
+        }
+        return Result.ok(data);
+    }
+
+    @Override
+    public Result<Object> checkRole(String userId) {
+        SysRole role = roleMapper.queryRoleByUserId(userId);
+        if (Check.isNull(role)) {
+            return Result.error("员工未划分角色");
+        }
+        boolean flag = false;
+        String roleCode = role.getRoleCode();
+        //TODO 后续去除 roleName相关的逻辑
+        String roleName = role.getRoleName();
+        if (roleName.contains("总监") || roleName.contains("经理") || roleName.contains("管理员")
+                || "genera_manager_of_operations".equals(roleCode)
+                || "kuaishou_operations_director".equals(roleCode)
+                || "kuaishou_operations_manager".equals(roleCode)) {
+            flag = true;
+        }
+        return Result.ok(flag);
+    }
+
+    @Override
+    public Result<Object> accountPageList(JSONObject request) throws Exception {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        String userId = request.getString("userId");
+        if (Check.isNull(startTime) && Check.isNull(userId)) {
+            return Result.error("请选择时间和用户");
+        }
+        //参数处理
+        configParameter(request);
+        List<JSONObject> list = null;
+        int total = 0;
+        //单日数据
+        if (endTime.equals(startTime)) {
+            if (startTime.equals(DateUtils.formatDate(new Date()))) {
+                request.put("hours", DateUtils.getNowHour());
+            } else {
+                request.put("hours", 24);
+            }
+            total = etlHourlyAccountMapper.accountPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlHourlyAccountMapper.accountPageList(request);
+        } else {
+            //多日数据
+            total = etlDailyAccountMapper.accountPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlDailyAccountMapper.accountPageList(request);
+        }
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
+        if (!Check.isNull(pageInfo)) {
+            pageInfo.setTotal(total);
+        }
+        return Result.ok(pageInfo);
+    }
+
+    /**
+     * 配置参数
+     */
+    private void configParameter(JSONObject request) throws Exception {
+        Map<String, Map<String, Object>> parameter = AccountReportConstants.dicMapKs;
+        parameter.remove("play3sRate");
+        String filedAll = JsonResourceUtil.joinAllFiled(parameter);
+        if (Check.isNull(filedAll)) {
+            throw new Exception("初始化查询字段,结果为空");
+        }
+        request.put("filed", filedAll);
+        String sortCode = request.getString("sortCode");
+        if (Check.isNull(sortCode)) {
+            request.put("sortCode", "sum(charge)");
+        } else {
+            request.put("sortCode", CheckParametersCostEnum.getFormula(sortCode));
+        }
+        if (Check.isNull(request.getString("sortType"))) {
+            request.put("sortType", "DESC");
+        }
+    }
+
+
+    @Override
+    public Result<Object> queryNewlyData(JSONObject request) {
+        String userId = request.getString("userId");
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        String parameterCode = request.getString("parameterCode");
+        if (Check.isNull(userId) || Check.isNull(startTime) || Check.isNull(endTime) || Check.isNull(parameterCode)) {
+            return Result.error("缺失参数");
+        }
+        request.put("userIds", getUserIdList(userId));
+        List<JSONObject> data = null;
+        //单日数据
+        if (startTime.equals(endTime)) {
+            data = etlHourlyAccountMapper.queryEveryHourlyCharge(request);
+        } else {
+            if (parameterCode.equals("campaign") || parameterCode.equals("unit")) {
+                data = etlDailyAccountMapper.queryEveryDayCount(request);
+            } else {
+                data = etlDailyAccountMapper.queryEveryDayCharge(request);
+            }
+        }
+        return Result.ok(data);
+    }
+
+    /**
+     * 通过经理或者总监userId,获取其部门的员工Id
+     */
+    private List<String> getUserIdList(String userId) {
+        SysRole role = roleMapper.queryRoleByUserId(userId);
+        String roleCode = role.getRoleCode();
+        List<String> ids = new ArrayList<>();
+        List<JSONObject> departIds = new ArrayList<>();
+        //管理员和运营总经理 可以查看所有快手的运营信息
+        if ("genera_manager_of_operations".equals(roleCode) || "admin".equals(roleCode)) {
+            JSONObject obj = new JSONObject();
+            //快手运营部 峰级部门 ID
+            obj.put("id", "024b0dc0840045afb048022a8c61253f");
+            departIds.add(obj);
+        } else {
+            departIds = departMapper.getDepartmentIds(userId);
+        }
+        if (!Check.isNull(departIds)) {
+            ids.add(departIds.get(0).getString("id"));
+            checkDepart(departIds, ids);
+        }
+        List<String> userIds = null;
+        if (!Check.isNull(ids)) {
+            userIds = sysUserDepartMapper.getUserIds(ids);
+        }
+        if (Check.isNull(userIds)) {
+            userIds = new ArrayList<>();
+            userIds.add(userId);
+        }
+        return userIds;
+    }
+
+    @Override
+    public Result<Object> operatingStaffDataList(JSONObject request) {
+        String userId = request.getString("userId");
+        if (Check.isNull(userId)) {
+            return Result.error("缺少账户入参");
+        }
+        String sortCode = request.getString("sortCode");
+        if (Check.isNull(sortCode)) {
+            request.put("sortCode", "SUM(t1.charge)");
+        } else {
+            if ("charge".equals(sortCode)) {
+                request.put("sortCode", "SUM(t1.charge)");
+            }
+        }
+        if (Check.isNull(request.getString("sortType"))) {
+            request.put("sortType", "DESC");
+        }
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        //本周一
+        String weekStartTime = DateUtils.getdateFromWeek(1);
+        //当天日期
+        String today = DateUtils.formatDate(new Date());
+        //上周一日期
+        String lweekStartTime = DateUtils.getLastDay(weekStartTime, 7);
+        //上周当天日期
+        String lweekEndTime = DateUtils.getLastDay(today, 7);
+        //昨天
+        String yesterday = DateUtils.getLastDay(today, 1);
+        request.put("today", today);
+        request.put("weekStartTime", weekStartTime);
+        request.put("lweekEndTime", lweekEndTime);
+        request.put("lweekStartTime", lweekStartTime);
+        request.put("yesterday", yesterday);
+        //获取人群集
+        request.put("userIds", getUserIdList(userId));
+        int totle = etlHourlyAccountMapper.operatingStaffDataListTotal(request);
+        PageHelper.startPage(pageNo, pageSize, false);
+        PageInfo pageInfo = new PageInfo(etlHourlyAccountMapper.operatingStaffDataList(request));
+        if (!Check.isNull(pageInfo)) {
+            pageInfo.setTotal(totle);
+        }
+        return Result.ok(pageInfo);
+    }
+
+    @Override
+    public Result<Object> projectList(JSONObject request) throws Exception {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        String userId = request.getString("userId");
+        if (Check.isNull(startTime) && Check.isNull(userId)) {
+            return Result.error("请选择时间和用户");
+        }
+        //参数处理
+        configParameter(request);
+        //获取人群集
+        request.put("userIds", getUserIdList(userId));
+        List<JSONObject> list = null;
+        int total = 0;
+        //单日数据
+        if (endTime.equals(startTime)) {
+            if (startTime.equals(DateUtils.formatDate(new Date()))) {
+                request.put("hours", DateUtils.getNowHour());
+            } else {
+                request.put("hours", 24);
+            }
+            total = etlHourlyAccountMapper.projectPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlHourlyAccountMapper.projectPageList(request);
+        } else {
+            //多日数据
+            total = etlDailyAccountMapper.projectPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlDailyAccountMapper.projectPageList(request);
+        }
+
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
+        if (!Check.isNull(pageInfo)) {
+            pageInfo.setTotal(total);
+        }
+        return Result.ok(pageInfo);
+    }
+
+    @Override
+    public Result<Object> leaderAccountPageList(JSONObject request) throws Exception {
+        Integer pageNo = request.getInteger("pageNo");
+        Integer pageSize = request.getInteger("pageSize");
+        if (Check.isNull(pageNo)) {
+            pageNo = 1;
+        }
+        if (Check.isNull(pageSize)) {
+            pageSize = 10;
+        }
+        String startTime = request.getString("startTime");
+        String endTime = request.getString("endTime");
+        String userId = request.getString("userId");
+        if (Check.isNull(startTime) && Check.isNull(userId)) {
+            return Result.error("请选择时间和用户");
+        }
+        //参数处理
+        configParameter(request);
+        List<JSONObject> list = null;
+        int total = 0;
+        if (Check.isNull(request.getLong("projectId"))) {
+            //获取人群集
+            request.put("userIds", getUserIdList(userId));
+        }
+        //单日数据
+        if (endTime.equals(startTime)) {
+            if (startTime.equals(DateUtils.formatDate(new Date()))) {
+                request.put("hours", DateUtils.getNowHour());
+            } else {
+                request.put("hours", 24);
+            }
+            total = etlHourlyAccountMapper.leaderAccountPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlHourlyAccountMapper.leaderAccountPageList(request);
+        } else {
+            //多日数据
+            total = etlDailyAccountMapper.leaderAccountPageListTotal(request);
+            PageHelper.startPage(pageNo, pageSize, false);
+            list = etlDailyAccountMapper.leaderAccountPageList(request);
+        }
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
+        if (!Check.isNull(pageInfo)) {
+            pageInfo.setTotal(total);
+        }
+        return Result.ok(pageInfo);
+    }
+
+    /**
+     * 递归查询出所有部门
+     */
+    private void checkDepart(List<JSONObject> departIds, List<String> ids) {
+        for (JSONObject depart : departIds) {
+            ids.add(depart.getString("id"));
+        }
+        departIds = departMapper.checkLowestLevelDepartment(departIds);
+        if (!Check.isNull(departIds)) {
+            checkDepart(departIds, ids);
         }
-        return Result.ok(obj);
     }
 }

+ 2 - 2
module-kuaishou/src/main/resources/json_template/kuaishou_filed_mapping.json

@@ -84,7 +84,7 @@
     "comment": "首日付费成本"
   },
   "firstDayPayROI": {
-    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge) IS NULL THEN 0 ELSE sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge) end AS firstDayPayROI ",
+    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge) IS NULL THEN '0%' ELSE concat(CAST(round(sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge)*100,2) AS CHAR) ,'%') end AS firstDayPayROI ",
     "comment": "首日ROI"
   },
   "eventPay": {
@@ -100,7 +100,7 @@
     "comment": "付费次数成本"
   },
   "ROI": {
-    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount) / sum(t1.charge) IS NULL THEN 0 ELSE sum(t1.event_pay_purchase_amount) / sum(t1.charge) end AS ROI ",
+    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount) / sum(t1.charge) IS NULL THEN '0%' ELSE concat(CAST(round(sum(t1.event_pay_purchase_amount) / sum(t1.charge)*100,2) AS CHAR) ,'%') end AS ROI ",
     "comment": "ROI"
   },
   "register": {