Pārlūkot izejas kodu

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

zhaoxian 4 gadi atpakaļ
vecāks
revīzija
87b75ce28f

+ 14 - 4
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -8,11 +8,11 @@ import cn.com.ctop.common.module.service.*;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAgentAccount;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouAgentAccountMapper;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
-import cn.com.ctop.toutiao.modules.report.service.IByteDanceVideoReportDailyService;
 import cn.com.ctop.toutiao.modules.report.service.IBytedanceFundDailyService;
 import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportService;
 import cn.com.ctop.toutiao.modules.report.service.IReportService;
@@ -32,6 +32,8 @@ import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
@@ -272,7 +274,18 @@ public class SampleTest {
             }
         }
     }
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
 
+    @Test
+    public void loadKuaishouGroupData() throws ParseException {
+        Date endDate = new Date();
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", DateUtils.formatDate(endDate), -1);
+        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
+        Date startDate = sim.parse(anotherDay);
+        CtopOauthToken token = tokenService.getTokenByAccountId(7087890L);
+        kuaishouInterfaceService.getGroupList(token, startDate, endDate);
+    }
 
 
 
@@ -308,9 +321,6 @@ public class SampleTest {
 
     @Autowired
     private IBytedanceReportService bytedanceReportService;
-
-    @Autowired
-    private IByteDanceVideoReportDailyService videoReportDailyService;
     @Test
     public void loadMatData(){
         List<UserAllocation> allocations = allocationService.getByParams(289L,null,0);

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -1211,6 +1211,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         headers.put("Content-Type", "application/json");
 
         String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        System.out.println(result);
         JSONObject resultJson = JSONObject.parseObject(result);
         if (Check.isNull(resultJson)) {
             log.error("获取广告组接口异常,advertiserId:{}", token.getAccountId());

+ 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>

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

@@ -107,7 +107,7 @@
     <select id="imageCost" resultType="cn.com.ctop.common.module.vo.KuaishouImageCostVO">
         select
         report.cover_url as 'image_url' ,
-        report.code as 'signature',
+        report.cover_id as 'signature',
         group_concat(distinct p.project_name) AS 'project_name',
         sum(report.charge) AS 'charge',
         sum(report.photo_click) AS 'photo_click',
@@ -125,7 +125,7 @@
         where
             1=1
         and
-            report.code is not null
+            report.cover_id is not null
         <if test="startDate!=null">
             and report.stat_date &gt;= #{startDate}
         </if>
@@ -139,9 +139,9 @@
             </foreach>
         </if>
         <if test="code!=null">
-            and report.code = #{code}
+            and report.cover_id = #{code}
         </if>
-        group by report.code
+        group by report.cover_id
         order by sum(report.charge) desc
     </select>
     <select id="imageCostEntity" resultType="cn.com.ctop.common.module.vo.KuaishouImageCostVOEntity">

+ 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);
+    }
+
+}

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

@@ -43,7 +43,6 @@ public class ByteDanceVideoReportDailyServiceImpl extends ServiceImpl<ByteDanceV
         videoInfoListByCompanyId(startDate, endDate, "d57fecdcf7a94d009736d9c850731582");
         //华东
         videoInfoListByCompanyId(startDate, endDate, "4b10089775c040119e139087517aed88");
-
     }
 
     private void videoInfoListByCompanyId(String startDate, String endDate, String companyId){