Browse Source

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

xdd 10 hours ago
parent
commit
7b0e83ef6e

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

@@ -69,6 +69,7 @@ public class LoginContextManager {
     }
 
 
+
     /**
      * 清理上下文
      */

+ 14 - 0
fs-common/src/main/java/com/fs/common/utils/TimeUtils.java

@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 public class TimeUtils
@@ -221,6 +222,19 @@ public class TimeUtils
          */
         private Long[] userIds;
 
+        /**
+         * 数据权限,用户可以看的范围
+         */
+        private List<Long> companyUserIds;
+
+        public List<Long> getCompanyUserIds() {
+            return companyUserIds;
+        }
+
+        public void setCompanyUserIds(List<Long> companyUserIds) {
+            this.companyUserIds = companyUserIds;
+        }
+
         public Integer getBeginTime() {
             return beginTime;
         }

+ 9 - 14
fs-company/src/main/java/com/fs/company/controller/company/IndexStatisticsController.java

@@ -98,9 +98,8 @@ public class IndexStatisticsController {
         Long companyId = loginUser.getCompany().getCompanyId();
         param.setCompanyId(companyId);
 
-        String key = String.format("%s:%d:%d:%d", DATA_OVERVIEW_DEALER_CHARTS, type,userType,param.getCompanyId());
-        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(key);
-        return R.ok().put("data", deaMemberTopTenDTOS);
+        List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = statisticsCompanyService.watchEndPlayTrendTask(type, userType, param.getCompanyId());
+        return R.ok().put("data", watchEndPlayTrendDTOS);
     }
 
     /**
@@ -122,10 +121,7 @@ public class IndexStatisticsController {
         Long companyId = loginUser.getCompany().getCompanyId();
         param.setCompanyId(companyId);
 
-        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type, statisticalType,userType,param.getCompanyId()));
-        if(deaMemberTopTenDTOS == null){
-            deaMemberTopTenDTOS = new ArrayList<>();
-        }
+        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = statisticsCompanyService.companyWatchCourseTopTenTask(type,statisticalType,userType,param.getCompanyId());
         return R.ok().put("data", deaMemberTopTenDTOS);
     }
 
@@ -141,7 +137,7 @@ public class IndexStatisticsController {
         Long companyId = loginUser.getCompany().getCompanyId();
         param.setCompanyId(companyId);
 
-        List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = redisCache.getCacheObject( String.format("%s:%d:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType,param.getCompanyId()));
+        List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = statisticsCompanyService.rewardMoneyTopTenTask(type,dataType,userType,param.getCompanyId());
         return R.ok().put("data", rewardMoneyTopTenDTOS);
     }
 
@@ -156,7 +152,8 @@ public class IndexStatisticsController {
         Long companyId = loginUser.getCompany().getCompanyId();
         param.setCompanyId(companyId);
 
-        List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS = redisCache.getCacheObject( String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType,param.getCompanyId()));
+        List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS = statisticsCompanyService.rewardMoneyTradeTask(type, userType, param.getCompanyId());
+
         return R.ok().put("data", rewardMoneyTrendDTOS);
     }
 
@@ -173,7 +170,7 @@ public class IndexStatisticsController {
         Long companyId = loginUser.getCompany().getCompanyId();
         param.setCompanyId(companyId);
 
-        List<CourseStatsDTO> courseStatsDTOS = redisCache.getCacheObject(String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,param.getCompanyId()));
+        List<CourseStatsDTO> courseStatsDTOS = statisticsCompanyService.watchCourseTopTenTask(type,statisticalType,userType,sort,companyId);
         return R.ok().put("data", courseStatsDTOS);
     }
 
@@ -227,8 +224,7 @@ public class IndexStatisticsController {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         Long companyId = loginUser.getCompany().getCompanyId();
 
-        R result = redisCache.getCacheObject(String.format("%s:%d",StatisticsRedisConstant.THIS_MONTH_ORDER_COUNT,companyId));
-        return result;
+        return statisticsCompanyService.thisMonthOrderCount(companyId);
     }
 
     /**
@@ -240,7 +236,6 @@ public class IndexStatisticsController {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         Long companyId = loginUser.getCompany().getCompanyId();
 
-        R result = redisCache.getCacheObject(String.format("%s:%d",StatisticsRedisConstant.THIS_MONTH_RECV_COUNT,companyId));
-        return result;
+        return statisticsCompanyService.thisMonthRecvCount(companyId);
     }
 }

+ 1 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyDeptMapper.java

@@ -1,6 +1,7 @@
 package com.fs.company.mapper;
 
 import com.fs.company.domain.CompanyDept;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 

+ 6 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -284,4 +284,10 @@ public interface CompanyUserMapper
 
 
     List<String> selectCompanyUserNameByIdsList(@Param("companyUserIDs")List<Long> companyUserID);
+
+    List<Long> getCompanyUserIdListById(@Param("companyUserId") Long companyUserId);
+
+    List<Long> getCompanyUserIdListByDeptId(@Param("deptId") Long deptId);
+
+    List<Long> getCompanyUserIdListByDeptIds(@Param("allSubDeptIds") List<Long> allSubDeptIds);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyUserService.java

@@ -1,6 +1,7 @@
 package com.fs.company.service;
 
 import com.fs.common.core.domain.R;
+import com.fs.common.enums.DataScopeEnum;
 import com.fs.company.domain.CompanyUser;
 import com.fs.company.param.CompanyUserAreaParam;
 import com.fs.company.param.CompanyUserCodeParam;
@@ -244,4 +245,6 @@ public interface ICompanyUserService {
      * @param batchUserRolesVO 批量修改角色参数
      */
     R updateBatchUserRoles(BatchUserRolesVO batchUserRolesVO);
+
+    List<Long> getCompanyUserIdsByDataScope(DataScopeEnum dataScope, Long companyUserId);
 }

+ 59 - 21
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -1,15 +1,11 @@
 package com.fs.company.service.impl;
 
-import cn.hutool.core.collection.ListUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
-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;
@@ -32,26 +28,16 @@ import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.service.IFsCityService;
 import com.fs.his.vo.CitysAreaVO;
 import com.fs.his.vo.OptionsVO;
-import com.fs.hisStore.domain.FsStoreProductAttrScrm;
-import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
-import com.fs.hisStore.domain.FsStoreProductScrm;
-import com.fs.hisStore.dto.ProductArrtDTO;
-import com.fs.hisStore.vo.FsStoreProductExportVO;
 import com.fs.qw.domain.QwUser;
 import com.fs.qw.dto.UserProjectDTO;
 import com.fs.qw.mapper.QwUserMapper;
-import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.service.IQwUserService;
 import com.fs.qw.vo.CompanyUserQwVO;
 import com.fs.qw.vo.QwOptionsVO;
 import com.fs.qw.vo.QwUserVO;
-import com.fs.system.domain.SysConfig;
-import com.fs.system.mapper.SysConfigMapper;
 import com.fs.system.oss.CloudStorageService;
 import com.fs.system.oss.OSSFactory;
-import com.fs.system.service.ISysConfigService;
 import com.fs.system.service.ISysRoleService;
-import com.fs.system.service.ISysUserService;
 import com.fs.voice.utils.StringUtil;
 import com.fs.wxUser.domain.CompanyWxUser;
 import com.github.pagehelper.PageHelper;
@@ -64,7 +50,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -1070,33 +1055,86 @@ public class CompanyUserServiceImpl implements ICompanyUserService
      * @param dataScope 数据权限
      * @return List<Long>
      */
-    private List<Long> getCompanyUserIdsByDataScope(DataScopeEnum dataScope){
+    @Override
+    public List<Long> getCompanyUserIdsByDataScope(DataScopeEnum dataScope, Long companyUserId){
+
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(companyUserId);
 
         if(DataScopeEnum.ALL == dataScope){
             throw new UnsupportedOperationException("全部数据权限无需获取所有销售!");
         }
 
-        // 自定义数据权限
+        // 自定义数据权限 员工-角色-部门-所有员工
         if(DataScopeEnum.CUSTOM == dataScope) {
-
+            return companyUserMapper.getCompanyUserIdListById(companyUserId);
         }
 
         // 本部门数据权限
         if(DataScopeEnum.DEPARTMENT == dataScope){
-
+            Long deptId = companyUser.getDeptId();
+            return companyUserMapper.getCompanyUserIdListByDeptId(deptId);
         }
 
         // 本部门及以下数据权限
         if(DataScopeEnum.DEPARTMENT_AND_BELOW == dataScope){
+            List<Long> allSubDeptIds = getAllSubDeptIds(companyUser.getDeptId());
+            return companyUserMapper.getCompanyUserIdListByDeptIds(allSubDeptIds);
 
         }
 
         // 仅本人数据权限
         if(DataScopeEnum.SELF_ONLY == dataScope){
-            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
-            return Collections.singletonList(currentCompanyUserId);
+            return Collections.singletonList(companyUserId);
         }
 
         return null;
     }
+
+    /**
+     * 获取指定部门的所有子部门(优化版)
+     * @param deptId 部门ID
+     * @return 所有子部门ID列表
+     */
+    private List<Long> getAllSubDeptIds(Long deptId) {
+        List<Long> subDeptIds = new ArrayList<>();
+
+        if (deptId == null) {
+            return subDeptIds;
+        }
+
+        // 获取所有部门数据
+        List<CompanyDept> companyDepts = companyDeptMapper.queryDeptDataAll();
+        if (companyDepts == null || companyDepts.isEmpty()) {
+            return subDeptIds;
+        }
+
+        // 构建索引:parentId -> List<子部门>
+        Map<Long, List<CompanyDept>> parentIdMap = new HashMap<>();
+        for (CompanyDept dept : companyDepts) {
+            if (dept.getParentId() != null) {
+                parentIdMap.computeIfAbsent(dept.getParentId(), k -> new ArrayList<>()).add(dept);
+            }
+        }
+
+        // 使用队列进行迭代查找
+        Queue<Long> queue = new LinkedList<>();
+        queue.offer(deptId);
+
+        while (!queue.isEmpty()) {
+            Long currentParentId = queue.poll();
+
+            List<CompanyDept> children = parentIdMap.get(currentParentId);
+            if (children != null) {
+                for (CompanyDept child : children) {
+                    Long childDeptId = child.getDeptId();
+                    subDeptIds.add(childDeptId);
+                    queue.offer(childDeptId);
+                }
+            }
+        }
+
+        return subDeptIds;
+    }
+
+
 }

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

@@ -1,5 +1,6 @@
 package com.fs.statis.service;
 
+import com.fs.common.core.domain.R;
 import com.fs.statis.dto.*;
 
 import java.util.List;
@@ -29,18 +30,18 @@ public interface IStatisticsCompanyService {
     /**
      * 经销商会员观看TOP10
      */
-    void companyWatchCourseTopTenTask(Integer type,Integer statisticalType,Integer userType,Long companyId);
+    List<DeaMemberTopTenDTO> companyWatchCourseTopTenTask(Integer type,Integer statisticalType,Integer userType,Long companyId);
 
     /**
      * 课程观看TOP10
      */
-    void watchCourseTopTenTask(Integer type,Integer statisticalType,Integer userType,String sort,Long companyId);
+    List<CourseStatsDTO> watchCourseTopTenTask(Integer type,Integer statisticalType,Integer userType,String sort,Long companyId);
 
     /**
      * 答题红包金额TOP10
      */
-    void rewardMoneyTopTenTask(Integer type,Integer dataType,Integer userType,Long companyId);
-    void rewardMoneyTradeTask(Integer type,Integer userType,Long companyId);
+    List<RewardMoneyTopTenDTO> rewardMoneyTopTenTask(Integer type,Integer dataType,Integer userType,Long companyId);
+    List<RewardMoneyTrendDTO> rewardMoneyTradeTask(Integer type,Integer userType,Long companyId);
 
 
 
@@ -99,10 +100,10 @@ public interface IStatisticsCompanyService {
     /**
      * 本月订单数
      */
-    void thisMonthOrderCount(Long companyId);
+    R thisMonthOrderCount(Long companyId);
 
     /**
      * 本月收款数
      */
-    void thisMonthRecvCount(Long companyId);
+    R thisMonthRecvCount(Long companyId);
 }

+ 111 - 352
fs-service/src/main/java/com/fs/statis/service/impl/StatisticsCompanyServiceImpl.java

@@ -11,6 +11,7 @@ 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.company.service.ICompanyUserService;
 import com.fs.course.mapper.FsCourseTrafficLogMapper;
 import com.fs.his.service.IFsStoreOrderService;
 import com.fs.his.service.IFsStorePaymentService;
@@ -91,7 +92,7 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
     private QwUserMapper qwUserMapper;
 
     @Autowired
-    private ICompanyRoleService companyRoleService;
+    private ICompanyUserService companyUserService;
     @Override
     public void dataOverviewTask() {
         List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
@@ -117,40 +118,7 @@ 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);
-//        }
-//    }
+
     @Override
     public AnalysisPreviewDTO analysisPreviewTask(Integer type, Integer userType,Long companyId) {
         // 根据type计算出时间范围
@@ -210,53 +178,16 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         // 看所有
         if(DataScopeEnum.ALL == dataScope) {
             analysisPreviewDTO = this.analysisPreview(param);
-
-            // 自定义数据权限
-        } else if(DataScopeEnum.CUSTOM == dataScope) {
-
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            param.setCompanyUserIds(companyUserIdsByDataScope);
+            analysisPreviewDTO = this.analysisPreview(param);
         }
 
         return analysisPreviewDTO;
     }
 
-
-
-
-
-
-    public void watchEndPlayTrendTask0(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if(companyId == null){
-                continue;
-            }
-            this.watchEndPlayTrendTask(0,1,companyId);
-            this.watchEndPlayTrendTask(0,2,companyId);
-        }
-
-    }
-
-    public void watchEndPlayTrendTask1(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if(companyId == null){
-                continue;
-            }
-            this.watchEndPlayTrendTask(1,1,companyId);
-
-            this.watchEndPlayTrendTask(2,1,companyId);
-            this.watchEndPlayTrendTask(3,1,companyId);
-            this.watchEndPlayTrendTask(4,1,companyId);
-
-            this.watchEndPlayTrendTask(1,2,companyId);
-            this.watchEndPlayTrendTask(2,2,companyId);
-            this.watchEndPlayTrendTask(3,2,companyId);
-            this.watchEndPlayTrendTask(4,2,companyId);
-        }
-
-    }
     @Override
     public List<WatchEndPlayTrendDTO> watchEndPlayTrendTask(Integer type, Integer userType,Long companyId) {
         // 根据type计算出时间范围
@@ -310,14 +241,26 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         param.setCompanyId(companyId);
 
         param.setUserType(userType);
-        List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = this.watchEndPlayTrend(param);
 
-        redisCache.setCacheObject(String.format("%s:%d:%d",DATA_OVERVIEW_DEALER_CHARTS,type,userType),watchEndPlayTrendDTOS);
+
+
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        List<WatchEndPlayTrendDTO> watchEndPlayTrendDTOS = null;
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            watchEndPlayTrendDTOS = this.watchEndPlayTrend(param);
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            param.setCompanyUserIds(companyUserIdsByDataScope);
+            watchEndPlayTrendDTOS = this.watchEndPlayTrend(param);
+        }
         return watchEndPlayTrendDTOS;
     }
 
     @Override
-    public void companyWatchCourseTopTenTask(Integer type, Integer statisticalType, Integer userType,Long companyId) {
+    public List<DeaMemberTopTenDTO> companyWatchCourseTopTenTask(Integer type, Integer statisticalType, Integer userType,Long companyId) {
 
         AnalysisPreviewQueryDTO dto = new AnalysisPreviewQueryDTO();
         dto.setType(type);
@@ -371,59 +314,23 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         dto.setUserType(userType);
         dto.setCompanyId(companyId);
 
-        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS = deaMemberTopTen(dto);
-        redisCache.setCacheObject(String.format("%s:%d:%d:%d:%d", CHARTS_MEMBER_TOP_TEN_WATCH, type,statisticalType,userType,companyId), deaMemberTopTenDTOS);
-    }
-
-    public void companyWatchCourseTopTenTask0(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-            companyWatchCourseTopTenTask(0,0,1,companyId);
-            companyWatchCourseTopTenTask(0,1,1,companyId);
-
-
-            companyWatchCourseTopTenTask(0,0,2,companyId);
-            companyWatchCourseTopTenTask(0,1,2,companyId);
-        }
-
-    }
-
-    public void companyWatchCourseTopTenTask1(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-            companyWatchCourseTopTenTask(1,0,1,companyId);
-            companyWatchCourseTopTenTask(1,1,1,companyId);
-            companyWatchCourseTopTenTask(2,0,1,companyId);
-            companyWatchCourseTopTenTask(2,1,1,companyId);
-            companyWatchCourseTopTenTask(3,0,1,companyId);
-            companyWatchCourseTopTenTask(3,1,1,companyId);
-            companyWatchCourseTopTenTask(4,0,1,companyId);
-            companyWatchCourseTopTenTask(4,1,1,companyId);
-
-            companyWatchCourseTopTenTask(1,0,2,companyId);
-            companyWatchCourseTopTenTask(1,1,2,companyId);
-            companyWatchCourseTopTenTask(2,0,2,companyId);
-            companyWatchCourseTopTenTask(2,1,2,companyId);
-            companyWatchCourseTopTenTask(3,0,2,companyId);
-            companyWatchCourseTopTenTask(3,1,2,companyId);
-            companyWatchCourseTopTenTask(4,0,2,companyId);
-            companyWatchCourseTopTenTask(4,1,2,companyId);
+        List<DeaMemberTopTenDTO> deaMemberTopTenDTOS;
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            deaMemberTopTenDTOS = this.deaMemberTopTen(dto);
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            dto.setCompanyUserIds(companyUserIdsByDataScope);
+            deaMemberTopTenDTOS = this.deaMemberTopTen(dto);
         }
-
-
-
+        return deaMemberTopTenDTOS;
     }
 
     @Override
-    public void watchCourseTopTenTask(Integer type, Integer statisticalType, Integer userType, String sort,Long companyId) {
+    public List<CourseStatsDTO> watchCourseTopTenTask(Integer type, Integer statisticalType, Integer userType, String sort,Long companyId) {
         AnalysisPreviewQueryDTO dto = new AnalysisPreviewQueryDTO();
         dto.setType(type);
         dto.setStatisticalType(statisticalType);
@@ -475,152 +382,25 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         dto.setEndTime(endDate);
         dto.setUserType(userType);
         dto.setCompanyId(companyId);
-        List<CourseStatsDTO> courseStatsDTOS = watchCourseTopTen(dto);
-
-        redisCache.setCacheObject( String.format("%s:%d:%d:%d:%s:%d", CHARTS_WATCH_TOP_TEN, type,statisticalType,userType,sort,companyId), courseStatsDTOS);
-
-    }
-
-
-    public void watchCourseTopTenTask0(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-
-            watchCourseTopTenTask(0,0,1,"DESC",companyId);
-            watchCourseTopTenTask(0,0,1,"ASC",companyId);
-            watchCourseTopTenTask(0,1,1,"DESC",companyId);
-            watchCourseTopTenTask(0,1,1,"ASC",companyId);
-            watchCourseTopTenTask(0,2,1,"DESC",companyId);
-            watchCourseTopTenTask(0,2,1,"ASC",companyId);
-            watchCourseTopTenTask(0,3,1,"DESC",companyId);
-            watchCourseTopTenTask(0,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(0,0,1,"DESC",companyId);
-            watchCourseTopTenTask(0,0,1,"ASC",companyId);
-            watchCourseTopTenTask(0,1,1,"DESC",companyId);
-            watchCourseTopTenTask(0,1,1,"ASC",companyId);
-            watchCourseTopTenTask(0,2,1,"DESC",companyId);
-            watchCourseTopTenTask(0,2,1,"ASC",companyId);
-            watchCourseTopTenTask(0,3,1,"DESC",companyId);
-            watchCourseTopTenTask(0,3,1,"ASC",companyId);
-
-        }
-
-    }
-
-    public void watchCourseTopTenTask1(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-
-            watchCourseTopTenTask(1,0,1,"DESC",companyId);
-            watchCourseTopTenTask(1,0,1,"ASC",companyId);
-
-            watchCourseTopTenTask(1,0,2,"DESC",companyId);
-            watchCourseTopTenTask(1,0,2,"ASC",companyId);
-
-
-            watchCourseTopTenTask(1,1,1,"DESC",companyId);
-            watchCourseTopTenTask(1,1,1,"ASC",companyId);
-
-            watchCourseTopTenTask(1,1,2,"DESC",companyId);
-            watchCourseTopTenTask(1,1,2,"ASC",companyId);
-
-            watchCourseTopTenTask(1,2,1,"DESC",companyId);
-            watchCourseTopTenTask(1,2,1,"ASC",companyId);
-
-            watchCourseTopTenTask(1,2,2,"DESC",companyId);
-            watchCourseTopTenTask(1,2,2,"ASC",companyId);
-
 
-            watchCourseTopTenTask(1,3,1,"DESC",companyId);
-            watchCourseTopTenTask(1,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(1,3,2,"DESC",companyId);
-            watchCourseTopTenTask(1,3,2,"ASC",companyId);
-
-            watchCourseTopTenTask(2,0,1,"DESC",companyId);
-            watchCourseTopTenTask(2,0,1,"ASC",companyId);
-
-            watchCourseTopTenTask(2,0,2,"DESC",companyId);
-            watchCourseTopTenTask(2,0,2,"ASC",companyId);
-
-            watchCourseTopTenTask(2,1,1,"DESC",companyId);
-            watchCourseTopTenTask(2,1,1,"ASC",companyId);
-
-            watchCourseTopTenTask(2,1,2,"DESC",companyId);
-            watchCourseTopTenTask(2,1,2,"ASC",companyId);
-
-            watchCourseTopTenTask(2,2,1,"DESC",companyId);
-            watchCourseTopTenTask(2,2,1,"ASC",companyId);
-
-            watchCourseTopTenTask(2,2,2,"DESC",companyId);
-            watchCourseTopTenTask(2,2,2,"ASC",companyId);
-
-
-            watchCourseTopTenTask(2,3,1,"DESC",companyId);
-            watchCourseTopTenTask(2,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(2,3,2,"DESC",companyId);
-            watchCourseTopTenTask(2,3,2,"ASC",companyId);
-
-            watchCourseTopTenTask(3,0,1,"DESC",companyId);
-            watchCourseTopTenTask(3,0,1,"ASC",companyId);
-
-            watchCourseTopTenTask(3,0,2,"DESC",companyId);
-            watchCourseTopTenTask(3,0,2,"ASC",companyId);
-
-            watchCourseTopTenTask(3,1,1,"DESC",companyId);
-            watchCourseTopTenTask(3,1,1,"ASC",companyId);
-
-            watchCourseTopTenTask(3,1,2,"DESC",companyId);
-            watchCourseTopTenTask(3,1,2,"ASC",companyId);
-
-            watchCourseTopTenTask(3,2,1,"DESC",companyId);
-            watchCourseTopTenTask(3,2,1,"ASC",companyId);
-
-            watchCourseTopTenTask(3,2,2,"DESC",companyId);
-            watchCourseTopTenTask(3,2,2,"ASC",companyId);
-
-            watchCourseTopTenTask(3,3,1,"DESC",companyId);
-            watchCourseTopTenTask(3,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(3,3,2,"DESC",companyId);
-            watchCourseTopTenTask(3,3,2,"ASC",companyId);
-
-            watchCourseTopTenTask(4,0,1,"DESC",companyId);
-            watchCourseTopTenTask(4,0,1,"ASC",companyId);
-
-            watchCourseTopTenTask(4,0,2,"DESC",companyId);
-            watchCourseTopTenTask(4,0,2,"ASC",companyId);
-
-            watchCourseTopTenTask(4,1,1,"DESC",companyId);
-            watchCourseTopTenTask(4,1,1,"ASC",companyId);
-            watchCourseTopTenTask(4,2,1,"DESC",companyId);
-            watchCourseTopTenTask(4,2,1,"ASC",companyId);
-            watchCourseTopTenTask(4,3,1,"DESC",companyId);
-            watchCourseTopTenTask(4,3,1,"ASC",companyId);
-
-            watchCourseTopTenTask(4,1,2,"DESC",companyId);
-            watchCourseTopTenTask(4,1,2,"ASC",companyId);
-            watchCourseTopTenTask(4,2,2,"DESC",companyId);
-            watchCourseTopTenTask(4,2,2,"ASC",companyId);
-            watchCourseTopTenTask(4,3,2,"DESC",companyId);
-            watchCourseTopTenTask(4,3,2,"ASC",companyId);
+        List<CourseStatsDTO> courseStatsDTOS;
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            courseStatsDTOS = this.watchCourseTopTen(dto);
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            dto.setCompanyUserIds(companyUserIdsByDataScope);
+            courseStatsDTOS = this.watchCourseTopTen(dto);
         }
 
+        return courseStatsDTOS;
     }
 
-
     @Override
-    public void rewardMoneyTopTenTask(Integer type, Integer dataType, Integer userType,Long companyId) {
+    public List<RewardMoneyTopTenDTO> rewardMoneyTopTenTask(Integer type, Integer dataType, Integer userType,Long companyId) {
         AnalysisPreviewQueryDTO dto = new AnalysisPreviewQueryDTO();
         dto.setType(type);
         dto.setDataType(dataType);
@@ -673,14 +453,24 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         dto.setUserType(userType);
         dto.setCompanyId(companyId);
 
-        List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = rewardMoneyTopTen(dto);
-
-        redisCache.setCacheObject( String.format("%s:%d:%d:%d:%d", CHARTS_REWARD_MONEY_TOP_TEN, type,dataType,userType,companyId), rewardMoneyTopTenDTOS);
+        List<RewardMoneyTopTenDTO> rewardMoneyTopTenDTOS = null;
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            rewardMoneyTopTenDTOS = this.rewardMoneyTopTen(dto);
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            dto.setCompanyUserIds(companyUserIdsByDataScope);
+            rewardMoneyTopTenDTOS = this.rewardMoneyTopTen(dto);
+        }
 
+        return rewardMoneyTopTenDTOS;
     }
 
     @Override
-    public void rewardMoneyTradeTask(Integer type, Integer userType,Long companyId) {
+    public List<RewardMoneyTrendDTO> rewardMoneyTradeTask(Integer type, Integer userType,Long companyId) {
         AnalysisPreviewQueryDTO dto = new AnalysisPreviewQueryDTO();
         dto.setType(type);
 
@@ -731,77 +521,28 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         dto.setEndTime(endDate);
         dto.setUserType(userType);
         dto.setCompanyId(companyId);
-        List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS = rewardMoneyTrendDTO(dto);
-        redisCache.setCacheObject( String.format("%s:%d:%d:%d", CHARTS_REWARD_MONEY_TREND, type,userType,companyId), rewardMoneyTrendDTOS);
 
-    }
 
+        List<RewardMoneyTrendDTO> rewardMoneyTrendDTOS;
 
-    public void rewardMoneyTask15Minutes(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-            rewardMoneyTopTenTask(0,0,1,companyId);
-            rewardMoneyTopTenTask(0,1,1,companyId);
-
-            rewardMoneyTradeTask(0,1,companyId);
-
-            rewardMoneyTopTenTask(0,0,2,companyId);
-            rewardMoneyTopTenTask(0,1,2,companyId);
-
-            rewardMoneyTradeTask(0,2,companyId);
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            rewardMoneyTrendDTOS = this.rewardMoneyTrendDTO(dto);
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            dto.setCompanyUserIds(companyUserIdsByDataScope);
+            rewardMoneyTrendDTOS = this.rewardMoneyTrendDTO(dto);
         }
 
-    }
-
-
-    public void rewardMoneyTaskEveryday(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-
-            rewardMoneyTopTenTask(1,0,1,companyId);
-            rewardMoneyTopTenTask(1,1,1,companyId);
-
-
-            rewardMoneyTopTenTask(2,0,1,companyId);
-            rewardMoneyTopTenTask(2,1,1,companyId);
-
-            rewardMoneyTopTenTask(3,0,1,companyId);
-            rewardMoneyTopTenTask(3,1,1,companyId);
-
-            rewardMoneyTopTenTask(4,0,1,companyId);
-            rewardMoneyTopTenTask(4,1,1,companyId);
-
-
-            rewardMoneyTradeTask(1,1,companyId);
-            rewardMoneyTradeTask(2,1,companyId);
-            rewardMoneyTradeTask(3,1,companyId);
-            rewardMoneyTradeTask(4,1,companyId);
 
+        return rewardMoneyTrendDTOS;
 
-            rewardMoneyTopTenTask(1,0,2,companyId);
-            rewardMoneyTopTenTask(1,1,2,companyId);
-            rewardMoneyTopTenTask(2,0,2,companyId);
-            rewardMoneyTopTenTask(2,1,2,companyId);
-            rewardMoneyTopTenTask(3,0,2,companyId);
-            rewardMoneyTopTenTask(3,1,2,companyId);
-            rewardMoneyTopTenTask(4,0,2,companyId);
-            rewardMoneyTopTenTask(4,1,2,companyId);
+    }
 
-            rewardMoneyTradeTask(1,2,companyId);
-            rewardMoneyTradeTask(2,2,companyId);
-            rewardMoneyTradeTask(3,2,companyId);
-            rewardMoneyTradeTask(4,2,companyId);
-        }
 
-    }
 
     @Override
     public DealerAggregatedDTO dealerAggregated(Long companyId) {
@@ -1065,23 +806,13 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
         return trafficLogDTO;
     }
 
-    public void companyThisMonthOrderCount(){
-        List<OptionsVO> optionsVOS = companyService.selectAllCompanyList(null);
-        for (OptionsVO optionsVO : optionsVOS) {
-            Long companyId = optionsVO.getDictValue();
-            if (companyId == null) {
-                continue;
-            }
-            this.thisMonthOrderCount(companyId);
-            this.thisMonthRecvCount(companyId);
-        }
-    }
     @Override
-    public void thisMonthOrderCount(Long companyId) {
+    public R thisMonthOrderCount(Long companyId) {
         Long[] users=new Long[0];
         TimeUtils.TimeEntity timeEntity=TimeUtils.parseTime("5",null,null);
         timeEntity.setUserIds(users);
         timeEntity.setCompanyId(companyId);
+
         Integer cycleNum = timeEntity.getCycleNum();
         Integer beginTime = timeEntity.getBeginTime();
         List<Integer> timeList = new ArrayList<>();
@@ -1089,16 +820,30 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
             timeList.add(beginTime);
             beginTime = TimeUtils.formatTime(beginTime);
         }
-        List<JSONObject> jsonObjectList = storeOrderService.selectFsStoreOrderCounts(timeEntity.toMap());
+
+        List<JSONObject> jsonObjectList;
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            jsonObjectList = storeOrderService.selectFsStoreOrderCounts(timeEntity.toMap());
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            timeEntity.setCompanyUserIds(companyUserIdsByDataScope);
+            jsonObjectList = storeOrderService.selectFsStoreOrderCounts(timeEntity.toMap());
+        }
+
+
         List<String> dates = jsonObjectList.stream().map(jsonObject -> jsonObject.getString("type")).collect(Collectors.toList());
         List<Integer> orderCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("orderCount")).collect(Collectors.toList());
         List<Integer> payPrice = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("payPrice")).collect(Collectors.toList());
         R result = R.ok().put("dates", dates).put("orderCount", orderCount).put("payPrice", payPrice);
-        redisCache.setCacheObject(String.format(THIS_MONTH_ORDER_COUNT+":%d",companyId),result);
+        return result;
     }
 
     @Override
-    public void thisMonthRecvCount(Long companyId) {
+    public R thisMonthRecvCount(Long companyId) {
         Long[] users=new Long[0];
         TimeUtils.TimeEntity timeEntity=TimeUtils.parseTime("5",null,null);
         timeEntity.setUserIds(users);
@@ -1110,11 +855,25 @@ public class StatisticsCompanyServiceImpl implements IStatisticsCompanyService {
             timeList.add(beginTime);
             beginTime = TimeUtils.formatTime(beginTime);
         }
-        List<JSONObject> jsonObjectList = paymentService.selectFsStorePaymentCounts(timeEntity.toMap());
+
+        List<JSONObject> jsonObjectList;
+        // 获取当前用户的数据权限
+        DataScopeEnum dataScope = LoginContextManager.getDataScope();
+        // 看所有
+        if(DataScopeEnum.ALL == dataScope) {
+            jsonObjectList = paymentService.selectFsStorePaymentCounts(timeEntity.toMap());
+        } else{
+            Long currentCompanyUserId = LoginContextManager.getCurrentCompanyUserId();
+            List<Long> companyUserIdsByDataScope = companyUserService.getCompanyUserIdsByDataScope(dataScope, currentCompanyUserId);
+            timeEntity.setCompanyUserIds(companyUserIdsByDataScope);
+            jsonObjectList = paymentService.selectFsStorePaymentCounts(timeEntity.toMap());
+        }
+
+
         List<String> dates = jsonObjectList.stream().map(jsonObject -> jsonObject.getString("type")).collect(Collectors.toList());
         List<Integer> orderCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("orderCount")).collect(Collectors.toList());
         List<Float> payMoney = jsonObjectList.stream().map(jsonObject -> jsonObject.getFloatValue("payMoney")).collect(Collectors.toList());
         R result = R.ok().put("dates", dates).put("orderCount", orderCount).put("payMoney", payMoney);
-        redisCache.setCacheObject(String.format(THIS_MONTH_RECV_COUNT+":%d",companyId),result);
+        return result;
     }
 }

+ 30 - 0
fs-service/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -697,5 +697,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </select>
+    <select id="getCompanyUserIdListById" resultType="java.lang.Long">
+        SELECT DISTINCT cu.user_id
+        FROM company_user cu
+        WHERE cu.del_flag = '0'
+          AND cu.dept_id IN (
+            SELECT crd.dept_id
+            FROM company_role_dept crd
+            WHERE crd.role_id IN (
+                SELECT cur.role_id
+                FROM company_user_role cur
+                WHERE cur.user_id = #{companyUserId}
+            )
+        )
+        ORDER BY cu.user_id
+    </select>
+    <select id="getCompanyUserIdListByDeptId" resultType="java.lang.Long">
+        select user_id from company_user where dept_id = #{deptId}
+    </select>
+    <select id="getCompanyUserIdListByDeptIds" resultType="java.lang.Long">
+        SELECT user_id
+        FROM company_user
+        <where>
+            <if test="allSubDeptIds != null and allSubDeptIds.size() > 0">
+                AND dept_id IN
+                <foreach collection="allSubDeptIds" item="deptId" open="(" separator="," close=")">
+                    #{deptId}
+                </foreach>
+            </if>
+        </where>
+    </select>
 
 </mapper>

+ 3 - 0
fs-service/src/main/resources/mapper/statis/ConsumptionBalanceMapper.xml

@@ -244,6 +244,7 @@
             <if test="companyId != null">
                 AND company_id = ${companyId}
             </if>
+            <include refid="deptDataPermission"/>
         </where>
         GROUP BY company_id
         limit 10
@@ -272,6 +273,7 @@
             <if test="companyId != null">
                 AND w.company_id = ${companyId}
             </if>
+            <include refid="deptDataPermission"/>
         </where>
         GROUP BY
         w.course_id
@@ -359,6 +361,7 @@
             <if test="companyId != null">
                 and log.company_id = ${companyId}
             </if>
+            <include refid="deptDataPermissionWithAlias"/>
         </where>
         group by start_date
     </select>