Browse Source

Merge remote-tracking branch 'origin/test' into test

zhaoxian 3 years ago
parent
commit
45d17c4e1a

+ 10 - 1
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 
 
 import java.beans.PropertyEditorSupport;
 import java.beans.PropertyEditorSupport;
+import java.math.BigDecimal;
 import java.sql.SQLOutput;
 import java.sql.SQLOutput;
 import java.sql.Timestamp;
 import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.DateFormat;
@@ -1982,7 +1983,15 @@ public class DateUtils extends PropertyEditorSupport {
        /* Double  a = 3.268890;
        /* Double  a = 3.268890;
         System.out.println(String.format("%.3f", a));
         System.out.println(String.format("%.3f", a));
 */
 */
-        System.out.println(DateUtils.addDayParse("20220224",-1));
+        //System.out.println(DateUtils.addDayParse("20220224",-1));
+
+        long groupNum = 7516;
+        double yesNum = 55690;
+
+        //BigDecimal unitRatio = BigDecimal.valueOf((groupNum - yesNum) / yesNum).multiply(new BigDecimal(100));
+        //System.out.println(unitRatio);
+
+        System.out.println(getFirstDayByMonth());;
 
 
     }
     }
 
 

+ 49 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/KuaiShouMaterialStareController.java

@@ -233,6 +233,53 @@ public class KuaiShouMaterialStareController {
 
 
 
 
 
 
+
+    /**
+     *
+     * @description:数据总览-快手-运营个人
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @author: zianY
+     * @time: 2022/2/15
+     */
+    @GetMapping("/kuaiShousumDataPersonal")
+    public Result<JSONObject> kuaiShousumDataPersonal(@RequestParam(name="mediaType",defaultValue = "2") String mediaType,
+                                              @RequestParam(name="startTime") String startTime,
+                                              @RequestParam(name="endTime") String endTime,
+                                              @RequestParam(name="userId") String userId) {
+        return materialStareService.kuaiShousumDataPersonal(mediaType, startTime, endTime, userId);
+    }
+
+
+    /**
+     *
+     * @description: 运营个人数据
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/3/3
+     */
+    @GetMapping("/kuaiShouOperateDateTotalPersonal")
+    public Result<JSONObject> kuaiShouOperateDateTotalPersonal(@RequestParam(name="mediaType") String mediaType,
+                                                       @RequestParam(name="startTime") String startTime,
+                                                       @RequestParam(name="endTime") String endTime,
+                                                       @RequestParam(name="userId") String userId) {
+
+        return materialStareService.kuaiShouOperateDateTotalPersonal(mediaType, startTime, endTime, userId);
+    }
+
+
+
+
+
+
     //获取当前用户所属公司的所有下级
     //获取当前用户所属公司的所有下级
     @GetMapping("/getCompanyAllSubordinateByUserId")
     @GetMapping("/getCompanyAllSubordinateByUserId")
     public Result getCompanyAllSubordinateByUserId(@RequestParam(name="userId") String userId) {
     public Result getCompanyAllSubordinateByUserId(@RequestParam(name="userId") String userId) {
@@ -248,4 +295,6 @@ public class KuaiShouMaterialStareController {
 
 
 
 
 
 
+
+
 }
 }

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

@@ -16,6 +16,8 @@ import java.util.Set;
 public interface MaterialStareMapper {
 public interface MaterialStareMapper {
 
 
 
 
+    String getRoleCodeByUserId(@Param("userId") String userId);
+    Set<String> getCompanyAllUserId(@Param("companyId") String companyId);
     String getUserCompanyByUserId(@Param("userId")String userId);
     String getUserCompanyByUserId(@Param("userId")String userId);
     Set<String> getAffiliateId(@Param("leaderId")String leaderId,@Param("companyId")String companyId);
     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> querySubordinateRecursive(@Param("companyId")String companyId,@Param("leaderIds")Set<String> leaderIds);
@@ -34,6 +36,8 @@ public interface MaterialStareMapper {
 
 
     //快手 时报总消耗
     //快手 时报总消耗
     JSONObject getKuaiShouTotalCost(@Param("startDate")Long startDate,@Param("endDate")Long endDate, @Param("nowHour")int nowHour, @Param("list")Set<String> operatorUserIds);
     JSONObject getKuaiShouTotalCost(@Param("startDate")Long startDate,@Param("endDate")Long endDate, @Param("nowHour")int nowHour, @Param("list")Set<String> operatorUserIds);
+    //快手 日报总消耗
+    JSONObject getKuaiShouTotalCostDaily(@Param("startDate")Long startDate,@Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
 
 
     //快手-查询账户数据信息
     //快手-查询账户数据信息
     List<KuaiShouOperateVo> getKuaiShouOperateInfo(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
     List<KuaiShouOperateVo> getKuaiShouOperateInfo(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
@@ -68,6 +72,15 @@ public interface MaterialStareMapper {
     List<KuaiShouAccountPieVo> getKuaiShouAccountPieGender(@Param("accountId")Long accountId, @Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("type")String type);
     List<KuaiShouAccountPieVo> getKuaiShouAccountPieGender(@Param("accountId")Long accountId, @Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("type")String type);
 
 
 
 
+    //快手 账户 框返 激励 消耗
+    JSONObject getKuaiShouAccountCharged(@Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("list")Set<String> operatorUserIds);
+
+    //快手 运营 组内消耗 排名
+    List<JSONObject> getKuaiShouPersonalGroupRank(@Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("companyId")String companyId);
+
+
+
+
 
 
 
 
 
 

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

@@ -5,7 +5,7 @@
     <!-- 快手 时报  -->
     <!-- 快手 时报  -->
     <select id="getKuaiShouCostHourlyByUserIdList" resultType="Map">
     <select id="getKuaiShouCostHourlyByUserIdList" resultType="Map">
         SELECT
         SELECT
-        t.`hour`,
+        CONCAT(t.`hour`,':00') `hour`,
         ROUND( SUM( charge ), 2 ) AS totalCost
         ROUND( SUM( charge ), 2 ) AS totalCost
         FROM
         FROM
         application.kuaishou_account_report_hourly_dw t
         application.kuaishou_account_report_hourly_dw t
@@ -110,7 +110,6 @@
         <if test="nowHour != null and nowHour != '' ">
         <if test="nowHour != null and nowHour != '' ">
             AND hour &lt;= #{nowHour}
             AND hour &lt;= #{nowHour}
         </if>
         </if>
-
         <if test='list!=null'>
         <if test='list!=null'>
             AND user_id IN
             AND user_id IN
             <foreach collection="list" item="item" separator=","
             <foreach collection="list" item="item" separator=","
@@ -118,7 +117,30 @@
                 #{item}
                 #{item}
             </foreach>
             </foreach>
         </if>
         </if>
+    </select>
 
 
+
+    <!-- 快手 日报总消耗 及 账户数量 -->
+    <select id="getKuaiShouTotalCostDaily" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ROUND( SUM( charge ), 2 ) AS totalCost,
+        COUNT(DISTINCT account_id) accountNum
+        FROM
+        application.kuaishou_account_report_daily_dw
+        where 1 = 1
+        <if test="startDate != null and startDate != '' ">
+            and stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and stat_date &lt;= #{endDate}
+        </if>
+        <if test='list!=null'>
+            AND user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
     </select>
     </select>
 
 
 
 
@@ -644,6 +666,59 @@
 
 
 
 
 
 
+    <!-- 快手 账户 框返 激励 消耗 -->
+    <select id="getKuaiShouAccountCharged" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ROUND( SUM( total_charged_in_yuan ), 2 ) AS totalCost,
+        ROUND( SUM( direct_rebate_real_charged_in_yuan ), 2 ) AS directCharged,
+        ROUND( SUM( contract_rebate_real_charged_in_yuan ), 2 ) AS contractCharged
+        FROM application.app_kuaishou_agent_report_d
+        <where>
+            <if test="startDate != null and startDate != '' ">
+                and stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and stat_date &lt;= #{endDate}
+            </if>
+            <if test='list!=null'>
+                AND user_id IN
+                <foreach collection="list" item="item" separator=","
+                         open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
+
+
+    <!-- 快手 运营 组内消耗 排名 -->
+    <select id="getKuaiShouPersonalGroupRank" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ROW_NUMBER() OVER ( ORDER BY SUM( total_charged_in_yuan ) DESC ) AS serialNumber,
+        ROUND( SUM( total_charged_in_yuan ), 2 ) AS totalCost,
+        user_id,
+        user_name
+        FROM
+        application.app_kuaishou_agent_report_d
+        <where>
+            <if test="startDate != null and startDate != '' ">
+                and stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and stat_date &lt;= #{endDate}
+            </if>
+            <if test="companyId != null and companyId != '' ">
+                and company_id = #{companyId}
+            </if>
+        </where>
+        GROUP BY user_id
+        ORDER BY totalCost DESC
+    </select>
+
+
+
+
+
 
 
 
 
 
 
@@ -651,7 +726,23 @@
 
 
 
 
 
 
+    <select id="getRoleCodeByUserId" resultType="java.lang.String">
+        select c.role_code
+        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}
+            LIMIT 1
+    </select>
 
 
+    <select id="getCompanyAllUserId" resultType="java.lang.String">
+        SELECT DISTINCT
+            user_id
+        FROM
+            user_company
+        WHERE
+            company_id = #{companyId}
+    </select>
 
 
     <select id="getUserCompanyByUserId" resultType="java.lang.String">
     <select id="getUserCompanyByUserId" resultType="java.lang.String">
         SELECT
         SELECT

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

@@ -12,8 +12,12 @@ public interface MaterialStareService {
 
 
     Result kuaiShousumData(String mediaType, String type, String startTime, String endTime, String userId);
     Result kuaiShousumData(String mediaType, String type, String startTime, String endTime, String userId);
 
 
+    Result kuaiShousumDataPersonal(String mediaType, String startTime, String endTime, String userId);
+
     Result kuaiShouOperateDateTotal(String mediaType,String startTime, String endTime, String userId);
     Result kuaiShouOperateDateTotal(String mediaType,String startTime, String endTime, String userId);
 
 
+    Result kuaiShouOperateDateTotalPersonal(String mediaType,String startTime, String endTime, String userId);
+
     Result getKuaiShouOperateInfo(Integer pageNum,int pageSize,String startTime, String endTime, String userId);
     Result getKuaiShouOperateInfo(Integer pageNum,int pageSize,String startTime, String endTime, String userId);
     Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response);
     Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response);
 
 

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

@@ -47,7 +47,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
 
     /**
     /**
      *
      *
-     * @description:数据总览-快手
+     * @description:数据总览-快手-运营经理
      *
      *
      * @param mediaType 媒体类型 1-头条 2-快手
      * @param mediaType 媒体类型 1-头条 2-快手
      * @param type 查询类型 1-汇总 2-运营个人
      * @param type 查询类型 1-汇总 2-运营个人
@@ -125,6 +125,52 @@ public class MaterialStareServiceImpl implements MaterialStareService {
         return null;
         return null;
     }
     }
 
 
+    /**
+     *
+     * @description: 数据总览-快手-运营个人
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/3/3
+     */
+    @Override
+    public Result kuaiShousumDataPersonal(String mediaType,String startTime, String endTime, String userId) {
+
+        long stratDate = DateUtils.getDateInteger(startTime);
+        long endDate = DateUtils.getDateInteger(endTime);
+        Set<String> userSet = new HashSet<String>(){{
+            add(userId);
+        }};
+
+        //头条
+        if (StringUtils.equals(mediaType,"1")){
+            return Result.successMsg("暂无头条数据。",null);
+        }
+        //快手
+        if (StringUtils.equals(mediaType,"2")){
+            //查询一天数据时 查询时报
+            if (stratDate == endDate){
+                Map resultMap = new HashMap<>();
+                //时报
+                List<Map> todayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(stratDate, endDate, userSet);
+                long time = DateUtils.getDateInteger(DateUtils.addDayParse(Long.toString(endDate), -1));
+                List<Map> yesterdayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(time,time , userSet);
+                resultMap.put("todayList",todayList);
+                resultMap.put("yesterdayList",yesterdayList);
+                return Result.successMsg("查询运营个人-时报-汇总。",resultMap);
+            }
+            //多天 数据
+            // 日报
+            List<Map> dailyList = materialStareMapper.getKuaiShouCostDailyByUserIdList(stratDate, endDate, userSet);
+            return Result.successMsg("查询运营个人-日报-汇总成功。",dailyList);
+        }
+        return null;
+    }
+
 
 
     /**
     /**
      *
      *
@@ -183,6 +229,89 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
 
     /**
     /**
      *
      *
+     * @description: 运营个人数据
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/3/3
+     */
+    @Override
+    public Result kuaiShouOperateDateTotalPersonal(String mediaType, String startTime, String endTime, String userId) {
+        Map resultMap = new HashMap();
+        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+
+        long stratDate = DateUtils.getDateInteger(startTime);
+        long endDate = DateUtils.getDateInteger(endTime);
+
+        try {
+            Set<String> userSet = new HashSet<String>(){{
+                add(userId);
+            }};
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            // ==>> 20220202
+            String now = sdf.format(new Date());
+            long nowDate = Long.valueOf(now);
+            int nowHour = DateUtils.getNowHour();
+            //昨天时间
+            long time = DateUtils.getDateInteger(DateUtils.addDayParse(now, -1));
+
+            //当天总消耗
+            JSONObject jsonObjectNow = materialStareMapper.getKuaiShouTotalCost(nowDate,nowDate,nowHour,userSet);
+            resultMap.put("todayCost",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"));
+            resultMap.put("todayCompare",decimalFormat.format(d));
+
+            //所选时段消耗
+            JSONObject timeNowCost = materialStareMapper.getKuaiShouTotalCostDaily(stratDate,endDate,userSet);
+            resultMap.put("timeCost",timeNowCost.getString("totalCost"));
+            //上阶段时间
+            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")));
+
+            //上阶段消耗
+            JSONObject timeLastCost = materialStareMapper.getKuaiShouTotalCostDaily(lastTimeStart,lastTimeEnd,userSet);
+            //同比 = (当前总消耗 - 上阶段总消耗 ) / 当前总消耗
+            Double timeCompare = (Double.valueOf(timeNowCost.getString("totalCost")) - Double.valueOf(timeLastCost.getString("totalCost"))) / Double.valueOf(timeNowCost.getString("totalCost"));
+            resultMap.put("timeCompare",decimalFormat.format(timeCompare));
+
+            //当前月份的框返 和 激励
+            // 当前月份第一天
+            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"));//激励
+
+            //公司 组内排名
+            //用户所属公司id
+            String companyId = materialStareMapper.getUserCompanyByUserId(userId);
+            //组内排名
+            List<JSONObject> groupRankList = materialStareMapper.getKuaiShouPersonalGroupRank(monthFirstDay,nowDate,companyId);
+            resultMap.put("userRankTotalNum",groupRankList.size());//排名总数
+            for (JSONObject group : groupRankList) {
+                if (group.getString("user_id").equals(userId)){
+                    resultMap.put("userIdRank",group.getString("serialNumber"));//排名
+                }
+            }
+
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return Result.successMsg("查询运营个人数据成功",resultMap);
+    }
+
+    /**
+     *
      * @description: 运营数据详情
      * @description: 运营数据详情
      *
      *
      * @param pageNum
      * @param pageNum
@@ -557,8 +686,16 @@ public class MaterialStareServiceImpl implements MaterialStareService {
      * 查询当前人员  所属公司 返回自己和下属id
      * 查询当前人员  所属公司 返回自己和下属id
      */
      */
     public Set<String> getAffiliateId(String userId) {
     public Set<String> getAffiliateId(String userId) {
+
         //查询用户所属公司
         //查询用户所属公司
         String companyId = materialStareMapper.getUserCompanyByUserId(userId);
         String companyId = materialStareMapper.getUserCompanyByUserId(userId);
+        //查询用户角色
+        String roleCode = materialStareMapper.getRoleCodeByUserId(userId);
+        //管理员查询公司下所有用户
+        if ("admin".equals(roleCode)) {
+            return materialStareMapper.getCompanyAllUserId(companyId);
+        }
+
         Set<String> result;
         Set<String> result;
         //查询当前用户是否存在下级
         //查询当前用户是否存在下级
         Set<String> subordinate = materialStareMapper.getAffiliateId(userId,companyId);
         Set<String> subordinate = materialStareMapper.getAffiliateId(userId,companyId);