Browse Source

release on 2020.8.26

jiequan.bi 4 years ago
parent
commit
0e06a40070
21 changed files with 1109 additions and 27 deletions
  1. 10 3
      jeecg-boot-base-common/src/main/java/org/jeecg/common/constant/AccountReportConstants.java
  2. 9 13
      jeecg-boot-base-common/src/main/java/org/jeecg/common/util/JsonResourceUtil.java
  3. 1 1
      module-check/src/main/java/cn/com/ctop/check/TestGroovy.groovy
  4. 1 1
      module-check/src/main/java/cn/com/ctop/check/controller/CtopCheckTaskExecuteLogController.java
  5. 1 1
      module-check/src/main/java/cn/com/ctop/check/controller/CtopCheckTaskListController.java
  6. 25 1
      module-check/src/main/java/cn/com/ctop/check/script/TestGroovyScript.java
  7. 21 1
      module-check/src/main/java/cn/com/ctop/notice/handler/SendWeChatHandle.java
  8. 26 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/CustomDataByAccountMapper.java
  9. 63 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CustomDataByAccountMapper.xml
  10. 25 0
      module-common/src/main/java/cn/com/ctop/common/module/service/ICustomDataByAccountService.java
  11. 44 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/CustomDataByAccountImpl.java
  12. 2 2
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java
  13. 150 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaiShouAccountReportCtrl.java
  14. 47 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaiShouAccountReportMapper.java
  15. 216 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaiShouAccountReportMapper.xml
  16. 21 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaiShouAccountReportService.java
  17. 206 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaiShouAccountReportServiceImpl.java
  18. 49 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/utils/LinkUtils.java
  19. 186 0
      module-kuaishou/src/main/resources/json_template/kuaishou_filed_mapping.json
  20. 3 2
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAccountReportCtrl.java
  21. 3 2
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceAccountReportServiceImpl.java

+ 10 - 3
jeecg-boot-base-common/src/main/java/org/jeecg/common/constant/AccountReportConstants.java

@@ -31,17 +31,24 @@ public class AccountReportConstants {
         return instance;
         return instance;
     }
     }
 
 
-    /** 字典数据 */
+    /**
+     * 字典数据
+     */
+    //头条字段映射
     public static Map<String, Map<String,Object>> dicMap = new HashMap<>();
     public static Map<String, Map<String,Object>> dicMap = new HashMap<>();
+    //快手字段映射
+    public static Map<String, Map<String,Object>> dicMapKs = new HashMap<>();
 
 
     /**
     /**
      * 初始化字典
      * 初始化字典
      */
      */
     public void init(){
     public void init(){
         //加载json文件
         //加载json文件
-        Object json=JsonResourceUtil.getJsonObjFromResource("/json_template/bytedance_filed_mapping.json");
+        Object jsonBy=JsonResourceUtil.getJsonObjFromResource("/json_template/bytedance_filed_mapping.json");
+        Object jsonKs=JsonResourceUtil.getJsonObjFromResource("/json_template/kuaishou_filed_mapping.json");
         //json 转为map存为静态常量
         //json 转为map存为静态常量
-        dicMap=JsonResourceUtil.jsonToMap(json);
+        dicMap=JsonResourceUtil.jsonToMap(jsonBy);
+        dicMapKs=JsonResourceUtil.jsonToMap(jsonKs);
     }
     }
 
 
 }
 }

+ 9 - 13
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/JsonResourceUtil.java

@@ -52,22 +52,20 @@ public class JsonResourceUtil {
     public static Map<String, Map<String, Object>> jsonToMap(Object jsonObj) {
     public static Map<String, Map<String, Object>> jsonToMap(Object jsonObj) {
         JSONObject jsonObject = JSONObject.parseObject(jsonObj.toString());
         JSONObject jsonObject = JSONObject.parseObject(jsonObj.toString());
         Map<String, Map<String, Object>> mapMap = new HashMap<>();
         Map<String, Map<String, Object>> mapMap = new HashMap<>();
-        jsonObject.forEach((key, value) -> {
-            mapMap.put(key, JSONObject.parseObject(value.toString()));
-        });
+        jsonObject.forEach((key, value) -> mapMap.put(key, JSONObject.parseObject(value.toString())));
         return mapMap;
         return mapMap;
     }
     }
 
 
     /**
     /**
      * 拼接字段
      * 拼接字段
      */
      */
-    public static String joinFiled(JSONArray array) {
+    public static String joinFiled(Map<String, Map<String,Object>> mapMap,JSONArray array) {
         StringBuilder sb = new StringBuilder();
         StringBuilder sb = new StringBuilder();
         array.forEach(it -> {
         array.forEach(it -> {
-            if (AccountReportConstants.dicMap.get(it.toString()).isEmpty()) {
+            if (mapMap.get(it.toString()).isEmpty()) {
                 sb.append(it).append(",");
                 sb.append(it).append(",");
             } else {
             } else {
-                sb.append(AccountReportConstants.dicMap.get(it.toString()).get("filed")).append(",");
+                sb.append(mapMap.get(it.toString()).get("filed")).append(",");
             }
             }
         });
         });
         return sb.deleteCharAt(sb.length() - 1).toString();
         return sb.deleteCharAt(sb.length() - 1).toString();
@@ -76,13 +74,13 @@ public class JsonResourceUtil {
     /**
     /**
      * 拼接title
      * 拼接title
      */
      */
-    public static List<String> joinTitle(JSONArray array) {
+    public static List<String> joinTitle(Map<String, Map<String,Object>> mapMap,JSONArray array) {
         List<String> titles = new ArrayList<>(20);
         List<String> titles = new ArrayList<>(20);
         array.forEach(it -> {
         array.forEach(it -> {
-            if (AccountReportConstants.dicMap.get(it.toString()).isEmpty()) {
+            if (mapMap.get(it.toString()).isEmpty()) {
                 titles.add(it.toString());
                 titles.add(it.toString());
             } else {
             } else {
-                titles.add(AccountReportConstants.dicMap.get(it.toString()).get("comment").toString());
+                titles.add(mapMap.get(it.toString()).get("comment").toString());
             }
             }
         });
         });
         return titles;
         return titles;
@@ -91,11 +89,9 @@ public class JsonResourceUtil {
     /**
     /**
      * 拼接字段
      * 拼接字段
      */
      */
-    public static String joinAllFiled() {
+    public static String joinAllFiled(Map<String, Map<String,Object>> mapMap) {
         StringBuilder sb = new StringBuilder();
         StringBuilder sb = new StringBuilder();
-        AccountReportConstants.dicMap.forEach((k, v) -> {
-            sb.append(v.get("filed")).append(",");
-        });
+        mapMap.forEach((k, v) -> sb.append(v.get("filed")).append(","));
         return sb.deleteCharAt(sb.length() - 1).toString();
         return sb.deleteCharAt(sb.length() - 1).toString();
     }
     }
 }
 }

+ 1 - 1
module-check/src/main/java/cn/com/ctop/check/TestGroovy.groovy

@@ -11,7 +11,7 @@ class TestGroovy extends AbstractScript {
     @Override
     @Override
     Result<Object> exec() {
     Result<Object> exec() {
         println("开始执行脚本")
         println("开始执行脚本")
-        sendWeChatHandle.SendWeChatByMail("bijiequan@c-top.com.cn","执行成功")
+        sendWeChatHandle.sendWeChatByMails("bijiequan@c-top.com.cn","执行成功")
         println("执行完成")
         println("执行完成")
         return Result.ok("666")
         return Result.ok("666")
     }
     }

+ 1 - 1
module-check/src/main/java/cn/com/ctop/check/controller/CtopCheckTaskExecuteLogController.java

@@ -19,7 +19,7 @@ import javax.servlet.http.HttpServletRequest;
 @Slf4j
 @Slf4j
 @RestController
 @RestController
 @RequestMapping("/ctop/checkTaskExecuteLog")
 @RequestMapping("/ctop/checkTaskExecuteLog")
-public class CtopCheckTaskExecuteLogController {
+public class CtopCheckTaskExecuteLogCtrl {
 
 
    @Autowired
    @Autowired
    private ICtopCheckTaskExecuteLogService ctopCheckTaskExecuteLogService;
    private ICtopCheckTaskExecuteLogService ctopCheckTaskExecuteLogService;

+ 1 - 1
module-check/src/main/java/cn/com/ctop/check/controller/CtopCheckTaskListController.java

@@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletRequest;
 @Slf4j
 @Slf4j
 @RestController
 @RestController
 @RequestMapping("/ctop/checkTaskList")
 @RequestMapping("/ctop/checkTaskList")
-public class  CtopCheckTaskListController {
+public class CtopCheckTaskListCtrl {
 
 
     @Autowired
     @Autowired
     private ICtopCheckTaskListService ctopCheckTaskListService;
     private ICtopCheckTaskListService ctopCheckTaskListService;

+ 25 - 1
module-check/src/main/java/cn/com/ctop/check/script/TestGroovyScript.java

@@ -2,13 +2,26 @@ package cn.com.ctop.check.script;
 
 
 import cn.com.ctop.check.component.execute.GroovyScriptExecutor;
 import cn.com.ctop.check.component.execute.GroovyScriptExecutor;
 import cn.com.ctop.check.service.ICtopCheckTaskListService;
 import cn.com.ctop.check.service.ICtopCheckTaskListService;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.ICustomDataByAccountService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.service.impl.CustomDataByAccountImpl;
+import cn.com.ctop.common.module.service.impl.UserAllocationServiceImpl;
+import cn.com.ctop.notice.handler.SendWeChatHandle;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.checkerframework.checker.units.qual.A;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.SystemDateConstant;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import java.util.List;
+
 @RestController
 @RestController
 @RequestMapping("/rest/script")
 @RequestMapping("/rest/script")
 public class TestGroovyScript {
 public class TestGroovyScript {
@@ -22,9 +35,20 @@ public class TestGroovyScript {
     @Autowired
     @Autowired
     GroovyScriptExecutor groovyScriptExecutor;
     GroovyScriptExecutor groovyScriptExecutor;
 
 
+    @Autowired
+    SendWeChatHandle sendWeChatHandle;
+
+    @Autowired
+    IUserAllocationService userAllocationService;
+
+    @Autowired
+    ICustomDataByAccountService customDataByAccountService;
+
     @GetMapping("/test")
     @GetMapping("/test")
     public Result testGroovy(){
     public Result testGroovy(){
-         groovyScriptExecutor.execute(2,"CheckAccountStatusScript");
+        //groovyScriptExecutor.execute(2,"CheckAccountStatusScript");
+        //groovyScriptExecutor.execute(13,"CheckKsDataDiffScript");
+        groovyScriptExecutor.execute(14,"CheckByDataDiffScript");
         return Result.ok();
         return Result.ok();
     }
     }
 }
 }

+ 21 - 1
module-check/src/main/java/cn/com/ctop/notice/handler/SendWeChatHandle.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 
 
@@ -22,7 +23,8 @@ public class SendWeChatHandle {
             log.error(String.format("mail's WeChat not found. mail =%s", mail));
             log.error(String.format("mail's WeChat not found. mail =%s", mail));
             //TODO 通知管理员添加邮箱
             //TODO 通知管理员添加邮箱
         }else{
         }else{
-            CorpWexinUtils.sendMessageByWeChatId(weChatId,message);
+            List<String> messageList= splitMessage(message);
+            messageList.forEach(it->CorpWexinUtils.sendMessageByWeChatId(weChatId,it));
         }
         }
     }
     }
 
 
@@ -35,4 +37,22 @@ public class SendWeChatHandle {
         List<String> mail= Arrays.asList(mails.split(","));
         List<String> mail= Arrays.asList(mails.split(","));
         mail.forEach(m-> this.sendWeChatByMail(m,message));
         mail.forEach(m-> this.sendWeChatByMail(m,message));
     }
     }
+
+    /**
+     *  消息切割
+     */
+    private List<String> splitMessage(String message){
+        List<String> messageList=new ArrayList<>();
+        if(message.length()>1006){
+            int number=message.length()/1006;
+            for(int i=0;i<number;i++){
+                if(i!=number-1){
+                    messageList.add(message.substring(i*1006,(i+1)*1006-1));
+                }else {
+                    messageList.add(message.substring((i+1)*1006));
+                }
+            }
+        }
+        return messageList;
+    }
 }
 }

+ 26 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/CustomDataByAccountMapper.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.common.module.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
+
+public interface CustomDataByAccountMapper {
+
+    //快手查询广告组日报数据
+    JSONObject queryKsGroupData(@Param("accountId") Long accountId,@Param("date") String date);
+
+    //快手查询广告计划日报数据
+    JSONObject queryKsCampaignData(@Param("accountId") Long accountId,@Param("date") String date);
+
+    //快手查询账户日报数据
+    JSONObject queryKsAccountData(@Param("accountId") Long accountId,@Param("date") String date);
+
+    //头条查询广告组日报数据
+    JSONObject queryByCampaignData(@Param("accountId") Long accountId,@Param("date") String date);
+
+    //头条查询广告计划日报数据
+    JSONObject queryByPlanData(@Param("accountId") Long accountId,@Param("date") String date);
+
+    //头条查询账户日报数据
+    JSONObject queryByAccountData(@Param("accountId") Long accountId,@Param("date") String date);
+
+}

+ 63 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CustomDataByAccountMapper.xml

@@ -0,0 +1,63 @@
+<?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.common.module.mapper.CustomDataByAccountMapper">
+
+    <select id="queryKsCampaignData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT sum(charge)      cost,
+               sum(photo_show)  photoShow,
+               sum(photo_click) photoClick,
+               sum(aclick)      aclick
+        FROM ctop_kuaishou_report_daily_campaign
+        where stat_date = #{date}
+          and account_id = #{accountId}
+    </select>
+
+    <select id="queryKsGroupData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT sum(charge)      cost,
+               sum(photo_show)  photoShow,
+               sum(photo_click) photoClick,
+               sum(aclick)      aclick
+        FROM ctop_kuaishou_report_daily_group
+        where stat_date = #{date}
+          and account_id = #{accountId}
+    </select>
+
+    <select id="queryKsAccountData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT sum(charge)      cost,
+               sum(photo_show)  photoShow,
+               sum(photo_click) photoClick,
+               sum(aclick)      aclick
+        FROM ctop_kuaishou_report_daily_account
+        where stat_date = #{date}
+          and account_id = #{accountId}
+    </select>
+
+    <select id="queryByCampaignData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            sum(cost) cost,
+            sum(show_num) showNum,
+            sum(click) click
+        from ctop_bytedance_report_campaign_daily
+        where stat_datetime = #{date}
+          and advertiser_id = #{accountId}
+    </select>
+
+    <select id="queryByPlanData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT sum(cost)     cost,
+               sum(show_num) showNum,
+               sum(click)    click
+        from ctop_bytedance_report_plan_daily
+        where stat_datetime = '${date} 00:00:00'
+          and advertiser_id = #{accountId}
+    </select>
+
+    <select id="queryByAccountData" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT sum(cost)     cost,
+               sum(show_num) showNum,
+               sum(click)    click
+        FROM ctop_bytedance_report_advertiser_daily
+        where stat_datetime = '${date} 00:00:00'
+          and advertiser_id = #{accountId}
+    </select>
+
+</mapper>

+ 25 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/ICustomDataByAccountService.java

@@ -0,0 +1,25 @@
+package cn.com.ctop.common.module.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface ICustomDataByAccountService {
+
+    //快手查询广告组日报数据
+    JSONObject getKsGroupData(Long account,String date);
+
+    //快手查询广告计划日报数据
+    JSONObject getKsCampaignData(Long account,String date);
+
+    //快手查询账户日报数据
+    JSONObject getKsAccountData(Long account,String date);
+
+    //头条查询广告组日报数据
+    JSONObject getByCampaignData(Long account,String date);
+
+    //头条查询广告计划日报数据
+    JSONObject getByPlanData(Long account,String date);
+
+    //头条查询账户日报数据
+    JSONObject getByAccountData(Long account,String date);
+
+}

+ 44 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CustomDataByAccountImpl.java

@@ -0,0 +1,44 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.mapper.CustomDataByAccountMapper;
+import cn.com.ctop.common.module.service.ICustomDataByAccountService;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CustomDataByAccountImpl implements ICustomDataByAccountService {
+
+    @Autowired
+    CustomDataByAccountMapper customDataByAccountMapper;
+
+    @Override
+    public JSONObject getKsGroupData(Long account, String date) {
+        return customDataByAccountMapper.queryKsGroupData(account,date);
+    }
+
+    @Override
+    public JSONObject getKsCampaignData(Long account, String date) {
+        return customDataByAccountMapper.queryKsCampaignData(account,date);
+    }
+
+    @Override
+    public JSONObject getKsAccountData(Long account, String date) {
+        return customDataByAccountMapper.queryKsAccountData(account,date);
+    }
+
+    @Override
+    public JSONObject getByCampaignData(Long account, String date) {
+        return customDataByAccountMapper.queryByCampaignData(account,date);
+    }
+
+    @Override
+    public JSONObject getByPlanData(Long account, String date) {
+        return customDataByAccountMapper.queryByPlanData(account,date);
+    }
+
+    @Override
+    public JSONObject getByAccountData(Long account, String date) {
+        return customDataByAccountMapper.queryByAccountData(account,date);
+    }
+}

+ 2 - 2
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -78,9 +78,9 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         String path = URLDecoder.decode(materialInfo.getUrl().substring(materialInfo.getUrl().indexOf("/", 10) + 1, materialInfo.getUrl().length()));
         String path = URLDecoder.decode(materialInfo.getUrl().substring(materialInfo.getUrl().indexOf("/", 10) + 1, materialInfo.getUrl().length()));
         String taskId = videoWatermarkHandle(path, tentcentWatermarkTemplate.getTemplateId());
         String taskId = videoWatermarkHandle(path, tentcentWatermarkTemplate.getTemplateId());
         DescribeTaskDetailResponse taskDetailResponse = null;
         DescribeTaskDetailResponse taskDetailResponse = null;
-        for (int i = 0; i < 10; i++) {
+        for (int i = 0; i < 30; i++) {
             try {
             try {
-                Thread.sleep(2000);
+                Thread.sleep(4000);
             } catch (InterruptedException e) {
             } catch (InterruptedException e) {
                 log.error(e.getMessage());
                 log.error(e.getMessage());
             }
             }

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

@@ -0,0 +1,150 @@
+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.IKuaiShouAccountReportService;
+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.jeecg.common.constant.AccountReportConstants;
+import org.jeecg.common.util.JsonResourceUtil;
+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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by JQ.bi on 2020.08.23
+ */
+@Slf4j
+@RestController
+@RequestMapping("/ctop/kuaishou/dailyPage")
+public class KuaiShouAccountReportCtrl {
+
+    @Autowired
+    IKuaiShouAccountReportService kuaiShouAccountReportService;
+
+    /**
+     * 查询素材报表chart数据
+     */
+    @PostMapping("/report/chart")
+    public Result<Map<String, Object>> getAccountChartReport(@RequestBody JSONObject requestBody) {
+        Result<Map<String, Object>> resultBody = new Result<>();
+        Map<String, Object> result = new HashMap<>();
+        if (requestBody.isEmpty()) {
+            log.error("request body is empty");
+            resultBody.setSuccess(false);
+        }
+        String mediaId = requestBody.getString("mediaId");
+        BigDecimal discount = requestBody.getBigDecimal("discount");
+        JSONArray accounts = requestBody.getJSONArray("accountIds");
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        try {
+            Map<String, Object> sumData = kuaiShouAccountReportService.getSumDataBy(mediaId, discount, accounts, startDate, endDate);
+            List<JSONObject> chartData = kuaiShouAccountReportService.getChartDataBy(mediaId, discount, accounts, startDate, endDate);
+            result.put("sumData",sumData);
+            result.put("chartData",chartData);
+            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<>();
+        if (requestBody.isEmpty()) {
+            log.error("request body is empty");
+            result.setSuccess(false);
+        }
+        String mediaId = requestBody.getString("mediaId");
+        BigDecimal discount = requestBody.getBigDecimal("discount");
+        JSONArray accounts = requestBody.getJSONArray("accountIds");
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        int hour= requestBody.getInteger("hour");
+        String target= requestBody.getString("target");
+        String order= requestBody.getString("order");
+        try {
+            List<JSONObject> listData= kuaiShouAccountReportService.getListDataBy(mediaId,discount,accounts,startDate,endDate,hour,target,order);
+            result.setResult(listData);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+    /**
+     *  导出数据
+     */
+    @PostMapping("/report/excel")
+    public void getExcelReport(@RequestBody JSONObject requestBody,
+                               HttpServletRequest request,
+                               HttpServletResponse response) {
+        JSONArray columns=requestBody.getJSONArray("columns");
+        if(columns.isEmpty()){
+            log.error("请选择需要导出的字段");
+        }
+        String filed= JsonResourceUtil.joinFiled(AccountReportConstants.dicMapKs,columns);
+        List<String> titles= new ArrayList<>();
+        titles.add("账户Id");
+        titles.add("账户名称");
+        titles.addAll(JsonResourceUtil.joinTitle(AccountReportConstants.dicMapKs,columns));
+        //此处增加两个元素是为了保证数据有序
+        columns.add(0,"accountId");
+        columns.add(1,"authName");
+        String mediaId = requestBody.getString("mediaId");
+        JSONArray accounts = requestBody.getJSONArray("accountIds");
+        String startDate = requestBody.getString("startDate");
+        String endDate = requestBody.getString("endDate");
+        String target= requestBody.getString("target");
+        String order= requestBody.getString("order");
+        int hour= requestBody.getInteger("hour");
+        List<JSONObject> excelData= kuaiShouAccountReportService.getExcelDataBy(filed,mediaId,accounts,startDate,endDate,hour,target,order);
+        if(excelData.isEmpty()){
+            return;
+        }
+        List<List<Object>> excelList= new ArrayList<>();
+        excelData.forEach(data->{
+            List<Object> temp= new ArrayList<>();
+            columns.forEach(k-> temp.add(data.get(k.toString())));
+            excelList.add(temp);
+        });
+        try{
+            String[] headers = titles.toArray(new String[titles.size()]);
+            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());
+        }
+    }
+
+}

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

@@ -0,0 +1,47 @@
+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 KuaiShouAccountReportMapper {
+
+    //今日汇总数据
+    JSONObject queryTodaySumReportBy(@Param("statDate") String statDate, @Param("accountIds") JSONArray accountIds);
+
+    //根据小时区间查询今日汇总数据
+    List<JSONObject> queryTodaySumByHourGroupAccount(@Param("filed") String filed, @Param("statDate") String statDate, @Param("hour") int hour, @Param("accountIds") JSONArray accountIds, String target, String order);
+
+    //根据小时区间查询今日汇总数据
+    JSONObject queryTodaySumByHour(@Param("statDate") String statDate, @Param("hour") int hour, @Param("accountIds") JSONArray accountIds);
+
+    //根据小时区间查询今日汇总数据
+    JSONObject querySumByHour(@Param("filed") String filed, @Param("statDate") String statDate, @Param("hour") int hour, @Param("accountIds") JSONArray accountIds);
+
+    //今日明细数据
+    List<JSONObject> queryTodayDetailReportBy(@Param("filed") String filed, @Param("statDate") String statDate, @Param("accountIds") JSONArray accountIds);
+
+    //根据开始、结束时间 查询汇总数据
+    JSONObject querySumByStartEndDate(@Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds);
+
+    //根据开始、结束时间 查询汇总数据
+    JSONObject queryAllSumByStartEndDate(@Param("filed") String filed, @Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds);
+
+    //根据时间查询数据按账户分组
+    List<JSONObject> querySumByDateGroupAccount(@Param("filed") String filed, @Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds, String target, String order);
+
+    //根据时间查询数据按账户时间分组
+    List<JSONObject> querySumByDateGroupAccountAndDate(@Param("filed") String filed, @Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds, String target, String order);
+
+    //根据开始、结束时间 查询明细数据
+    List<JSONObject> queryDetailByStartEndDate(@Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds);
+
+    //按月分组查询明细数据
+    List<JSONObject> queryDetailGroupMonthByDate(@Param("endDate") String endDate, @Param("startDate") String startDate, @Param("accountIds") JSONArray accountIds);
+
+    //查询固定月的明细数据
+    List<JSONObject> queryDetailGroupDayByMonth(@Param("month") String month);
+
+}

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

@@ -0,0 +1,216 @@
+<?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.KuaiShouAccountReportMapper">
+
+    <select id="queryTodaySumReportBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ROUND(sum(charge),2) cost,
+        sum(photo_show) photoShow,
+        sum(photo_click) photoClick,
+        sum(aClick) as aClick,
+        max(stat_hour) maxHour
+        FROM
+        ctop_kuaishou_report_hourly_account
+        WHERE
+        stat_date = #{statDate}
+        AND account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="queryTodaySumByHourGroupAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t2.account_id as accountId,
+        t2.auth_name as authName,
+        ${filed}
+        FROM ctop_kuaishou_report_hourly_account t1
+        left join ctop_user_allocation t2 on t1.account_id=t2.account_id
+        WHERE t1.stat_date = #{statDate}
+        and t1.stat_hour &lt;= #{hour}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by t1.account_id
+        order by ${target} ${order}
+    </select>
+
+    <select id="queryTodaySumByHour" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+          ROUND(sum(charge),2) cost,
+          sum(photo_show) photoShow,
+          sum(photo_click) photoClick,
+          sum(aClick) as aClick
+        FROM
+          ctop_kuaishou_report_hourly_account
+        WHERE
+          stat_date = #{statDate}
+        AND stat_hour &lt;= #{hour}
+        AND account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="querySumByHour" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed}
+        FROM
+        ctop_kuaishou_report_hourly_account t1
+        WHERE
+        t1.stat_date = #{statDate}
+        and t1.stat_hour &lt;= #{hour}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="queryTodayDetailReportBy" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+          ROUND(sum(charge),2) cost,
+          sum(photo_show) photoShow,
+          sum(photo_click) photoClick,
+          sum(aClick) as aClick,
+          stat_hour as statHour
+        FROM
+          ctop_kuaishou_report_hourly_account
+        WHERE
+          stat_date = #{statDate}
+        AND account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        GROUP BY
+        stat_hour
+        ORDER BY
+        stat_hour ASC
+    </select>
+
+    <select id="queryAllSumByStartEndDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ${filed}
+        FROM ctop_kuaishou_report_daily_account t1
+        WHERE t1.stat_date &lt;= #{endDate}
+        AND t1.stat_date &gt;= #{startDate}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="querySumByStartEndDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+          ROUND(sum(charge),2) cost,
+          sum(photo_show) photoShow,
+          sum(photo_click) photoClick,
+          sum(aClick) as aClick
+        FROM ctop_kuaishou_report_daily_account t1
+        WHERE t1.stat_date &lt;= #{endDate}
+        AND t1.stat_date &gt;= #{startDate}
+        AND account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="querySumByDateGroupAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.stat_date as statDate,
+        t2.account_id as accountId,
+        t2.auth_name as authName,
+        ${filed}
+        FROM
+        ctop_kuaishou_report_daily_account t1
+        left join ctop_user_allocation t2 on t1.account_id=t2.account_id
+        WHERE
+        t1.stat_date &lt;= #{endDate}
+        AND t1.stat_date &gt;= #{startDate}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by t1.account_id
+        order by ${target} ${order}
+    </select>
+
+    <select id="querySumByDateGroupAccountAndDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t1.stat_date as statDate,
+        t2.account_id as accountId,
+        t2.auth_name as authName,
+        ${filed}
+        FROM
+        ctop_kuaishou_report_daily_account t1
+        left join ctop_user_allocation t2 on t1.account_id=t2.account_id
+        WHERE
+        t1.stat_date &lt;= #{endDate}
+        AND t1.stat_date &gt;= #{startDate}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by t1.stat_date
+        order by ${target} ${order}
+    </select>
+
+    <select id="queryDetailByStartEndDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+          ROUND(sum(charge),2) cost,
+          sum(photo_show) photoShow,
+          sum(photo_click) photoClick,
+          sum(aClick) as aClick,
+          stat_date as statDate
+        FROM
+          ctop_kuaishou_report_daily_account
+        WHERE stat_date &lt;= #{endDate}
+        AND stat_date &gt;= #{startDate}
+        AND account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by stat_date
+        order by stat_date asc
+    </select>
+
+    <select id="queryDetailGroupMonthByDate" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+          ROUND(sum(charge),2) cost,
+          sum(photo_show) photoShow,
+          sum(photo_click) photoClick,
+          sum(aClick) as aClick,
+          DATE_FORMAT(t1.stat_date, '%Y-%m') statDate
+        FROM ctop_kuaishou_report_daily_account t1
+        WHERE t1.stat_date &lt;= #{endDate}
+        AND t1.stat_date &gt;= #{startDate}
+        AND t1.account_id in
+        <foreach item="item" index="index" collection="accountIds"
+                 open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        group by DATE_FORMAT(t1.stat_date, '%Y-%m')
+        order by t1.stat_date asc
+    </select>
+
+    <select id="queryDetailGroupDayByMonth" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            stat_date as statDate,
+            SUBSTR(stat_date FROM 9 FOR 2) day
+        FROM ctop_kuaishou_report_daily_account
+        WHERE stat_date like '${month}%'
+        group by DATE_FORMAT(stat_date, '%Y-%m-%d')
+        order by stat_date asc
+    </select>
+
+</mapper>

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

@@ -0,0 +1,21 @@
+package cn.com.ctop.kuaishou.modules.report.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+
+public interface IKuaiShouAccountReportService {
+
+    Map<String,Object> getSumDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate);
+
+    List<JSONObject> getChartDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate) throws ParseException;
+
+    List<JSONObject> getListDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate, int hour, String target, String order);
+
+    List<JSONObject> getExcelDataBy(String filed, String mediaId, JSONArray accounts, String startDate, String endDate, int hour, String target, String order);
+
+}

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

@@ -0,0 +1,206 @@
+package cn.com.ctop.kuaishou.modules.report.service.impl;
+
+import cn.com.ctop.common.module.utils.CtopAdConstant;
+
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaiShouAccountReportMapper;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouAccountReportService;
+import cn.com.ctop.kuaishou.modules.utils.LinkUtils;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.constant.AccountReportConstants;
+import org.jeecg.common.constant.SystemDateConstant;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.JsonResourceUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by JQ.bi on 2020.08.23
+ */
+@Service
+public class KuaiShouAccountReportServiceImpl implements IKuaiShouAccountReportService {
+
+    @Autowired
+    KuaiShouAccountReportMapper kuaiShouAccountReportMapper;
+
+    private static final BigDecimal zero=BigDecimal.ZERO;
+
+    @Override
+    public Map<String, Object> getSumDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate) {
+        Map<String, Object> result = new HashMap<>();
+        JSONObject after;
+        JSONObject before;
+        if (startDate.equals(endDate)) {
+            after = kuaiShouAccountReportMapper.queryTodaySumReportBy(startDate, accounts);
+            if (after == null) {
+                return result;
+            }
+            before = kuaiShouAccountReportMapper.queryTodaySumByHour(DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), after.getInteger("maxHour"), accounts);
+            if(before==null){
+                before = after;
+            }
+        } else {
+            after = kuaiShouAccountReportMapper.querySumByStartEndDate(endDate, startDate, accounts);
+            if(after==null){
+                return result;
+            }
+            before = after;
+        }
+        result.put("Sum", getSumLink(mediaId, discount, after, before));
+        return result;
+    }
+
+    @Override
+    public List<JSONObject> getChartDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate) throws ParseException {
+        List<JSONObject> result=new ArrayList<>();
+        String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMapKs);
+        if (startDate.equals(endDate)) {
+            List<JSONObject> after = kuaiShouAccountReportMapper.queryTodayDetailReportBy(filedAll, startDate, accounts);
+            List<JSONObject> before = kuaiShouAccountReportMapper.queryTodayDetailReportBy(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), accounts);
+            if(after.size()==0){
+                return result;
+            }
+            if(before.size()==0){
+                before=nullDataHandle();
+            }
+            List<JSONObject> afterDis = this.countDiscountCost(mediaId, discount, after);
+            List<JSONObject> beforeDis = this.countDiscountCost(mediaId, discount, before);
+            result = LinkUtils.getCompareDate(beforeDis, afterDis, "statHour");
+        } else {
+            List<JSONObject> after;
+            //判断是不是日期间隔大于半年
+            if(DateUtils.isMoreSixMonth(startDate,endDate)){
+                after = kuaiShouAccountReportMapper.queryDetailGroupMonthByDate(endDate, startDate, accounts);
+            }
+            else {
+                after = kuaiShouAccountReportMapper.queryDetailByStartEndDate(endDate, startDate, accounts);
+            }
+            if(after==null){
+                return result;
+            }
+            result = this.countDiscountCost(mediaId, discount, after);
+        }
+        return result;
+    }
+
+    @Override
+    public List<JSONObject> getListDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
+        List<JSONObject> result;
+        String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMapKs);
+        if (startDate.equals(endDate)) {
+            result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
+            JSONObject afterSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
+            JSONObject beforeSum = kuaiShouAccountReportMapper.querySumByHour(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), hour, accounts);
+            result.add(afterSum);
+            result.add(beforeSum);
+            result.add(countTotal(afterSum, beforeSum));
+        } else {
+            if(accounts.size()>1){
+                result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filedAll, endDate, startDate, accounts, target, order);
+            }else{
+                result = kuaiShouAccountReportMapper.querySumByDateGroupAccountAndDate(filedAll, endDate, startDate, accounts, target, order);
+            }
+            result.add(kuaiShouAccountReportMapper.queryAllSumByStartEndDate(filedAll, endDate, startDate, accounts));
+        }
+        return result;
+    }
+
+    @Override
+    public List<JSONObject> getExcelDataBy(String filed, String mediaId, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
+        List<JSONObject> result;
+        if (startDate.equals(endDate)) {
+            result = kuaiShouAccountReportMapper.queryTodaySumByHourGroupAccount(filed, startDate, hour, accounts, target, order);
+        } else {
+            result = kuaiShouAccountReportMapper.querySumByDateGroupAccount(filed, endDate, startDate, accounts, target, order);
+        }
+        return result;
+    }
+
+    //计算汇总数据环比
+    private Map<String, Object> getSumLink(String mediaId, BigDecimal discount, JSONObject after, JSONObject before) {
+
+        Map<String, Object> result = new HashMap<>();
+
+        JSONObject costLink = new JSONObject();
+        JSONObject discountCostLink = new JSONObject();
+        JSONObject photoClickLink = new JSONObject();
+        JSONObject photoShowLink = new JSONObject();
+        JSONObject aClickLink = new JSONObject();
+
+        costLink.put("cost", after.getBigDecimal("cost"));
+        costLink.put("CostSumLink", LinkUtils.countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
+        if (mediaId.equals(CtopAdConstant.PLATFORM_TYPE_KUAISHOU)) {
+            discountCostLink.put("discountCost", after.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP));
+            discountCostLink.put("discountCostLink", LinkUtils.countLink(after.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP), before.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP)));
+        } else {
+            discountCostLink.put("discountCost", after.getBigDecimal("cost").multiply(discount));
+            discountCostLink.put("discountCostLink", LinkUtils.countLink(after.getBigDecimal("cost").multiply(discount), before.getBigDecimal("cost").multiply(discount)));
+        }
+        photoClickLink.put("photoClick", after.getBigDecimal("photoClick"));
+        photoClickLink.put("photoClickLink", LinkUtils.countLink(after.getBigDecimal("photoClick"), before.getBigDecimal("photoClick")));
+        photoShowLink.put("photoShow", after.getBigDecimal("photoShow"));
+        photoShowLink.put("photoShowLink", LinkUtils.countLink(after.getBigDecimal("photoShow"), before.getBigDecimal("photoShow")));
+        aClickLink.put("aClick", after.getBigDecimal("aClick"));
+        aClickLink.put("aClickLink", LinkUtils.countLink(after.getBigDecimal("aClick"), before.getBigDecimal("aClick")));
+        result.put("costLink", costLink);
+        result.put("discountCostLink", discountCostLink);
+        result.put("photoClickLink", photoClickLink);
+        result.put("photoShowLink", photoShowLink);
+        result.put("aClickLink", aClickLink);
+        return result;
+    }
+
+    //计算折后消耗
+    private List<JSONObject> countDiscountCost(String mediaId, BigDecimal discount, List<JSONObject> data) {
+        if (data.isEmpty()) {
+            return data;
+        }
+        if (mediaId.equals(CtopAdConstant.PLATFORM_TYPE_KUAISHOU)) {
+            data.forEach(it -> {
+                it.put("discountCost", it.getBigDecimal("cost").divide(discount, 4, RoundingMode.HALF_UP));
+            });
+        } else {
+            data.forEach(it -> {
+                it.put("discountCost", it.getBigDecimal("cost").multiply(discount));
+            });
+        }
+        return data;
+    }
+
+    //计算总计环比
+    private JSONObject countTotal(JSONObject after, JSONObject before) {
+        JSONObject jsonObject = new JSONObject();
+        after.forEach((k, v) -> {
+            //去除没法计算的字段
+            if (k.equals("accountId") || k.equals("authName") || v.toString().contains("%")) {
+                jsonObject.put(k, "-");
+            } else {
+                jsonObject.put(k, LinkUtils.countLink(after.getBigDecimal(k)==null?zero:after.getBigDecimal(k), before.getBigDecimal(k)==null?zero:before.getBigDecimal(k)));
+            }
+        });
+        return jsonObject;
+    }
+
+    private List<JSONObject> nullDataHandle(){
+        List<JSONObject> objectList= new ArrayList<>();
+        JSONObject jsonObject;
+        for(int i=0;i<24;i++){
+            jsonObject=new JSONObject();
+            jsonObject.put("cost",0);
+            jsonObject.put("photoShow",0);
+            jsonObject.put("photoClick",0);
+            jsonObject.put("aClick",0);
+            jsonObject.put("statHour",i);
+            objectList.add(jsonObject);
+        }
+        return objectList;
+    }
+}

+ 49 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/utils/LinkUtils.java

@@ -0,0 +1,49 @@
+package cn.com.ctop.kuaishou.modules.utils;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by JQ.bi on 2020.08.23
+ */
+public class LinkUtils {
+
+
+    //数据对比,环比计算
+    public static List<JSONObject> getCompareDate(List<JSONObject> beforeData, List<JSONObject> AfterData, String standard) {
+        List<JSONObject> result = new ArrayList<>();
+        beforeData.forEach(before -> {
+            String yesStat = String.valueOf(before.get(standard));
+            AfterData.forEach(after -> {
+                if ((String.valueOf(after.get(standard))).equals(yesStat)) {
+                    //消耗较昨日环比
+                    after.put("costProportion", countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
+                    //展示量较昨日环比
+                    after.put("photoShowProportion", countLink(BigDecimal.valueOf(after.getLong("photoShow")), BigDecimal.valueOf(before.getLong("photoShow"))));
+                    //点击量较昨日环比
+                    after.put("photoClickProportion", countLink(BigDecimal.valueOf(after.getLong("photoClick")), BigDecimal.valueOf(before.getLong("photoClick"))));
+                    if(after.getLong("aClick")!=null){
+                        after.put("aClickProportion", countLink(BigDecimal.valueOf(after.getLong("aClick")), BigDecimal.valueOf(before.getLong("aClick"))));
+                    }
+                    before.put("afterData", after);
+                }
+            });
+            result.add(before);
+        });
+        return result;
+    }
+
+    //环比计算
+    public static BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
+        BigDecimal link = new BigDecimal(0);
+        if (!(numB.compareTo(BigDecimal.ZERO)==0)) {
+            link = (numA.subtract(numB)).divide(numB, 4, RoundingMode.HALF_UP);
+        }
+        return link;
+    }
+
+}

+ 186 - 0
module-kuaishou/src/main/resources/json_template/kuaishou_filed_mapping.json

@@ -0,0 +1,186 @@
+{
+  "cost": {
+    "filed": "sum(t1.charge) as cost ",
+    "comment": "消耗"
+  },
+  "photoShow": {
+    "filed": "sum(t1.photo_show) as photoShow ",
+    "comment": "封面曝光数"
+  },
+  "photoClick": {
+    "filed": "sum(t1.photo_click) as photoClick ",
+    "comment": "封面点击数"
+  },
+  "aClick": {
+    "filed": "sum(t1.aclick) as aClick ",
+    "comment": "素材曝光数"
+  },
+  "bClick": {
+    "filed": "sum(t1.bclick) as bClick ",
+    "comment": "行为数"
+  },
+  "clickRate": {
+    "filed": "CASE WHEN sum(t1.photo_click) / sum(t1.photo_show) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.photo_click) / sum(t1.photo_show)) * 100,2),'%') END AS clickRate ",
+    "comment": "封面点击率"
+  },
+  "bClickRate": {
+    "filed": "CASE WHEN sum(t1.bclick) / sum(t1.aclick) IS NULL THEN 0 ELSE CONCAT( ROUND((sum(t1.bclick) / sum(t1.aclick)) * 100,2),'%') END AS bClickRate ",
+    "comment": "行为率"
+  },
+  "cpm": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.photo_show) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_show)) * 1000, 2 ) END AS cpm ",
+    "comment": "平均千次封面曝光花费"
+  },
+  "cpc": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.photo_click) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.photo_click)), 2) END AS cpc ",
+    "comment": "平均封面点击单价"
+  },
+  "cpb": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.bclick) IS NULL THEN 0 ELSE ROUND((sum(t1.charge) / sum(t1.bclick)), 2) END AS cpb ",
+    "comment": "平均行为单价"
+  },
+  "downloadStart": {
+    "filed": "sum(download_started) as downloadStart ",
+    "comment": "安卓开始下载数"
+  },
+  "downloadStartCost": {
+    "filed": "CASE WHEN sum(t1.charge) / (t1.download_started) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.download_started) end AS downloadStartCost ",
+    "comment": "安卓开始下载单价"
+  },
+  "downloadStartRate": {
+    "filed": "CASE WHEN sum(t1.download_started) / sum(t1.bclick) IS NULL THEN 0 ELSE concat(round(sum(t1.download_started) / sum(t1.bclick)*100,2),'%') end AS downloadStartRate ",
+    "comment": "安卓开始下载率"
+  },
+  "downloadFinish": {
+    "filed": "sum(download_completed) as downloadFinish ",
+    "comment": "安卓下载完成数"
+  },
+  "downloadFinishCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.download_completed) IS NULL THEN 0 ELSE  sum(t1.charge) / sum(t1.download_completed) end AS downloadFinishCost ",
+    "comment": "安卓下载完成单价"
+  },
+  "downloadFinishRate": {
+    "filed": "CASE WHEN sum(t1.download_completed) / sum(t1.download_started) IS NULL THEN 0 ELSE  concat(round(sum(t1.download_completed) / sum(t1.download_started)*100,2),'%') end AS downloadFinishRate ",
+    "comment": "安卓下载完成率"
+  },
+  "active": {
+    "filed": "sum(activation) as active ",
+    "comment": "激活数"
+  },
+  "activeCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.activation) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.activation) end AS activeCost ",
+    "comment": "激活单价"
+  },
+  "activeRate": {
+    "filed": "CASE WHEN sum(t1.activation) / sum(t1.download_completed) IS NULL THEN 0 ELSE concat(round(sum(t1.activation) / sum(t1.download_completed)*100,2),'%') end as activeRate ",
+    "comment": "下载完成激活率"
+  },
+  "firstDayPay": {
+    "filed": "sum(t1.event_pay_first_day) as firstDayPay  ",
+    "comment": "首日付费次数"
+  },
+  "firstDayPayAmount": {
+    "filed": "sum(t1.event_pay_purchase_amount_first_day) as firstDayPayAmount  ",
+    "comment": "首日付费金额"
+  },
+  "firstDayPayCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_pay_first_day) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.event_pay_first_day) end AS firstDayPayCost ",
+    "comment": "首日付费成本"
+  },
+  "firstDayPayROI": {
+    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge) IS NULL THEN 0 ELSE sum(t1.event_pay_purchase_amount_first_day) / sum(t1.charge) end AS firstDayPayROI ",
+    "comment": "首日ROI"
+  },
+  "eventPay": {
+    "filed": "sum(t1.event_pay) as eventPay  ",
+    "comment": "付费次数"
+  },
+  "eventPayPurchaseAmount": {
+    "filed": "sum(t1.event_pay_purchase_amount) as eventPayPurchaseAmount  ",
+    "comment": "付费金额"
+  },
+  "eventPayCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_pay) IS NULL THEN 0 ELSE sum(t1.charge) / sum(t1.event_pay) end AS eventPayCost ",
+    "comment": "付费次数成本"
+  },
+  "ROI": {
+    "filed": "CASE WHEN sum(t1.event_pay_purchase_amount) / sum(t1.charge) IS NULL THEN 0 ELSE sum(t1.event_pay_purchase_amount) / sum(t1.charge) end AS ROI ",
+    "comment": "ROI"
+  },
+  "register": {
+    "filed": "sum(t1.event_register) as register ",
+    "comment": "注册数"
+  },
+  "activeRegisterCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_register) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_register),3) end as activeRegisterCost ",
+    "comment": "注册成本"
+  },
+  "activeRegisterRate": {
+    "filed": " CASE WHEN sum(t1.event_register) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.event_register) / sum(t1.activation)*100,2),'%') end as activeRegisterRate ",
+    "comment": "注册率"
+  },
+  "eventJinJianApp": {
+    "filed": "sum(event_jin_jian_app) as eventJinJianApp ",
+    "comment": "完件数"
+  },
+  "eventJinJianAppCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_jin_jian_app) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_jin_jian_app),3) end as eventJinJianAppCost ",
+    "comment": "完件成本"
+  },
+  "eventCreditGrantApp": {
+    "filed": "sum(event_credit_grant_app) as eventCreditGrantApp ",
+    "comment": "授信数"
+  },
+  "eventCreditGrantAppCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_credit_grant_app) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_credit_grant_app),3) end as eventCreditGrantAppCost ",
+    "comment": "授信成本"
+  },
+  "eventCreditGrantAppRate": {
+    "filed": "CASE WHEN sum(t1.event_credit_grant_app) / sum(t1.event_jin_jian_app) IS NULL THEN 0 ELSE concat(round(sum(t1.event_credit_grant_app) / sum(t1.event_jin_jian_app)*100,2),'%') end as eventCreditGrantAppRate ",
+    "comment": "授信率"
+  },
+  "formCount": {
+    "filed": "sum(t1.form_count) as formCount ",
+    "comment": "表单提交数"
+  },
+  "formCountRate": {
+    "filed": "CASE WHEN sum(t1.form_count) / sum(t1.activation) IS NULL THEN 0 ELSE concat(round(sum(t1.form_count) / sum(t1.activation)*100,2),'%') end as formCountRate ",
+    "comment": "表单提交率"
+  },
+  "formCountCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.form_count) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.form_count),3) end as eventCreditGrantAppCost ",
+    "comment": "授信成本"
+  },
+  "eventJinJianLandingPage": {
+    "filed": "sum(t1.event_jin_jian_landing_page) as eventJinJianLandingPage ",
+    "comment": "落地页完件数"
+  },
+  "eventJinJianLandingPageCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_jin_jian_landing_page) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_jin_jian_landing_page),3) end as eventJinJianLandingPageCost ",
+    "comment": "落地页完件成本"
+  },
+  "eventCreditGrantLandingPage": {
+    "filed": "sum(t1.event_credit_grant_landing_page) as eventCreditGrantLandingPage ",
+    "comment": "落地页授信数"
+  },
+  "eventCreditGrantLandingPageCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.event_credit_grant_landing_page) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.event_credit_grant_landing_page),3) end as eventCreditGrantLandingPageCost ",
+    "comment": "落地页授信成本"
+  },
+  "eventCreditGrantLandingPageRate": {
+    "filed": "CASE WHEN sum(t1.event_credit_grant_landing_page) / sum(t1.event_jin_jian_landing_page) IS NULL THEN 0 ELSE concat(round(sum(t1.event_credit_grant_landing_page) / sum(t1.event_jin_jian_landing_page)*100,2),'%') end as formCountRate ",
+    "comment": "落地页授信率"
+  },
+  "submit": {
+    "filed": "sum(t1.submit) as submit ",
+    "comment": "按钮点击数"
+  },
+  "submitCost": {
+    "filed": "CASE WHEN sum(t1.charge) / sum(t1.submit) IS NULL THEN 0 ELSE round(sum(t1.charge)/sum(t1.submit),3) end as submitCost ",
+    "comment": "按钮点击成本"
+  },
+  "submitRate": {
+    "filed": "CASE WHEN sum(t1.submit) / sum(t1.bclick) IS NULL THEN 0 ELSE concat(round(sum(t1.submit) / sum(t1.bclick)*100,2),'%') end as submitRate ",
+    "comment": "按钮点击率"
+  }
+}

+ 3 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/controller/BytedanceAccountReportCtrl.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.AccountReportConstants;
 import org.jeecg.common.util.JsonResourceUtil;
 import org.jeecg.common.util.JsonResourceUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -113,11 +114,11 @@ public class BytedanceAccountReportCtrl {
         if(columns.isEmpty()){
         if(columns.isEmpty()){
             log.error("请选择需要导出的字段");
             log.error("请选择需要导出的字段");
         }
         }
-        String filed= JsonResourceUtil.joinFiled(columns);
+        String filed= JsonResourceUtil.joinFiled(AccountReportConstants.dicMap,columns);
         List<String> titles= new ArrayList<>();
         List<String> titles= new ArrayList<>();
         titles.add("账户Id");
         titles.add("账户Id");
         titles.add("账户名称");
         titles.add("账户名称");
-        titles.addAll(JsonResourceUtil.joinTitle(columns));
+        titles.addAll(JsonResourceUtil.joinTitle(AccountReportConstants.dicMap,columns));
         //此处增加两个元素是为了保证数据有序
         //此处增加两个元素是为了保证数据有序
         columns.add(0,"accountId");
         columns.add(0,"accountId");
         columns.add(1,"authName");
         columns.add(1,"authName");

+ 3 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/service/impl/BytedanceAccountReportServiceImpl.java

@@ -11,6 +11,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.constant.AccountReportConstants;
 import org.jeecg.common.constant.SystemDateConstant;
 import org.jeecg.common.constant.SystemDateConstant;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.DateUtils;
@@ -65,7 +66,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
     @Override
     @Override
     public List<JSONObject> getChartDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate) throws ParseException {
     public List<JSONObject> getChartDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate) throws ParseException {
         List<JSONObject> result=new ArrayList<>();
         List<JSONObject> result=new ArrayList<>();
-        String filedAll = JsonResourceUtil.joinAllFiled();
+        String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMap);
         if (startDate.equals(endDate)) {
         if (startDate.equals(endDate)) {
             List<JSONObject> after = bytedanceAccountReportMapper.queryTodayDetailReportBy(filedAll, startDate, accounts);
             List<JSONObject> after = bytedanceAccountReportMapper.queryTodayDetailReportBy(filedAll, startDate, accounts);
             List<JSONObject> before = bytedanceAccountReportMapper.queryTodayDetailReportBy(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), accounts);
             List<JSONObject> before = bytedanceAccountReportMapper.queryTodayDetailReportBy(filedAll, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, startDate, -1), accounts);
@@ -98,7 +99,7 @@ public class BytedanceAccountReportServiceImpl implements IBytedanceAccountRepor
     @Override
     @Override
     public List<JSONObject> getListDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
     public List<JSONObject> getListDataBy(String mediaId, BigDecimal discount, JSONArray accounts, String startDate, String endDate, int hour, String target, String order) {
         List<JSONObject> result;
         List<JSONObject> result;
-        String filedAll = JsonResourceUtil.joinAllFiled();
+        String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMap);
         if (startDate.equals(endDate)) {
         if (startDate.equals(endDate)) {
             result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
             result = bytedanceAccountReportMapper.queryTodaySumByHourGroupAccount(filedAll, startDate, hour, accounts, target, order);
             JSONObject afterSum = bytedanceAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);
             JSONObject afterSum = bytedanceAccountReportMapper.querySumByHour(filedAll, startDate, hour, accounts);