Procházet zdrojové kódy

add newPlanReport on 2020.11.04

jiequan.bi před 4 roky
rodič
revize
5a7a44e9bb

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

@@ -0,0 +1,109 @@
+package cn.com.ctop.kuaishou.modules.report.controller;
+
+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/newPlan")
+public class KsNewPlanReportCtrl {
+
+    @Autowired
+    IKsNewPlanReportService 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");
+        String userId= requestBody.getString("userId");
+        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.getKsNewPlanGroupByStatDate(accountIds, startDate, endDate);
+            List<JSONObject> listData = newPlanReportService.getKsNewPlanGroupByAccount(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.getKsNewPlanGroupByAccount(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;
+    }
+
+}

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

@@ -0,0 +1,22 @@
+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 KsNewPlanReportMapper {
+
+    List<JSONObject> queryKsNewPlanGroupByAccount(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate,@Param("target") String target,@Param("order") String order);
+
+    List<JSONObject> queryKsNewPlanGroupByStatDate(@Param("accountIds") JSONArray accountIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+    List<JSONObject> queryKsNewPlanGroupByMonth(@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);
+}

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

@@ -0,0 +1,279 @@
+<?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.KsNewPlanReportMapper">
+
+    <select id="queryKsNewPlanGroupByAccount" 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.campaign_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid,
+        max(t.put_create_time) maxCreateTime
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.campaign_id,
+        t1.put_create_time,
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_campaign t2
+        WHERE
+        t2.campaign_id = t1.campaign_id
+        AND stat_date >= DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_campaign t1
+        WHERE
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.put_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,
+        campaign_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="queryKsNewPlanGroupByMonth" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        DATE_FORMAT(t.statDate, '%Y-%m') statDate,
+        COUNT(t.campaign_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.campaign_id,
+        t1.put_create_time,
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_campaign t2
+        WHERE
+        t2.campaign_id = t1.campaign_id
+        AND stat_date >= DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_campaign t1
+        WHERE
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.put_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,
+        campaign_id
+        ) t
+        GROUP BY DATE_FORMAT(t.statDate, '%Y-%m')
+        ORDER BY statDate
+    </select>
+
+    <select id="queryKsNewPlanGroupByStatDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t.statDate,
+        COUNT(t.campaign_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.campaign_id,
+        t1.put_create_time,
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_campaign t2
+        WHERE
+        t2.campaign_id = t1.campaign_id
+        AND stat_date >= DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_campaign t1
+        WHERE
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.put_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,
+        campaign_id
+        ) t
+        GROUP BY
+        statDate
+        ORDER BY statDate
+    </select>
+
+    <select id="querySumNewPlanBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        COUNT(t.campaign_id) new,
+        COUNT(IF(t.charge > 500, TRUE, NULL)) valid
+        FROM
+        (
+        SELECT
+        t1.account_id,
+        t1.campaign_id,
+        t1.put_create_time,
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) AS statDate,
+        (
+        SELECT
+        ifnull(sum(charge), 0)
+        FROM
+        ctop_kuaishou_report_daily_campaign t2
+        WHERE
+        t2.campaign_id = t1.campaign_id
+        AND stat_date >= DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        )
+        AND stat_date &lt; DATE_ADD(
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ),
+        INTERVAL '7' DAY
+        )
+        ) AS charge
+        FROM
+        ctop_kuaishou_campaign t1
+        WHERE
+        DATE_FORMAT(
+        t1.put_create_time,
+        '%Y-%m-%d'
+        ) >= #{startDate}
+        AND DATE_FORMAT(
+        t1.put_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,
+        campaign_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 = 2
+            )
+          and
+                role_code IN (
+                              'operator',
+                              'kuaishouOperationManager',
+                              'operationAssistant'
+                )
+    </select>
+
+    <select id="queryAccountIdsByUserId" resultType="java.lang.Long">
+        SELECT
+            account_id
+        FROM
+            ctop_user_allocation
+        WHERE
+            user_id = #{userId}
+    </select>
+
+</mapper>

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

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+public interface IKsNewPlanReportService {
+
+    List<JSONObject> getKsNewPlanGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order);
+
+    List<JSONObject> getKsNewPlanGroupByStatDate(JSONArray accountIds, String startDate, String endDate);
+
+    JSONObject getSumNewPlanBy(JSONArray accountIds, String startDate, String endDate);
+
+    List<JSONObject> getAllOperator();
+
+    JSONArray getAccountIdsByUserId(String userId);
+}

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

@@ -0,0 +1,62 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.kuaishou.modules.report.mapper.KsNewPlanReportMapper;
+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.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 KsNewPlanReportServiceImpl  implements IKsNewPlanReportService {
+
+    @Autowired
+    private KsNewPlanReportMapper newPlanReportMapper;
+
+    @Override
+    public List<JSONObject> getKsNewPlanGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order) {
+        return newPlanReportMapper.queryKsNewPlanGroupByAccount(accountIds,startDate,endDate,target,order);
+    }
+
+    @Override
+    public List<JSONObject> getKsNewPlanGroupByStatDate(JSONArray accountIds, String startDate, String endDate) {
+        List<JSONObject> resultList= new ArrayList<>();
+        try {
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                resultList = newPlanReportMapper.queryKsNewPlanGroupByMonth(accountIds,startDate,endDate);
+            }
+            else {
+                resultList = newPlanReportMapper.queryKsNewPlanGroupByStatDate(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);
+    }
+
+}