Explorar el Código

feat:销售app管理员可以看到所有数据

caoliqin hace 1 día
padre
commit
8b1f7bab84

+ 7 - 1
fs-service/src/main/java/com/fs/company/service/impl/CompanyTagUserServiceImpl.java

@@ -117,8 +117,14 @@ public class CompanyTagUserServiceImpl implements ICompanyTagUserService
                 keywords = param.getKeyword().split(",");
             }
         }
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param != null ? param.getUserId() : null);
+        if (companyUser != null && companyUser.isAdmin()){
+            companyId = companyUser.getCompanyId();
+        }
         //获取所有销售
-        List<CompanyUser> companyUsers = companyUserMapper.selectAllCompanyUserAndSelf(param != null ? param.getUserId() : null,null);
+        List<CompanyUser> companyUsers = companyUserMapper.selectAllCompanyUserAndSelf(param != null ? param.getUserId() : null, companyId);
         List<Long> userIds = Collections.emptyList();
         if(companyUsers != null && !companyUsers.isEmpty()){
             userIds = companyUsers.stream().map(CompanyUser::getUserId).collect(Collectors.toList());

+ 9 - 9
fs-service/src/main/java/com/fs/his/mapper/FsUserMapper.java

@@ -299,7 +299,7 @@ public interface FsUserMapper
     @Select("select * from fs_user where union_id=#{unionId}")
     FsUser selectFsUserByUnionId(String unionId);
 
-    List<UserListCountVO> getUserNumber(@Param("userId") Long userId);
+    List<UserListCountVO> getUserNumber(@Param("userId") Long userId, @Param("companyId") Long companyId);
 
     int getRepeatUserNumber(@Param("userId") Long userId);
 
@@ -309,9 +309,9 @@ public interface FsUserMapper
 
     UserDetailsVO getCountRedPacket(@Param("userId") Long userId, @Param("fsUserId") Long fsUserId, @Param("dateTag") String dateTag);
 
-    FsUserSummaryCountVO countUserSummary(@Param("userId") Long userId);
+    FsUserSummaryCountVO countUserSummary(@Param("userId") Long userId, @Param("companyId") Long companyId);
 
-    List<FsUserSummaryCountTagVO> countTag(@Param("userId") Long userId);
+    List<FsUserSummaryCountTagVO> countTag(@Param("userId") Long userId, @Param("companyId") Long companyId);
 
     Map<String, Long> countUserCourse(UserStatisticsCommonParam param);
 
@@ -319,21 +319,21 @@ public interface FsUserMapper
 
     Map<String, Long> countCourseDetails(UserStatisticsCommonParam param);
 
-    List<FsUserRankingVO> countUserRankingByComplete(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId") String periodId, @Param("videoId") String videoId, @Param("order") String order);
+    List<FsUserRankingVO> countUserRankingByComplete(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId")String periodId, @Param("videoId")String videoId, @Param("order")String order);
 
-    List<FsUserRankingVO> countUserRankingByRight(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId") String periodId, @Param("videoId") String videoId, @Param("order") String order);
+    List<FsUserRankingVO> countUserRankingByRight(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId")String periodId, @Param("videoId")String videoId, @Param("order")String order);
 
-    List<FsCourseRankingVO> countCourseRankingByComplete(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId") String periodId, @Param("videoId") String videoId, @Param("order") String order);
+    List<FsCourseRankingVO> countCourseRankingByComplete(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId")String periodId, @Param("videoId")String videoId, @Param("order")String order);
 
-    List<FsCourseRankingVO> countCourseRankingByRight(@Param("userId") Long userId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId") String periodId, @Param("videoId") String videoId, @Param("order") String order);
+    List<FsCourseRankingVO> countCourseRankingByRight(@Param("userId") Long userId, @Param("companyId") Long companyId, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("periodId")String periodId, @Param("videoId")String videoId, @Param("order")String order);
 
     Map<String, Object> countUserRedPacket(UserStatisticsCommonParam param);
 
     List<FsCourseAnalysisCountVO> courseAnalysisCourseCount(CourseAnalysisParam param);
 
-    CompanyUserSummaryCountVO companyUserCount(@Param("companyUserId") String companyUserId);
+    CompanyUserSummaryCountVO companyUserCount(@Param("companyUserId")String companyUserId, @Param("companyId") Long companyId);
 
-    CompanyUserSummaryCountVO newUserRedPacketCount(@Param("companyUserId") String companyUserId);
+    CompanyUserSummaryCountVO newUserRedPacketCount(@Param("companyUserId")String companyUserId, @Param("companyId") Long companyId);
 
 
     @Select("select * from fs_user where course_ma_open_id=#{openId}")

+ 55 - 9
fs-service/src/main/java/com/fs/his/service/impl/FsUserServiceImpl.java

@@ -700,7 +700,14 @@ public class FsUserServiceImpl implements IFsUserService
 
     @Override
     public UserListPageVO getUserNumber(Long userId) {
-        List<UserListCountVO> list = fsUserMapper.getUserNumber(userId);
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
+        if (companyUser != null && companyUser.isAdmin()){
+            userId = 0L;
+            companyId = companyUser.getCompanyId();
+        }
+        List<UserListCountVO> list = fsUserMapper.getUserNumber(userId, companyId);
         Map<String, Integer> map = list.stream()
                 .collect(Collectors.toMap(UserListCountVO::getStatus, UserListCountVO::getNum, (v1, v2) -> v1));
         UserListPageVO pageVO = new UserListPageVO();
@@ -744,8 +751,15 @@ public class FsUserServiceImpl implements IFsUserService
 
     @Override
     public FsUserSummaryCountVO userSummaryCount(Long userId) {
-        FsUserSummaryCountVO fsUserSummaryCountVO = fsUserMapper.countUserSummary(userId);
-        List<FsUserSummaryCountTagVO> countTagList = fsUserMapper.countTag(userId);
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
+        if (companyUser != null && companyUser.isAdmin()){
+            userId = 0L;
+            companyId = companyUser.getCompanyId();
+        }
+        FsUserSummaryCountVO fsUserSummaryCountVO = fsUserMapper.countUserSummary(userId, companyId);
+        List<FsUserSummaryCountTagVO> countTagList = fsUserMapper.countTag(userId, companyId);
         fsUserSummaryCountVO.setTagList(countTagList);
         return fsUserSummaryCountVO;
     }
@@ -759,6 +773,11 @@ public class FsUserServiceImpl implements IFsUserService
     public FsUserStatisticsVO userStatisticsDetails(UserStatisticsCommonParam param) {
         FsUserStatisticsVO userStatisticsVO = getUserStatistics(param);
 
+        // 判断是否是管理员
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getUserId());
+        if (companyUser != null && companyUser.isAdmin()){
+            param.setUserId(0L);
+        }
         //统计课程数据详情,在查询统计详情的时候需要显示
         Map<String, Long> courseDetailsMap = fsUserMapper.countCourseDetails(param);
         if(courseDetailsMap != null && courseDetailsMap.get("courseNum") != null && courseDetailsMap.get("videoNum") != null && courseDetailsMap.get("courseUserNum") != null){
@@ -772,25 +791,39 @@ public class FsUserServiceImpl implements IFsUserService
     @Override
     public List<FsUserRankingVO> userRanking(Long userId, String startTime, String endTime, String periodId, String videoId, String order, Integer type) {
         List<FsUserRankingVO> listVO = Collections.emptyList();
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
+        if (companyUser != null && companyUser.isAdmin()){
+            userId = 0L;
+            companyId = companyUser.getCompanyId();
+        }
         if(type == 1){
             //按完播率
-            listVO = fsUserMapper.countUserRankingByComplete(userId, startTime, endTime, periodId, videoId, order);
+            listVO = fsUserMapper.countUserRankingByComplete(userId, companyId, startTime, endTime, periodId, videoId, order);
         }
         if(type == 2){
             //按正确率
-            listVO = fsUserMapper.countUserRankingByRight(userId, startTime, endTime, periodId, videoId, order);
+            listVO = fsUserMapper.countUserRankingByRight(userId, companyId, startTime, endTime, periodId, videoId, order);
         }
         return listVO;
     }
 
     @Override
     public List<FsCourseRankingVO> courseRanking(Long userId, String startTime, String endTime, String periodId, String videoId, String order, Integer type) {
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
+        if (companyUser != null && companyUser.isAdmin()){
+            userId = 0L;
+            companyId = companyUser.getCompanyId();
+        }
         List<FsCourseRankingVO> list = Collections.emptyList();
         if(type == 1){
-            list = fsUserMapper.countCourseRankingByComplete(userId, startTime, endTime, periodId, videoId, order);
+            list = fsUserMapper.countCourseRankingByComplete(userId, companyId, startTime, endTime, periodId, videoId, order);
         }
         if(type == 2){
-            list = fsUserMapper.countCourseRankingByRight(userId, startTime, endTime, periodId, videoId, order);
+            list = fsUserMapper.countCourseRankingByRight(userId, companyId, startTime, endTime, periodId, videoId, order);
         }
 
         return list;
@@ -862,8 +895,15 @@ public class FsUserServiceImpl implements IFsUserService
 
     @Override
     public CompanyUserSummaryCountVO companyUserSummaryCount(Long userId, String companyUserId) {
-        CompanyUserSummaryCountVO companyUserCount = fsUserMapper.companyUserCount(companyUserId);
-        CompanyUserSummaryCountVO newUserRedPacketCount = fsUserMapper.newUserRedPacketCount(companyUserId);
+        // 判断是否是管理员
+        Long companyId = null;
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(userId);
+        if (companyUser != null && companyUser.isAdmin()){
+            companyUserId = String.valueOf(0);
+            companyId = companyUser.getCompanyId();
+        }
+        CompanyUserSummaryCountVO companyUserCount = fsUserMapper.companyUserCount(companyUserId, companyId);
+        CompanyUserSummaryCountVO newUserRedPacketCount = fsUserMapper.newUserRedPacketCount(companyUserId, companyId);
         CompanyUserSummaryCountVO vo = new CompanyUserSummaryCountVO();
         BeanUtils.copyProperties(companyUserCount, vo);
         vo.setUserRedPacketNum(newUserRedPacketCount.getUserRedPacketNum());
@@ -948,6 +988,12 @@ public class FsUserServiceImpl implements IFsUserService
     private FsUserStatisticsVO getUserStatistics(UserStatisticsCommonParam param) {
         FsUserStatisticsVO fsUserStatisticsVO = new FsUserStatisticsVO();
 
+        // 判断是否是管理员
+        CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getUserId());
+        if (companyUser != null && companyUser.isAdmin()){
+            param.setUserId(0L);
+            param.setCompanyId(companyUser.getCompanyId());
+        }
         // 获取课程统计
         Map<String, Long> couserMap = fsUserMapper.countUserCourse(param);
         if (couserMap != null) {

+ 397 - 263
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -124,8 +124,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
         <where>
-            <if test="companyUserId != null and companyUserId !='' ">
-                AND company_user.user_id = #{companyUserId}
+            <if test="companyUserId != null and companyUserId != 0 ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId == 0 ">
+                and fs_user.company_id = #{companyId}
             </if>
             <if test="periodId != null and periodId != ''">
                 AND flog.period_id =  #{periodId}
@@ -163,8 +166,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
         <where>
-            <if test="companyUserId != null and companyUserId !='' ">
-                AND company_user.user_id = #{companyUserId}
+            <if test="companyUserId != null and companyUserId != 0 ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId == 0 ">
+                and fs_user.company_id = #{companyId}
             </if>
             <if test="periodId != null and periodId != ''">
                 AND fs_course_answer_logs.period_id =  #{periodId}
@@ -579,9 +585,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_user
         LEFT JOIN fs_user_company_user ON fs_user_company_user.user_id = fs_user.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user_company_user.company_user_id
-        WHERE
-        (company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        and fs_user.is_del = 0
+        WHERE fs_user.is_del = 0
+        <if test="userId != null and userId != 0 ">
+            and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+        </if>
+        <if test="companyId != null ">
+            and fs_user.company_id = #{companyId}
+        </if>
         GROUP BY
         fs_user.`status`
     </select>
@@ -601,8 +611,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="getCountWatchCourse" resultType="com.fs.store.vo.h5.UserDetailsVO">
         SELECT
-        ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
-        ifnull( watch_times, 0 ) AS watchTimes,
+        <if test="dateTag == null or dateTag =='' ">
+            ifnull( sum(complete_watch_count), 0 ) AS completeWatchCount ,
+            ifnull( sum(watch_times), 0 ) AS watchTimes,
+        </if>
+        <if test="dateTag != null and dateTag !='' ">
+            ifnull( complete_watch_count, 0 ) AS completeWatchCount ,
+            ifnull( watch_times, 0 ) AS watchTimes,
+        </if>
         fs_user.user_id
         FROM
         fs_user_course_count
@@ -625,11 +641,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                     </when>
                 </choose>
             </if>
+            and fs_user.user_id = #{fsUserId}
         </where>
         GROUP BY
         fs_user.user_id
-        HAVING
-        fs_user.user_id = #{fsUserId}
     </select>
 
     <select id="getCountAnswer" resultType="com.fs.store.vo.h5.UserDetailsVO">
@@ -641,28 +656,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_answer_logs
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        (company_user.user_id = #{userId} or company_user.parent_id = #{userId} )
-        <if test="dateTag != null and dateTag !='' ">
-            <choose>
-                <when test = "dateTag == '今天'">
-                    and to_days(fs_course_answer_logs.create_time) = to_days(now())
-                </when>
-                <when test = "dateTag == '昨天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
-                </when>
-                <when test = "dateTag == '前天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
-                </when>
-                <when test = "dateTag == '近七天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
-                </when>
-            </choose>
-        </if>
+        <where>
+
+            <if test="dateTag != null and dateTag !='' ">
+                <choose>
+                    <when test = "dateTag == '今天'">
+                        and to_days(fs_course_answer_logs.create_time) = to_days(now())
+                    </when>
+                    <when test = "dateTag == '昨天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
+                    </when>
+                    <when test = "dateTag == '前天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
+                    </when>
+                    <when test = "dateTag == '近七天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
+                    </when>
+                </choose>
+            </if>
+            and fs_user.user_id = #{fsUserId}
+        </where>
         GROUP BY
         fs_user.user_id
-        HAVING
-        fs_user.user_id = #{fsUserId}
         ) AS answerTime,
         (
         SELECT
@@ -671,29 +686,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_answer_logs
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        (company_user.user_id = #{userId} or company_user.parent_id = #{userId} )
-        AND fs_course_answer_logs.is_right = 1
-        <if test="dateTag != null and dateTag !='' ">
-            <choose>
-                <when test = "dateTag == '今天'">
-                    and to_days(fs_course_answer_logs.create_time) = to_days(now())
-                </when>
-                <when test = "dateTag == '昨天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
-                </when>
-                <when test = "dateTag == '前天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
-                </when>
-                <when test = "dateTag == '近七天'">
-                    and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
-                </when>
-            </choose>
-        </if>
+        <where>
+            fs_course_answer_logs.is_right = 1
+            <if test="dateTag != null and dateTag !='' ">
+                <choose>
+                    <when test = "dateTag == '今天'">
+                        and to_days(fs_course_answer_logs.create_time) = to_days(now())
+                    </when>
+                    <when test = "dateTag == '昨天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_answer_logs.create_time &lt; CURDATE()
+                    </when>
+                    <when test = "dateTag == '前天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_answer_logs.create_time &lt; CURDATE() - INTERVAL 1 DAY
+                    </when>
+                    <when test = "dateTag == '近七天'">
+                        and fs_course_answer_logs.create_time &gt;= CURDATE() - INTERVAL 7 DAY
+                    </when>
+                </choose>
+            </if>
+            and fs_user.user_id = #{fsUserId}
+        </where>
         GROUP BY
         fs_user.user_id
-        HAVING
-        fs_user.user_id = #{fsUserId}
         ) AS answerRightTime;
     </select>
 
@@ -706,44 +720,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_red_packet_log
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_red_packet_log.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        (company_user.user_id = #{userId} or company_user.parent_id = #{userId} )
-        and fs_course_red_packet_log.status = 1
-        <if test="dateTag != null and dateTag !='' ">
-            <choose>
-                <when test = "dateTag == '今天'">
-                    and to_days(fs_course_red_packet_log.create_time) = to_days(now())
-                </when>
-                <when test = "dateTag == '昨天'">
-                    and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
-                </when>
-                <when test = "dateTag == '前天'">
-                    and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE() - INTERVAL 1 DAY
-                </when>
-                <when test = "dateTag == '近七天'">
-                    and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
-                </when>
-            </choose>
-        </if>
+        <where>
+            fs_course_red_packet_log.status = 1
+            <if test="dateTag != null and dateTag !='' ">
+                <choose>
+                    <when test = "dateTag == '今天'">
+                        and to_days(fs_course_red_packet_log.create_time) = to_days(now())
+                    </when>
+                    <when test = "dateTag == '昨天'">
+                        and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 1 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE()
+                    </when>
+                    <when test = "dateTag == '前天'">
+                        and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 2 DAY AND fs_course_red_packet_log.create_time &lt; CURDATE() - INTERVAL 1 DAY
+                    </when>
+                    <when test = "dateTag == '近七天'">
+                        and fs_course_red_packet_log.create_time &gt;= CURDATE() - INTERVAL 7 DAY
+                    </when>
+                </choose>
+            </if>
+            and  fs_user.user_id = #{fsUserId}
+        </where>
         GROUP BY
         fs_user.user_id
-        HAVING
-        fs_user.user_id = #{fsUserId}
     </select>
 
     <select id="countUserSummary" resultType="com.fs.store.vo.h5.FsUserSummaryCountVO">
         SELECT (SELECT count(fs_user.user_id)
         FROM fs_user
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-        WHERE (
-        company_user.user_id = #{userId}
-        OR company_user.parent_id = #{userId}
-        ) and fs_user.is_del = 0) as userTotal,
+        WHERE fs_user.is_del = 0
+        <if test="userId != null and userId != 0 ">
+            and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+        </if>
+        <if test="companyId != null ">
+            and fs_user.company_id = #{companyId}
+        </if>
+        ) as userTotal,
         (SELECT count(fs_user.user_id)
         FROM fs_user
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-        WHERE (company_user.user_id = #{userId} OR company_user.parent_id = #{userId})
-        and fs_user.is_del = 0
+        WHERE fs_user.is_del = 0
+        <if test="userId != null and userId != 0 ">
+            and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+        </if>
+        <if test="companyId != null ">
+            and fs_user.company_id = #{companyId}
+        </if>
         AND to_days(fs_user.create_time) = to_days(now())) as todayNewUser
     </select>
 
@@ -756,7 +778,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = company_tag_user.user_id
         LEFT JOIN company_tag ON FIND_IN_SET( company_tag.tag_id, company_tag_user.tag_ids ) > 0
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-        where (company_user.user_id = #{userId} or company_user.parent_id = #{userId} ) and company_tag.tag_id is not null
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="companyId != null ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            and company_tag.tag_id is not null
+        </where>
         GROUP BY
         company_tag.tag_id
     </select>
@@ -771,25 +801,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
         LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
-        WHERE
-        ( company_user.user_id = #{userId}  OR company_user.parent_id = #{userId}  )
-        <if test="startTime != null and startTime !='' ">
-            and fcc.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            and fcc.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fcpd.period_id = #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fcpd.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
-
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                and fcc.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                and fcc.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fcpd.period_id = #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fcpd.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) as courseWatchNum,
         (
         SELECT
@@ -799,25 +834,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
         LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET(fcpd.period_id, fcc.course_ids) > 0
-        WHERE
-        ( company_user.user_id = #{userId}  OR company_user.parent_id = #{userId}  )
-        AND fcc.complete_watch_count > 0
-        <if test="startTime != null and startTime !='' ">
-            and fcc.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            and fcc.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fcpd.period_id = #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fcpd.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            AND fcc.complete_watch_count > 0
+            <if test="startTime != null and startTime !='' ">
+                and fcc.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                and fcc.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fcpd.period_id = #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fcpd.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) as courseCompleteNum
     </select>
 
@@ -830,24 +871,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_answer_logs
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        <if test="startTime != null and startTime !='' ">
-            AND fs_course_answer_logs.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fs_course_answer_logs.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fs_course_answer_logs.period_id = #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fs_course_answer_logs.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND fs_course_answer_logs.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fs_course_answer_logs.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fs_course_answer_logs.period_id = #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fs_course_answer_logs.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) AS answerNum,
         (
         SELECT
@@ -856,25 +903,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_answer_logs
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        AND fs_course_answer_logs.is_right = 1
-        <if test="startTime != null and startTime !='' ">
-            AND fs_course_answer_logs.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fs_course_answer_logs.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fs_course_answer_logs.period_id = #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fs_course_answer_logs.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            AND fs_course_answer_logs.is_right = 1
+            <if test="startTime != null and startTime !='' ">
+                AND fs_course_answer_logs.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fs_course_answer_logs.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fs_course_answer_logs.period_id = #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fs_course_answer_logs.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) AS answerRightNum
     </select>
 
@@ -888,6 +941,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         WHERE 1=1
         AND FIND_IN_SET(#{companyId}, fpd.company_id)
+        <if test="userId != null and userId != 0 ">
+            AND fs_user.company_user_id = #{userId}
+        </if>
+        <if test="userId != null and userId == 0 ">
+            and fs_user.company_id = #{companyId}
+        </if>
         <if test="periodId != null and periodId != ''">
             AND fcpd.period_id =  #{periodId}
         </if>
@@ -904,6 +963,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         WHERE 1=1
         AND FIND_IN_SET(#{companyId}, fpd.company_id)
+        <if test="userId != null and userId != 0 ">
+            AND fs_user.company_user_id = #{userId}
+        </if>
+        <if test="userId != null and userId == 0 ">
+            and fs_user.company_id = #{companyId}
+        </if>
         <if test="periodId != null and periodId != ''">
             AND fcpd.period_id =  #{periodId}
         </if>
@@ -929,6 +994,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="companyUserId != null and companyUserId != ''">
             AND fs_user.company_user_id = #{companyUserId}
         </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                AND fs_user.company_user_id = #{userId}
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+        </where>
         ) as courseUserNum
     </select>
 
@@ -943,20 +1016,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
         LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        <if test="startTime != null and startTime !='' ">
-            AND fcc.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fcc.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fcpd.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fcpd.video_id = #{videoId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                AND  ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND fcc.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fcc.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fcpd.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fcpd.video_id = #{videoId}
+            </if>
+        </where>
         group by fcc.user_id
         <choose>
             <when test="order != null and order == 'asc'">
@@ -983,20 +1062,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_answer_logs
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        <if test="startTime != null and startTime !='' ">
-            AND fs_course_answer_logs.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fs_course_answer_logs.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fs_course_answer_logs.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fs_course_answer_logs.video_id = #{videoId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                AND  ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND fs_course_answer_logs.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fs_course_answer_logs.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fs_course_answer_logs.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fs_course_answer_logs.video_id = #{videoId}
+            </if>
+        </where>
         group by fs_user.user_id
         <choose>
             <when test="order != null and order == 'asc'">
@@ -1028,20 +1113,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
         LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
         LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fcpd.video_id
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        <if test="startTime != null and startTime !='' ">
-            AND fcc.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fcc.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fcpd.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fcpd.video_id = #{videoId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND fcc.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fcc.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fcpd.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fcpd.video_id = #{videoId}
+            </if>
+        </where>
         GROUP BY
         fcpd.video_id
         <choose>
@@ -1074,20 +1165,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fs_course_answer_logs.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
         LEFT JOIN fs_user_course_video fcv ON fcv.video_id = fs_course_answer_logs.video_id
-        WHERE
-        ( company_user.user_id = #{userId} OR company_user.parent_id = #{userId} )
-        <if test="startTime != null and startTime !='' ">
-            AND fs_course_answer_logs.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND fs_course_answer_logs.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND fs_course_answer_logs.period_id = #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fs_course_answer_logs.video_id = #{videoId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                AND ( fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND fs_course_answer_logs.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND fs_course_answer_logs.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fs_course_answer_logs.period_id = #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fs_course_answer_logs.video_id = #{videoId}
+            </if>
+        </where>
         GROUP BY
         fs_course_answer_logs.video_id
         <choose>
@@ -1113,24 +1210,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_red_packet_log flog
         LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        ( company_user.user_id = #{userId}  OR company_user.parent_id = #{userId}  )
-        <if test="startTime != null and startTime !='' ">
-            AND flog.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND flog.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND flog.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND flog.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND flog.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND flog.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND flog.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND flog.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) AS redPacketNum,
         (
         SELECT
@@ -1139,24 +1242,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         fs_course_red_packet_log flog
         LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
         LEFT JOIN company_user ON company_user.user_id = fs_user.company_user_id
-        WHERE
-        ( company_user.user_id = #{userId}  OR company_user.parent_id = #{userId}  )
-        <if test="startTime != null and startTime !='' ">
-            AND flog.create_time &gt;= #{startTime}
-        </if>
-        <if test="endTime != null and endTime != ''">
-            AND flog.create_time &lt;= #{endTime}
-        </if>
-        <if test="periodId != null and periodId != ''">
-            AND flog.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND flog.video_id = #{videoId}
-        </if>
-        -- 单独通过销售id查询
-        <if test="companyUserId != null and companyUserId != ''">
-            AND company_user.user_id = #{companyUserId}
-        </if>
+        <where>
+            <if test="userId != null and userId != 0 ">
+                and (fs_user.company_user_id = #{userId} OR company_user.parent_id = #{userId} )
+            </if>
+            <if test="userId != null and userId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="startTime != null and startTime !='' ">
+                AND flog.create_time &gt;= #{startTime}
+            </if>
+            <if test="endTime != null and endTime != ''">
+                AND flog.create_time &lt;= #{endTime}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND flog.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND flog.video_id = #{videoId}
+            </if>
+            -- 单独通过销售id查询
+            <if test="companyUserId != null and companyUserId != ''">
+                AND company_user.user_id = #{companyUserId}
+            </if>
+        </where>
         ) AS redPacketAmount
     </select>
 
@@ -1178,14 +1287,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         LEFT JOIN fs_user ON fs_user.user_id = fcc.user_id
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
         LEFT JOIN fs_user_course_period_days fcpd ON FIND_IN_SET( fcpd.period_id, fcc.course_ids ) > 0
-        WHERE
-        company_user.user_id = #{companyUserId}
-        <if test="periodId != null and periodId != ''">
-            AND fcpd.period_id =  #{periodId}
-        </if>
-        <if test="videoId != null and videoId != ''">
-            AND fcpd.video_id = #{videoId}
-        </if>
+        <where>
+            <if test="companyUserId != null and companyUserId != 0 ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId == 0 ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            <if test="periodId != null and periodId != ''">
+                AND fcpd.period_id =  #{periodId}
+            </if>
+            <if test="videoId != null and videoId != ''">
+                AND fcpd.video_id = #{videoId}
+            </if>
+        </where>
         GROUP BY
         fcpd.video_id
     </select>
@@ -1194,7 +1309,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         SELECT
         (
         SELECT count( fs_user.user_id ) FROM fs_user LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-        WHERE company_user.user_id = #{companyUserId}
+        <where>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
+                and fs_user.company_id = #{companyId}
+            </if>
+        </where>
         ) AS userTotal,
         (
         SELECT
@@ -1202,11 +1324,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
         fs_user
         LEFT JOIN company_user ON fs_user.company_user_id = company_user.user_id
-        WHERE
-        company_user.user_id = #{companyUserId}
-        and fs_user.is_del = 0
-        AND to_days( fs_user.create_time ) = to_days(
-        now())
+        <where>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
+                and fs_user.company_id = #{companyId}
+            </if>
+            and fs_user.is_del = 0
+            AND to_days( fs_user.create_time ) = to_days(
+            now())
+        </where>
         ) AS todayNewUser
     </select>
 
@@ -1217,7 +1345,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         FROM
         fs_course_red_packet_log flog
         LEFT JOIN fs_user ON fs_user.user_id = flog.user_id
-        WHERE
-        fs_user.company_user_id = #{companyUserId}
+        <where>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId != '0' ">
+                AND fs_user.company_user_id = #{companyUserId}
+            </if>
+            <if test="companyUserId != null and companyUserId != '' and companyUserId == '0' ">
+                and fs_user.company_id = #{companyId}
+            </if>
+        </where>
     </select>
 </mapper>