he2802 3 роки тому
батько
коміт
82dae19dae

+ 6 - 1
zhongzheng-common/src/main/java/com/zhongzheng/common/annotation/DataScope.java

@@ -8,7 +8,7 @@ import java.lang.annotation.Target;
 
 /**
  * 数据权限过滤注解
- * 
+ *
  * @author zhongzheng
  */
 @Target(ElementType.METHOD)
@@ -25,4 +25,9 @@ public @interface DataScope
      * 用户表的别名
      */
     public String userAlias() default "";
+
+    /**
+     * 业务层次表的别名
+     */
+    public String businessAlias() default "";
 }

+ 13 - 2
zhongzheng-framework/src/main/java/com/zhongzheng/framework/aspectj/DataScopeAspect.java

@@ -54,6 +54,11 @@ public class DataScopeAspect
      */
     public static final String DATA_SCOPE_SELF = "5";
 
+    /**
+     * 业务层次数据权限
+     */
+    public static final String DATA_SCOPE_BUSINESS = "6";
+
     /**
      * 数据权限过滤关键字
      */
@@ -88,7 +93,7 @@ public class DataScopeAspect
             if (Validator.isNotNull(currentUser) && !currentUser.isAdmin())
             {
                 dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
-                        controllerDataScope.userAlias());
+                        controllerDataScope.userAlias(),controllerDataScope.businessAlias());
             }
         }
     }
@@ -100,7 +105,7 @@ public class DataScopeAspect
      * @param user 用户
      * @param userAlias 别名
      */
-    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
+    public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String businessAlias)
     {
         StringBuilder sqlString = new StringBuilder();
 
@@ -140,6 +145,12 @@ public class DataScopeAspect
                     sqlString.append(" OR 1=0 ");
                 }
             }
+            else if (DATA_SCOPE_BUSINESS.equals(dataScope))
+            {
+                sqlString.append(StrUtil.format(
+                        " OR {}.id IN ( SELECT business_id FROM sys_role_business WHERE role_id = {} ) ", businessAlias,
+                        role.getRoleId()));
+            }
         }
 
         if (StrUtil.isNotBlank(sqlString.toString()))

+ 2 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/base/service/impl/UserProfileServiceImpl.java

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.fasterxml.jackson.databind.exc.InvalidFormatException;
 import com.openhtmltopdf.swing.Java2DRenderer;
 import com.openhtmltopdf.util.FSImageWriter;
+import com.zhongzheng.common.annotation.DataScope;
 import com.zhongzheng.common.core.domain.model.LoginUser;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.SecurityUtils;
@@ -122,9 +123,9 @@ public class UserProfileServiceImpl extends ServiceImpl<UserProfileMapper, UserP
         return userProfileVo;
     }
 
+    @DataScope(businessAlias = "cb")
     @Override
     public List<UserProfileVo> queryList(UserProfileQueryBo bo) {
-
         return baseMapper.selectUserProfile(bo);
     }
 

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserSubscribeServiceImpl.java

@@ -218,7 +218,7 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
             throw new IllegalArgumentException("当前选择的考试时间已过期,请重新预约,选择未过期考试时间");
         }
         ExamApplyQueryBo queryTimeBo = new ExamApplyQueryBo();
-        queryTimeBo.setApplySiteId(bo.getApplyId());
+        queryTimeBo.setApplyId(bo.getApplyId());
         queryTimeBo.setStartTime(bo.getApplySiteStartTime().replace("-", ":"));
         queryTimeBo.setEndTime(bo.getApplySiteEndTime().replace("-", ":"));
         queryTimeBo.setExamTime(time);

+ 4 - 1
zhongzheng-system/src/main/resources/mapper/modules/base/UserProfileMapper.xml

@@ -59,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         (SELECT cet.business_name FROM goods g LEFT JOIN course_business cet on g.business_id = cet.id where up.goods_id = g.goods_id) as business_name
         FROM
         user_profile up
+        LEFT JOIN goods g ON  up.goods_id = g.goods_id LEFT JOIN course_business cb on g.business_id = cb.id
         where 1=1
         and up.current_status = 1
         <if test="status != null and status.size()!=0 ">
@@ -83,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             AND (SELECT cet.id FROM goods g LEFT JOIN course_education_type cet on g.education_type_id = cet.id where up.goods_id = g.goods_id) =#{educationTypeId}
         </if>
         <if test="businessId != null and businessId !='' ">
-            AND (SELECT cet.id FROM goods g LEFT JOIN course_business cet on g.business_id = cet.id where up.goods_id = g.goods_id) =#{businessId}
+            AND cb.id =#{businessId}
         </if>
         <if test="schoolId != null and schoolId !='' ">
             AND (SELECT g.school_id FROM goods g  where up.goods_id = g.goods_id)  =#{schoolId}
@@ -97,6 +98,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="realname != null and realname !='' ">
             AND (SELECT count(1) FROM `user` u where u.user_id = up.user_id and u.realname like concat('%', #{realname}, '%') )> 0
         </if>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
         order by up.create_time desc
     </select>
 

+ 11 - 1
zhongzheng-system/src/main/resources/mapper/modules/exam/ExamApplyMapper.xml

@@ -415,6 +415,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="siteTimeJson" parameterType="com.zhongzheng.modules.exam.bo.ExamApplyQueryBo" resultType="String">
-        SELECT site_time FROM exam_apply_site_time  where apply_site_id = #{applySiteId} and  exam_time = #{examTime}
+        SELECT
+            site_time
+        FROM
+            exam_apply_site_time e1
+                LEFT JOIN exam_apply_site ea ON e1.apply_site_id = ea.id
+                LEFT JOIN exam_site es ON ea.site_id = es.site_id
+        WHERE
+            e1.apply_id = #{applyId}
+          AND e1.exam_time = #{examTime}
+          AND es.site_address = #{applySiteAddress}
+
     </select>
 </mapper>