Browse Source

权限设置列表显示问题修复

chenw 7 years ago
parent
commit
15c66b2816

+ 7 - 0
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/mapper/RoleResourceMapper.java

@@ -75,6 +75,13 @@ public interface RoleResourceMapper {
      */
     List<OtherPower> selectOthersPower();
 
+    /**
+     * 通过角色ID查询拥友的其他权限
+     * @param id
+     * @return
+     */
+    List<OtherPower> selectOthersPowerByRoleId(Long id);
+
     /**
      * 批量插入
      * @param roleResourceList

+ 26 - 3
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/RoleServiceImpl.java

@@ -94,6 +94,7 @@ public class RoleServiceImpl extends CommonBaseServiceImpl<RoleMapper, Role> imp
         List<Map<String, Object>> classifyList = roleResourceMapper.selectClassifyByRoleId(id);
         List<PowerInfo> powerInfoList = roleResourceMapper.selectPowerInfo();
         List<OtherPower> otherPowerList = roleResourceMapper.selectOthersPower();
+        List<OtherPower> hasOtherPowerList = roleResourceMapper.selectOthersPowerByRoleId(id);
 
         for (PowerInfo powerInfo : powerInfoList){
             PowerDTO powerDTO = new PowerDTO();
@@ -103,6 +104,7 @@ public class RoleServiceImpl extends CommonBaseServiceImpl<RoleMapper, Role> imp
             powerDTO.setModuleId(powerInfo.getModuleId());
             //赋值默认权限,在权限列表中的资源默认置为false
             setPowerValue(powerDTO, powerInfo.getClassify(), false);
+            setDefaultOtherPower(powerDTO, powerDTO.getGroupId(), id, otherPowerList);
             //赋值权限
             for (Map<String, Object> map : classifyList){
                 if (powerInfo.getGrougId().equals(map.get("group_id"))){
@@ -111,7 +113,7 @@ public class RoleServiceImpl extends CommonBaseServiceImpl<RoleMapper, Role> imp
                     setPowerValue(powerDTO, classify, true);
                 }
                 //设置其他权限
-                setOtherPower(powerDTO, powerInfo.getGrougId(), id, otherPowerList);
+                setOtherPower(powerDTO, hasOtherPowerList);
             }
             powerDTOList.add(powerDTO);
         }
@@ -164,10 +166,17 @@ public class RoleServiceImpl extends CommonBaseServiceImpl<RoleMapper, Role> imp
         return true;
     }
 
-    private void setOtherPower(PowerDTO powerDTO, Long groupId, Long roleId, List<OtherPower> otherPowerList) {
+    /**
+     * 设置其他默认权限,用于生成设置按钮
+     * @param powerDTO
+     * @param groupId
+     * @param roleId
+     * @param otherPowerList
+     */
+    private void setDefaultOtherPower(PowerDTO powerDTO, Long groupId, Long roleId, List<OtherPower> otherPowerList){
         List<OtherPower> otherPowers = new ArrayList<OtherPower>();
         for (OtherPower otherPower : otherPowerList){
-            if (groupId.equals(otherPower.getGroupId()) && roleId.equals(otherPower.getRoleId())){
+            if (groupId.equals(otherPower.getGroupId())){
                 otherPowers.add(otherPower);
             }
         }
@@ -175,6 +184,20 @@ public class RoleServiceImpl extends CommonBaseServiceImpl<RoleMapper, Role> imp
         powerDTO.setOther(otherPowerDTOList);
     }
 
+    private void setOtherPower(PowerDTO powerDTO, List<OtherPower> otherPowerList) {
+        List<OtherPowerDTO> otherPowers = powerDTO.getOther();
+        if (!CollectionUtils.isEmpty(otherPowers)) {
+            for (OtherPower otherPower : otherPowerList) {
+                for (OtherPowerDTO otherPowerDTO : otherPowers) {
+                    if (otherPowerDTO.getResourceId().equals(otherPower.getResourceId())) {
+                        otherPowerDTO.setChecked(otherPower.isChecked());
+                    }
+                }
+            }
+        }
+        powerDTO.setOther(otherPowers);
+    }
+
     private void setPowerValue(PowerDTO powerDTO, String classify , boolean status) {
         String[] array = classify.split(",");
         for(int i = 0; i < array.length; i++){

+ 6 - 2
base-servers/account/account-server/src/main/resources/mapper/RoleResourceMapper.xml

@@ -48,10 +48,14 @@
         <result column="role_id" property="roleId" jdbcType="BIGINT" />
     </resultMap>
     <select id="selectOthersPower" resultMap="OtherPowerResultMap">
-      SELECT name,id,group_id,role_id,CASE WHEN ROLE_ID IS NULL THEN false ELSE true end checked FROM AC_RESOURCE
-      LEFT JOIN ac_role_resource ON ID = RESOURCE_ID
+      SELECT name,id,group_id FROM AC_RESOURCE
       WHERE CLASSIFY='OTHER'
     </select>
+    <select id="selectOthersPowerByRoleId" resultMap="OtherPowerResultMap">
+        SELECT name,id,group_id,role_id,CASE WHEN ROLE_ID IS NULL THEN false ELSE true end checked FROM AC_RESOURCE
+        LEFT JOIN ac_role_resource ON ID = RESOURCE_ID
+        WHERE CLASSIFY='OTHER' and role_id = #{id};
+    </select>
     <insert id="batchInsert" parameterType="java.util.List">
         INSERT INTO AC_ROLE_RESOURCE(ROLE_ID, RESOURCE_ID, COMPANY_ID, APP_ID)
         VALUES