Browse Source

Merge branch 'test' of http://git.tjyourong.com.cn/ctop/adsp-cloud into test

huangxuechao 4 years ago
parent
commit
d2d91e0e96

+ 0 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -528,7 +528,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
             info.setCreateTime(new Date());
             info.setUpdateTime(new Date());
             info.setType(type);
-
             if (!Check.isNull(project.getSupplierCode())) {
                 info.setSupplierCode(project.getSupplierCode());
             }

+ 11 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KsNewGroupReportCtrl.java

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.utils.ExportExcelUtils;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.report.service.IKsNewGroupReportService;
 import cn.com.ctop.kuaishou.modules.report.service.IKsNewPlanReportService;
+import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -38,6 +39,9 @@ public class KsNewGroupReportCtrl {
     @Autowired
     IKsNewPlanReportService newPlanReportService;
 
+    @Autowired
+    NewMonitorService newMonitorService;
+
     /**
      * 新建计划、有效计划 chart数据
      */
@@ -64,9 +68,12 @@ public class KsNewGroupReportCtrl {
         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);
+            //JSONObject sumData = newGroupReportService.getSumNewGroupBy(accountIds, startDate, endDate);
+            JSONObject sumData = newMonitorService.getKuaiShouGroupSum(accountIds, startDate, endDate);
+            //List<JSONObject> chartData = newGroupReportService.getKsNewGroupGroupByStatDate(accountIds, startDate, endDate);
+            List<JSONObject> chartData = newMonitorService.getKuaiShouGroupMessageGroup(accountIds, startDate, endDate);
+            //List<JSONObject> listData = newGroupReportService.getKsNewGroupGroupByAccount(accountIds, startDate, endDate, target, order);
+            List<JSONObject> listData = newMonitorService.getKuaiShouGroupMessage(accountIds, startDate, endDate, target);
             result.put("sumData", sumData);
             result.put("chartData", chartData);
             result.put("listData", listData);
@@ -123,7 +130,7 @@ public class KsNewGroupReportCtrl {
         String endDate = requestBody.getString("endDate");
         String target = requestBody.getString("target");
         String order = requestBody.getString("order");
-        List<JSONObject> listData = newGroupReportService.getKsNewGroupGroupByAccount(accountIds, startDate, endDate, target, order);
+        List<JSONObject> listData = newMonitorService.getKuaiShouGroupMessage(accountIds, startDate, endDate, target);
 
         List<List<Object>> excelList = new ArrayList<>();
         listData.forEach(data -> {

+ 11 - 4
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KsNewPlanReportCtrl.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.report.controller;
 import cn.com.ctop.common.module.utils.ExportExcelUtils;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.report.service.IKsNewPlanReportService;
+import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
@@ -34,6 +35,9 @@ public class KsNewPlanReportCtrl {
     @Autowired
     IKsNewPlanReportService newPlanReportService;
 
+    @Autowired
+    NewMonitorService newMonitorService;
+
     /**
      * 新建计划、有效计划 chart数据
      */
@@ -59,9 +63,12 @@ public class KsNewPlanReportCtrl {
         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);
+            //JSONObject sumData = newPlanReportService.getSumNewPlanBy(accountIds, startDate, endDate);
+            JSONObject sumData = newMonitorService.getPlanSum(accountIds, startDate, endDate, "1");
+            //List<JSONObject> chartData = newPlanReportService.getKsNewPlanGroupByStatDate(accountIds, startDate, endDate);
+            List<JSONObject> chartData = newMonitorService.getPlanMessageGroup(accountIds, startDate, endDate, "1");
+            //List<JSONObject> listData = newPlanReportService.getKsNewPlanGroupByAccount(accountIds, startDate, endDate, target, order);
+            List<JSONObject> listData = newMonitorService.getPlanMessage(accountIds, startDate, endDate, target, "1");
             result.put("sumData", sumData);
             result.put("chartData", chartData);
             result.put("listData", listData);
@@ -122,7 +129,7 @@ public class KsNewPlanReportCtrl {
         String endDate = requestBody.getString("endDate");
         String target = requestBody.getString("target");
         String order = requestBody.getString("order");
-        List<JSONObject> listData = newPlanReportService.getKsNewPlanGroupByAccount(accountIds, startDate, endDate, target, order);
+        List<JSONObject> listData = newMonitorService.getPlanMessage(accountIds, startDate, endDate, target, "1");
 
         List<List<Object>> excelList = new ArrayList<>();
         listData.forEach(data -> {

+ 35 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/NewMonitorController.java

@@ -0,0 +1,35 @@
+package cn.com.ctop.kuaishou.modules.report.controller;
+
+import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Description: 新上监控
+ * @Author: zzy
+ * @Date: 2021-08-13
+ * @Version: V1.0
+ */
+@RestController
+@RequestMapping("/newMonitor")
+public class NewMonitorController {
+
+    @Autowired
+    NewMonitorService newMonitorService;
+
+    /**
+     *
+     *
+     * @param type
+     * @return
+     */
+    @GetMapping("/synchronousMonitor")
+    public Result synchronousMonitor(@Param("type") String type) {
+        return newMonitorService.synchronousMonitor(type);
+    }
+}

+ 49 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/NewMonitorMapper.java

@@ -0,0 +1,49 @@
+package cn.com.ctop.kuaishou.modules.report.mapper;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+@Mapper
+public interface NewMonitorMapper {
+
+    List<Map> getKuaiShouGroup(@Param("date")String date);
+
+    List<Map> getKuaiShouCampaign(@Param("date")String date);
+
+    List<Map> getTouTiaoCampaign(@Param("date")String date);
+
+    String getGroupCharge(@Param("unitId")String unitId,@Param("afterDate")String afterDate);
+
+    String getCampaignCharge(@Param("campaignId")String campaignId,@Param("afterDate")String afterDate);
+
+    String getCampaignChargeTouTiao(@Param("campaignId")String campaignId,@Param("afterDate")String afterDate);
+
+    void saveMonitorGroup(@Param("accountId")String accountId,@Param("accountName")String accountName,@Param("operatingName")String operatingName,@Param("unitId")String unitId,@Param("createTime")String createTime,@Param("projectType")String projectType,@Param("effective")String effective);
+
+    void saveMonitorCampaign(@Param("accountId")String accountId,@Param("accountName")String accountName,@Param("operatingName")String operatingName,@Param("campaignId")String campaignId,@Param("createTime")String createTime,@Param("projectType")String projectType,@Param("effective")String effective);
+
+    String  getMonitorGroupByUnitId(@Param("unitId")String unitId);
+
+    String  getMonitorPlanByCampaignId(@Param("campaignId")String campaignId);
+
+    void  updateMonitorGroupByUnitId(@Param("unitId")String unitId,@Param("effective")String effective);
+
+    void  updateMonitorPlanByCampaignId(@Param("campaignId")String campaignId,@Param("effective")String effective);
+
+    List<JSONObject> getKuaiShouGroupMessage(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate);
+
+    JSONObject getKuaiShouGroupSum(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate);
+
+    List<JSONObject> getKuaiShouGroupMessageGroup(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate,@Param("group")String group);
+
+    List<JSONObject> getPlanMessage(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate,@Param("project")String project);
+
+    JSONObject getPlanSum(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate,@Param("project")String project);
+
+    List<JSONObject> getPlanMessageGroup(@Param("array") JSONArray array, @Param("startDate")String startDate, @Param("endDate")String endDate,@Param("group")String group,@Param("project")String project);
+}

+ 164 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/NewMonitorMapper.xml

@@ -0,0 +1,164 @@
+<?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.NewMonitorMapper">
+
+    <select id="getKuaiShouGroup" resultType="Map">
+    SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.unit_id as 'unitId',t.group_create_time as 'groupCreatTime',DATE_FORMAT(DATE_ADD(t.group_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
+     from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_group t on t1.account_id=t.account_id
+     <where>
+         <choose>
+             <when test="date!= null and date!=''">
+                 and  t.group_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
+             </when>
+             <otherwise>
+                 t.group_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+             </otherwise>
+         </choose>
+     </where>
+    </select>
+
+    <select id="getKuaiShouCampaign" resultType="Map">
+        SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.campaign_id as 'campaignId',t.put_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.put_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
+        from ctop_user_allocation t1 LEFT JOIN  ctop_kuaishou_campaign t on t1.account_id=t.account_id
+        <where>
+            <choose>
+                <when test="date != null and date !=''">
+                    and  t.put_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
+                </when>
+                <otherwise>
+                    t.put_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                </otherwise>
+            </choose>
+        </where>
+    </select>
+
+    <select id="getTouTiaoCampaign" resultType="Map">
+        SELECT t1.account_id as 'accountId',t1.auth_name as 'accountName',t1.user_name as 'userName',t.id as 'campaignId',t.ad_create_time as 'campaignCreatTime',DATE_FORMAT(DATE_ADD(t.ad_create_time,INTERVAL 7 DAY),'%Y-%m-%d') as 'afterTime'
+        from ctop_user_allocation t1 LEFT JOIN  ctop_bytedance_advertise_plan t on t1.account_id=t.account_id
+        <where>
+            <choose>
+                <when test="date != null and date !=''">
+                    and  t.ad_create_time &gt;= DATE_SUB(#{date},INTERVAL 7 DAY)
+                </when>
+                <otherwise>
+                    t.ad_create_time &gt;= DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 YEAR),'%Y-%m-%d')
+                </otherwise>
+            </choose>
+        </where>
+    </select>
+
+    <select id="getGroupCharge" resultType="String">
+
+        select sum(charge) from ctop_kuaishou_report_daily_group t where t.stat_date &lt; #{afterDate} and t.unit_id=#{unitId}
+    </select>
+
+    <select id="getCampaignCharge" resultType="String">
+
+        select sum(charge) from ctop_kuaishou_report_daily_campaign t where t.stat_date &lt; #{afterDate} and t.campaign_id=#{campaignId}
+    </select>
+
+    <select id="getCampaignChargeTouTiao" resultType="String">
+
+        select sum(cost) from ctop_bytedance_report_plan_daily t where t.stat_datetime &lt; #{afterDate} and t.ad_id=#{campaignId}
+    </select>
+
+    <insert id="saveMonitorGroup">
+        insert into  ctop_new_monitor_group(account_id,account_name,operating_name,unit_id,create_time,project_type,effective) values
+        (#{accountId},#{accountName},#{operatingName},#{unitId},#{createTime},#{projectType},#{effective})
+    </insert>
+
+    <insert id="saveMonitorCampaign">
+        insert into ctop_new_monitor_campaign (account_id,account_name,operating_name,campaign_id,create_time,project_type,effective) values
+        (#{accountId},#{accountName},#{operatingName},#{campaignId},#{createTime},#{projectType},#{effective})
+    </insert>
+
+    <select id="getMonitorGroupByUnitId" resultType="int" >
+        select  t.effective from ctop_new_monitor_group t where t.unit_id=#{unitId}
+    </select>
+
+    <select id="getMonitorPlanByCampaignId" resultType="int" >
+        select  t.effective from ctop_new_monitor_campaign t where t.campaign_id=#{campaignId}
+    </select>
+
+    <update id="updateMonitorGroupByUnitId" >
+        update ctop_new_monitor_group  t set t.effective=#{effective} where  t.unit_id=#{unitId}
+    </update>
+
+    <update id="updateMonitorPlanByCampaignId" >
+        update ctop_new_monitor_campaign  t set t.effective=#{effective} where  t.campaign_id=#{campaignId}
+    </update>
+
+    <select id="getKuaiShouGroupMessage" resultType="com.alibaba.fastjson.JSONObject">
+        select account_id as 'accountId',account_name as 'authName',MAX(create_time) as 'maxCreateTime',COUNT(IF(effective ='1', TRUE, NULL))  as 'valid',count(effective) as 'new',operating_name as 'userName','' as 'projectName'
+         from ctop_new_monitor_group  where ( create_time between #{startDate}  and #{endDate})
+        and account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+               #{item}
+        </foreach>
+        GROUP BY account_id
+
+    </select>
+
+
+    <select id="getPlanMessage" resultType="com.alibaba.fastjson.JSONObject">
+        select account_id as 'accountId',account_name as 'authName',MAX(create_time) as 'maxCreateTime',COUNT(IF(effective ='1', TRUE, NULL))  as 'valid',count(effective) as 'new',operating_name as 'userName','' as 'projectName'
+        from ctop_new_monitor_campaign  where ( create_time between #{startDate}  and #{endDate}) and project_type=#{project}
+        and account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+            #{item}
+        </foreach>
+        GROUP BY account_id
+
+    </select>
+
+    <select id="getKuaiShouGroupSum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT COUNT(IF(t.effective ='1', TRUE, NULL)) as 'valid',COUNT(t.effective)  as 'new' from ctop_new_monitor_group t
+        where  create_time between #{startDate}  and #{endDate}
+        and t.account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="getPlanSum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT COUNT(IF(t.effective ='1', TRUE, NULL)) as 'valid',COUNT(t.effective)  as 'new' from ctop_new_monitor_campaign t
+        where  (create_time between #{startDate}  and #{endDate}) and project_type=#{project}
+        and t.account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="getKuaiShouGroupMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
+    SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_group t
+     where  (create_time between #{startDate}  and #{endDate}) and t.account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+            #{item}
+        </foreach>
+        <choose>
+            <when test='group=="1"'>
+                GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m')
+            </when>
+            <otherwise>
+                GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m-%d')
+            </otherwise>
+        </choose>
+    </select>
+
+    <select id="getPlanMessageGroup" resultType="com.alibaba.fastjson.JSONObject" >
+        SELECT DATE_FORMAT(t.create_time,'%Y-%m-%d') as 'statDate',COUNT(t.effective) as 'new',COUNT(IF(t.effective ='1', TRUE, NULL))  as 'valid' from ctop_new_monitor_campaign t
+        where project_type=#{project} and  (create_time between #{startDate}  and #{endDate}) and t.account_id in
+        <foreach item="item" collection="array" separator="," open="(" close=")" index="">
+            #{item}
+        </foreach>
+        <choose>
+            <when test='group=="1"'>
+                GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m')
+            </when>
+            <otherwise>
+                GROUP BY  DATE_FORMAT(t.create_time,'%Y-%m-%d')
+            </otherwise>
+        </choose>
+    </select>
+
+</mapper>

+ 23 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/NewMonitorService.java

@@ -0,0 +1,23 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
+
+import java.util.List;
+
+public interface NewMonitorService {
+    public Result synchronousMonitor(String type);
+
+    List<JSONObject> getKuaiShouGroupMessage(JSONArray array, String startDate, String endDate,String target);
+
+    JSONObject getKuaiShouGroupSum(JSONArray array, String startDate, String endDate);
+
+    List<JSONObject> getKuaiShouGroupMessageGroup(JSONArray array, String startDate, String endDate);
+
+    List<JSONObject> getPlanMessage(JSONArray array, String startDate, String endDate,String target,String project);
+
+    JSONObject getPlanSum(JSONArray array, String startDate, String endDate,String project);
+
+    List<JSONObject> getPlanMessageGroup(JSONArray array, String startDate, String endDate,String project);
+}

+ 242 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/NewMonitorServiceImpl.java

@@ -0,0 +1,242 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.kuaishou.modules.report.mapper.NewMonitorMapper;
+import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class NewMonitorServiceImpl implements NewMonitorService {
+
+    @Resource
+    NewMonitorMapper newMonitorMapper;
+
+    /**
+     * 同步新上监控数据
+     *
+     * @param
+     * @return
+     */
+    public Result synchronousMonitor(String type) {
+        Result result = new Result();
+        List<Map> kuaiShouGroup = new ArrayList<>();
+        List<Map> kuaiShouCampaign = new ArrayList<>();
+        List<Map> TouTiaoCampaign = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        /*--------------------快手广告组-----------------------*/
+        if (type.equals("0")) {
+            //查询创建不满7天的快手组信息
+            kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(sdf.format(new Date()));
+        } else {
+            //查询全量快手组信息
+            kuaiShouGroup = newMonitorMapper.getKuaiShouGroup(null);
+        }
+        //处理快手组数据
+        if (!kuaiShouGroup.isEmpty()) {
+            kuaiShouGroup.stream().forEach(obj -> {
+                if (obj != null) {
+                    String unitId = obj.get("unitId") == null ? null : String.valueOf(obj.get("unitId"));
+                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                    String groupCreatTime = obj.get("groupCreatTime") == null ? null : (String) obj.get("groupCreatTime");
+                    if (unitId != null && afterTime != null) {
+                        String groupCharge = newMonitorMapper.getGroupCharge(unitId, afterTime);
+                        //大于500为有效广告组
+                        String effective = "0";
+                        if (groupCharge != null && Long.parseLong(groupCharge) > 500) {
+                            //有效
+                            effective = "1";
+                        }
+                        String effectiveResult = newMonitorMapper.getMonitorGroupByUnitId(unitId);
+                        //判断是否存在
+                        if (effectiveResult != null) {
+                            if (!effectiveResult.equals(effective)) {
+                                //存在更新
+                                newMonitorMapper.updateMonitorGroupByUnitId(unitId, effective);
+                            }
+
+                        } else {
+                            //不存在插入
+                            newMonitorMapper.saveMonitorGroup(accountId, accountName, userName, unitId, groupCreatTime, "1", effective);
+                        }
+                    }
+                }
+            });
+        }
+
+
+        /*---------------快手广告计划------------------*/
+        if (type.equals("0")) {
+            //查询创建不满7天的快手广告计划
+            kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(sdf.format(new Date()));
+        } else {
+            //查询全量快手广告计划
+            kuaiShouCampaign = newMonitorMapper.getKuaiShouCampaign(null);
+        }
+        //处理快手广告计划数据
+        if (!kuaiShouCampaign.isEmpty()) {
+            kuaiShouCampaign.stream().forEach(obj -> {
+                if (obj != null) {
+                    String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                    String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                    if (campaignId != null && afterTime != null) {
+                        String campaignCharge = newMonitorMapper.getCampaignCharge(campaignId, afterTime);
+                        //大于500为有效广告计划
+                        String effective = "0";
+                        if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
+                            //有效
+                            effective = "1";
+                        }
+                        String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                        //判断是否存在
+                        if (effectiveResult != null) {
+                            if (!effectiveResult.equals(effective)) {
+                                //存在更新
+                                newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                            }
+                        } else {
+                            //不存在插入
+                            newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "1", effective);
+                        }
+                    }
+                }
+            });
+        }
+
+        /*---------------头条广告计划------------------*/
+        if (type.equals("0")) {
+            //查询创建不满7天的头条广告计划
+            TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(sdf.format(new Date()));
+        } else {
+            //查询全量头条广告计划
+            TouTiaoCampaign = newMonitorMapper.getTouTiaoCampaign(null);
+        }
+        //处理快手广告计划数据
+        if (!TouTiaoCampaign.isEmpty()) {
+            TouTiaoCampaign.stream().forEach(obj -> {
+                if (obj != null) {
+                    String campaignId = obj.get("campaignId") == null ? null : String.valueOf(obj.get("campaignId"));
+                    String afterTime = obj.get("afterTime") == null ? null : (String) obj.get("afterTime");
+                    String accountId = obj.get("accountId") == null ? null : String.valueOf(obj.get("accountId"));
+                    String accountName = obj.get("accountName") == null ? null : (String) obj.get("accountName");
+                    String userName = obj.get("userName") == null ? null : (String) obj.get("userName");
+                    String campaignCreatTime = obj.get("campaignCreatTime") == null ? null : (String) obj.get("campaignCreatTime");
+                    if (campaignId != null && afterTime != null) {
+                        String campaignCharge = newMonitorMapper.getCampaignChargeTouTiao(campaignId, afterTime);
+                        //大于500为有效广告计划
+                        String effective = "0";
+                        if (campaignCharge != null && Long.parseLong(campaignCharge) > 500) {
+                            //有效
+                            effective = "1";
+                        }
+                        String effectiveResult = newMonitorMapper.getMonitorPlanByCampaignId(campaignId);
+                        //判断是否存在
+                        if (effectiveResult != null) {
+                            if (!effectiveResult.equals(effective)) {
+                                //存在更新
+                                newMonitorMapper.updateMonitorPlanByCampaignId(campaignId, effective);
+                            }
+                        } else {
+                            //不存在插入
+                            newMonitorMapper.saveMonitorCampaign(accountId, accountName, userName, campaignId, campaignCreatTime, "0", effective);
+                        }
+                    }
+                }
+            });
+        }
+
+        return result;
+    }
+
+
+    /**
+     * 查询快手组信息
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public List<JSONObject> getKuaiShouGroupMessage(JSONArray array, String startDate, String endDate, String target) {
+        return  newMonitorMapper.getKuaiShouGroupMessage(array,startDate,endDate);
+    }
+    /**
+     * 查询快手组新上和有效数量
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public JSONObject getKuaiShouGroupSum(JSONArray array, String startDate, String endDate) {
+        return newMonitorMapper.getKuaiShouGroupSum(array,startDate,endDate);
+    }
+    /**
+     * 查询快手组时间轴数据
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public List<JSONObject> getKuaiShouGroupMessageGroup(JSONArray array, String startDate, String endDate) {
+        String group="0";
+        List<JSONObject> kuaiShouGroupMessageGroup=new ArrayList<>();
+        try {
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                group="1";
+            }
+            kuaiShouGroupMessageGroup= newMonitorMapper.getKuaiShouGroupMessageGroup(array, startDate, endDate, group);
+        }catch (Exception e){
+            log.info("查询数据错误:{}",e.toString());
+        }
+
+        return kuaiShouGroupMessageGroup;
+    }
+
+    @Override
+    public List<JSONObject> getPlanMessage(JSONArray array, String startDate, String endDate, String target, String project) {
+        return newMonitorMapper.getPlanMessage(array,startDate,endDate,project);
+    }
+    /**
+     * 查询快手广告计划 新上和有效数量
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public JSONObject getPlanSum(JSONArray array, String startDate, String endDate, String project) {
+        return newMonitorMapper.getPlanSum(array,startDate,endDate,project);
+    }
+
+    @Override
+    public List<JSONObject> getPlanMessageGroup(JSONArray array, String startDate, String endDate, String project) {
+        String group="0";
+        List<JSONObject> planGroupMessageGroup=new ArrayList<>();
+        try {
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                group="1";
+            }
+            planGroupMessageGroup= newMonitorMapper.getPlanMessageGroup(array, startDate, endDate, group,project);
+        }catch (Exception e){
+            log.info("查询数据错误:{}",e.toString());
+        }
+
+        return planGroupMessageGroup;
+    }
+}

+ 71 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceNewPlanReportCtrl.java

@@ -1,9 +1,13 @@
 package cn.com.ctop.toutiao.modules.report.controller;
 
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
 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.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -11,6 +15,11 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,6 +35,9 @@ public class BytedanceNewPlanReportCtrl {
     @Autowired
     IBytedanceNewPlanReportService newPlanReportService;
 
+    @Autowired
+    NewMonitorService newMonitorService;
+
     /**
      * 新建计划、有效计划 chart数据
      */
@@ -51,9 +63,15 @@ public class BytedanceNewPlanReportCtrl {
         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);
+            //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);
+
+            JSONObject sumData = newMonitorService.getPlanSum(accountIds, startDate, endDate, "0");
+
+            List<JSONObject> chartData = newMonitorService.getPlanMessageGroup(accountIds, startDate, endDate, "0");
+
+            List<JSONObject> listData = newMonitorService.getPlanMessage(accountIds, startDate, endDate, target, "0");
             result.put("sumData", sumData);
             result.put("chartData", chartData);
             result.put("listData", listData);
@@ -66,6 +84,56 @@ public class BytedanceNewPlanReportCtrl {
         return resultBody;
     }
 
+    @PostMapping("/report/excel")
+    public void getExcelReport(@RequestBody JSONObject requestBody,
+                               HttpServletRequest request,
+                               HttpServletResponse response) {
+
+        JSONArray accountIds = requestBody.getJSONArray("accountIds");
+        String userId = requestBody.getString("userId");
+        //TODO 没有维护快手事业部负责人角色,增加判断
+        if ("6b4c821adc414dc8b7718ab63ccbfcaf".equals(userId)) {
+            accountIds = newPlanReportService.getAccountIdsByMedia();
+        } else {
+            if (!userId.isEmpty()) {
+                accountIds = newPlanReportService.getAccountIdsByUserId(userId);
+            }
+            if (accountIds.isEmpty()) {
+                return;
+            }
+        }
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target = requestBody.getString("target");
+        String order = requestBody.getString("order");
+        List<JSONObject> listData = newMonitorService.getPlanMessage(accountIds, startDate, endDate, target, "0");
+
+        List<List<Object>> excelList = new ArrayList<>();
+        listData.forEach(data -> {
+            List<Object> temp = new ArrayList<>();
+            temp.add(data.getString("authName"));
+            temp.add(data.getLong("accountId"));
+            temp.add(data.getString("userName"));
+            temp.add(data.getLong("new"));
+            temp.add(data.getLong("valid"));
+            temp.add(data.getString("maxCreateTime"));
+            excelList.add(temp);
+        });
+        try {
+            String[] headers = {"账户名称","账户ID","账户所属人","新上计划数","有效计划数","最近上新时间"};
+            OutputStream os = response.getOutputStream();
+            ExportExcelUtils eeu = new ExportExcelUtils();
+            XSSFWorkbook workbook = new XSSFWorkbook();
+            eeu.exportExcel(workbook, 0, "头条新上计划数", headers, excelList);
+            HttpUtils.setResponseHeader(response, "头条新上计划数.xlsx");
+            workbook.write(os);
+            os.flush();
+            os.close();
+        } catch (IOException e) {
+            log.error(e.getMessage());
+        }
+    }
+
     /**
      * 查询素材报表表格数据
      */

+ 14 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialAscriptionController.java

@@ -150,6 +150,20 @@ public class MaterialAscriptionController {
             if (!Check.isNull(clip)) {
                 clipName = clip.getRealname();
                 materialAscription.setClipName(clipName);
+                String roleCode = sysUserService.getRoleCodeByUserId(clipId);
+                log.info("剪辑人员名称:"+clip.getRealname()+";ID:"+clipId);
+                String leaderName = "";
+                String leaderId = "";
+                if("designTeamLeader".equals(roleCode)){
+                    leaderId = clipId;
+                    leaderName = clip.getRealname();
+                }else{
+                    leaderId = clip.getLeaderId();
+                    leaderName = clip.getLeaderName();
+                }
+                log.info("负责人名称:"+leaderName+";ID:"+leaderId);
+                materialAscription.setLeaderName(leaderName);
+                materialAscription.setLeaderId(leaderId);
             }
         }
         QueryWrapper<MaterialAscription> ascriptionQueryWrapper = new QueryWrapper<>();
@@ -185,7 +199,6 @@ public class MaterialAscriptionController {
             reportBytedanceVideoService.update(updateByteDanceVideoInfo, updateByteDanceQueryWrapper);
         }
 
-
         boolean ok;
         if (Check.isNull(one)) {
             ok = materialAscriptionService.save(materialAscription);