zhaoxian 3 роки тому
батько
коміт
8823f06b8a
19 змінених файлів з 3038 додано та 201 видалено
  1. 55 2
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
  2. 2 1
      jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  3. 251 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/KuaiShouMaterialStareController.java
  4. 0 42
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/MaterialStareController.java
  5. 148 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/SysManagerCompanyController.java
  6. 87 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/SysManagerCompany.java
  7. 59 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouAccountPieVo.java
  8. 119 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateAccountVo.java
  9. 109 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateProjectVo.java
  10. 47 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateVo.java
  11. 58 6
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialStareMapper.java
  12. 55 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/SysManagerCompanyMapper.java
  13. 650 39
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/MaterialStareMapper.xml
  14. 325 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/SysManagerCompanyMapper.xml
  15. 33 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/ISysManagerCompanyService.java
  16. 26 1
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/MaterialStareService.java
  17. 517 108
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/MaterialStareServiceImpl.java
  18. 460 0
      jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/SysManagerCompanyServiceImpl.java
  19. 37 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/UserCompanyController.java

+ 55 - 2
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.util.StringUtils;
 
 import java.beans.PropertyEditorSupport;
+import java.sql.SQLOutput;
 import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.ParseException;
@@ -1089,6 +1090,7 @@ public class DateUtils extends PropertyEditorSupport {
         return sdf.format(calendar.getTime());
     }
 
+
     public static Date addDay(Date date, int day) {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(date);
@@ -1924,12 +1926,63 @@ public class DateUtils extends PropertyEditorSupport {
 
 
 
+    /**
+     * 根据本阶段日期 获取上阶段 开始 和 截至 日期
+     * @param startTime 本阶段开始时间
+     * @param endTime 本阶段截至时间
+     * @return
+     * @throws ParseException
+     */
+    public static Map<String,String> getStartEndTime(String startTime,String endTime) throws ParseException {
+        Map<String,String> timeMap = new HashMap();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date start = sdf.parse(startTime);
+        Date end = sdf.parse(endTime);
+        //相差天数
+        Long daysBetween = (end.getTime()-start.getTime())/(60*60*24*1000);
+        String lastTimeStart = getSubtractTime(start, daysBetween.intValue());
+        String lastTimeEnd = getSubtractTime(end, daysBetween.intValue());
+        timeMap.put("lastTimeStart",lastTimeStart);
+        timeMap.put("lastTimeEnd",lastTimeEnd);
+        timeMap.put("daysBetween",daysBetween.toString());
+        return timeMap;
+    }
+
+    /**
+     * 返回 日期 - 天数 的string 日期
+     * @param time 时间
+     * @param daysBetween 天数
+     * @return
+     */
+    public static String getSubtractTime(Date time,Integer daysBetween){
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar rightNow  = Calendar.getInstance();
+        rightNow .setTime(time);
+        if (daysBetween.intValue() > 0){
+            rightNow .add(Calendar.DAY_OF_YEAR,-daysBetween.intValue()-1);//日期加 相差的 天数 再 -1
+        }else {
+            rightNow .add(Calendar.DAY_OF_YEAR,-1);//日期 -1
+        }
+        Date rightNowTime = rightNow .getTime();
+        String nowTime = sdf.format(rightNowTime);
+        return nowTime;
+    }
+
 
 
-    public static void main(String[] args) {
+
+
+    public static void main(String[] args) throws Exception{
         //System.out.println(DateUtils.getFirstDayByMonth());
-        System.out.println(intDateToString("20210101"));
+        //System.out.println(intDateToString("20210101"));
+
+       // SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
+        //System.out.println(sdf1.parse("20220115"));
 
+       /* Double  a = 3.268890;
+        System.out.println(String.format("%.3f", a));
+*/
+        System.out.println(DateUtils.addDayParse("20220224",-1));
 
     }
 

+ 2 - 1
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -245,7 +245,8 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/stare/**", "anon");
         filterChainDefinitionMap.put("/boss/**", "anon");
         filterChainDefinitionMap.put("/external/materialCollection/*", "anon");
-
+        filterChainDefinitionMap.put("/kuaiShouOpreate/**", "anon");
+        filterChainDefinitionMap.put("/manager/company/*", "anon");
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);
         filterMap.put("jwt", new JwtFilter());

+ 251 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/KuaiShouMaterialStareController.java

@@ -0,0 +1,251 @@
+package org.jeecg.ctop.material.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.material.service.MaterialStareService;
+import org.jeecg.ctop.material.service.impl.MaterialStareServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Set;
+
+/**
+ * 快手-运营数据盯盘
+ */
+@Slf4j
+@RestController
+@RequestMapping("/kuaiShouOpreate/kuaiShouMaterialStareController")
+public class KuaiShouMaterialStareController {
+
+
+    @Autowired
+    MaterialStareService materialStareService;
+
+
+    /**
+     *
+     * @description:数据总览-快手
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param type 查询类型 1-汇总 2-运营个人
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @author: zianY
+     * @time: 2022/2/15
+     */
+    @GetMapping("/kuaiShousumData")
+    public Result<JSONObject> kuaiShousumData(@RequestParam(name="mediaType",defaultValue = "2") String mediaType,
+                                              @RequestParam(name="type") String type,
+                                              @RequestParam(name="startTime") String startTime,
+                                              @RequestParam(name="endTime") String endTime,
+                                              @RequestParam(name="userId") String userId) {
+        return materialStareService.kuaiShousumData(mediaType, type, startTime, endTime, userId);
+    }
+
+
+    /**
+     *
+     * @description: 快手-运营组数据
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/15
+     */
+    @GetMapping("/kuaiShouOperateDateTotal")
+    public Result<JSONObject> kuaiShouOperateDateTotal(@RequestParam(name="mediaType") String mediaType,
+                                              @RequestParam(name="startTime") String startTime,
+                                              @RequestParam(name="endTime") String endTime,
+                                              @RequestParam(name="userId") String userId) {
+
+        return materialStareService.kuaiShouOperateDateTotal(mediaType, startTime, endTime, userId);
+    }
+
+
+    /**
+     *
+     * @description: 运营数据详情
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/16
+     */
+    @GetMapping("/getKuaiShouOperateInfo")
+    public Result<JSONObject> getKuaiShouOperateInfo(@RequestParam(name="pageNum",defaultValue = "1") Integer pageNum,
+                                                       @RequestParam(name="pageSize",defaultValue = "5") int pageSize,
+                                              @RequestParam(name="startTime") String startTime,
+                                              @RequestParam(name="endTime") String endTime,
+                                              @RequestParam(name="userId") String userId) {
+        return materialStareService.getKuaiShouOperateInfo(pageNum, pageSize,startTime, endTime, userId);
+    }
+
+    @GetMapping("/exportKuaiShouOperateInfo")
+    public Result<JSONObject> exportKuaiShouOperateInfo(@RequestParam(name="startTime") String startTime,
+                                              @RequestParam(name="endTime") String endTime,
+                                              @RequestParam(name="userId") String userId,
+                                                        HttpServletResponse response) {
+        return materialStareService.exportKuaiShouOperateInfo(startTime, endTime, userId,response);
+    }
+
+
+    /**
+     *
+     * @description:运营数据-项目列表
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/17
+     */
+    @GetMapping("/getKuaiShouOperateProjectInfo")
+    public Result<JSONObject> getKuaiShouOperateProjectInfo(@RequestParam(name="pageNum",defaultValue = "1") Integer pageNum,
+                                                     @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
+                                                     @RequestParam(name="startTime") String startTime,
+                                                     @RequestParam(name="endTime") String endTime,
+                                                     @RequestParam(name="userId") String userId) {
+
+        return materialStareService.getKuaiShouOperateProjectInfo(pageNum, pageSize,startTime, endTime, userId);
+    }
+
+
+
+    /**
+     *
+     * @description:运营数据-账户列表
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param projectId
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/18
+     */
+    @GetMapping("/getKuaiShouOperateAccountInfo")
+    public Result<JSONObject> getKuaiShouOperateAccountInfo(@RequestParam(name="pageNum",defaultValue = "1") Integer pageNum,
+                                                     @RequestParam(name="pageSize",defaultValue = "1000") int pageSize,
+                                                     @RequestParam(name="startTime") String startTime,
+                                                     @RequestParam(name="endTime") String endTime,
+                                                     @RequestParam(name="projectId",required = false) String projectId,
+                                                     @RequestParam(name="userId") String userId) {
+
+
+        return materialStareService.getKuaiShouOperateAccountInfo(pageNum, pageSize,startTime, endTime,projectId, userId);
+    }
+
+
+    /**
+     *
+     * @description: 查询账户余额 以及 账户状态 和 消耗
+     *
+     * @param accountId
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/21 14:39
+     */
+    @GetMapping("/getKuaiShouAccountInfo")
+    public Result<JSONObject> getKuaiShouAccountInfo(@RequestParam(name="accountId") long accountId) {
+        return materialStareService.getKuaiShouAccountInfo(accountId);
+    }
+
+
+    /**
+     *
+     * @description: 账户 折线图 查询时间为当天查询时报;查询时间为多天 查询日报
+     *
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/21
+     */
+    @GetMapping("/getKuaiShouAccountInfoBrokenLine")
+    public Result<JSONObject> getKuaiShouAccountInfoBrokenLine(@RequestParam(name="accountId") long accountId,
+                                                     @RequestParam(name="startTime") String startTime,
+                                                     @RequestParam(name="endTime") String endTime) {
+        return materialStareService.getKuaiShouAccountInfoBrokenLine(accountId,startTime,endTime);
+    }
+
+
+
+    /**
+     *
+     * @description: 快手 账户 素材上新-有效-爆款
+     *
+     * @param accountId
+     * @param searchType searchType:查询类型  0-全部 1-上新 2-有效 3-爆款
+     * @param startTime
+     * @param endTime
+     * @return: org.jeecg.common.api.vo.Result<com.alibaba.fastjson.JSONObject>
+     * @author: zianY
+     * @time: 2022/2/21
+     */
+    @GetMapping("/getKuaiShouAccountMaterialNewAndEffectAndFaddish")
+    public Result<JSONObject> getKuaiShouAccountMaterialNewAndEffectAndFaddish(@RequestParam(name="accountId") long accountId,
+                                                                               @RequestParam(name="searchType") String searchType,
+                                                                               @RequestParam(name="startTime") String startTime,
+                                                                               @RequestParam(name="endTime") String endTime,
+                                                                               @RequestParam(name="pageNum",defaultValue = "1") Integer pageNum,
+                                                                               @RequestParam(name="pageSize",defaultValue = "10") Integer pageSize) {
+        return materialStareService.getKuaiShouAccountMaterialNewAndEffectAndFaddish(accountId,searchType,startTime,endTime,pageNum,pageSize);
+    }
+
+
+
+    /**
+     *
+     * @description: 查询账户饼图数据信息 分版位;年龄;性别
+     *
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @param type 查询类型 额。。。 查询选中的指标 --、 给前端组装数据格式  I didn't want to write
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/22
+     */
+    @GetMapping("/getKuaiShouAccountPieChar")
+    public Result getKuaiShouAccountPieChar(@RequestParam(name="accountId") long accountId,
+                                            @RequestParam(name="startTime") String startTime,
+                                            @RequestParam(name="endTime") String endTime,
+                                            @RequestParam(name="type") String type) {
+        return materialStareService.getKuaiShouAccountPieChar(accountId,startTime,endTime,type);
+    }
+
+
+
+
+    //获取当前用户所属公司的所有下级
+    @GetMapping("/getCompanyAllSubordinateByUserId")
+    public Result getCompanyAllSubordinateByUserId(@RequestParam(name="userId") String userId) {
+       return materialStareService.getCompanyAllSubordinateByUserId(userId);
+    }
+
+
+
+
+
+
+
+
+
+
+}

+ 0 - 42
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/MaterialStareController.java

@@ -1,42 +0,0 @@
-package org.jeecg.ctop.material.controller;
-
-import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.ctop.material.service.MaterialStareService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.Set;
-
-/**
- * 盯盘接口
- */
-@Slf4j
-@RestController
-@RequestMapping("/stare")
-public class MaterialStareController {
-
-
-    @Autowired
-    MaterialStareService materialStareService;
-
-    /**
-     * 数据总览
-     */
-    @PostMapping("/sumData")
-    public Result<JSONObject> sumData(@RequestBody JSONObject params) {
-        Result<Set<JSONObject>> result = new Result<>();
-        return materialStareService.sumData(params.getInteger("mediaId"),
-                params.getInteger("userType"),
-                params.getString("userId"),
-                params.getString("startDate"),
-                params.getString("endDate"),
-                params.getInteger("type"));
-    }
-
-
-}

+ 148 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/controller/SysManagerCompanyController.java

@@ -0,0 +1,148 @@
+package org.jeecg.ctop.material.controller;
+
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.material.constants.Check;
+import org.jeecg.ctop.material.service.ISysManagerCompanyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 总经理&公司记录表
+ */
+@Slf4j
+@Api(tags = "总经理&公司记录表")
+@RestController
+@RequestMapping("/manager/company")
+public class SysManagerCompanyController {
+    @Autowired
+    private ISysManagerCompanyService sysManagerCompanyService;
+
+    /**
+     * 列表查询
+     */
+    @GetMapping(value = "/getCompanyList")
+    public Result<Object> queryPageList() {
+        return Result.ok(sysManagerCompanyService.list());
+    }
+
+
+    /**
+     * 素材产出
+     */
+    @GetMapping(value = "/getMaterialProduce")
+    public Result<Object> getMaterialProduce(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        return sysManagerCompanyService.getMaterialProduce(startTime, endTime, companyId, mediaId);
+    }
+
+    /**
+     * 素材产出消耗
+     */
+    @GetMapping(value = "/getMaterialProduceConsume")
+    public Result<Object> getMaterialProduceConsume(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        return sysManagerCompanyService.getMaterialProduceConsume(startTime, endTime, companyId, mediaId);
+    }
+
+    /**
+     * 运营消耗情况
+     */
+    @GetMapping(value = "/getOperaterConsume")
+    public Result<Object> getOperaterConsume(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        return sysManagerCompanyService.getOperaterConsume(startTime, endTime, companyId, mediaId);
+    }
+
+    /**
+     * 设置本月消耗完成度
+     */
+    @GetMapping(value = "/setConsumeValue")
+    public Result<Object> setConsumeValue(String companyId, String targetValue, int mediaId) {
+        if (Check.isNull(companyId) || Check.isNull(mediaId) || Check.isNull(targetValue)) {
+            return Result.error("缺少参数");
+        }
+        try {
+            sysManagerCompanyService.setConsumeValue(companyId, targetValue, mediaId);
+            return Result.ok("success");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("修改失败");
+        }
+    }
+
+    /**
+     * 项目消耗Top10
+     */
+    @GetMapping(value = "/getProjectConsumeTop")
+    public Result<Object> getProjectConsumeTop(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(companyId) || Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        try {
+            return sysManagerCompanyService.getProjectConsumeTop(startTime, endTime, companyId, mediaId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询失败");
+        }
+    }
+
+
+    /**
+     * 分媒体投放数据
+     */
+    @GetMapping(value = "/getMediaData")
+    public Result<Object> getMediaData(String companyId) {
+        if (Check.isNull(companyId)) {
+            return Result.error("缺少参数");
+        }
+        try {
+            return sysManagerCompanyService.getMediaData(companyId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询失败");
+        }
+    }
+
+    /**
+     * 当日实时整体数据概览
+     */
+    @GetMapping(value = "/getRealTimeData")
+    public Result<Object> getRealTimeData(String companyId,int mediaId) {
+        if (Check.isNull(companyId)||Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        try {
+            return sysManagerCompanyService.getRealTimeData(companyId,mediaId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询失败");
+        }
+    }
+
+    /**
+     * 查询本月总消耗
+     */
+    @GetMapping(value = "/getTotalConsume")
+    public Result<Object> getTotalConsume(String companyId,int mediaId) {
+        if (Check.isNull(companyId)||Check.isNull(mediaId)) {
+            return Result.error("缺少参数");
+        }
+        try {
+            return sysManagerCompanyService.getTotalConsume(companyId,mediaId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return Result.error("查询失败");
+        }
+    }
+
+}

+ 87 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/SysManagerCompany.java

@@ -0,0 +1,87 @@
+package org.jeecg.ctop.material.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * 总经理&公司记录表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2022-02-22
+ */
+@Data
+@TableName("sys_manager_company")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "sys_manager_company对象", description = "总经理&公司记录表")
+public class SysManagerCompany {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 经理id
+     */
+    @Excel(name = "经理id", width = 15)
+    @ApiModelProperty(value = "经理id")
+    private String manageId;
+    /**
+     * 部门id
+     */
+    @Excel(name = "部门id", width = 15)
+    @ApiModelProperty(value = "部门id")
+    private String companyId;
+    /**
+     * 公司名称
+     */
+    @Excel(name = "公司名称", width = 15)
+    @ApiModelProperty(value = "公司名称")
+    private String companyName;
+    /**
+     * 快手运营部ID
+     */
+    @Excel(name = "快手运营部ID", width = 15)
+    @ApiModelProperty(value = "快手运营部ID")
+    private String ksOperateId;
+    /**
+     * 快手设计部ID
+     */
+    @Excel(name = "快手设计部ID", width = 15)
+    @ApiModelProperty(value = "快手设计部ID")
+    private String ksDesignId;
+    /**
+     * 快手消耗目标值
+     */
+    @Excel(name = "快手消耗目标值", width = 15)
+    @ApiModelProperty(value = "快手消耗目标值")
+    private String ksTargetValue;
+    /**
+     * 头条运营部ID
+     */
+    @Excel(name = "头条运营部ID", width = 15)
+    @ApiModelProperty(value = "头条运营部ID")
+    private String ttOperateId;
+    /**
+     * 头条设计部ID
+     */
+    @Excel(name = "头条设计部ID", width = 15)
+    @ApiModelProperty(value = "头条设计部ID")
+    private String ttDesignId;
+    /**
+     * 头条消耗目标值
+     */
+    @Excel(name = "头条消耗目标值", width = 15)
+    @ApiModelProperty(value = "头条消耗目标值")
+    private String ttTargetValue;
+}

+ 59 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouAccountPieVo.java

@@ -0,0 +1,59 @@
+package org.jeecg.ctop.material.entity.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 盯盘- 账户维度 数据  环形图
+ * zian Y
+ * 2022/2/16
+ **/
+
+@Data
+public class KuaiShouAccountPieVo implements Serializable {
+
+
+    @ApiModelProperty(value = "版位")
+    private String adScene;
+
+    @ApiModelProperty(value = "年龄段落")
+    private String ageSegment;
+
+    @ApiModelProperty(value = "性别")
+    private String gender;
+
+    @ApiModelProperty(value = "花费")
+    private Double cost;
+
+    @ApiModelProperty(value = "激活数")
+    private Integer activation;
+
+    @ApiModelProperty(value = "激活成本")
+    private Double activationPrice;
+
+    @ApiModelProperty(value = "ROI")
+    private Double eventPayRoi;
+
+    @ApiModelProperty(value = "付费次数")
+    private Integer eventPay;
+
+    @ApiModelProperty(value = "付费成本")
+    private Double eventPayCost;
+
+    @ApiModelProperty(value = "首日付费金额")
+    private Double eventPayPurchaseAmountFirstDay;
+
+    @ApiModelProperty(value = "次留数")
+    private Integer eventNextDayStay;
+
+    @ApiModelProperty(value = "次留")
+    private String leave;
+
+
+
+
+
+}

+ 119 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateAccountVo.java

@@ -0,0 +1,119 @@
+package org.jeecg.ctop.material.entity.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 盯盘-运营数据 账户维度
+ * zian Y
+ * 2022/2/16
+ **/
+
+@Data
+public class KuaiShouOperateAccountVo {
+
+
+    @ApiModelProperty(value = "账户id")
+    private long accountId;
+    private String accountName;
+
+    @ApiModelProperty(value = "总花费")
+    private Double totalCost;
+
+    private String projectId;
+    private String projectName;
+
+    @ApiModelProperty(value = "运营姓名")
+    private String userName;
+
+    @ApiModelProperty(value = "激活数")
+    private Integer activation;
+
+    @ApiModelProperty(value = "激活单价")
+    private String activationPrice;
+
+    @ApiModelProperty(value = "次留")
+    private String leave;
+
+    @ApiModelProperty(value = "付费次数")
+    private Integer eventPay;
+
+    @ApiModelProperty(value = "付费成本")
+    private String eventPayCost;
+
+    @ApiModelProperty(value = "付费率")
+    private String eventPayRate;
+
+    @ApiModelProperty(value = "新增付费人数")
+    private Integer eventNewUserPay;
+
+    @ApiModelProperty(value = "新增付费成本")
+    private String eventNewUserPayCost;
+
+    @ApiModelProperty(value = "新增付费率")
+    private String eventNewUserPayRate;
+
+    @ApiModelProperty(value = "唤起应用数")
+    private Integer eventAppInvoked;
+
+    @ApiModelProperty(value = "唤起应用成本")
+    private String eventAppInvokedCost;
+
+    @ApiModelProperty(value = "注册数")
+    private Integer eventRegister;
+
+    @ApiModelProperty(value = "注册成本")
+    private String eventRegisterCost;
+
+    @ApiModelProperty(value = "关键行为数")
+    private Integer keyAction;
+
+    @ApiModelProperty(value = "关键行为成本")
+    private String keyActionCost;
+
+    @ApiModelProperty(value = "关键行为率")
+    private String keyActionRate;
+
+    @ApiModelProperty(value = "首日付费金额")
+    private String eventPayPurchaseAmountFirstDay;
+
+    @ApiModelProperty(value = "首日ROI")
+    private String eventPayFirstDayRoi;
+
+    @ApiModelProperty(value = "表单提交数")
+    private Integer formCount;
+
+    @ApiModelProperty(value = "表单提交单价")
+    private String formCountPrice;
+
+    @ApiModelProperty(value = "有效视频数量")
+    private Integer newEffectNum;
+
+    @ApiModelProperty(value = "上新视频数量")
+    private Integer newVideoNum;
+
+    @ApiModelProperty(value = "爆款视频数量")
+    private Integer newHotNum;
+
+    @ApiModelProperty(value = "封面曝光数")
+    private Integer photoShow;
+
+    @ApiModelProperty(value = "封面点击数")
+    private Integer photoClick;
+
+
+
+
+
+
+    @ApiModelProperty(value = "环比")
+    private Double yearOnYear;
+
+    @ApiModelProperty(value = "同比")
+    private Double equallyRate;
+
+
+
+
+
+}

+ 109 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateProjectVo.java

@@ -0,0 +1,109 @@
+package org.jeecg.ctop.material.entity.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 盯盘-运营数据 项目维度
+ * zian Y
+ * 2022/2/16
+ **/
+
+@Data
+public class KuaiShouOperateProjectVo {
+
+
+    @ApiModelProperty(value = "账户数量")
+    private Integer accountNum;
+
+    @ApiModelProperty(value = "总花费")
+    private Double totalCost;
+
+    private String projectId;
+    private String projectName;
+
+    @ApiModelProperty(value = "用户数量")
+    private Integer userNum;
+
+    @ApiModelProperty(value = "激活数")
+    private Integer activation;
+
+    @ApiModelProperty(value = "激活单价")
+    private String activationPrice;
+
+    @ApiModelProperty(value = "次留")
+    private String leave;
+
+    @ApiModelProperty(value = "付费次数")
+    private Integer eventPay;
+
+    @ApiModelProperty(value = "付费成本")
+    private String eventPayCost;
+
+    @ApiModelProperty(value = "付费率")
+    private String eventPayRate;
+
+    @ApiModelProperty(value = "新增付费人数")
+    private Integer eventNewUserPay;
+
+    @ApiModelProperty(value = "新增付费成本")
+    private String eventNewUserPayCost;
+
+    @ApiModelProperty(value = "新增付费率")
+    private String eventNewUserPayRate;
+
+    @ApiModelProperty(value = "唤起应用数")
+    private Integer eventAppInvoked;
+
+    @ApiModelProperty(value = "唤起应用成本")
+    private String eventAppInvokedCost;
+
+    @ApiModelProperty(value = "注册数")
+    private Integer eventRegister;
+
+    @ApiModelProperty(value = "注册成本")
+    private String eventRegisterCost;
+
+    @ApiModelProperty(value = "关键行为数")
+    private Integer keyAction;
+
+    @ApiModelProperty(value = "关键行为成本")
+    private String keyActionCost;
+
+    @ApiModelProperty(value = "关键行为率")
+    private String keyActionRate;
+
+    @ApiModelProperty(value = "首日付费金额")
+    private String eventPayPurchaseAmountFirstDay;
+
+    @ApiModelProperty(value = "首日ROI")
+    private String eventPayFirstDayRoi;
+
+    @ApiModelProperty(value = "表单提交数")
+    private Integer formCount;
+
+    @ApiModelProperty(value = "表单提交单价")
+    private String formCountPrice;
+
+    @ApiModelProperty(value = "有效视频数量")
+    private Integer newEffectNum;
+
+    @ApiModelProperty(value = "上新视频数量")
+    private Integer newVideoNum;
+
+    @ApiModelProperty(value = "爆款视频数量")
+    private Integer newHotNum;
+
+
+    @ApiModelProperty(value = "环比")
+    private Double yearOnYear;
+
+    @ApiModelProperty(value = "同比")
+    private Double equallyRate;
+
+
+
+
+
+}

+ 47 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/entity/vo/KuaiShouOperateVo.java

@@ -0,0 +1,47 @@
+package org.jeecg.ctop.material.entity.vo;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 盯盘-运营数据
+ * zian Y
+ * 2022/2/16
+ **/
+
+@Data
+public class KuaiShouOperateVo implements Serializable {
+
+
+
+    @Excel(name = "运营人员",width = 15)
+    private String userName;
+
+    @Excel(name = "账户数量",width = 10)
+    private Integer accountNum;
+
+    @Excel(name = "总花费",width = 20)
+    private Double totalCost;
+
+    @Excel(name = "花费环比",width = 10)
+    private Double rate;
+
+    private String userId;
+
+    @Excel(name = "有效素材数",width = 15)
+    private Integer newEffectNum;
+
+    @Excel(name = "新上计划数",width = 15)
+    private Integer newCampaignNum;
+
+    @Excel(name = "新上组数",width = 15)
+    private Integer newUnitNum;
+
+
+
+
+
+}

+ 58 - 6
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/MaterialStareMapper.java

@@ -3,6 +3,10 @@ package org.jeecg.ctop.material.mapper;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateVo;
 
 import java.util.List;
 import java.util.Map;
@@ -11,15 +15,63 @@ import java.util.Set;
 @Mapper
 public interface MaterialStareMapper {
 
-    List<Map> getCostByUserIdList(@Param("today") Long today, @Param("yesterday") Long yesterday, @Param("list") Set<String> operatorUserIds);
 
-    List<Map> getCostByUserIdListMoreDay(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
+    String getUserCompanyByUserId(@Param("userId")String userId);
+    Set<String> getAffiliateId(@Param("leaderId")String leaderId,@Param("companyId")String companyId);
+    Set<String> querySubordinateRecursive(@Param("companyId")String companyId,@Param("leaderIds")Set<String> leaderIds);
+
+
+
+    // 快手 - 时报 查询
+    List<Map> getKuaiShouCostHourlyByUserIdList(@Param("startDate") Long today, @Param("endDate") Long yesterday, @Param("list") Set<String> operatorUserIds);
+    //快手-查询时报 消耗 前5
+    List<JSONObject> getKuaiShouCostByTop5HourList(@Param("startDate")Long start, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
+
+    //快手 -日报查询
+    List<Map> getKuaiShouCostDailyByUserIdList(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
+    //快手-查询日报 消耗 前5
+    List<JSONObject> getKuaiShouCostByTop5DailyList(@Param("startDate")Long start, @Param("endDate")Long end, @Param("list")Set<String> operatorUserIds);
+
+    //快手 时报总消耗
+    JSONObject getKuaiShouTotalCost(@Param("startDate")Long startDate,@Param("endDate")Long endDate, @Param("nowHour")int nowHour, @Param("list")Set<String> operatorUserIds);
+
+    //快手-查询账户数据信息
+    List<KuaiShouOperateVo> getKuaiShouOperateInfo(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("list")Set<String> operatorUserIds);
+
+    //快手 -查询 项目 数据信息
+    List<KuaiShouOperateProjectVo> getKuaiShouOperateProjectInfo(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("projectId")String projectId,@Param("list")Set<String> operatorUserIds);
+
+    //快手 -查询 账户 数据信息
+    List<KuaiShouOperateAccountVo> getKuaiShouOperateAccountInfo(@Param("startDate")Long startDate, @Param("endDate")Long endDate, @Param("projectId")String projectId,@Param("accountId")Long accountId, @Param("list")Set<String> operatorUserIds);
+
+
+
+    //快手 账户 余额
+    JSONObject getKuaiShouAccountBalance(@Param("accountId")Long accountId,@Param("statDate")Long statDate);
+    //快手 账户 消耗以及状态
+    JSONObject getKuaiShouAccountTotalCost(@Param("accountId")Long accountId,@Param("statDate")Long statDate);
+
+    //快手 账户趋势图-时报
+    List<JSONObject> getKuaiShouAccountInfoBrokenLineHour(@Param("accountId")Long accountId,@Param("statDate")Long statDate,@Param("endDate")Long endDate);
+    //快手 账户趋势图-日报
+    List<JSONObject> getKuaiShouAccountInfoBrokenLineDaily(@Param("accountId")Long accountId,@Param("startDate")Long startDate, @Param("endDate")Long endDate);
+
+    //快手 账户 素材上新-有效-爆款   searchType: 0-全部 1-上新 2-有效 3-爆款
+    List<JSONObject> getKuaiShouAccountMaterialNewAndEffectAndFaddish(@Param("accountId")Long accountId,@Param("searchType")String searchType,@Param("startDate")Long startDate, @Param("endDate")Long endDate);
+
+
+    //快手 账户饼图图-分版位
+    List<KuaiShouAccountPieVo> getKuaiShouAccountPieScene(@Param("accountId")Long accountId, @Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("type")String type);
+    //快手 账户饼图图-分年龄
+    List<KuaiShouAccountPieVo> getKuaiShouAccountPieAge(@Param("accountId")Long accountId, @Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("type")String type);
+    //快手 账户饼图图-分性别
+    List<KuaiShouAccountPieVo> getKuaiShouAccountPieGender(@Param("accountId")Long accountId, @Param("startDate")Long startDate, @Param("endDate")Long endDate,@Param("type")String type);
+
+
+
+
 
-    List<JSONObject> getCostByTop5List(@Param("startDate")Long start, @Param("list")Set<String> operatorUserIds);
 
-    List<JSONObject> getCostByTop5ListMoreDay(@Param("startDate")Long start, @Param("endDate")Long end, @Param("list")Set<String> operatorUserIds);
 
-    Set<String> getAffiliateId(@Param("leaderId")String userId);
 
-    Set<String> querySubordinateRecursive(@Param("leaderIds")Set<String> leaderIds);
 }

+ 55 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/SysManagerCompanyMapper.java

@@ -0,0 +1,55 @@
+package org.jeecg.ctop.material.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.ctop.material.entity.SysManagerCompany;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 总经理&公司记录表
+ *
+ * @author jeecg-boot
+ * 2022-02-22
+ * @version V1.0
+ */
+public interface SysManagerCompanyMapper extends BaseMapper<SysManagerCompany> {
+
+    List<JSONObject> queryDepartByParentId(@Param("designId") String designId);
+
+    List<String> queryAllPersonnel(@Param("list") List<JSONObject> list);
+
+    Long queryMaterialNumber(@Param("allPersonnel") List<String> allPersonnel, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<String> queryPersonnels(@Param("id") String id);
+
+    double queryKsMaterialCharge(@Param("clipIds") List<String> clipIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userIds") List<String> userIds);
+
+    Double queryTtMaterialCharge(@Param("clipIds") List<String> clipIds, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("userIds") List<String> userIds);
+
+    List<JSONObject> queryTtProjectConsumeTop(@Param("companyId") String companyId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<JSONObject> queryKsProjectConsumeTop(@Param("companyId") String companyId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    List<Map<String, String>> getKsMonthlyData(@Param("companyId") String companyId, @Param("startTime") Integer startTime, @Param("endTime") String endTime);
+
+    List<Map<String, String>> getTtMonthlyData(@Param("companyId") String companyId, @Param("startTime") Integer startTime, @Param("endTime") String endTime);
+
+    JSONObject queryKsRealTimeCost(@Param("companyId") String companyId, @Param("today") String today, @Param("lastDay") String lastDay, @Param("hour") Integer hour);
+
+    JSONObject queryKsRealTimeGroupNum(@Param("companyId") String companyId, @Param("today") String today, @Param("lastDay") String lastDay);
+
+    JSONObject queryTtRealTimeMaterialNum(@Param("companyId") String companyId,@Param("userIds") List<String> userIds, @Param("today") String today, @Param("lastDay") String lastDay);
+
+    JSONObject queryTtRealTimeCost(@Param("companyId") String companyId, @Param("today") String today, @Param("lastDay") String lastDay, @Param("hour") Integer hour);
+
+    JSONObject queryTtRealTimeGroupNum(@Param("companyId") String companyId, @Param("today") String today, @Param("lastDay") String lastDay);
+
+    JSONObject queryKsRealTimeMaterialNum(@Param("companyId") String companyId,@Param("userIds") List<String> userIds, @Param("today") String today, @Param("lastDay") String lastDay);
+
+    String getKsTotalConsume(@Param("companyId") String companyId, @Param("startTime") Integer startTime, @Param("endTime") String endTime);
+
+    String getTtTotalConsume(@Param("companyId") String companyId, @Param("startTime") Integer startTime, @Param("endTime") String endTime);
+}

+ 650 - 39
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/MaterialStareMapper.xml

@@ -2,14 +2,16 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.ctop.material.mapper.MaterialStareMapper">
 
-    <select id="getCostByUserIdList" resultType="Map">
-        SELECT t.`hour`,ROUND(SUM(charge),2) as todayCost,
-        (SELECT IFNULL(ROUND(SUM(charge),2),0)
-        from application.kuaishou_account_report_hourly_dw
-        WHERE stat_date =#{today}
-        and `hour`=t.`hour`) as yesterdayCost
-        from application.kuaishou_account_report_hourly_dw t
-        WHERE t.stat_date =#{yesterday}
+    <!-- 快手 时报  -->
+    <select id="getKuaiShouCostHourlyByUserIdList" resultType="Map">
+        SELECT
+        t.`hour`,
+        ROUND( SUM( charge ), 2 ) AS totalCost
+        FROM
+        application.kuaishou_account_report_hourly_dw t
+        where
+        stat_date &gt;= #{startDate}
+        AND stat_date &lt;= #{endDate}
         <if test='list!=null'>
             AND t.user_id IN
             <foreach collection="list" item="item" separator=","
@@ -17,13 +19,45 @@
                 #{item}
             </foreach>
         </if>
-        GROUP BY t.`hour` ORDER BY t.`hour`
+        GROUP BY t.`hour`
+        ORDER BY t.`hour`
     </select>
 
-    <select id="getCostByUserIdListMoreDay" resultType="Map">
-        SELECT DATE_FORMAT(t.stat_date,'%Y-%m-%d') as date,ROUND(SUM(charge),2) as cost
+
+
+
+    <!-- 快手-查询时报 消耗 前5 -->
+    <select id="getKuaiShouCostByTop5HourList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        user_id,
+        SUM( charge ) totalCost,
+        (SELECT realname from `jeecg-boot`.sys_user u where u.id = user_id) as userName
+        FROM
+        application.kuaishou_account_report_hourly_dw
+        WHERE
+        stat_date &gt;= #{startDate}
+        AND stat_date &lt;= #{endDate}
+        <if test='list!=null'>
+            AND user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY user_id ORDER BY SUM(charge) DESC LIMIT 5
+    </select>
+
+
+
+
+<!--快手 -日报  -->
+    <select id="getKuaiShouCostDailyByUserIdList" resultType="Map">
+        SELECT DATE_FORMAT(t.stat_date,'%Y-%m-%d') as dateTime,
+        ROUND(SUM(charge),2) as totalCost
         FROM application.kuaishou_account_report_daily_dw t
-        WHERE t.stat_date BETWEEN #{startDate} and #{endDate}
+        WHERE
+        t.stat_date &gt;= #{startDate}
+        AND t.stat_date &lt;= #{endDate}
         <if test='list!=null'>
             AND t.user_id IN
             <foreach collection="list" item="item" separator=","
@@ -31,13 +65,22 @@
                 #{item}
             </foreach>
         </if>
-        GROUP BY t.stat_date ORDER BY t.stat_date;
+        GROUP BY t.stat_date
+        ORDER BY t.stat_date;
     </select>
 
-    <select id="getCostByTop5List" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT SUM(t.charge)as cost,t.`hour` from
-        (SELECT user_id,SUM(charge) from application.kuaishou_account_report_hourly_dw
-        WHERE stat_date =#{startDate}
+
+    <!-- 快手-查询日报 消耗 前5 -->
+    <select id="getKuaiShouCostByTop5DailyList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        user_id,
+        SUM( charge ) totalCost,
+        (SELECT realname from `jeecg-boot`.sys_user u where u.id = user_id) as userName
+        FROM
+        application.kuaishou_account_report_daily_dw
+        WHERE
+        stat_date &gt;= #{startDate}
+        AND stat_date &lt;= #{endDate}
         <if test='list!=null'>
             AND user_id IN
             <foreach collection="list" item="item" separator=","
@@ -45,17 +88,29 @@
                 #{item}
             </foreach>
         </if>
-        GROUP BY user_id ORDER BY SUM(charge) DESC LIMIT 5) tt
-        LEFT JOIN application.kuaishou_account_report_hourly_dw t
-        on tt.user_id=t.user_id
-        WHERE t.stat_date =#{startDate} GROUP BY t.`hour`,tt.user_id ORDER BY t.`hour`,SUM(t.charge) ASC
+        GROUP BY user_id ORDER BY SUM(charge) DESC LIMIT 5
     </select>
 
 
-    <select id="getCostByTop5ListMoreDay" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT SUM(t.charge)as cost,t.stat_date as statDate from
-        (SELECT user_id,SUM(charge) from application.kuaishou_account_report_daily_dw
-        WHERE stat_date BETWEEN #{startDate}  and #{endDate}
+
+    <!-- 快手 时报总消耗 及 账户数量 -->
+    <select id="getKuaiShouTotalCost" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        ROUND( SUM( charge ), 2 ) AS totalCost,
+        COUNT(DISTINCT account_id) accountNum
+        FROM
+        application.kuaishou_account_report_hourly_dw
+        where 1 = 1
+        <if test="startDate != null and startDate != '' ">
+            and stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and stat_date &lt;= #{endDate}
+        </if>
+        <if test="nowHour != null and nowHour != '' ">
+            AND hour &lt;= #{nowHour}
+        </if>
+
         <if test='list!=null'>
             AND user_id IN
             <foreach collection="list" item="item" separator=","
@@ -63,27 +118,583 @@
                 #{item}
             </foreach>
         </if>
-        GROUP BY user_id ORDER BY SUM(charge) DESC LIMIT 5) tt
-        LEFT JOIN application.kuaishou_account_report_daily_dw t
-        on tt.user_id=t.user_id
-        WHERE t.stat_date BETWEEN #{startDate}  and #{endDate} GROUP BY t.stat_date,tt.user_id ORDER BY t.stat_date,SUM(t.charge) ASC
+
+    </select>
+
+
+
+    <!-- 快手 快手-查询账户数据信息 -->
+    <select id="getKuaiShouOperateInfo" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouOperateVo">
+        SELECT
+        SUM( d.charge ) totalCost,
+        COUNT(DISTINCT d.account_id) accountNum,
+        d.user_id as userId,
+        (SELECT u.realname from `jeecg-boot`.sys_user u where u.id = d.user_id) as userName,
+        m.newEffectNum,
+        m.newCampaignNum,
+        m.newUnitNum
+        FROM
+        application.kuaishou_account_report_daily_dw d
+        LEFT JOIN
+        (
+        SELECT abi.account_id ,
+        COUNT(abi.new_effect_num) as newEffectNum,
+        COUNT(abi.new_campaign_num) as newCampaignNum,
+        COUNT(abi.new_unit_num) as newUnitNum
+        from application.app_kuaishou_account_base_info_d abi
+            <where>
+                <if test="startDate != null and startDate != '' ">
+                    and abi.stat_date &gt;= #{startDate}
+                </if>
+                <if test="endDate != null and endDate != '' ">
+                    and abi.stat_date &lt;= #{endDate}
+                </if>
+            </where>
+            GROUP BY abi.account_id
+        ) m
+        on d.account_id = m.account_id
+        WHERE
+        d.charge > 0
+        <if test="startDate != null and startDate != '' ">
+            and d.stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and d.stat_date &lt;= #{endDate}
+        </if>
+        <if test='list!=null'>
+            AND d.user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY d.user_id
+        ORDER BY SUM( d.charge ) DESC
+    </select>
+
+    <!-- 快手 -查询项目数据信息 -->
+    <select id="getKuaiShouOperateProjectInfo" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo">
+        SELECT
+        SUM( d.charge ) AS totalCost,
+        COUNT( DISTINCT d.account_id ) AS accountNum,
+        d.project_id AS projectId,
+        d.project_name AS projectName,
+        COUNT( DISTINCT d.user_id ) AS userNum,
+        SUM( d.activation ) AS activation,
+        ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ) AS activationPrice,
+        CONCAT(ROUND(SUM( d.event_next_day_stay ) / SUM( d.activation ) * 100, 2 ),'%') AS leave,
+        SUM( d.event_pay ) AS eventPay,
+        ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ) AS eventPayCost,
+        CONCAT(ROUND( SUM( d.event_pay ) / ( SUM( d.activation ) + SUM( d.form_count )) * 100, 2 ),'%') AS eventPayRate,
+        SUM( d.event_new_user_pay ) AS eventNewUserPay,
+        ROUND( SUM( d.charge ) / SUM( d.event_new_user_pay ), 2 ) AS eventNewUserPayCost,
+        CONCAT(ROUND( SUM( d.event_new_user_pay ) / ( SUM( d.activation ) + SUM( d.form_count )) * 100, 2 ),'%') AS eventNewUserPayRate,
+        SUM( d.event_app_invoked ) AS eventAppInvoked,
+        ROUND( SUM( d.charge ) / SUM( d.event_app_invoked ), 2 ) AS eventAppInvokedCost,
+        SUM( d.event_register ) AS eventRegister,
+        ROUND( SUM( d.charge ) / SUM( d.event_register ), 2 ) AS eventRegisterCost,
+        SUM( d.key_action ) AS keyAction,
+        ROUND( SUM( d.charge ) / SUM( d.key_action ), 2 ) AS keyActionCost,
+        CONCAT( ROUND( SUM( d.charge )/ SUM( d.key_action )* 100, 2 ), '%' ) AS keyActionRate,
+        SUM( d.event_pay_purchase_amount_first_day ) AS eventPayPurchaseAmountFirstDay,
+        SUM( d.event_pay_first_day_roi ) AS eventPayFirstDayRoi,
+        SUM( d.form_count ) AS formCount,
+        ROUND( SUM( d.charge ) / SUM( d.form_count ), 2 ) AS formCountPrice,
+        m.newEffectNum AS newEffectNum,
+        m.newVideoNum AS newVideoNum,
+        m.newHotNum AS newHotNum
+        FROM
+        application.kuaishou_account_report_daily_dw d
+        LEFT JOIN (
+            SELECT
+            abi.account_id,
+            COUNT( abi.new_effect_num ) AS newEffectNum,
+            COUNT( abi.new_video_num ) AS newVideoNum,
+            COUNT( abi.new_hot_num ) AS newHotNum
+            FROM
+            application.app_kuaishou_account_base_info_d abi
+            <where>
+                    <if test="startDate != null and startDate != '' ">
+                        and abi.stat_date &gt;= #{startDate}
+                    </if>
+                    <if test="endDate != null and endDate != '' ">
+                        and abi.stat_date &lt;= #{endDate}
+                    </if>
+                </where>
+                GROUP BY abi.account_id
+        ) m
+        on d.account_id = m.account_id
+        WHERE
+        d.charge > 0
+        <if test="startDate != null and startDate != '' ">
+            and d.stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and d.stat_date &lt;= #{endDate}
+        </if>
+        <if test="projectId != null and projectId != '' ">
+            and d.project_id = #{projectId}
+        </if>
+        <if test='list!=null'>
+            AND d.user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY d.project_id
+        ORDER BY SUM( d.charge ) DESC
+    </select>
+
+
+
+    <!-- 快手 -查询 账户 数据信息  -->
+    <select id="getKuaiShouOperateAccountInfo" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo">
+        SELECT
+        SUM( d.charge ) AS totalCost,
+        d.account_id as accountId,
+        d.account_name as accountName,
+        d.project_id AS projectId,
+        d.project_name AS projectName,
+        COUNT( DISTINCT d.user_id ) AS userNum,
+        ( SELECT u.realname FROM `jeecg-boot`.sys_user u WHERE u.id = d.user_id ) AS userName,
+        SUM( d.activation ) AS activation,
+        ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ) AS activationPrice,
+        CONCAT(ROUND(SUM( d.event_next_day_stay ) / SUM( d.activation ) * 100, 2 ),'%') AS leave,
+        SUM( d.event_pay ) AS eventPay,
+        ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ) AS eventPayCost,
+        CONCAT(ROUND( SUM( d.event_pay ) / ( SUM( d.activation ) + SUM( d.form_count )) * 100, 2 ),'%') AS eventPayRate,
+        SUM( d.event_new_user_pay ) AS eventNewUserPay,
+        ROUND( SUM( d.charge ) / SUM( d.event_new_user_pay ), 2 ) AS eventNewUserPayCost,
+        ROUND( SUM( d.event_new_user_pay ) / ( SUM( d.activation ) + SUM( d.form_count )), 2 ) AS eventNewUserPayRate,
+        SUM( d.event_app_invoked ) AS eventAppInvoked,
+        ROUND( SUM( d.charge ) / SUM( d.event_app_invoked ), 2 ) AS eventAppInvokedCost,
+        SUM( d.event_register ) AS eventRegister,
+        ROUND( SUM( d.charge ) / SUM( d.event_register ), 2 ) AS eventRegisterCost,
+        SUM( d.key_action ) AS keyAction,
+        ROUND( SUM( d.charge ) / SUM( d.key_action ), 2 ) AS keyActionCost,
+        CONCAT( ROUND( SUM( d.charge )/ SUM( d.activation )* 100, 2 ), '%' ) AS keyActionRate,
+        SUM( d.event_pay_purchase_amount_first_day ) AS eventPayPurchaseAmountFirstDay,
+        SUM( d.event_pay_first_day_roi ) AS eventPayFirstDayRoi,
+        SUM( d.form_count ) AS formCount,
+        ROUND( SUM( d.charge ) / SUM( d.form_count ), 2 ) AS formCountPrice,
+        SUM(d.`show`) as photoShow,
+        SUM(d.photo_click) as photoClick,
+        m.newEffectNum AS newEffectNum,
+        m.newVideoNum AS newVideoNum,
+        m.newHotNum AS newHotNum
+        FROM
+        application.kuaishou_account_report_daily_dw d
+        LEFT JOIN (
+            SELECT
+            abi.account_id,
+            COUNT( abi.new_effect_num ) AS newEffectNum,
+            COUNT( abi.new_video_num ) AS newVideoNum,
+            COUNT( abi.new_hot_num ) AS newHotNum
+            FROM
+            application.app_kuaishou_account_base_info_d abi
+            <where>
+                    <if test="startDate != null and startDate != '' ">
+                        and abi.stat_date &gt;= #{startDate}
+                    </if>
+                    <if test="endDate != null and endDate != '' ">
+                        and abi.stat_date &lt;= #{endDate}
+                    </if>
+                </where>
+                GROUP BY abi.account_id
+        ) m
+        on d.account_id = m.account_id
+        WHERE
+        d.charge > 0
+        <if test="startDate != null and startDate != '' ">
+            and d.stat_date &gt;= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != '' ">
+            and d.stat_date &lt;= #{endDate}
+        </if>
+        <if test="projectId != null and projectId != '' ">
+            and d.project_id = #{projectId}
+        </if>
+        <if test="accountId != null and accountId != '' ">
+            and d.account_id = #{accountId}
+        </if>
+        <if test='list!=null'>
+            AND d.user_id IN
+            <foreach collection="list" item="item" separator=","
+                     open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY d.account_id
+        ORDER BY SUM( d.charge ) DESC
+    </select>
+
+
+
+    <!-- 快手 账户 余额 -->
+    <select id="getKuaiShouAccountBalance" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            d.total_charged_in_yuan as totalCost,
+            d.total_balance_in_yuan as balance
+        FROM application.app_kuaishou_agent_report_d d
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and d.account_id = #{accountId}
+            </if>
+            <if test="statDate != null and statDate != '' ">
+                and d.stat_date = #{statDate}
+            </if>
+        </where>
+    </select>
+
+
+    <!-- 快手 账户 余额 以及状态 -->
+    <select id="getKuaiShouAccountTotalCost" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        SUM(h.charge) todayCost,
+        u.account_status as accountStatus,
+        u.account_id as accountId,
+        u.auth_name as accountName
+        from
+        application.kuaishou_account_report_hourly_dw h
+        LEFT JOIN `jeecg-boot`.`ctop_user_allocation` u
+        on u.account_id = h.account_id
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and h.account_id = #{accountId}
+            </if>
+            <if test="statDate != null and statDate != '' ">
+                and h.stat_date = #{statDate}
+            </if>
+        </where>
+    </select>
+
+
+
+    <!-- 快手 账户趋势图-时报 -->
+    <select id="getKuaiShouAccountInfoBrokenLineHour" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t.*,y.*
+        FROM
+            (
+                SELECT
+                    h.`hour` as tHour,
+                    h.charge AS tCost,
+                    IFNULL( ROUND(( h.charge / h.activation ), 2 ), 0 ) AS tActivationPrice,
+                    IFNULL( ROUND(( h.charge / h.event_new_user_pay ), 2 ), 0 ) AS tEventNewUserPayCost,
+                    IFNULL( ROUND( ( h.event_next_day_stay / h.activation ), 2 ), 0 ) AS tLeave
+                FROM
+                    application.kuaishou_account_report_hourly_dw h
+                <where>
+                    <if test="accountId != null and accountId != '' ">
+                        and h.account_id = #{accountId}
+                    </if>
+                    <if test="statDate != null and statDate != '' ">
+                        and h.stat_date = #{statDate}
+                    </if>
+                </where>
+                ORDER BY
+                    h.hour) t
+                RIGHT JOIN
+            (
+                SELECT
+                    h.`hour` as yHour,
+                    h.charge AS yCost,
+                    IFNULL( ROUND(( h.charge / h.activation ), 2 ), 0 ) AS yActivationPrice,
+                    IFNULL( ROUND(( h.charge / h.event_new_user_pay ), 2 ), 0 ) AS yEventNewUserPayCost,
+                    IFNULL( ROUND( ( h.event_next_day_stay / h.activation ), 2 ), 0 ) AS yLeave
+                FROM
+                    application.kuaishou_account_report_hourly_dw h
+                <where>
+                    <if test="accountId != null and accountId != '' ">
+                        and h.account_id = #{accountId}
+                    </if>
+                    <if test="endDate != null and endDate != '' ">
+                        and h.stat_date = #{endDate}
+                    </if>
+                </where>
+                ORDER BY
+                    h.HOUR) y
+            on t.tHour = y.yHour
+    </select>
+
+
+
+    <!-- 快手 账户趋势图-日报 -->
+    <select id="getKuaiShouAccountInfoBrokenLineDaily" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            DATE_FORMAT(d.stat_date,'%Y-%m-%d') as dateTime,
+            SUM( d.charge ) as cost,
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ), 0 ) AS activationPrice,
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.event_new_user_pay ), 2 ), 0 ) AS eventNewUserPayCost,
+            IFNULL( ROUND( SUM( d.event_next_day_stay ) / SUM( d.activation ), 2 ), 0 ) AS leave
+        FROM
+            application.kuaishou_account_report_daily_dw d
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and d.account_id = #{accountId}
+            </if>
+            <if test="startDate != null and startDate != '' ">
+                and d.stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and d.stat_date &lt;= #{endDate}
+            </if>
+        </where>
+        GROUP BY
+        d.stat_date
+        ORDER BY
+        d.stat_date
+    </select>
+
+    <!-- 快手 账户 素材上新-有效-爆款   searchType: 0-全部 1-上新 2-有效 3-爆款-->
+    <select id="getKuaiShouAccountPieScene" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo">
+        SELECT
+        <if test='type == "cost"'>
+            SUM( d.charge ) AS cost,
+        </if>
+        <if test='type == "activation"'>
+            SUM( d.activation ) AS activation,
+        </if>
+        <if test='type == "activationPrice"'>
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ), 0 ) AS activationPrice,
+        </if>
+        <if test='type == "eventPayRoi"'>
+             SUM( d.event_pay_roi ) AS eventPayRoi,
+        </if>
+        <if test='type == "eventPay"'>
+                SUM( d.event_pay ) AS eventPay,
+        </if>
+        <if test='type == "eventPayCost"'>
+              IFNULL( ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ), 0 ) AS eventPayCost,
+        </if>
+        <if test='type == "eventPayPurchaseAmountFirstDay"'>
+              SUM( d.event_pay_purchase_amount_first_day ) AS eventPayPurchaseAmountFirstDay,
+        </if>
+        <if test='type == "eventNextDayStay"'>
+            SUM( d.event_next_day_stay ) AS eventNextDayStay,
+        </if>
+        <if test='type == "leave"'>
+             IFNULL( ROUND( SUM( d.event_next_day_stay ) / SUM( d.activation ), 2 ), 0 ) AS leave,
+        </if>
+        d.ad_scene AS adScene
+        FROM
+        application.app_kuaishou_account_ad_scene_report_d d
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and d.account_id = #{accountId}
+            </if>
+            <if test="startDate != null and startDate != '' ">
+                and d.stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and d.stat_date &lt;= #{endDate}
+            </if>
+        </where>
+        GROUP BY
+        d.ad_scene
+        ORDER BY
+        d.ad_scene
+    </select>
+
+
+
+
+
+    <!-- 快手 账户饼图图-分版位 -->
+    <select id="getKuaiShouAccountMaterialNewAndEffectAndFaddish" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        DATE_FORMAT(m.media_time,'%Y-%m-%d') as dateTime,
+        vd.signature,
+        m.material_name as videoName,
+        m.video_url as videoUrl,
+        SUM( vd.charge ) AS totalCost,
+        SUM( vd.activation ) AS activation,
+        ROUND(( SUM( vd.charge ) / SUM( vd.activation ) ), 2 ) AS activationPrice,
+        vd.stat_date AS statDate,
+        m.media_time AS mediaTime,
+        SUM(vd.show) as showNum
+        FROM
+        application.kuaishou_material_video_report_daily_dw vd,
+        application.app_kuaishou_material_info m
+        WHERE
+        vd.signature = m.material_id
+        AND vd.account_id = #{accountId}
+        AND vd.stat_date &gt;= #{startDate}
+        AND vd.stat_date &lt;= #{endDate}
+        <if test="searchType == '1'.toString()">
+            and material_innovate = 2
+        </if>
+        <if test="searchType == '2'.toString()">
+            AND m.effect_flag = 2
+            AND m.effect_date &gt;= #{startDate}
+            AND m.effect_date &lt;= #{endDate}
+        </if>
+         <if test="searchType == '3'.toString()">
+             and m.faddish_flag = 2
+             and m.faddish_date &gt;= #{startDate}
+            AND m.faddish_date &lt;= #{endDate}
+        </if>
+        GROUP BY
+            vd.signature
+        ORDER BY
+            m.media_time DESC
+    </select>
+
+
+    <!-- 快手 账户饼图图-分年龄 -->
+    <select id="getKuaiShouAccountPieAge" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo">
+        SELECT
+        <if test='type == "cost"'>
+            SUM( d.charge ) AS cost,
+        </if>
+        <if test='type == "activation"'>
+            SUM( d.activation ) AS activation,
+        </if>
+        <if test='type == "activationPrice"'>
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ), 0 ) AS activationPrice,
+        </if>
+        <if test='type == "eventPayRoi"'>
+            SUM( d.event_pay_roi ) AS eventPayRoi,
+        </if>
+        <if test='type == "eventPay"'>
+            SUM( d.event_pay ) AS eventPay,
+        </if>
+        <if test='type == "eventPayCost"'>
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ), 0 ) AS eventPayCost,
+        </if>
+        <if test='type == "eventPayPurchaseAmountFirstDay"'>
+            SUM( d.event_pay_purchase_amount_first_day ) AS eventPayPurchaseAmountFirstDay,
+        </if>
+        <if test='type == "eventNextDayStay"'>
+            SUM( d.event_next_day_stay ) AS eventNextDayStay,
+        </if>
+        <if test='type == "leave"'>
+            IFNULL( ROUND( SUM( d.event_next_day_stay ) / SUM( d.activation ), 2 ), 0 ) AS leave,
+        </if>
+        d.age_segment AS ageSegment
+        FROM
+        media_api.kuaishou_audience_age_report_daily d
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and d.advertiser_id = #{accountId}
+            </if>
+            <if test="startDate != null and startDate != '' ">
+                and d.stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and d.stat_date &lt;= #{endDate}
+            </if>
+        </where>
+        GROUP BY
+            d.age_segment
+        ORDER BY
+            d.age_segment
+    </select>
+
+
+    <!-- 快手 账户饼图图-分性别 -->
+    <select id="getKuaiShouAccountPieGender" resultType="org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo">
+        SELECT
+        <if test='type == "cost"'>
+            SUM( d.charge ) AS cost,
+        </if>
+        <if test='type == "activation"'>
+            SUM( d.activation ) AS activation,
+        </if>
+        <if test='type == "activationPrice"'>
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.activation ), 2 ), 0 ) AS activationPrice,
+        </if>
+        <if test='type == "eventPayRoi"'>
+            SUM( d.event_pay_roi ) AS eventPayRoi,
+        </if>
+        <if test='type == "eventPay"'>
+            SUM( d.event_pay ) AS eventPay,
+        </if>
+        <if test='type == "eventPayCost"'>
+            IFNULL( ROUND( SUM( d.charge ) / SUM( d.event_pay ), 2 ), 0 ) AS eventPayCost,
+        </if>
+        <if test='type == "eventPayPurchaseAmountFirstDay"'>
+            SUM( d.event_pay_purchase_amount_first_day ) AS eventPayPurchaseAmountFirstDay,
+        </if>
+        <if test='type == "eventNextDayStay"'>
+            SUM( d.event_next_day_stay ) AS eventNextDayStay,
+        </if>
+        <if test='type == "leave"'>
+            IFNULL( ROUND( SUM( d.event_next_day_stay ) / SUM( d.activation ), 2 ), 0 ) AS leave,
+        </if>
+        d.gender AS gender
+        FROM
+        media_api.kuaishou_audience_gender_report_daily d
+        <where>
+            <if test="accountId != null and accountId != '' ">
+                and d.advertiser_id = #{accountId}
+            </if>
+            <if test="startDate != null and startDate != '' ">
+                and d.stat_date &gt;= #{startDate}
+            </if>
+            <if test="endDate != null and endDate != '' ">
+                and d.stat_date &lt;= #{endDate}
+            </if>
+        </where>
+        GROUP BY
+            d.gender
+        ORDER BY
+            d.gender
+    </select>
+
+
+
+
+
+
+
+
+
+
+
+
+    <select id="getUserCompanyByUserId" resultType="java.lang.String">
+        SELECT
+            company_id as companyId
+        FROM
+            user_company
+        WHERE
+            user_id = #{userId}
+            LIMIT 1
     </select>
 
     <select id="getAffiliateId" resultType="java.lang.String">
-        SELECT distinct id
-        FROM sys_user
-        WHERE leader_id = #{leaderId}
-          and status = 1
-          and del_flag = 0
+        SELECT DISTINCT
+            u.id
+        FROM
+            sys_user u,
+            user_company c
+        WHERE
+            u.id = c.user_id
+        <if test="leaderId != null and leaderId != '' ">
+            AND u.leader_id = #{leaderId}
+        </if>
+        <if test="companyId != null and companyId != '' ">
+              AND c.company_id = #{companyId}
+        </if>
+          AND u.STATUS = 1
+          AND u.del_flag = 0
     </select>
 
     <select id="querySubordinateRecursive" resultType="java.lang.String">
-        SELECT distinct id
-        FROM sys_user
+        SELECT DISTINCT
+        u.id
+        FROM
+        sys_user u,
+        user_company c
         WHERE
-        status = 1
-        and del_flag = 0
-        and leader_id in
+        u.id = c.user_id
+        AND u.STATUS = 1
+        AND u.del_flag = 0
+        <if test="companyId != null and companyId != '' ">
+            AND c.company_id = #{companyId}
+        </if>
+        and u.leader_id in
         <foreach collection="leaderIds" item="item" separator=","
                  open="(" close=")">
             #{item}

+ 325 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/mapper/xml/SysManagerCompanyMapper.xml

@@ -0,0 +1,325 @@
+<?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="org.jeecg.ctop.material.mapper.SysManagerCompanyMapper">
+
+    <select id="queryDepartByParentId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT id, depart_name
+        FROM `jeecg-boot`.sys_depart
+        WHERE parent_id = #{designId}
+        ORDER BY depart_order
+    </select>
+
+    <select id="queryAllPersonnel" resultType="string">
+        SELECT DISTINCT lvl FROM application.app_user_lvl_info
+        <if test='list!=null and list.size>0'>
+            where dep_id in
+            <foreach collection="list" item="obj" separator=","
+                     open="(" close=")">
+                #{obj.id}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="queryPersonnels" resultType="string">
+        SELECT DISTINCT lvl
+        FROM application.app_user_lvl_info
+        where dep_id = #{id}
+    </select>
+
+    <select id="queryMaterialNumber" resultType="long">
+        SELECT COUNT(1) FROM `jeecg-boot`.ctop_material_info t1
+        INNER JOIN `jeecg-boot`.ctop_material_ascription t2 ON t1.code = t2.material_id
+        WHERE t1.create_time &gt;= #{startTime}
+        AND t1.create_time &lt;= concat(#{endTime},' 23:59:59')
+        AND t1.status != 2
+        <if test='allPersonnel!=null and allPersonnel.size>0'>
+            AND t2.clip_id in
+            <foreach collection="allPersonnel" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="queryKsMaterialCharge" resultType="double">
+        SELECT IFNULL(SUM(charge),0) FROM application.kuaishou_material_video_report_daily_dw
+        WHERE stat_date &gt;= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        <if test='clipIds!=null and clipIds.size>0'>
+            AND clip_id in
+            <foreach collection="clipIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test='userIds!=null and userIds.size>0'>
+            AND user_id in
+            <foreach collection="userIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+    </select>
+
+
+    <select id="queryTtMaterialCharge" resultType="double">
+        SELECT IFNULL(SUM(cost),0) FROM application.bytedance_material_video_report_daily_dw
+        WHERE stat_datetime &gt;= DATE_FORMAT(#{startTime}, '%Y%m%d')
+        AND stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        <if test='clipIds!=null and clipIds.size>0'>
+            AND clip_id in
+            <foreach collection="clipIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+        <if test='userIds!=null and userIds.size>0'>
+            AND user_id in
+            <foreach collection="userIds" item="id" separator=","
+                     open="(" close=")">
+                #{id}
+            </foreach>
+        </if>
+    </select>
+
+
+    <select id="queryTtProjectConsumeTop" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.project_name as 'projectName', t1.project_id as 'projectId', IFNULL(sum(cost), 0) as 'allCost',IFNULL(adNum, 0) as 'adNum'
+        FROM application.bytedance_advertiser_report_hourly_dw t1
+                 LEFT JOIN
+             (SELECT project_id, IFNULL(SUM(new_ad_num), 0) as 'adNum'
+              FROM application.app_bytedance_account_base_info_d
+              WHERE project_id IN (
+                  SELECT id
+                  FROM `jeecg-boot`.ctop_project
+                  WHERE media_id = 1
+                    and company_id = #{companyId}
+              )
+                AND stat_date &gt;= DATE_FORMAT(#{startTime}, '%Y%m%d')
+                AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+              GROUP BY project_id) t2 ON t1.project_id = t2.project_id
+        WHERE t1.project_id IN (
+            SELECT id
+            FROM `jeecg-boot`.ctop_project
+            WHERE media_id = 1
+              and company_id = #{companyId}
+        )
+          AND t1.stat_datetime &gt;= DATE_FORMAT(#{startTime}, '%Y%m%d')
+          AND t1.stat_datetime &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        GROUP BY t1.project_id
+        ORDER BY allCost Desc LIMIT 10
+    </select>
+
+    <select id="queryKsProjectConsumeTop" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.project_name as 'projectName', t1.project_id as 'projectId', IFNULL(sum(charge), 0) as 'allCost',IFNULL(adNum, 0) as 'adNum'
+        FROM application.kuaishou_account_report_hourly_dw t1
+                 LEFT JOIN
+             (SELECT project_id, SUM(new_unit_num) as 'adNum'
+              FROM application.app_kuaishou_account_base_info_d
+              WHERE project_id IN (
+                  SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId}
+              )
+                AND stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+                AND stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+              GROUP BY project_id) t2 ON t1.project_id = t2.project_id
+        WHERE t1.project_id IN (
+            SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId}
+        )
+          AND t1.stat_date >= DATE_FORMAT(#{startTime}, '%Y%m%d')
+          AND t1.stat_date &lt;= DATE_FORMAT(#{endTime}, '%Y%m%d')
+        GROUP BY t1.project_id
+        ORDER BY allCost Desc LIMIT 10
+    </select>
+
+    <select id="getKsMonthlyData" resultType="Map">
+        SELECT DATE_FORMAT(stat_date, '%Y-%m-%d') as 'statDate', sum(charge) as 'allCost'
+        FROM application.kuaishou_material_video_report_daily_dw
+        WHERE project_id IN (
+            SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId}
+        )
+          AND stat_date >= #{startTime}
+          AND stat_date &lt;= #{endTime}
+        GROUP BY stat_date
+        ORDER BY stat_date
+    </select>
+
+    <select id="getTtMonthlyData" resultType="Map">
+        SELECT DATE_FORMAT(stat_datetime, '%Y-%m-%d') as 'statDate', sum(cost) as 'allCost'
+        FROM application.bytedance_material_video_report_daily_dw
+        WHERE project_id IN (
+            SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 1 and company_id = #{companyId}
+        )
+          AND stat_datetime >= #{startTime}
+          AND stat_datetime &lt;= #{endTime}
+        GROUP BY stat_datetime
+        ORDER BY stat_datetime
+    </select>
+
+
+    <select id="queryKsRealTimeCost" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.allCost as 'todayCost',t2.allCost as 'yesCost'
+        FROM (SELECT SUM(charge) as 'allCost'
+              FROM application.kuaishou_account_report_hourly_dw
+              WHERE project_id IN
+                    (SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId})
+                AND stat_date = DATE_FORMAT(#{today}, '%Y%m%d')
+                AND `hour` &lt;= #{hour}) t1
+                 LEFT JOIN
+             (SELECT SUM(charge) as 'allCost'
+              FROM application.kuaishou_account_report_hourly_dw
+              WHERE project_id IN
+                    (SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId})
+                AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+                AND `hour` &lt;= #{hour}) t2 ON 1 = 1
+    </select>
+
+
+    <select id="queryTtRealTimeCost" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (SELECT SUM(cost) as 'todayCost'
+              FROM application.bytedance_advertiser_report_hourly_dw
+              WHERE project_id IN
+                    (SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 1 and company_id = #{companyId})
+                AND stat_datetime = DATE_FORMAT(#{today}, '%Y%m%d')
+                AND `hour` &lt;= #{hour}) t1
+                 LEFT JOIN
+             (SELECT SUM(cost) as 'yesCost'
+              FROM application.bytedance_advertiser_report_hourly_dw
+              WHERE project_id IN
+                    (SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 1 and company_id = #{companyId})
+                AND stat_datetime = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+                AND `hour` &lt;= #{hour}) t2 ON 1 = 1
+    </select>
+
+    <select id="queryKsRealTimeGroupNum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (
+                 SELECT COUNT(1) as 'todayNum'
+                 FROM media_api.kuaishou_ad_unit_list
+                 WHERE advertiser_id IN (
+                     SELECT account_id
+                     FROM `jeecg-boot`.ctop_user_allocation t1
+                              left JOIN `jeecg-boot`.ctop_project t2 ON t2.id = t1.project_id
+                     WHERE t2.media_id = 2
+                       and company_id = #{companyId}
+                 )
+                   AND create_time >= #{today}
+             ) t1
+                 LEFT JOIN
+             (
+                 SELECT SUM(new_unit_num) as 'yesNum'
+                 FROM application.app_kuaishou_account_base_info_d
+                 WHERE project_id IN (
+                     SELECT id
+                     FROM `jeecg-boot`.ctop_project
+                     WHERE media_id = 2
+                       and company_id = #{companyId}
+                 )
+                   AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+             ) t2 on 1 = 1
+    </select>
+
+
+    <select id="queryTtRealTimeGroupNum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (
+                 SELECT COUNT(1) as 'todayNum'
+                 FROM media_api.bytedance_ad_get
+                 WHERE account_id IN (
+                     SELECT account_id
+                     FROM `jeecg-boot`.ctop_user_allocation t1
+                              left JOIN `jeecg-boot`.ctop_project t2 ON t2.id = t1.project_id
+                     WHERE t2.media_id = 1
+                       and company_id = #{companyId}
+                 )
+                   AND create_time >= #{today}
+             ) t1
+                 LEFT JOIN
+             (
+                 SELECT SUM(new_ad_num) as 'yesNum'
+                 FROM application.app_bytedance_account_base_info_d
+                 WHERE project_id IN (
+                     SELECT id
+                     FROM `jeecg-boot`.ctop_project
+                     WHERE media_id = 1
+                       and company_id = #{companyId}
+                 )
+                   AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+             ) t2 on 1 = 1
+    </select>
+
+
+    <select id="queryKsRealTimeMaterialNum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (SELECT COUNT(1) as 'todayCount'
+        FROM `jeecg-boot`.ctop_material_info
+        WHERE create_time >= #{today}
+        AND user_id in
+        <foreach collection="userIds" item="id" separator=","
+                 open="(" close=")">
+            #{id}
+        </foreach>
+
+        ) t1
+        LEFT JOIN
+        (
+        SELECT SUM(new_video_num) as 'yesCount'
+        FROM application.app_kuaishou_account_base_info_d
+        WHERE project_id IN (
+        SELECT id
+        FROM `jeecg-boot`.ctop_project
+        WHERE media_id = 2
+        and company_id = #{companyId}
+        )
+        AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+        ) t2 ON 1 = 1
+    </select>
+
+
+    <select id="queryTtRealTimeMaterialNum" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT *
+        FROM (SELECT COUNT(1) as 'todayCount'
+        FROM `jeecg-boot`.ctop_material_info
+        WHERE create_time >= #{today}
+        AND user_id in
+        <foreach collection="userIds" item="id" separator=","
+                 open="(" close=")">
+            #{id}
+        </foreach>
+        ) t1
+        LEFT JOIN
+        (
+        SELECT SUM(new_video_num) as 'yesCount'
+        FROM application.app_bytedance_account_base_info_d
+        WHERE project_id IN (
+        SELECT id
+        FROM `jeecg-boot`.ctop_project
+        WHERE media_id = 1
+        and company_id = #{companyId}
+        )
+        AND stat_date = DATE_FORMAT(#{lastDay}, '%Y%m%d')
+        ) t2 ON 1 = 1
+    </select>
+
+
+    <select id="getKsTotalConsume" resultType="String">
+        SELECT IFNULL(sum(charge), 0)
+        FROM application.kuaishou_material_video_report_daily_dw
+        WHERE project_id IN (
+            SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 2 and company_id = #{companyId}
+        )
+          AND stat_date >= #{startTime}
+          AND stat_date &lt;= #{endTime}
+    </select>
+
+
+    <select id="getTtTotalConsume" resultType="String">
+        SELECT IFNULL(sum(cost), 0)
+        FROM application.bytedance_material_video_report_daily_dw
+        WHERE project_id IN (
+            SELECT id FROM `jeecg-boot`.ctop_project WHERE media_id = 1 and company_id = #{companyId}
+        )
+          AND stat_datetime >= #{startTime}
+          AND stat_datetime &lt;= #{endTime}
+    </select>
+</mapper>

+ 33 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/ISysManagerCompanyService.java

@@ -0,0 +1,33 @@
+package org.jeecg.ctop.material.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.material.entity.SysManagerCompany;
+
+import java.text.ParseException;
+
+/**
+ * 总经理&公司记录表
+ *
+ * @author jeecg-boot
+ * 2022-02-22
+ * @version V1.0
+ */
+public interface ISysManagerCompanyService extends IService<SysManagerCompany> {
+
+    Result<Object> getMaterialProduce(String startTime, String endTime, String companyId, int mediaId);
+
+    Result<Object> getMaterialProduceConsume(String startTime, String endTime, String companyId, int mediaId);
+
+    Result<Object> getOperaterConsume(String startTime, String endTime, String companyId, int mediaId);
+
+    void setConsumeValue(String companyId, String targetValue, int mediaId) throws Exception;
+
+    Result<Object> getProjectConsumeTop(String startTime, String endTime, String companyId, int mediaId);
+
+    Result<Object> getMediaData(String companyId);
+
+    Result<Object> getRealTimeData(String companyId,int mediaId) throws ParseException;
+
+    Result<Object> getTotalConsume(String companyId, int mediaId);
+}

+ 26 - 1
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/MaterialStareService.java

@@ -3,10 +3,35 @@ package org.jeecg.ctop.material.service;
 import com.alibaba.fastjson.JSONObject;
 import org.jeecg.common.api.vo.Result;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 盯盘接口
  */
 public interface MaterialStareService {
 
-    Result<JSONObject> sumData(Integer mediaId, Integer userType, String userId, String startDate, String endDate, Integer type);
+    Result kuaiShousumData(String mediaType, String type, String startTime, String endTime, String userId);
+
+    Result kuaiShouOperateDateTotal(String mediaType,String startTime, String endTime, String userId);
+
+    Result getKuaiShouOperateInfo(Integer pageNum,int pageSize,String startTime, String endTime, String userId);
+    Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response);
+
+    Result getKuaiShouOperateProjectInfo(Integer pageNum,int pageSize,String startTime, String endTime, String userId);
+
+    Result getKuaiShouOperateAccountInfo(Integer pageNum,int pageSize,String startTime, String endTime, String projectId,String userId);
+
+    Result getKuaiShouAccountInfo(long accountId);
+
+    Result getKuaiShouAccountInfoBrokenLine(long accountId,String startTime, String endTime);
+
+    Result getKuaiShouAccountMaterialNewAndEffectAndFaddish(long accountId,String searchType,String startTime, String endTime,Integer pageNum,Integer pageSize);
+
+    Result getKuaiShouAccountPieChar(long accountId,String startTime, String endTime,String type);
+
+
+    Result getCompanyAllSubordinateByUserId(String userId);
+
+
+
 }

+ 517 - 108
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/MaterialStareServiceImpl.java

@@ -1,18 +1,36 @@
 package org.jeecg.ctop.material.service.impl;
 
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.ctop.material.constants.Check;
 import org.jeecg.ctop.material.constants.CtopAdConstant;
+import org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo;
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateVo;
 import org.jeecg.ctop.material.mapper.MaterialStareMapper;
 import org.jeecg.ctop.material.service.MaterialStareService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.net.URLEncoder;
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 盯盘接口
@@ -25,103 +43,83 @@ public class MaterialStareServiceImpl implements MaterialStareService {
     MaterialStareMapper materialStareMapper;
 
 
+
+
     /**
-     * 数据总览
+     *
+     * @description:数据总览-快手
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param type 查询类型 1-汇总 2-运营个人
+     * @param userId
+     * @param startTime
+     * @param startTime
+     * @author: zianY
+     * @time: 2022/2/15
      */
     @Override
-    public Result<JSONObject> sumData(Integer mediaId, Integer userType, String userId, String startDate, String endDate, Integer type) {
-        Result result = new Result();
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-        Long start = Long.parseLong(startDate.replace("-", ""));
-        Long end = Long.parseLong(endDate.replace("-", ""));
-
-        if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
-            //头条
-            //功能待完善
-        } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
-            //快手
-            if (userType == 1) {  //运营经理界面
-                //查询当前人员所有下级
-                Set<String> operatorUserIds = getAffiliateId(userId);
-                if (type == 1) {  //汇总查看
-                    if (start.equals(end)) {  //查看当日
-                        Long beforeDay = dayBefore(start);
-                        //查询账户时报表当日数据
-                        List<Map> list = materialStareMapper.getCostByUserIdList(start, beforeDay, operatorUserIds);
-                        result.setResult(list);
-                        result.setSuccess(true);
-                        return result;
-                    } else { //查看多日
-                        //查询账户日报表当日数据
-                        List<Map> list = materialStareMapper.getCostByUserIdListMoreDay(start, end, operatorUserIds);
-                        result.setResult(list);
-                        result.setSuccess(true);
-                        return result;
-                    }
+    public Result kuaiShousumData(String mediaType, String type, String startTime, String endTime, String userId) {
+        long stratDate = DateUtils.getDateInteger(startTime);
+        long endDate = DateUtils.getDateInteger(endTime);
+        //查询当前人员所有下级
+        Set<String> operatorUserIds = getAffiliateId(userId);
+        //头条
+        if (StringUtils.equals(mediaType,"1")){
+            return Result.successMsg("暂无头条数据。",null);
+        }
+        //快手
+        if (StringUtils.equals(mediaType,"2")){
+            //汇总
+            if (StringUtils.equals(type,"1")){
+                //查询一天数据时 查询时报
+                if (stratDate == endDate){
+                    Map resultMap = new HashMap<>();
+                    //时报
+                    List<Map> todayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(stratDate, endDate, operatorUserIds);
+                    long time = DateUtils.getDateInteger(DateUtils.addDayParse(Long.toString(endDate), -1));
+                    List<Map> yesterdayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(time,time , operatorUserIds);
+                    resultMap.put("todayList",todayList);
+                    resultMap.put("yesterdayList",yesterdayList);
+                    return Result.successMsg("查询-时报-汇总。",resultMap);
+                }
+                //多天 数据
+                // 日报
+                List<Map> dailyList = materialStareMapper.getKuaiShouCostDailyByUserIdList(stratDate, endDate, operatorUserIds);
+                return Result.successMsg("查询-日报-汇总成功。",dailyList);
 
-                } else if (type == 2) {  //运营个人查看
-                    if (start.equals(end)) { //查看当日
-                        //查询个人top5当日时报
-                        List<JSONObject> resultList = new ArrayList<>();
-                        List<JSONObject> list = materialStareMapper.getCostByTop5List(start, operatorUserIds);
-                        int size = 0;
-                        int firstHour = list.get(0).getInteger("hour");
-                        //判断每个小时取出几条
-                        for (JSONObject jsonObject : list) {
-                            //判断每个小时取出几条
-                            Integer hour = jsonObject.getInteger("hour");
-                            if (hour == firstHour) {
-                                size++;
-                            }
-                        }
-                        for (int i = 0; i < list.size() / size; i++) {
-                            //没top条数据切割出来封装
-                            List<JSONObject> objects = list.subList(i * size, (i + 1) * size);
-                            JSONObject resultObj = new JSONObject();
-                            int j = 1;
-                            for (JSONObject object : objects) {
-                                resultObj.put("hours", object.getInteger("hour"));
-                                resultObj.put("top" + j, object.getBigDecimal("cost"));
-                                j++;
-                            }
-                            resultList.add(resultObj);
-                        }
-                        result.setResult(resultList);
-                        result.setSuccess(true);
-                        return result;
-                    } else {   //查看多日
-                        List<JSONObject> resultList = new ArrayList<>();
-                        //查询个人top5当日日报
-                        List<JSONObject> list = materialStareMapper.getCostByTop5ListMoreDay(start, end, operatorUserIds);
-                        int size = 0;
-                        int firstDate = list.get(0).getInteger("statDate");
-                        //判断每个小时取出几条
-                        for (JSONObject jsonObject : list) {
-                            //判断每个小时取出几条
-                            Integer hour = jsonObject.getInteger("statDate");
-                            if (hour == firstDate) {
-                                size++;
-                            }
-                        }
-                        for (int i = 0; i < list.size() / size; i++) {
-                            //没top条数据切割出来封装
-                            List<JSONObject> objects = list.subList(i * size, (i + 1) * size);
-                            JSONObject resultObj = new JSONObject();
-                            int j = 1;
-                            for (JSONObject object : objects) {
-                                resultObj.put("date", object.getInteger("statDate"));
-                                resultObj.put("top" + j, object.getBigDecimal("cost"));
-                                j++;
-                            }
-                            resultList.add(resultObj);
-                        }
-                        result.setResult(resultList);
-                        result.setSuccess(true);
-                        return result;
+            //运营个人
+            }else if (StringUtils.equals(type,"2")){
+                if (stratDate == endDate){
+                    //时报 消耗前5
+                    List<JSONObject> userList = materialStareMapper.getKuaiShouCostByTop5HourList(stratDate, endDate, operatorUserIds);
+                    List<Map> resultList = new ArrayList<>();
+                    for (JSONObject jsonObject : userList) {
+                        Map map = new HashMap();
+                        Set<String> userSet = new HashSet<String>(){{
+                            add(jsonObject.getString("user_id"));
+                        }};
+                        List<Map> usertopList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(stratDate, endDate, userSet);
+                        map.put("userName",jsonObject.getString("userName"));
+                        map.put("data",usertopList);
+                        resultList.add(map);
                     }
+                    return Result.successMsg("查询-时报-运营个人消耗top5成功。",resultList);
+                }
+
+                //日报 消耗前5
+                List<JSONObject> userList = materialStareMapper.getKuaiShouCostByTop5DailyList(stratDate,endDate, operatorUserIds);
+                List<Map> resultList = new ArrayList<>();
+                for (JSONObject jsonObject : userList) {
+                    Map map = new HashMap();
+                    Set<String> userSet = new HashSet<String>(){{
+                        add(jsonObject.getString("user_id"));
+                    }};
+                    List<Map> usertopList = materialStareMapper.getKuaiShouCostDailyByUserIdList(stratDate, endDate, userSet);
+                    map.put("userName",jsonObject.getString("userName"));
+                    map.put("data",usertopList);
+                    resultList.add(map);
                 }
-            } else if (userType == 2) {
-                //运营个人界面
+                return Result.successMsg("查询-日报-运营个人消耗top5成功。",resultList);
             }
         }
         return null;
@@ -129,50 +127,461 @@ public class MaterialStareServiceImpl implements MaterialStareService {
 
 
     /**
-     * 获取指定日期前一日 LONG类型
+     *
+     * @description: 快手-运营组数据
+     *
+     * @param mediaType 媒体类型 1-头条 2-快手
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/15
+     */
+    @Override
+    public Result kuaiShouOperateDateTotal(String mediaType, String startTime, String endTime, String userId) {
+        Map resultMap = new HashMap();
+        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+        try {
+            //查询当前人员所有下级
+            Set<String> operatorUserIds = getAffiliateId(userId);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            // ==>> 20220202
+            String now = sdf.format(new Date());
+            long nowDate = Long.valueOf(now);
+            int nowHour = DateUtils.getNowHour();
+            //昨天时间
+            long time = DateUtils.getDateInteger(DateUtils.addDayParse(now, -1));
+
+            //当天总消耗
+            JSONObject jsonObjectNow = materialStareMapper.getKuaiShouTotalCost(nowDate,nowDate,nowHour,operatorUserIds);
+            resultMap.put("todayCost",jsonObjectNow.getString("totalCost"));
+            //昨天总消耗
+            JSONObject jsonObjectYesterday = materialStareMapper.getKuaiShouTotalCost(time,time,nowHour,operatorUserIds);
+            //今日同比 = (今天总消耗 - 昨天总消耗 ) / 昨天总消耗
+            Double d = (Double.valueOf(jsonObjectNow.getString("totalCost")) - Double.valueOf(jsonObjectYesterday.getString("totalCost"))) / Double.valueOf(jsonObjectYesterday.getString("totalCost"));
+            resultMap.put("compare",decimalFormat.format(d));
+
+            //时间段内 总消耗 及 账户数量
+            JSONObject totalCost = materialStareMapper.getKuaiShouTotalCost(Long.valueOf(DateUtils.getDateInteger(startTime)),
+                    Long.valueOf(DateUtils.getDateInteger(endTime)),
+                    0,
+                    operatorUserIds);
+            resultMap.put("sectionCost",totalCost.getDoubleValue("totalCost"));
+            // 人均账户数量 = 时间段内 账户总数量 / 人数
+            Double userAverageAccount = Double.valueOf(totalCost.getString("accountNum")) / operatorUserIds.size();
+            // 人均消耗 = 时间段内 总消耗 / 人数
+            Double userAveragecost = Double.valueOf(totalCost.getString("totalCost")) / operatorUserIds.size();
+            DecimalFormat df = new DecimalFormat("#.00");
+            resultMap.put("userAverageAccount",df.format(userAverageAccount));
+            resultMap.put("userAveragecost",df.format(userAveragecost));
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return Result.successMsg("查询成功",resultMap);
+    }
+
+    /**
+     *
+     * @description: 运营数据详情
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/16
+     */
+    @Override
+    public Result getKuaiShouOperateInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
+       try {
+        //查询当前人员所有下级
+        Set<String> operatorUserIds = getAffiliateId(userId);
+        //2022-02-15 ==>> 20220215
+        long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+        long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+        //上阶段时间
+        Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+        long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+        long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+
+        PageHelper.startPage(pageNum,pageSize);
+        //查询运营数据
+        List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
+        for (KuaiShouOperateVo operate : listOperate) {
+            Set<String> userSet = new HashSet<String>(){{
+                add(operate.getUserId());
+            }};
+            List<KuaiShouOperateVo> userOperate = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,userSet);
+            Double rate = new Double(0);
+            if (!Check.isNull(userOperate)){
+                //环比
+                rate = (operate.getTotalCost() - userOperate.get(0).getTotalCost()) / userOperate.get(0).getTotalCost() * 100;
+                rate = Double.valueOf(String.format("%.3f", rate));
+            }
+            operate.setRate(rate);
+        }
+        PageInfo<KuaiShouOperateVo> pageInfo = new PageInfo<>(listOperate);
+        return Result.successMsg("运营数据查询成功。",pageInfo);
+       }catch (Exception e){
+           e.printStackTrace();
+       }
+        return Result.errorMsg("哎呀,查询失败了。");
+    }
+
+    @Override
+    public Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response) {
+       try {
+        //查询当前人员所有下级
+        Set<String> operatorUserIds = getAffiliateId(userId);
+        //2022-02-15 ==>> 20220215
+        long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+        long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+        //上阶段时间
+        Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+        long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+        long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+
+        //查询运营数据
+        List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
+        for (KuaiShouOperateVo operate : listOperate) {
+            Set<String> userSet = new HashSet<String>(){{
+                add(operate.getUserId());
+            }};
+            List<KuaiShouOperateVo> userOperate = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,userSet);
+            Double rate = new Double(0);
+            if (!Check.isNull(userOperate)){
+                //环比 = (当前 - 上阶段 ) / 上阶段
+                rate = (operate.getTotalCost() - userOperate.get(0).getTotalCost() ) / userOperate.get(0).getTotalCost() * 100;
+                rate = Double.valueOf(String.format("%.3f", rate));
+            }
+            operate.setRate(rate);
+        }
+       Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("运营数据详情", "运营数据"), KuaiShouOperateVo.class, listOperate);
+       response.setCharacterEncoding("UTF-8");
+       response.setHeader("content-Type", "application/vnd.ms-excel");
+       response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("运营数据详情.xlsx", "UTF-8"));
+       workbook.write(response.getOutputStream());
+       return null;
+       }catch (Exception e){
+           e.printStackTrace();
+       }
+        return Result.errorMsg("哎呀,查询失败了。");
+    }
+
+
+    /**
+     *
+     * @description: 运营数据-项目列表
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/17
+     */
+    @Override
+    public Result getKuaiShouOperateProjectInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
+        try {
+            //查询当前人员所有下级
+            Set<String> operatorUserIds = getAffiliateId(userId);
+            //2022-02-15 ==>> 20220215
+            long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+            long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+            //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
+            Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+            long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+            long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
+
+            //计算同比 时间值 只支持7天
+            long startEqually = new Long("0");
+            long endEqually = new Long("0");
+            if (daysBetween <= 7) {
+                startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
+                endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
+            }
+
+            PageHelper.startPage(pageNum,pageSize);
+            //查询运营数据-项目维度
+            List<KuaiShouOperateProjectVo> listOperate = materialStareMapper.getKuaiShouOperateProjectInfo(startDate,entDate,null,operatorUserIds);
+            for (KuaiShouOperateProjectVo projectInfo : listOperate) {
+                String projectId = projectInfo.getProjectId();
+                List<KuaiShouOperateProjectVo> projectYearOnYearInfo = materialStareMapper.getKuaiShouOperateProjectInfo(lastTimeStart,lastTimeEnd,projectId,operatorUserIds);
+                //环比 = (当前 - 上阶段 ) / 上阶段
+                Double yearOnYear = new Double(0);
+                if (!Check.isNull(projectYearOnYearInfo)){
+                    yearOnYear = (projectInfo.getTotalCost() - projectYearOnYearInfo.get(0).getTotalCost()) / projectYearOnYearInfo.get(0).getTotalCost() * 100;
+                    yearOnYear = Double.valueOf(String.format("%.2f", yearOnYear));
+                }
+                projectInfo.setYearOnYear(yearOnYear);
+
+                //同比 日期超过 7 天 则不显示
+                Double equallyRate = new Double(0);
+                if (daysBetween <= 7){
+                    List<KuaiShouOperateProjectVo> projectEquallyInfo = materialStareMapper.getKuaiShouOperateProjectInfo(startEqually,endEqually,projectId,operatorUserIds);
+                    if (!Check.isNull(projectEquallyInfo)){
+                        equallyRate = (projectInfo.getTotalCost() - projectEquallyInfo.get(0).getTotalCost()) / projectEquallyInfo.get(0).getTotalCost() * 100;
+                        equallyRate = Double.valueOf(String.format("%.2f", equallyRate));
+                    }
+                }
+                projectInfo.setEquallyRate(equallyRate);
+
+            }
+
+            PageInfo<KuaiShouOperateProjectVo> pageInfo = new PageInfo<>(listOperate);
+            return Result.successMsg("运营项目列表数据查询成功。",pageInfo);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return Result.errorMsg("哎呀,查询失败了。");
+    }
+
+
+
+    /**
+     *
+     * @description: 运营数据-账户列表
+     *
+     * @param pageNum
+     * @param pageSize
+     * @param startTime
+     * @param endTime
+     * @param userId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/18
      */
-    public Long dayBefore(Long date) {
+    @Override
+    public Result getKuaiShouOperateAccountInfo(Integer pageNum, int pageSize, String startTime, String endTime,String projectId, String userId) {
+        try {
+            //查询当前人员所有下级
+            Set<String> operatorUserIds = getAffiliateId(userId);
+            //2022-02-15 ==>> 20220215
+            long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+            long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+            //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
+            Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+            long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
+            long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
+
+            //计算同比 时间值 只支持7天
+            long startEqually = new Long("0");
+            long endEqually = new Long("0");
+            if (daysBetween <= 7) {
+                startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
+                endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
+            }
+
+            PageHelper.startPage(pageNum,pageSize);
+            //查询运营数据-账户 维度
+            List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getKuaiShouOperateAccountInfo(startDate,entDate,projectId,null,operatorUserIds);
+            for (KuaiShouOperateAccountVo accountInfo : listOperate) {
+                long accountId = accountInfo.getAccountId();
+                List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getKuaiShouOperateAccountInfo(lastTimeStart,lastTimeEnd,projectId,accountId,operatorUserIds);
+                //环比 = (当前 - 上阶段 ) / 上阶段
+                Double yearOnYear = new Double(0);
+                if (!Check.isNull(accountYearOnYearInfo)){
+                    yearOnYear = (accountInfo.getTotalCost() - accountYearOnYearInfo.get(0).getTotalCost()) / accountYearOnYearInfo.get(0).getTotalCost() * 100;
+                    yearOnYear = Double.valueOf(String.format("%.2f", yearOnYear));
+                }
+                accountInfo.setYearOnYear(yearOnYear);
+
+                //同比 日期超过 7 天 则不显示
+                Double equallyRate = new Double(0);
+                if (daysBetween <= 7){
+                    List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getKuaiShouOperateAccountInfo(startEqually,endEqually,projectId,accountId,operatorUserIds);
+                    if (!Check.isNull(accountEquallyInfo)){
+                        equallyRate = (accountInfo.getTotalCost() - accountEquallyInfo.get(0).getTotalCost()) / accountEquallyInfo.get(0).getTotalCost() * 100;
+                        equallyRate = Double.valueOf(String.format("%.2f", equallyRate));
+                    }
+                }
+                accountInfo.setEquallyRate(equallyRate);
+            }
+
+            PageInfo<KuaiShouOperateAccountVo> pageInfo = new PageInfo<>(listOperate);
+            return Result.successMsg("运营账户列表数据查询成功。",pageInfo);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return Result.errorMsg("哎呀,查询失败了。");
+    }
+
+
+    /**
+     *
+     * @description: 查询账户余额 以及 账户状态 和 消耗
+     *
+     * @param accountId
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/21
+     */
+    @Override
+    public Result getKuaiShouAccountInfo(long accountId) {
+        Map resultMap = new HashMap();
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
-        Long beforeDay = null;
+        // ==>> 20220202
+        String now = sdf.format(new Date());
+        long nowDate = Long.valueOf(now);
+
+        //账户余额
+        JSONObject balance = materialStareMapper.getKuaiShouAccountBalance(accountId, nowDate);
+        resultMap.put("balance",Check.isNull(balance) ? "0" : balance.getString("balance"));
+        //账户今日消耗 以及状态
+        JSONObject totalCost = materialStareMapper.getKuaiShouAccountTotalCost(accountId, nowDate);
+
+        resultMap.put("accountId",Check.isNull(totalCost) ? "-" : totalCost.getString("accountId"));
+        resultMap.put("accountName",Check.isNull(totalCost) ? "0" : totalCost.getString("accountName"));
+
+        resultMap.put("totalCost",Check.isNull(totalCost) ? "0" : totalCost.getString("todayCost"));
+        //0-开 1-关
+        resultMap.put("state", Check.isNull(totalCost) ? "1" : totalCost.getString("accountStatus"));
+        return Result.successMsg("账户查询成功",resultMap);
+    }
+
+
+    /**
+     *
+     * @description: 账户 折线图 查询时间为当天查询时报;查询时间为多天 查询日报
+     *
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/21
+     */
+    @Override
+    public Result getKuaiShouAccountInfoBrokenLine(long accountId, String startTime, String endTime) {
+
+        List<JSONObject> resultList = new ArrayList<>();
         try {
-            Date parse = sdf.parse(date.toString());
-            Calendar c = Calendar.getInstance();
-            c.setTime(parse);
-            int day1 = c.get(Calendar.DATE);
-            c.set(Calendar.DATE, day1 - 1);
-            beforeDay = Long.parseLong(sdf.format(c.getTime()));
-        } catch (ParseException e) {
+            //2022-02-15 ==>> 20220215
+            long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+            long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+
+            //两个日期之间的 间隔天数
+            Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
+            Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
+
+            if (daysBetween == 0){
+                //昨天
+                long yesterday = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(entDate), -1));
+                resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineHour(accountId,startDate,yesterday);
+                return Result.successMsg("账户时报报折线图查询成功",resultList);
+            }
+            resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineDaily(accountId,startDate,entDate);
+            return Result.successMsg("账户日报折线图查询成功",resultList);
+
+        }catch (Exception e){
             e.printStackTrace();
         }
-        return beforeDay;
+        return Result.errorMsg("账户折线图查询异常");
+    }
+
+
+    /**
+     *
+     * @description: 快手 账户 素材上新-有效-爆款
+     *
+     * @param accountId
+     * @param searchType searchType:查询类型  0-全部 1-上新 2-有效 3-爆款
+     * @param startTime
+     * @param endTime
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/21
+     */
+    @Override
+    public Result getKuaiShouAccountMaterialNewAndEffectAndFaddish(long accountId, String searchType, String startTime, String endTime,Integer pageNum,Integer pageSize) {
+        //2022-02-15 ==>> 20220215
+        long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+        long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+        PageHelper.startPage(pageNum,pageSize);
+        List<JSONObject> resultList = materialStareMapper.getKuaiShouAccountMaterialNewAndEffectAndFaddish(accountId,searchType,startDate,entDate);
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(resultList);
+        return Result.successMsg("查询账户素材信息成功。",pageInfo);
     }
 
     /**
-     * 查询当前人员所有下级 返回自己和下属id
+     *
+     * @description: 查询账户饼图数据信息
+     *
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @return: org.jeecg.common.api.vo.Result
+     * @author: zianY
+     * @time: 2022/2/22
      */
+    @Override
+    public Result getKuaiShouAccountPieChar(long accountId, String startTime, String endTime,String type) {
+        Map resultMap = new HashMap();
+        //2022-02-15 ==>> 20220215
+        long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
+        long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
+        //版位
+        List<KuaiShouAccountPieVo> sceneList = materialStareMapper.getKuaiShouAccountPieScene(accountId,startDate,entDate,type);
+        //年龄
+        List<KuaiShouAccountPieVo> ageList = materialStareMapper.getKuaiShouAccountPieAge(accountId,startDate,entDate,type);
+        //性别
+        List<KuaiShouAccountPieVo> genderList = materialStareMapper.getKuaiShouAccountPieGender(accountId,startDate,entDate,type);
+        resultMap.put("scene",sceneList);
+        resultMap.put("age",ageList);
+        resultMap.put("gender",genderList);
+        return Result.successMsg("查询饼图数据成功。",resultMap);
+    }
+
+
+//===========================================查询下级员工========================
+
+    public Result getCompanyAllSubordinateByUserId(String userId){
+        Set<String> operatorUserIds = getAffiliateId(userId);
+        return Result.successMsg("查询该用户所有下级userId",operatorUserIds);
+    }
+
 
+
+
+
+    /**
+     * 查询当前人员  所属公司 返回自己和下属id
+     */
     public Set<String> getAffiliateId(String userId) {
+        //查询用户所属公司
+        String companyId = materialStareMapper.getUserCompanyByUserId(userId);
         Set<String> result;
         //查询当前用户是否存在下级
-        Set<String> subordinate = materialStareMapper.getAffiliateId(userId);
+        Set<String> subordinate = materialStareMapper.getAffiliateId(userId,companyId);
         if (subordinate.isEmpty()) {
             subordinate.add(userId);
             return subordinate;
         } else {
-            result = querySubordinate(subordinate, subordinate);
+            result = querySubordinate(subordinate, subordinate,companyId);
             result.add(userId);
         }
         return result;
     }
 
     //递归查询
-    private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result) {
+    private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result,String companyId) {
         if (leaderIds.isEmpty()) {
             return result;
         }
-        Set<String> temp = materialStareMapper.querySubordinateRecursive(leaderIds);
+        Set<String> temp = materialStareMapper.querySubordinateRecursive(companyId,leaderIds);
         result.addAll(temp);
-        querySubordinate(temp, result);
+        querySubordinate(temp, result,companyId);
         return result;
     }
+//===========================================查询下级员工========================
+
 }

+ 460 - 0
jeecg-boot-material-view/src/main/java/org/jeecg/ctop/material/service/impl/SysManagerCompanyServiceImpl.java

@@ -0,0 +1,460 @@
+package org.jeecg.ctop.material.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.ctop.material.constants.Check;
+import org.jeecg.ctop.material.entity.SysManagerCompany;
+import org.jeecg.ctop.material.mapper.SysManagerCompanyMapper;
+import org.jeecg.ctop.material.service.ISysManagerCompanyService;
+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.List;
+import java.util.Map;
+
+/**
+ * 总经理&公司记录表
+ *
+ * @author jeecg-boot
+ * 2022-02-22
+ * @version V1.0
+ */
+@Service
+public class SysManagerCompanyServiceImpl extends ServiceImpl<SysManagerCompanyMapper, SysManagerCompany> implements ISysManagerCompanyService {
+
+    @Autowired
+    private SysManagerCompanyMapper mapper;
+
+
+    @Override
+    public Result<Object> getMaterialProduce(String startTime, String endTime, String companyId, int mediaId) {
+
+        if (Check.isNull(startTime) && Check.isNull(endTime)) {
+            startTime = DateUtils.getDate(DateUtils.WEB_FORMAT);
+            endTime = startTime;
+        }
+        SysManagerCompany company = this.getById(companyId);
+        if (Check.isNull(company)) {
+            return Result.ok("未查到公司:" + companyId);
+        }
+
+        //查询子集部门
+        List<JSONObject> list = null;
+        if (mediaId == 1) {
+            list = mapper.queryDepartByParentId(company.getTtDesignId());
+        } else if (mediaId == 2) {
+            list = mapper.queryDepartByParentId(company.getKsDesignId());
+        }
+        if (Check.isNull(list) || list.isEmpty()) {
+            return Result.ok("未查询到设计组");
+        }
+        //查询部门所有人员
+        List<String> allPersonnel = mapper.queryAllPersonnel(list);
+        if (Check.isNull(allPersonnel) || allPersonnel.isEmpty()) {
+            return Result.ok("未查询到人员");
+        }
+        //查询数量
+        Long total = mapper.queryMaterialNumber(allPersonnel, startTime, endTime);
+
+        BigDecimal hundred = new BigDecimal(100 + "");
+        for (JSONObject obj : list) {
+            List<String> personnels = mapper.queryPersonnels(obj.getString("id"));
+            if (Check.isNull(personnels)) {
+                obj.put("count", 0);
+                obj.put("ratio", 0.00);
+                continue;
+            }
+            Long count = mapper.queryMaterialNumber(personnels, startTime, endTime);
+            if (Check.isNull(count)) {
+                obj.put("count", 0);
+                obj.put("ratio", 0.00);
+                continue;
+            }
+            obj.put("count", count);
+            if (total != 0) {
+                BigDecimal ratio = BigDecimal.valueOf(Double.valueOf(count) / total).multiply(hundred);
+                String ratioStr = ratio.setScale(2, RoundingMode.HALF_UP).toString();
+                obj.put("ratio", ratioStr);
+            }
+        }
+        JSONObject result = new JSONObject();
+        result.put("total", total);
+        result.put("list", list);
+        return Result.ok(result);
+    }
+
+    @Override
+    public Result<Object> getMaterialProduceConsume(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(startTime) && Check.isNull(endTime)) {
+            startTime = DateUtils.getDate(DateUtils.WEB_FORMAT);
+            endTime = startTime;
+        }
+        SysManagerCompany company = this.getById(companyId);
+        if (Check.isNull(company)) {
+            return Result.ok("未查到公司:" + companyId);
+        }
+        //查询子集部门
+        List<JSONObject> list = null;
+        //总消耗
+        Double totalCharge = null;
+        if (mediaId == 1) {
+            list = mapper.queryDepartByParentId(company.getTtDesignId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到设计组");
+            }
+            //查询部门所有人员
+            List<String> clipIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(clipIds)) {
+                return Result.ok("未查询到人员");
+            }
+            //总消耗
+            totalCharge = mapper.queryTtMaterialCharge(clipIds, startTime, endTime, null);
+            BigDecimal hundred = new BigDecimal(100 + "");
+            for (JSONObject obj : list) {
+                if (Check.isNull(totalCharge) || totalCharge == 0.0) {
+                    obj.put("charge", 0);
+                    obj.put("ratio", 0.0);
+                    continue;
+                } else {
+                    List<String> clipids = mapper.queryPersonnels(obj.getString("id"));
+                    if (Check.isNull(clipids)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    Double charge = mapper.queryTtMaterialCharge(clipids, startTime, endTime, null);
+                    if (Check.isNull(charge)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    BigDecimal ratio = BigDecimal.valueOf(Double.valueOf(charge) / totalCharge).multiply(hundred);
+                    String ratioStr = ratio.setScale(2, RoundingMode.HALF_UP).toString();
+                    obj.put("ratio", ratioStr);
+                    obj.put("charge", charge);
+                }
+            }
+        } else if (mediaId == 2) {
+            list = mapper.queryDepartByParentId(company.getKsDesignId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到设计组");
+            }
+            //查询部门所有人员
+            List<String> clipIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(clipIds)) {
+                return Result.ok("未查询到人员");
+            }
+            //总消耗
+            totalCharge = mapper.queryKsMaterialCharge(clipIds, startTime, endTime, null);
+            BigDecimal hundred = new BigDecimal(100 + "");
+            for (JSONObject obj : list) {
+                if (Check.isNull(totalCharge) || totalCharge == 0.0) {
+                    obj.put("charge", 0);
+                    obj.put("ratio", 0.0);
+                    continue;
+                } else {
+                    List<String> clipids = mapper.queryPersonnels(obj.getString("id"));
+                    if (Check.isNull(clipids)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    Double charge = mapper.queryKsMaterialCharge(clipids, startTime, endTime, null);
+                    if (Check.isNull(charge)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    BigDecimal ratio = BigDecimal.valueOf(Double.valueOf(charge) / totalCharge).multiply(hundred);
+                    String ratioStr = ratio.setScale(2, RoundingMode.HALF_UP).toString();
+                    obj.put("ratio", ratioStr);
+                    obj.put("charge", charge);
+                }
+            }
+        }
+        JSONObject result = new JSONObject();
+        result.put("totalCharge", totalCharge);
+        result.put("list", list);
+        return Result.ok(result);
+    }
+
+    @Override
+    public Result<Object> getOperaterConsume(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(startTime) && Check.isNull(endTime)) {
+            startTime = DateUtils.getDate(DateUtils.WEB_FORMAT);
+            endTime = startTime;
+        }
+        SysManagerCompany company = this.getById(companyId);
+        if (Check.isNull(company)) {
+            return Result.ok("未查到公司:" + companyId);
+        }
+        //查询子集部门
+        List<JSONObject> list = null;
+        //总消耗
+        Double totalCharge = null;
+        if (mediaId == 1) {
+            list = mapper.queryDepartByParentId(company.getTtOperateId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到销售组");
+            }
+            //查询部门所有人员
+            List<String> userIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(userIds)) {
+                return Result.ok("未查询到人员");
+            }
+            //总消耗
+            totalCharge = mapper.queryTtMaterialCharge(null, startTime, endTime, userIds);
+            BigDecimal hundred = new BigDecimal(100 + "");
+            for (JSONObject obj : list) {
+                if (Check.isNull(totalCharge) || totalCharge == 0.0) {
+                    obj.put("charge", 0);
+                    obj.put("ratio", 0.0);
+                    continue;
+                } else {
+                    List<String> userids = mapper.queryPersonnels(obj.getString("id"));
+                    if (Check.isNull(userids)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    Double charge = mapper.queryTtMaterialCharge(null, startTime, endTime, userids);
+                    if (Check.isNull(charge)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    BigDecimal ratio = BigDecimal.valueOf(Double.valueOf(charge) / totalCharge).multiply(hundred);
+                    String ratioStr = ratio.setScale(2, RoundingMode.HALF_UP).toString();
+                    obj.put("ratio", ratioStr);
+                    obj.put("charge", charge);
+                }
+            }
+        } else if (mediaId == 2) {
+            list = mapper.queryDepartByParentId(company.getKsOperateId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到销售组");
+            }
+            //查询部门所有人员
+            List<String> userIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(userIds)) {
+                return Result.ok("未查询到人员");
+            }
+            //总消耗
+            totalCharge = mapper.queryKsMaterialCharge(null, startTime, endTime, userIds);
+            BigDecimal hundred = new BigDecimal(100 + "");
+            for (JSONObject obj : list) {
+                if (Check.isNull(totalCharge) || totalCharge == 0.0) {
+                    obj.put("charge", 0);
+                    obj.put("ratio", 0.0);
+                    continue;
+                } else {
+                    List<String> userids = mapper.queryPersonnels(obj.getString("id"));
+                    if (Check.isNull(userids)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    Double charge = mapper.queryKsMaterialCharge(null, startTime, endTime, userids);
+                    if (Check.isNull(charge)) {
+                        obj.put("charge", 0);
+                        obj.put("ratio", 0.0);
+                        continue;
+                    }
+                    BigDecimal ratio = BigDecimal.valueOf(Double.valueOf(charge) / totalCharge).multiply(hundred);
+                    String ratioStr = ratio.setScale(2, RoundingMode.HALF_UP).toString();
+                    obj.put("ratio", ratioStr);
+                    obj.put("charge", charge);
+                }
+            }
+        }
+
+        JSONObject result = new JSONObject();
+        result.put("totalCharge", totalCharge);
+        result.put("list", list);
+        return Result.ok(result);
+    }
+
+    @Override
+    public void setConsumeValue(String companyId, String targetValue, int mediaId) throws Exception {
+        SysManagerCompany company = this.getById(companyId);
+        if (Check.isNull(company)) {
+            throw new Exception("未查询到公司");
+        }
+        if (mediaId == 1) {
+            company.setTtTargetValue(targetValue);
+        } else if (mediaId == 2) {
+            company.setKsTargetValue(targetValue);
+        }
+        this.updateById(company);
+    }
+
+    @Override
+    public Result<Object> getProjectConsumeTop(String startTime, String endTime, String companyId, int mediaId) {
+        if (Check.isNull(startTime) && Check.isNull(endTime)) {
+            startTime = DateUtils.getDate(DateUtils.WEB_FORMAT);
+            endTime = startTime;
+        }
+        List<JSONObject> list = null;
+        if (mediaId == 1) {
+            list = mapper.queryTtProjectConsumeTop(companyId, startTime, endTime);
+        } else if (mediaId == 2) {
+            list = mapper.queryKsProjectConsumeTop(companyId, startTime, endTime);
+        }
+        return Result.ok(list);
+    }
+
+    @Override
+    public Result<Object> getMediaData(String companyId) {
+        Integer startTime = DateUtils.getFirstDayByMonth();
+        String endTime = DateUtils.getDate(DateUtils.SHORT_FORMAT);
+        List<Map<String, String>> ksdata = mapper.getKsMonthlyData(companyId, startTime, endTime);
+        List<Map<String, String>> ttdate = mapper.getTtMonthlyData(companyId, startTime, endTime);
+        JSONObject obj = new JSONObject();
+        obj.put("ksdata", ksdata);
+        obj.put("ttdate", ttdate);
+        return Result.ok(obj);
+    }
+
+    @Override
+    public Result<Object> getRealTimeData(String companyId, int mediaId) throws ParseException {
+        String today = DateUtils.getDate(DateUtils.WEB_FORMAT);
+        String lastDay = DateUtils.getLastDay(today, 1);
+        Integer hour = DateUtils.getNowHour();
+        SysManagerCompany company = this.getById(companyId);
+        JSONObject result = new JSONObject();
+        if (Check.isNull(company)) {
+            return Result.ok("未查到公司:" + companyId);
+        }
+        BigDecimal hundred = new BigDecimal(100 + "");
+        if (mediaId == 1) {
+            List<JSONObject> list = mapper.queryDepartByParentId(company.getTtDesignId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到销售组");
+            }
+            //查询部门所有人员
+            List<String> userIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(userIds)) {
+                return Result.ok("未查询到人员");
+            }
+
+            //查询消耗
+            JSONObject cost = mapper.queryTtRealTimeCost(companyId, today, lastDay, hour);
+            Double todayCost = cost.getDouble("todayCost");
+            Double yesCost = cost.getDouble("yesCost");
+            BigDecimal costRatio = BigDecimal.valueOf((todayCost - yesCost) / yesCost).multiply(hundred);
+            String costRatioStr = costRatio.setScale(2, RoundingMode.HALF_UP).toString();
+            //查询广告组数
+            JSONObject group = mapper.queryTtRealTimeGroupNum(companyId, today, lastDay);
+            Long groupNum = group.getLong("todayNum");
+            Double yesNum = group.getDouble("yesNum");
+            BigDecimal unitRatio = BigDecimal.valueOf((groupNum - yesNum) / yesNum).multiply(hundred);
+            String unitRatioStr = unitRatio.setScale(2, RoundingMode.HALF_UP).toString();
+
+            //查询素材数
+            JSONObject material = mapper.queryTtRealTimeMaterialNum(companyId, userIds, today, lastDay);
+            Long materialNum = material.getLong("todayCount");
+            Double yesCount = material.getDouble("yesCount");
+            BigDecimal materialRatio = BigDecimal.valueOf((materialNum - yesCount) / yesCount).multiply(hundred);
+            String materialRatioStr = materialRatio.setScale(2, RoundingMode.HALF_UP).toString();
+
+            List<JSONObject> operateList = mapper.queryDepartByParentId(company.getTtOperateId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到技术组");
+            }
+            //查询运营部门所有人员
+            List<String> operateUserIds = mapper.queryAllPersonnel(operateList);
+            //人效比:公式=该分公司今日消耗/该分公司运营人数
+            if (Check.isNull(operateUserIds)) {
+                result.put("renXiao", 0);
+            } else {
+                BigDecimal renXiaoRatio = BigDecimal.valueOf(todayCost / operateUserIds.size());
+                String renXiaoRatioStr = renXiaoRatio.setScale(2, RoundingMode.HALF_UP).toString();
+                result.put("renXiao", renXiaoRatioStr);
+            }
+            result.put("cost", todayCost);
+            result.put("costRatio", costRatioStr);
+            result.put("groupNum", groupNum);
+            result.put("unitRatio", unitRatioStr);
+            result.put("materialNum", materialNum);
+            result.put("materialRatio", materialRatioStr);
+        } else if (mediaId == 2) {
+            List<JSONObject> list = mapper.queryDepartByParentId(company.getKsDesignId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到技术组");
+            }
+            //查询技术部门所有人员
+            List<String> userIds = mapper.queryAllPersonnel(list);
+            if (Check.isNull(userIds)) {
+                return Result.ok("未查询到人员");
+            }
+
+            //查询消耗
+            JSONObject cost = mapper.queryKsRealTimeCost(companyId, today, lastDay, hour);
+            Double todayCost = cost.getDouble("todayCost");
+            Double yesCost = cost.getDouble("yesCost");
+            BigDecimal costRatio = BigDecimal.valueOf((todayCost - yesCost) / yesCost).multiply(hundred);
+            String costRatioStr = costRatio.setScale(2, RoundingMode.HALF_UP).toString();
+            //查询广告组数
+            JSONObject group = mapper.queryKsRealTimeGroupNum(companyId, today, lastDay);
+            Long groupNum = group.getLong("todayNum");
+            Double yesNum = group.getDouble("yesNum");
+            BigDecimal unitRatio = BigDecimal.valueOf((groupNum - yesNum) / yesNum).multiply(hundred);
+            String unitRatioStr = unitRatio.setScale(2, RoundingMode.HALF_UP).toString();
+
+            //查询素材数
+            JSONObject material = mapper.queryKsRealTimeMaterialNum(companyId, userIds, today, lastDay);
+            Long materialNum = material.getLong("todayCount");
+            Double yesCount = material.getDouble("yesCount");
+            BigDecimal materialRatio = BigDecimal.valueOf((materialNum - yesCount) / yesCount).multiply(hundred);
+            String materialRatioStr = materialRatio.setScale(2, RoundingMode.HALF_UP).toString();
+
+            List<JSONObject> operateList = mapper.queryDepartByParentId(company.getKsOperateId());
+            if (Check.isNull(list) || list.isEmpty()) {
+                return Result.ok("未查询到技术组");
+            }
+            //查询运营部门所有人员
+            List<String> operateUserIds = mapper.queryAllPersonnel(operateList);
+            //人效比:公式=该分公司今日消耗/该分公司运营人数
+            if (Check.isNull(operateUserIds)) {
+                result.put("renXiao", 0);
+            } else {
+                BigDecimal renXiaoRatio = BigDecimal.valueOf(todayCost / operateUserIds.size());
+                String renXiaoRatioStr = renXiaoRatio.setScale(2, RoundingMode.HALF_UP).toString();
+                result.put("renXiao", renXiaoRatioStr);
+            }
+            result.put("cost", todayCost);
+            result.put("costRatio", costRatioStr);
+            result.put("groupNum", groupNum);
+            result.put("unitRatio", unitRatioStr);
+            result.put("materialNum", materialNum);
+            result.put("materialRatio", materialRatioStr);
+        }
+        return Result.ok(result);
+    }
+
+    @Override
+    public Result<Object> getTotalConsume(String companyId, int mediaId) {
+        Integer startTime = DateUtils.getFirstDayByMonth();
+        String endTime = DateUtils.getDate(DateUtils.SHORT_FORMAT);
+        JSONObject obj = new JSONObject();
+        SysManagerCompany company = this.getById(companyId);
+        if (Check.isNull(company)) {
+            return Result.error("未查询到公司");
+        }
+        String totalConsume = null;
+        if (mediaId == 1) {
+            totalConsume = mapper.getTtTotalConsume(companyId, startTime, endTime);
+            obj.put("targetValue", company.getTtTargetValue());
+        } else if (mediaId == 2) {
+            totalConsume = mapper.getKsTotalConsume(companyId, startTime, endTime);
+            obj.put("targetValue", company.getKsTargetValue());
+        }
+        obj.put("totalConsume", totalConsume);
+        return Result.ok(obj);
+    }
+}

+ 37 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/UserCompanyController.java

@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.mapper.UserCompanyMapper;
 import cn.com.ctop.common.module.service.IUserCompanyService;
 import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -16,13 +17,22 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.entity.SysUser;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.system.service.ISysRoleService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
@@ -55,7 +65,8 @@ public class UserCompanyController {
     private SysUserMapper sysUserMapper;
     @Resource
     private UserCompanyMapper userCompanyMapper;
-
+    @Autowired
+    private ISysRoleService sysRoleService;
 
     @GetMapping(value = "/companyUser")
     public void companyUser() {
@@ -296,4 +307,28 @@ public class UserCompanyController {
         return Result.ok("文件导入失败!");
     }
 
+    /**
+     * 通过id查询
+     */
+    @GetMapping(value = "/queryCompanyByUserId")
+    public Result<Object> queryCompanyByUserId(@RequestParam(name = "userId", required = true) String userId) {
+        Result<Object> result = new Result<Object>();
+        if (Check.isNull(userId)) {
+            return Result.error("缺少参数");
+        }
+        String roleCode = sysRoleService.getRoleCodeByUserId(userId);
+        if ("CompanyManager".equals(roleCode) || "admin".equals(roleCode)) {
+            JSONObject obj = userCompanyService.getCompanyInfoByUserId(userId);
+            String companyId = obj.getString("companyId");
+            if (Check.isNull(companyId)) {
+                return Result.error("用户未指派公司,请优先分配公司");
+            }
+            result.setResult(companyId);
+            result.setSuccess(true);
+            return result;
+        } else {
+            return Result.error("权限不足");
+        }
+    }
+
 }