Browse Source

角色增加机构字段,并在查询时对此字段进行过滤

hym 4 years ago
parent
commit
f99dbf9d4a

+ 4 - 1
user_auth/src/main/java/com/huaxu/service/impl/UserServiceImpl.java

@@ -275,7 +275,10 @@ public class UserServiceImpl implements UserService {
     }
 
     private void getDataPermission(int permissionType,User user, List<ProgramItem> programItemList){
-
+        ProgramItem defaultProgramItem=new ProgramItem();
+        defaultProgramItem.setOrgCompanyId(-999);
+        defaultProgramItem.setOrgDeparmtmentId(-999);
+        programItemList.add(defaultProgramItem);
         if(permissionType==1){
             ProgramItem programItem=new ProgramItem();
             programItem.setOrgId(user.getCompanyOrgId());

+ 7 - 1
user_center/src/main/java/com/huaxu/entity/Role.java

@@ -1,5 +1,6 @@
 package com.huaxu.entity;
 
+import com.huaxu.model.ProgramItem;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -75,5 +76,10 @@ public class Role implements Serializable {
     private String updateBy;
     @ApiModelProperty(value = "菜单IDs")
     private List<Long> menuIds;
-
+    /**
+     * 机构id
+     */
+    @ApiModelProperty(value = "机构id")
+    private Integer orgId;
+    private List<ProgramItem>items;
 }

+ 7 - 0
user_center/src/main/java/com/huaxu/service/impl/RoleServiceImpl.java

@@ -73,6 +73,7 @@ public class RoleServiceImpl implements RoleService {
 
         LoginUser currentUser = UserUtil.getCurrentUser();
         role.setTenantId(currentUser.getTenantId());
+        role.setItems(currentUser.getProgramItemList());
         return this.roleMapper.selectList(role);
     }
 
@@ -88,6 +89,11 @@ public class RoleServiceImpl implements RoleService {
 
         Role role = roleRequestDto.getRole();
         LoginUser currentUser = UserUtil.getCurrentUser();
+        if(currentUser.getDepartmentId()!=null){
+            role.setOrgId(currentUser.getDepartmentId());
+        }else {
+            role.setOrgId(currentUser.getCompanyId());
+        }
         role.setTenantId(currentUser.getTenantId());
         role.setCreateBy(currentUser.getUsername());
         role.setDateCreate(new Date());
@@ -207,6 +213,7 @@ public class RoleServiceImpl implements RoleService {
     public IPage<RoleDto> selectPage(Role role, IPage<RoleDto> page) {
         LoginUser currentUser = UserUtil.getCurrentUser();
         role.setTenantId(currentUser.getTenantId());
+        role.setItems(currentUser.getProgramItemList());
         return this.roleMapper.selectPage(page, role);
     }
 

+ 44 - 4
user_center/src/main/resources/mapper/RoleMapper.xml

@@ -15,6 +15,7 @@
         <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
         <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
         <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
+        <result property="orgId" column="ORG_ID" jdbcType="VARCHAR"/>
     </resultMap>
     <resultMap type="com.huaxu.dto.RoleDto" id="RoleDtoMap">
         <result property="id" column="ID" jdbcType="INTEGER"/>
@@ -51,7 +52,26 @@
         <include refid="Base_Column_List"/>
         from uims_role
         <where>
-            and status!=0
+            and status =1
+            <if test="items != null">
+                and (org_id in
+                <foreach item="item" index="index" collection="items" open="(" separator="," close=")">
+                    <if test="item.orgCompanyId!= null">
+
+                        #{item.orgCompanyId}
+                    </if>
+
+                </foreach>
+                or org_id in
+                <foreach item="item" index="index" collection="items" open="(" separator="," close=")">
+                    <if test="item.orgDeparmtmentId!= null">
+
+                        #{item.orgDeparmtmentId}
+                    </if>
+
+                </foreach>
+                )
+            </if>
             <if test="id != null">
                 and ID = #{id}
             </if>
@@ -93,8 +113,8 @@
 
     <!-- 新增所有列 -->
     <insert id="insert" keyProperty="id" useGeneratedKeys="true">
-        insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
-        values ( #{id}, #{tenantId}, #{roleName}, #{description}, #{roleState}, #{permissionType}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
+        insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY,ORG_ID)
+        values ( #{id}, #{tenantId}, #{roleName}, #{description}, #{roleState}, #{permissionType}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy},#{orgId})
     </insert>
 
     <!-- 批量新增 -->
@@ -173,7 +193,27 @@
        group by b.ROLE_ID ) b
         ON a.id=b.ROLE_ID
         <where>
-            and status!=0
+            and status =1
+            <if test="role.items != null">
+                and (org_id in
+                <foreach item="item" index="index" collection="role.items" open="(" separator="," close=")">
+                    <if test="item.orgCompanyId!= null">
+
+                        #{item.orgCompanyId}
+                    </if>
+
+                </foreach>
+                or org_id in
+                <foreach item="item" index="index" collection="role.items" open="(" separator="," close=")">
+                    <if test="item.orgDeparmtmentId!= null">
+
+                        #{item.orgDeparmtmentId}
+                    </if>
+
+                </foreach>
+                )
+            </if>
+
             <if test="role.id != null">
                 and ID = #{role.id}
             </if>