Преглед изворни кода

add newGroupReport on 2020.11.06

jiequan.bi пре 4 година
родитељ
комит
433512d96d
15 измењених фајлова са 992 додато и 2 уклоњено
  1. 114 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KsNewGroupReportCtrl.java
  2. 0 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KsNewPlanReportCtrl.java
  3. 18 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KsNewGroupReportMapper.java
  4. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KsNewPlanReportMapper.java
  5. 248 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KsNewGroupReportMapper.xml
  6. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KsNewPlanReportMapper.xml
  7. 16 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKsNewGroupReportService.java
  8. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKsNewPlanReportService.java
  9. 52 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KsNewGroupReportServiceImpl.java
  10. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KsNewPlanReportServiceImpl.java
  11. 114 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceNewPlanReportCtrl.java
  12. 25 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/BytedanceNewPlanReportMapper.java
  13. 294 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceNewPlanReportMapper.xml
  14. 22 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceNewPlanReportService.java
  15. 67 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceNewPlanReportServiceImpl.java

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

@@ -0,0 +1,114 @@
+package cn.com.ctop.kuaishou.modules.report.controller;
+
+import cn.com.ctop.kuaishou.modules.report.service.IKsNewGroupReportService;
+import cn.com.ctop.kuaishou.modules.report.service.IKsNewPlanReportService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *  Created by JQ.bi on 2020.11.2
+ */
+@Slf4j
+@RestController
+@RequestMapping("/ctop/kuaishou/newGroup")
+public class KsNewGroupReportCtrl {
+
+    @Autowired
+    IKsNewGroupReportService newGroupReportService;
+
+    @Autowired
+    IKsNewPlanReportService newPlanReportService;
+
+    /**
+     * 新建计划、有效计划 chart数据
+     */
+    @PostMapping("/report/data")
+    public Result<Map<String, Object>> getNewGroupChartReport(@RequestBody JSONObject requestBody) {
+        Result<Map<String, Object>> resultBody = new Result<>();
+        Map<String, Object> result = new HashMap<>();
+        JSONArray accountIds = requestBody.getJSONArray("accountIds");
+        String userId= requestBody.getString("userId");
+        //TODO 没有维护快手事业部负责人角色,增加判断
+        if(userId.equals("e9ca23d68d884d4ebb19d07889727dae")){
+            accountIds= newPlanReportService.getAccountIdsByMedia();
+        }else{
+            if(!userId.isEmpty()){
+                accountIds= newPlanReportService.getAccountIdsByUserId(userId);
+            }
+            if(accountIds.isEmpty()){
+                return resultBody;
+            }
+        }
+
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target= requestBody.getString("target");
+        String order= requestBody.getString("order");
+        try {
+            JSONObject sumData = newGroupReportService.getSumNewGroupBy(accountIds, startDate, endDate);
+            List<JSONObject> chartData = newGroupReportService.getKsNewGroupGroupByStatDate(accountIds, startDate, endDate);
+            List<JSONObject> listData = newGroupReportService.getKsNewGroupGroupByAccount(accountIds, startDate, endDate,target,order);
+            result.put("sumData",sumData);
+            result.put("chartData",chartData);
+            result.put("listData",listData);
+            resultBody.setResult(result);
+            resultBody.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            resultBody.setSuccess(false);
+        }
+        return resultBody;
+    }
+
+    @PostMapping("/report/list")
+    public Result<List<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
+        Result<List<JSONObject>> result = new Result<>();
+
+        JSONArray accountIds = requestBody.getJSONArray("accountIds");
+        if(accountIds.isEmpty()){
+            return result;
+        }
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target= requestBody.getString("target");
+        String order= requestBody.getString("order");
+        try {
+            List<JSONObject> listData = newGroupReportService.getKsNewGroupGroupByAccount(accountIds, startDate, endDate,target,order);
+            result.setResult(listData);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+    /**
+     * 查询所有的快手运营
+     */
+    @PostMapping("/report/AllOperator")
+    public Result<List<JSONObject>> getAllOperator() {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            List<JSONObject> listData = newPlanReportService.getAllOperator();
+            result.setResult(listData);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+}

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

@@ -38,8 +38,6 @@ public class KsNewPlanReportCtrl {
         if(!userId.isEmpty()){
             accountIds= newPlanReportService.getAccountIdsByUserId(userId);
         }
-
-
         if(accountIds.isEmpty()){
             return resultBody;
         }

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

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.report.mapper;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface KsNewGroupReportMapper {
+
+    List<JSONObject> queryKsNewGroupGroupByAccount(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("target") String target, @Param("order") String order);
+
+    List<JSONObject> queryKsNewGroupGroupByStatDate(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryKsNewGroupGroupByMonth(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    JSONObject querySumNewGroupBy(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+}

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

@@ -19,4 +19,7 @@ public interface KsNewPlanReportMapper {
     List<JSONObject> queryAllOperator();
 
     JSONArray queryAccountIdsByUserId(String userId);
+
+    JSONArray queryAccountIdsByMedia();
+
 }

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

@@ -0,0 +1,248 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KsNewGroupReportMapper">
+
+    <select id="queryKsNewGroupGroupByAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        u.project_name as projectName,
+        u.auth_name as authName,
+        u.user_name as userName,
+        t.account_id accountId,
+        COUNT(t.unit_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid,
+        max(t.group_create_time) maxCreateTime
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.unit_id,
+        t1.group_create_time,
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_group t2
+        WHERE
+        t2.unit_id = t1.unit_id
+        AND stat_date >= DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_group t1
+        WHERE
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        unit_id
+        ) t LEFT JOIN ctop_user_allocation u on t.account_id=u.account_id
+        GROUP BY
+        t.account_id
+        ORDER BY ${target} ${order}
+    </select>
+
+    <select id="queryKsNewGroupGroupByMonth" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        DATE_FORMAT(t.statDate, '%Y-%m') statDate,
+        COUNT(t.unit_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.unit_id,
+        t1.group_create_time,
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_group t2
+        WHERE
+        t2.unit_id = t1.unit_id
+        AND stat_date >= DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_group t1
+        WHERE
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        unit_id
+        ) t
+        GROUP BY DATE_FORMAT(t.statDate, '%Y-%m')
+        ORDER BY statDate
+    </select>
+
+    <select id="queryKsNewGroupGroupByStatDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.statDate,
+        COUNT(t.unit_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.unit_id,
+        t1.group_create_time,
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_group t2
+        WHERE
+        t2.unit_id = t1.unit_id
+        AND stat_date >= DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_group t1
+        WHERE
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        unit_id
+        ) t
+        GROUP BY
+        statDate
+        ORDER BY statDate
+    </select>
+
+    <select id="querySumNewGroupBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        COUNT(t.unit_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.unit_id,
+        t1.group_create_time,
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_group t2
+        WHERE
+        t2.unit_id = t1.unit_id
+        AND stat_date >= DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_group t1
+        WHERE
+        DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.group_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        unit_id
+        ) t
+    </select>
+
+</mapper>

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

@@ -274,6 +274,17 @@
             ctop_user_allocation
         WHERE
             user_id = #{userId}
+        and account_status=0
+    </select>
+
+    <select id="queryAccountIdsByMedia" resultType="java.lang.Long">
+        SELECT
+            account_id
+        FROM
+            ctop_user_allocation
+        WHERE
+            media_id = 2
+          and account_status=0
     </select>
 
 </mapper>

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

@@ -0,0 +1,16 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+public interface IKsNewGroupReportService {
+
+    List<JSONObject> getKsNewGroupGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order);
+
+    List<JSONObject> getKsNewGroupGroupByStatDate(JSONArray accountIds, String startDate, String endDate);
+
+    JSONObject getSumNewGroupBy(JSONArray accountIds, String startDate, String endDate);
+
+}

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

@@ -16,4 +16,7 @@ public interface IKsNewPlanReportService {
     List<JSONObject> getAllOperator();
 
     JSONArray getAccountIdsByUserId(String userId);
+
+    JSONArray getAccountIdsByMedia();
+
 }

+ 52 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KsNewGroupReportServiceImpl.java

@@ -0,0 +1,52 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.kuaishou.modules.report.mapper.KsNewGroupReportMapper;
+import cn.com.ctop.kuaishou.modules.report.service.IKsNewGroupReportService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *  Created By JQ.bi on 2020.11.2
+ */
+@Slf4j
+@Service
+public class KsNewGroupReportServiceImpl implements IKsNewGroupReportService {
+
+    @Autowired
+    private KsNewGroupReportMapper NewGroupReportMapper;
+
+    @Override
+    public List<JSONObject> getKsNewGroupGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order) {
+        return NewGroupReportMapper.queryKsNewGroupGroupByAccount(accountIds,startDate,endDate,target,order);
+    }
+
+    @Override
+    public List<JSONObject> getKsNewGroupGroupByStatDate(JSONArray accountIds, String startDate, String endDate) {
+        List<JSONObject> resultList= new ArrayList<>();
+        try {
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                resultList = NewGroupReportMapper.queryKsNewGroupGroupByMonth(accountIds,startDate,endDate);
+            }
+            else {
+                resultList = NewGroupReportMapper.queryKsNewGroupGroupByStatDate(accountIds,startDate,endDate);
+            }
+        } catch (ParseException e) {
+            log.error(e.getMessage());
+        }
+        return resultList;
+    }
+
+    @Override
+    public JSONObject getSumNewGroupBy(JSONArray accountIds, String startDate, String endDate) {
+        return NewGroupReportMapper.querySumNewGroupBy(accountIds,startDate,endDate);
+    }
+
+}

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KsNewPlanReportServiceImpl.java

@@ -59,4 +59,9 @@ public class KsNewPlanReportServiceImpl  implements IKsNewPlanReportService {
         return newPlanReportMapper.queryAccountIdsByUserId(userId);
     }
 
+    @Override
+    public JSONArray getAccountIdsByMedia() {
+        return newPlanReportMapper.queryAccountIdsByMedia();
+    }
+
 }

+ 114 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceNewPlanReportCtrl.java

@@ -0,0 +1,114 @@
+package cn.com.ctop.toutiao.modules.report.controller;
+
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceNewPlanReportService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.vo.LoginUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by JQ.bi on 2020.11.4
+ */
+@Slf4j
+@RestController
+@RequestMapping("/ctop/bytedance/newPlan")
+public class BytedanceNewPlanReportCtrl {
+
+    @Autowired
+    IBytedanceNewPlanReportService newPlanReportService;
+
+    /**
+     * 新建计划、有效计划 chart数据
+     */
+    @PostMapping("/report/data")
+    public Result<Map<String, Object>> getNewPlanChartReport(@RequestBody JSONObject requestBody) {
+        Result<Map<String, Object>> resultBody = new Result<>();
+        Map<String, Object> result = new HashMap<>();
+        JSONArray accountIds = requestBody.getJSONArray("accountIds");
+        //TODO 没有维护头条事业部负责人角色,增加判断
+        String userId = requestBody.getString("userId");
+        if (userId.equals("e9ca23d68d884d4ebb19d07889727dae")) {
+            accountIds = newPlanReportService.getAccountIdsByMedia();
+        } else {
+            if (!userId.isEmpty()) {
+                accountIds = newPlanReportService.getAccountIdsByUserId(userId);
+            }
+            if (accountIds.isEmpty()) {
+                return resultBody;
+            }
+        }
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target = requestBody.getString("target");
+        String order = requestBody.getString("order");
+        try {
+            JSONObject sumData = newPlanReportService.getSumNewPlanBy(accountIds, startDate, endDate);
+            List<JSONObject> chartData = newPlanReportService.getBytedanceNewPlanGroupByStatDate(accountIds, startDate, endDate);
+            List<JSONObject> listData = newPlanReportService.getBytedanceNewPlanGroupByAccount(accountIds, startDate, endDate, target, order);
+            result.put("sumData", sumData);
+            result.put("chartData", chartData);
+            result.put("listData", listData);
+            resultBody.setResult(result);
+            resultBody.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            resultBody.setSuccess(false);
+        }
+        return resultBody;
+    }
+
+    /**
+     * 查询素材报表表格数据
+     */
+    @PostMapping("/report/list")
+    public Result<List<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
+        Result<List<JSONObject>> result = new Result<>();
+
+        JSONArray accountIds = requestBody.getJSONArray("accountIds");
+        if (accountIds.isEmpty()) {
+            return result;
+        }
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target = requestBody.getString("target");
+        String order = requestBody.getString("order");
+        try {
+            List<JSONObject> listData = newPlanReportService.getBytedanceNewPlanGroupByAccount(accountIds, startDate, endDate, target, order);
+            result.setResult(listData);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+    /**
+     * 查询所有的快手运营
+     */
+    @PostMapping("/report/AllOperator")
+    public Result<List<JSONObject>> getAllOperator() {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            List<JSONObject> listData = newPlanReportService.getAllOperator();
+            result.setResult(listData);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+}

+ 25 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/BytedanceNewPlanReportMapper.java

@@ -0,0 +1,25 @@
+package cn.com.ctop.toutiao.modules.report.mapper;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface BytedanceNewPlanReportMapper {
+
+    List<JSONObject> queryBytedanceNewPlanGroupByAccount(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("target") String target, @Param("order") String order);
+
+    List<JSONObject> queryBytedanceNewPlanGroupByStatDate(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryBytedanceNewPlanGroupByMonth(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    JSONObject querySumNewPlanBy(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryAllOperator();
+
+    JSONArray queryAccountIdsByUserId(String userId);
+
+    JSONArray queryAccountIdsByMedia();
+
+}

+ 294 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceNewPlanReportMapper.xml

@@ -0,0 +1,294 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.toutiao.modules.report.mapper.BytedanceNewPlanReportMapper">
+
+    <select id="queryBytedanceNewPlanGroupByAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        u.project_name AS projectName,
+        u.auth_name AS authName,
+        u.user_name AS userName,
+        t.accountId,
+        COUNT(t.planId) new,
+        COUNT(IF(t.cost > 500, TRUE, NULL)) valid,
+        max(t.ad_create_time) maxCreateTime
+        FROM
+        (
+        SELECT
+        t1.account_id as accountId,
+        t1.id as planId,
+        t1.ad_create_time,
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(cost), 0)
+        FROM
+        ctop_bytedance_report_plan_daily t2
+        WHERE
+        t2.ad_id = t1.id
+        AND stat_datetime >= DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_datetime &lt;DATE_ADD(
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS cost
+        FROM
+        ctop_bytedance_advertise_plan t1
+        WHERE
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        id
+        ) t
+        LEFT JOIN ctop_user_allocation u ON t.accountId = u.account_id
+        GROUP BY
+        t.accountId
+        ORDER BY ${target} ${order}
+    </select>
+
+    <select id="queryBytedanceNewPlanGroupByMonth" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        DATE_FORMAT(t.statDate, '%Y-%m') statDate,
+        COUNT(t.planId) new,
+        COUNT(IF(t.cost > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id as accountId,
+        t1.id as planId,
+        t1.ad_create_time,
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(cost), 0)
+        FROM
+        ctop_bytedance_report_plan_daily t2
+        WHERE
+        t2.ad_id = t1.id
+        AND stat_datetime >= DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_datetime &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS cost
+        FROM
+        ctop_bytedance_advertise_plan t1
+        WHERE
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        id
+        ) t
+        GROUP BY DATE_FORMAT(t.statDate, '%Y-%m')
+        ORDER BY statDate
+    </select>
+
+    <select id="queryBytedanceNewPlanGroupByStatDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.statDate,
+        COUNT(t.planId) new,
+        COUNT(IF(t.cost > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id as accountId,
+        t1.id as planId,
+        t1.ad_create_time,
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(cost), 0)
+        FROM
+        ctop_bytedance_report_plan_daily t2
+        WHERE
+        t2.ad_id = t1.id
+        AND stat_datetime >= DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_datetime &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS cost
+        FROM
+        ctop_bytedance_advertise_plan t1
+        WHERE
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        id
+        ) t
+        GROUP BY
+        statDate
+        ORDER BY statDate
+    </select>
+
+    <select id="querySumNewPlanBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        COUNT(t.planId) new,
+        COUNT(IF(t.cost > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id as accountId,
+        t1.id as planId,
+        t1.ad_create_time,
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(cost), 0)
+        FROM
+        ctop_bytedance_report_plan_daily t2
+        WHERE
+        t2.ad_id = t1.id
+        AND stat_datetime >= DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_datetime &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS cost
+        FROM
+        ctop_bytedance_advertise_plan t1
+        WHERE
+        DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.ad_create_time,
+        '%Y-%m-%d'
+        ) &lt;= #{endDate}
+        <if test="accountIds != null">
+            AND t1.account_id in
+            <foreach item="item" index="index" collection="accountIds"
+                     open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY
+        account_id,
+        id
+        ) t
+    </select>
+
+    <select id="queryAllOperator"  resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            DISTINCT user_id,user_name
+        FROM
+            ctop_project_member
+        WHERE
+                project_id IN (
+                SELECT
+                    id
+                FROM
+                    ctop_project
+                WHERE
+                    media_id = 1
+            )
+          and
+                role_code IN (
+                              'operator',
+                              'toutiaoOperationManager',
+                              'operationAssistant'
+                )
+    </select>
+
+    <select id="queryAccountIdsByUserId" resultType="java.lang.Long">
+        SELECT
+            account_id
+        FROM
+            ctop_user_allocation
+        WHERE
+            user_id = #{userId}
+          and account_status=0
+    </select>
+
+
+    <select id="queryAccountIdsByMedia" resultType="java.lang.Long">
+        SELECT
+            account_id
+        FROM
+            ctop_user_allocation
+        WHERE
+            media_id = 1
+          and account_status=0
+    </select>
+
+
+
+</mapper>

+ 22 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/IBytedanceNewPlanReportService.java

@@ -0,0 +1,22 @@
+package cn.com.ctop.toutiao.modules.report.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+public interface IBytedanceNewPlanReportService {
+
+    List<JSONObject> getBytedanceNewPlanGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order);
+
+    List<JSONObject> getBytedanceNewPlanGroupByStatDate(JSONArray accountIds, String startDate, String endDate);
+
+    JSONObject getSumNewPlanBy(JSONArray accountIds, String startDate, String endDate);
+
+    List<JSONObject> getAllOperator();
+
+    JSONArray getAccountIdsByUserId(String userId);
+
+    JSONArray getAccountIdsByMedia();
+
+}

+ 67 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceNewPlanReportServiceImpl.java

@@ -0,0 +1,67 @@
+package cn.com.ctop.toutiao.modules.report.service.impl;
+
+import cn.com.ctop.toutiao.modules.report.mapper.BytedanceNewPlanReportMapper;
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceNewPlanReportService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *  Created By JQ.bi on 2020.11.4
+ */
+@Slf4j
+@Service
+public class BytedanceNewPlanReportServiceImpl implements IBytedanceNewPlanReportService {
+
+    @Autowired
+    private BytedanceNewPlanReportMapper newPlanReportMapper;
+
+    @Override
+    public List<JSONObject> getBytedanceNewPlanGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order) {
+        return newPlanReportMapper.queryBytedanceNewPlanGroupByAccount(accountIds,startDate,endDate,target,order);
+    }
+
+    @Override
+    public List<JSONObject> getBytedanceNewPlanGroupByStatDate(JSONArray accountIds, String startDate, String endDate) {
+        List<JSONObject> resultList= new ArrayList<>();
+        try {
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                resultList = newPlanReportMapper.queryBytedanceNewPlanGroupByMonth(accountIds,startDate,endDate);
+            }
+            else {
+                resultList = newPlanReportMapper.queryBytedanceNewPlanGroupByStatDate(accountIds,startDate,endDate);
+            }
+        } catch (ParseException e) {
+            log.error(e.getMessage());
+        }
+        return resultList;
+    }
+
+    @Override
+    public JSONObject getSumNewPlanBy(JSONArray accountIds, String startDate, String endDate) {
+        return newPlanReportMapper.querySumNewPlanBy(accountIds,startDate,endDate);
+    }
+
+    @Override
+    public List<JSONObject> getAllOperator() {
+        return newPlanReportMapper.queryAllOperator();
+    }
+
+    @Override
+    public JSONArray getAccountIdsByUserId(String userId) {
+        return newPlanReportMapper.queryAccountIdsByUserId(userId);
+    }
+
+    @Override
+    public JSONArray getAccountIdsByMedia() {
+        return newPlanReportMapper.queryAccountIdsByMedia();
+    }
+
+}