Browse Source

feat: 销售后台首页显示的统计量要按登录用户来筛选

xdd 1 day ago
parent
commit
23e696fa35

+ 51 - 0
fs-common/src/main/java/com/fs/common/config/LoginContextCallback.java

@@ -0,0 +1,51 @@
+// fs-service模块
+package com.fs.common.config;
+
+import com.fs.common.enums.DataScopeEnum;
+
+import java.util.List;
+
+/**
+ * 登录上下文回调接口
+ */
+public interface LoginContextCallback {
+
+    /**
+     * 获取当前用户ID
+     */
+    Long getUserId();
+
+    /**
+     * 获取companyUserId
+     * 销售端有值
+     */
+    Long getCompanyUserId();
+
+    /**
+     * 获取用户名
+     */
+    String getUsername();
+
+    /**
+     * 获取当前销售用户名
+     * @return String
+     */
+    String getCompanyUserName();
+
+    /**
+     * 获取租户ID
+     */
+    Long getCompanyId();
+
+    /**
+     * 获取部门ID
+     * @return 部门ID
+     */
+    Long getDeptId();
+
+    /**
+     * 获取当前登录用户数据权限
+     * @return DataScopeEnum
+     */
+    DataScopeEnum getDataScope();
+}

+ 86 - 0
fs-common/src/main/java/com/fs/common/config/LoginContextManager.java

@@ -0,0 +1,86 @@
+// fs-service模块
+package com.fs.common.config;
+
+import com.fs.common.enums.DataScopeEnum;
+
+/**
+ * 登录上下文管理器
+ * 线程安全的上下文管理
+ */
+public class LoginContextManager {
+
+    private static final ThreadLocal<LoginContextCallback> callbackHolder = new ThreadLocal<>();
+
+    /**
+     * 设置上下文回调函数
+     */
+    public static void setContextCallback(LoginContextCallback callback) {
+        callbackHolder.set(callback);
+    }
+
+    /**
+     * 获取当前用户ID
+     */
+    public static Long getCurrentUserId() {
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getUserId() : null;
+    }
+
+    /**
+     * 获取companyUserId
+     */
+    public static Long getCurrentCompanyUserId() {
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getCompanyUserId() : null;
+    }
+
+    /**
+     * 获取用户名
+     */
+    public static String getCurrentUsername() {
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getUsername() : null;
+    }
+
+    /**
+     * 获取租户ID
+     */
+    public static Long getCurrentCompanyId() {
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getCompanyId() : null;
+    }
+
+    /**
+     * 获取当前部门ID
+     * @return 部门ID
+     */
+    public static Long getCurrentDeptId(){
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getDeptId() : null;
+    }
+
+    /**
+     * 获取当前用户的数据权限
+     * @return DataScopeEnum
+     */
+    public static DataScopeEnum getDataScope(){
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null ? callback.getDataScope() : null;
+    }
+
+
+    /**
+     * 清理上下文
+     */
+    public static void clearContext() {
+        callbackHolder.remove();
+    }
+
+    /**
+     * 检查是否有有效的上下文
+     */
+    public static boolean hasContext() {
+        LoginContextCallback callback = callbackHolder.get();
+        return callback != null && callback.getUserId() != null;
+    }
+}

+ 174 - 0
fs-common/src/main/java/com/fs/common/enums/DataScopeEnum.java

@@ -0,0 +1,174 @@
+package com.fs.common.enums;
+
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 数据权限范围枚举
+ * 定义系统中不同层级的数据访问权限
+ *
+ * @author System
+ * @date 2024年
+ */
+@Getter
+public enum DataScopeEnum {
+
+    /**
+     * 全部数据权限 - 最高权限级别,可以访问所有数据
+     */
+    ALL("1", "全部数据权限"),
+
+    /**
+     * 自定义数据权限 - 根据用户自定义的权限规则访问数据
+     */
+    CUSTOM("2", "自定数据权限"),
+
+    /**
+     * 本部门数据权限 - 只能访问用户所属部门的数据
+     */
+    DEPARTMENT("3", "本部门数据权限"),
+
+    /**
+     * 本部门及以下数据权限 - 可以访问用户所属部门及其下级部门的数据
+     */
+    DEPARTMENT_AND_BELOW("4", "本部门及以下数据权限"),
+    /**
+     * 仅本人数据权限
+     */
+    SELF_ONLY("5", "仅本人数据权限");
+
+    /**
+     * 权限类型代码
+     * -- GETTER --
+     *  获取权限代码
+     *
+     * @return 权限代码
+
+     */
+    private final String code;
+
+    /**
+     * 权限描述信息
+     * -- GETTER --
+     *  获取权限描述
+     *
+     * @return 权限描述
+
+     */
+    private final String description;
+
+    /**
+     * 代码到枚举值的映射缓存,用于快速查找
+     */
+    private static final Map<String, DataScopeEnum> CODE_MAP = Arrays.stream(values())
+            .collect(Collectors.toMap(DataScopeEnum::getCode, Function.identity()));
+
+    /**
+     * 构造函数
+     *
+     * @param code 权限代码
+     * @param description 权限描述
+     */
+    DataScopeEnum(String code, String description) {
+        this.code = code;
+        this.description = description;
+    }
+
+    /**
+     * 根据代码获取对应的枚举值
+     *
+     * @param code 权限代码
+     * @return 对应的枚举值,如果不存在则返回null
+     */
+    public static DataScopeEnum getByCode(String code) {
+        return CODE_MAP.get(code);
+    }
+
+    /**
+     * 根据代码获取对应的枚举值,如果不存在则抛出异常
+     *
+     * @param code 权限代码
+     * @return 对应的枚举值
+     * @throws IllegalArgumentException 如果代码对应的枚举值不存在
+     */
+    public static DataScopeEnum getByCodeOrThrow(String code) {
+        DataScopeEnum enumValue = CODE_MAP.get(code);
+        if (enumValue == null) {
+            throw new IllegalArgumentException("无效的数据权限代码: " + code);
+        }
+        return enumValue;
+    }
+
+    /**
+     * 验证代码是否有效
+     *
+     * @param code 待验证的权限代码
+     * @return 如果代码有效返回true,否则返回false
+     */
+    public static boolean isValidCode(String code) {
+        return CODE_MAP.containsKey(code);
+    }
+
+    /**
+     * 获取所有有效的权限代码数组
+     *
+     * @return 权限代码数组
+     */
+    public static String[] getAllCodes() {
+        return CODE_MAP.keySet().toArray(new String[0]);
+    }
+
+    /**
+     * 检查当前权限是否包含另一个权限
+     * 权限层级关系:ALL > DEPARTMENT_AND_BELOW > DEPARTMENT > CUSTOM
+     *
+     * @param other 另一个权限
+     * @return 如果当前权限包含或等于另一个权限返回true
+     */
+    public boolean contains(DataScopeEnum other) {
+        if (this == ALL) {
+            return true; // 全部权限包含所有权限
+        }
+        if (this == DEPARTMENT_AND_BELOW) {
+            return other == DEPARTMENT_AND_BELOW || other == DEPARTMENT || other == CUSTOM;
+        }
+        if (this == DEPARTMENT) {
+            return other == DEPARTMENT || other == CUSTOM;
+        }
+        return this == other; // CUSTOM 只包含自己
+    }
+
+    /**
+     * 获取权限的层级值(数值越小权限越大)
+     *
+     * @return 层级值
+     */
+    public int getLevel() {
+        switch (this) {
+            case ALL: return 1;
+            case DEPARTMENT_AND_BELOW: return 2;
+            case DEPARTMENT: return 3;
+            case CUSTOM: return 4;
+            default: return 5;
+        }
+    }
+
+    /**
+     * 比较两个权限的层级
+     *
+     * @param other 另一个权限
+     * @return 如果当前权限层级更高返回正数,相同返回0,更低返回负数
+     */
+    public int compareLevel(DataScopeEnum other) {
+        return Integer.compare(other.getLevel(), this.getLevel());
+    }
+
+    @Override
+    public String toString() {
+        return code + ":" + description;
+    }
+}

+ 5 - 1
fs-company/src/main/java/com/fs/company/controller/company/IndexStatisticsController.java

@@ -7,6 +7,7 @@ import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
 import com.fs.statis.StatisticsRedisConstant;
 import com.fs.statis.dto.*;
+import com.fs.statis.service.IStatisticsCompanyService;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +29,9 @@ public class IndexStatisticsController {
 
     @Autowired
     private TokenService tokenService;
+
+    @Autowired
+    private IStatisticsCompanyService statisticsCompanyService;
     /**
      * 分析概览
      */
@@ -46,8 +50,8 @@ public class IndexStatisticsController {
         }
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         param.setCompanyId(loginUser.getCompany().getCompanyId());
-        analysisPreviewDTO = redisCache.getCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,param.getCompanyId()));
 
+        analysisPreviewDTO = statisticsCompanyService.analysisPreviewTask(type,userType,param.getCompanyId());
         return R.ok().put("data",analysisPreviewDTO);
     }
 

+ 80 - 0
fs-company/src/main/java/com/fs/framework/config/CompanyLoginContextCallback.java

@@ -0,0 +1,80 @@
+// fs-company模块
+package com.fs.framework.config;
+
+import cn.hutool.extra.spring.SpringUtil;
+import com.fs.common.config.LoginContextCallback;
+import com.fs.common.enums.DataScopeEnum;
+import com.fs.company.domain.CompanyRole;
+import com.fs.company.domain.CompanyUser;
+import com.fs.company.mapper.CompanyRoleMapper;
+import com.fs.framework.security.LoginUser;
+import com.fs.framework.security.SecurityUtils;
+
+import java.util.*;
+
+/**
+ * 登录上下文回调实现
+ */
+public class CompanyLoginContextCallback implements LoginContextCallback {
+
+    @Override
+    public Long getUserId() {
+       throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public Long getCompanyUserId() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        return loginUser != null ? loginUser.getUser().getUserId() : null;
+    }
+
+    @Override
+    public String getUsername() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public String getCompanyUserName() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        return loginUser.getUsername();
+    }
+
+    @Override
+    public Long getCompanyId() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        return loginUser.getCompany().getCompanyId();
+    }
+
+    @Override
+    public Long getDeptId() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        CompanyUser user = loginUser.getUser();
+        return user.getDeptId();
+    }
+
+
+    @Override
+    public DataScopeEnum getDataScope(){
+        CompanyRoleMapper companyRoleMapper = SpringUtil.getBean(CompanyRoleMapper.class);
+        List<String> dataScope = companyRoleMapper.queryCompanyUserDataScope(getCompanyUserId());
+        if (dataScope == null || dataScope.isEmpty()) {
+            return null;
+        }
+        Set<String> dataScopeSet = new TreeSet<>(dataScope);
+
+        // 按优先级顺序检查
+        for (DataScopeEnum scope : Arrays.asList(
+                DataScopeEnum.ALL,
+                DataScopeEnum.CUSTOM,
+                DataScopeEnum.DEPARTMENT,
+                DataScopeEnum.DEPARTMENT_AND_BELOW,
+                DataScopeEnum.SELF_ONLY
+        )) {
+            if (dataScopeSet.contains(scope.getCode())) {
+                return scope;
+            }
+        }
+        return null;
+    }
+
+}

+ 16 - 5
fs-company/src/main/java/com/fs/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -1,8 +1,10 @@
 package com.fs.framework.security.filter;
 
+import com.fs.common.config.LoginContextManager;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.StringUtils;
 
+import com.fs.framework.config.CompanyLoginContextCallback;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.security.SecurityUtils;
 import com.fs.framework.service.TokenService;
@@ -21,16 +23,15 @@ import java.io.IOException;
 
 /**
  * token过滤器 验证token有效性
- * 
- 
+ *
+
  */
 @Component
 public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
 {
     @Autowired
     private TokenService tokenService;
-    @Autowired
-    private RedisCache redisCache;
+
     @Override
     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
             throws ServletException, IOException
@@ -42,7 +43,17 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
             UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
             authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
             SecurityContextHolder.getContext().setAuthentication(authenticationToken);
+
+            // 设置上下文回调
+            CompanyLoginContextCallback callback = new CompanyLoginContextCallback();
+            LoginContextManager.setContextCallback(callback);
+
+        }
+        try{
+            chain.doFilter(request, response);
+        }finally {
+            LoginContextManager.clearContext();
         }
-        chain.doFilter(request, response);
+
     }
 }

+ 7 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyRoleMapper.java

@@ -2,6 +2,7 @@ package com.fs.company.mapper;
 
 import com.fs.company.domain.CompanyRole;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -85,4 +86,10 @@ public interface CompanyRoleMapper
      * **/
     CompanyRole selectCompanyRoleByRoleKey(@Param("roleKey") String roleKey);
     Long selectRolesByUserNameAndCompanyId(@Param("roleName") String roleName,@Param("companyId") Long companyId);
+
+
+    @Select("select distinct cr.data_scope from company_user_role cur\n" +
+            "          inner join company_role cr on cur.role_id=cr.role_id\n" +
+            "        where cur.user_id = #{companyUserId}")
+    List<String> queryCompanyUserDataScope(@Param("companyUserId") Long companyUserId);
 }

+ 8 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyRoleService.java

@@ -109,4 +109,12 @@ public interface ICompanyRoleService
      * @return
      * **/
     int insertDefaultRole(CompanyRole role);
+
+
+    /**
+     * 查询销售所有数据权限
+     * @param companyUserId
+     * @return
+     */
+    List<String> queryCompanyUserDataScope(Long companyUserId);
 }

+ 5 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyRoleServiceImpl.java

@@ -281,4 +281,9 @@ public class CompanyRoleServiceImpl implements ICompanyRoleService
     public int insertDefaultRole(CompanyRole role) {
         return companyRoleMapper.insertCompanyRole(role);
     }
+
+    @Override
+    public List<String> queryCompanyUserDataScope(Long companyUserId) {
+        return companyRoleMapper.queryCompanyUserDataScope(companyUserId);
+    }
 }

+ 38 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -7,10 +7,12 @@ import com.alibaba.fastjson.JSONObject;
 import com.fs.common.BeanCopyUtils;
 import com.fs.common.QRutils;
 import com.fs.common.annotation.DataScope;
+import com.fs.common.config.LoginContextManager;
 import com.fs.common.constant.UserConstants;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.enums.DataScopeEnum;
 import com.fs.common.exception.CustomException;
 import com.fs.common.exception.ServiceException;
 import com.fs.common.exception.file.OssException;
@@ -1061,4 +1063,40 @@ public class CompanyUserServiceImpl implements ICompanyUserService
         }
         return R.ok("修改成功");
     }
+
+
+    /**
+     * 获取数据权限下的所有销售
+     * @param dataScope 数据权限
+     * @return List<Long>
+     */
+    private List<Long> getCompanyUserIdsByDataScope(DataScopeEnum dataScope){
+
+        if(DataScopeEnum.ALL == dataScope){
+            throw new UnsupportedOperationException("全部数据权限无需获取所有销售!");
+        }
+
+        // 自定义数据权限
+        if(DataScopeEnum.CUSTOM == dataScope) {
+
+        }
+
+        // 本部门数据权限
+        if(DataScopeEnum.DEPARTMENT == dataScope){
+
+        }
+
+        // 本部门及以下数据权限
+        if(DataScopeEnum.DEPARTMENT_AND_BELOW == dataScope){
+
+        }
+
+        // 仅本人数据权限
+        if(DataScopeEnum.SELF_ONLY == dataScope){
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            return Collections.singletonList(currentCompanyUserId);
+        }
+
+        return null;
+    }
 }

+ 6 - 0
fs-service/src/main/java/com/fs/statis/dto/AnalysisPreviewQueryDTO.java

@@ -4,6 +4,7 @@ import lombok.Data;
 import lombok.Setter;
 
 import java.io.Serializable;
+import java.util.List;
 
 @Data
 @Setter
@@ -52,4 +53,9 @@ public class AnalysisPreviewQueryDTO implements Serializable {
      * */
     private Long deptId;
 
+
+    /**
+     * 数据权限,销售列表
+     */
+    private List<Long> companyUserIds;
 }

+ 2 - 2
fs-service/src/main/java/com/fs/statis/service/IStatisticsCompanyService.java

@@ -17,13 +17,13 @@ public interface IStatisticsCompanyService {
     /**
      * 分析概览定时任务
      */
-    void analysisPreviewTask(Integer type,Integer userType,Long companyId);
+    AnalysisPreviewDTO analysisPreviewTask(Integer type,Integer userType,Long companyId);
 
 
     /**
      * 会员观看、完播人数趋势图
      */
-    void watchEndPlayTrendTask(Integer type,Integer userType,Long companyId);
+    List<WatchEndPlayTrendDTO> watchEndPlayTrendTask(Integer type,Integer userType,Long companyId);
 
 
     /**

+ 65 - 38
fs-service/src/main/java/com/fs/statis/service/impl/StatisticsCompanyServiceImpl.java

@@ -2,10 +2,14 @@ package com.fs.statis.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fs.common.config.LoginContextManager;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.enums.DataScopeEnum;
+import com.fs.common.utils.SecurityUtils;
 import com.fs.common.utils.TimeUtils;
 import com.fs.company.cache.ICompanyCacheService;
+import com.fs.company.service.ICompanyRoleService;
 import com.fs.company.service.ICompanyService;
 import com.fs.course.mapper.FsCourseTrafficLogMapper;
 import com.fs.his.service.IFsStoreOrderService;
@@ -24,9 +28,11 @@ import com.fs.statis.service.utils.TrendDataFiller;
 import com.fs.store.service.cache.IFsUserCourseCacheService;
 import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
+import com.google.common.collect.Lists;
 import com.hc.openapi.tool.util.ObjectUtils;
 import com.hc.openapi.tool.util.StringUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.http.util.Asserts;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -39,6 +45,8 @@ import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -81,6 +89,9 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
 
     @Autowired
     private QwUserMapper qwUserMapper;
+
+    @Autowired
+    private ICompanyRoleService companyRoleService;
     @Override
     public void dataOverviewTask() {
         List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
@@ -106,42 +117,42 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         redisCache.setCacheObject(String.format(StatisticsRedisConstant.DATA_OVERVIEW_DEALER_SMS_BALANCE+":%d",companyId), smsBalance);
         redisCache.setCacheObject(String.format(StatisticsRedisConstant.DATA_OVERVIEW_TRAFFIC_LOG+":%d",companyId),trafficLog);
     }
-    public void analysisPreviewTask0(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-            analysisPreviewTask(0,1,companyId);
-            analysisPreviewTask(0,2,companyId);
-        }
-
-    }
-
-    public void analysisPreviewTask1(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-
-            analysisPreviewTask(0,1,companyId);
-            analysisPreviewTask(1,1,companyId);
-            analysisPreviewTask(2,1,companyId);
-            analysisPreviewTask(3,1,companyId);
-            analysisPreviewTask(4,1,companyId);
-
-            analysisPreviewTask(0,2,companyId);
-            analysisPreviewTask(1,2,companyId);
-            analysisPreviewTask(2,2,companyId);
-            analysisPreviewTask(3,2,companyId);
-            analysisPreviewTask(4,2,companyId);
-        }
-    }
+//    public void analysisPreviewTask0(){
+//        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
+//        for (OptionsVO optionsVO : optionsVOS) {
+//            Long companyId = optionsVO.getDictValue();
+//            if (companyId == null) {
+//                continue;
+//            }
+//            analysisPreviewTask(0,1,companyId);
+//            analysisPreviewTask(0,2,companyId);
+//        }
+//
+//    }
+
+//    public void analysisPreviewTask1(){
+//        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
+//        for (OptionsVO optionsVO : optionsVOS) {
+//            Long companyId = optionsVO.getDictValue();
+//            if (companyId == null) {
+//                continue;
+//            }
+//
+//            analysisPreviewTask(0,1,companyId);
+//            analysisPreviewTask(1,1,companyId);
+//            analysisPreviewTask(2,1,companyId);
+//            analysisPreviewTask(3,1,companyId);
+//            analysisPreviewTask(4,1,companyId);
+//
+//            analysisPreviewTask(0,2,companyId);
+//            analysisPreviewTask(1,2,companyId);
+//            analysisPreviewTask(2,2,companyId);
+//            analysisPreviewTask(3,2,companyId);
+//            analysisPreviewTask(4,2,companyId);
+//        }
+//    }
     @Override
-    public void analysisPreviewTask(Integer type, Integer userType,Long companyId) {
+    public AnalysisPreviewDTO analysisPreviewTask(Integer type, Integer userType,Long companyId) {
         // 根据type计算出时间范围
         String startDate = "";
         String endDate = "";
@@ -193,12 +204,26 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         param.setUserType(userType);
         param.setCompanyId(companyId);
 
-        AnalysisPreviewDTO analysisPreviewDTO = this.analysisPreview(param);
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        AnalysisPreviewDTO analysisPreviewDTO = null;
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            analysisPreviewDTO = this.analysisPreview(param);
 
-        redisCache.setCacheObject(String.format("%s:%d:%d:%d",DATA_OVERVIEW_DEALER_ANALYSISPREVIEW,type,userType,companyId), analysisPreviewDTO);
+            // 自定义数据权限
+        } else if(DataScopeEnum.CUSTOM == dataScope) {
+
+        }
+
+        return analysisPreviewDTO;
     }
 
 
+
+
+
+
     public void watchEndPlayTrendTask0(){
         List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
         for (OptionsVO optionsVO : optionsVOS) {
@@ -220,6 +245,7 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
                 continue;
             }
             this.watchEndPlayTrendTask(1,1,companyId);
+
             this.watchEndPlayTrendTask(2,1,companyId);
             this.watchEndPlayTrendTask(3,1,companyId);
             this.watchEndPlayTrendTask(4,1,companyId);
@@ -232,7 +258,7 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
 
     }
     @Override
-    public void watchEndPlayTrendTask(Integer type, Integer userType,Long companyId) {
+    public List<WatchEndPlayTrendDTO> watchEndPlayTrendTask(Integer type, Integer userType,Long companyId) {
         // 根据type计算出时间范围
         String startDate = "";
         String endDate = "";
@@ -287,6 +313,7 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = this.watchEndPlayTrend(param);
 
         redisCache.setCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_CHARTS,type,userType),watchEndPlayTrendDTOS);
+        return watchEndPlayTrendDTOS;
     }
 
     @Override

+ 25 - 1
fs-service/src/main/resources/mapper/statis/ConsumptionBalanceMapper.xml

@@ -5,6 +5,23 @@
 <mapper namespace="com.fs.statis.mapper.ConsumptionBalanceMapper">
 
 
+    <!--部门数据权限-->
+    <sql id="deptDataPermission">
+        <if test="companyUserIds!= null and companyUserIds.length > 0">
+            and company_user_id in
+            <foreach collection="companyUserIds" item="item" open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+    </sql>
+    <sql id="deptDataPermissionWithAlias">
+        <if test="companyUserIds!= null and companyUserIds.length > 0">
+            and log.company_user_id in
+            <foreach collection="companyUserIds" item="item" open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+    </sql>
     <select id="rechargeConsumption" resultType="com.fs.statis.dto.ConsumptionBalanceDataDTO">
         select
             14371277 AS balance,
@@ -50,6 +67,7 @@
             <if test="companyId != null">
                 and company_id = #{companyId}
             </if>
+            <include refid="deptDataPermission"/>
         </where>
     </select>
     <select id="queryCompletedUserCount" resultType="java.lang.Long">
@@ -65,6 +83,7 @@
             <if test="companyId != null">
                 and company_id = #{companyId}
             </if>
+            <include refid="deptDataPermission"/>
         </where>
     </select>
     <select id="queryWatchUserCount" resultType="java.lang.Long">
@@ -79,7 +98,7 @@
             <if test="companyId != null">
                 and company_id = #{companyId}
             </if>
-
+            <include refid="deptDataPermission"/>
         </where>
     </select>
     <select id="queryCompletedCount" resultType="java.lang.Long">
@@ -95,6 +114,7 @@
              <if test="companyId != null">
                  and company_id = #{companyId}
              </if>
+             <include refid="deptDataPermission"/>
          </where>
     </select>
     <select id="queryAnswerMemberCount" resultType="java.lang.Long">
@@ -106,6 +126,7 @@
            <if test="companyId != null">
                and company_id = #{companyId}
            </if>
+           <include refid="deptDataPermission"/>
        </where>
     </select>
     <select id="queryCorrectUserCount" resultType="java.lang.Long">
@@ -118,6 +139,7 @@
             <if test="companyId != null">
                 and company_id = #{companyId}
             </if>
+            <include refid="deptDataPermission"/>
         </where>
     </select>
     <select id="queryRewardCount" resultType="java.lang.Long">
@@ -134,6 +156,7 @@
             <if test="companyId != null">
                 and log.company_id = #{companyId}
             </if>
+            <include refid="deptDataPermissionWithAlias"/>
         </where>
     </select>
     <select id="queryRewardMoney" resultType="java.math.BigDecimal">
@@ -150,6 +173,7 @@
             <if test="companyId != null">
                 and log.company_id = #{companyId}
             </if>
+            <include refid="deptDataPermissionWithAlias"/>
         </where>
     </select>
     <select id="smsBalance" resultType="java.lang.Long">