Kaynağa Gözat

user menu auth modify....

shjung 3 yıl önce
ebeveyn
işleme
28762a3fbc

+ 24 - 12
src/main/java/com/its/op/model/dto/database/GropMenuAthrDto.java

@@ -15,31 +15,43 @@ public class GropMenuAthrDto implements Serializable {
     @Getter
     public static class GropMenuAthrInfo {
         private final String GROP_ID;             //	N	VARCHAR2(30)	N			그룹ID
+        private final String GROP_NM;
+        private final String OPERSYST_ID;       //	N	VARCHAR2(30)	Y			운영시스템ID
+        private final String OPERSYST_NM;
         private final String OPERSYST_MENU_ID;    //	N	VARCHAR2(30)	N			운영시스템메뉴ID
-        private String ATHR_YN;             //	N	CHAR(1)	        Y	'N'		권한 여부
+        private final String OPERSYST_MENU_NM;
 
+        private String ATHR_YN;             //	N	CHAR(1)	        Y	'N'		권한 여부
         private String ATHR_YN_DESC;
-        private final String GROP_NM;
-        private final String MENU_NAME;
 
+        // 메뉴권한 변경할 때 사용하는 생성자
         public GropMenuAthrInfo(GropMenuAthr entity) {
-            this.GROP_ID   = entity.getGROP_ID();
-            this.OPERSYST_MENU_ID   = entity.getOPERSYST_MENU_ID();
+            this.GROP_ID = entity.getGROP_ID();
+            this.GROP_NM = entity.getUserGrop().getGROP_NM();
+
+            this.OPERSYST_ID = entity.getOperMenu().getOPER_SYST_ID();
+            this.OPERSYST_NM = entity.getOperMenu().getOPER_SYST_NM();
+
+            this.OPERSYST_MENU_ID = entity.getOPERSYST_MENU_ID();
+            this.OPERSYST_MENU_NM = entity.getOperMenu().getMENU_NAME();
             this.ATHR_YN = entity.getATHR_YN();
 
             this.ATHR_YN_DESC = this.ATHR_YN.equals("Y") ? "[Y] 권한있음" : "[N] 권한없음";
-            this.GROP_NM = entity.getUserGrop().getGROP_NM();
-            this.MENU_NAME = entity.getOperMenu().getMENU_NAME();
         }
 
+        // 메뉴권한 조회할 때 사용하는 생성자
         public GropMenuAthrInfo(UserGropInfr userGrop, OperSystMenu systMenu) {
-            this.GROP_ID   = userGrop.getGROP_ID();
-            this.OPERSYST_MENU_ID   = systMenu.getOPERSYST_MENU_ID();
-            this.ATHR_YN = "Y";
+            this.GROP_ID = userGrop.getGROP_ID();
+            this.GROP_NM = userGrop.getGROP_NM();
+
+            this.OPERSYST_ID = systMenu.getOPER_SYST_ID();
+            this.OPERSYST_NM = systMenu.getOPER_SYST_NM();
 
+            this.OPERSYST_MENU_ID = systMenu.getOPERSYST_MENU_ID();
+            this.OPERSYST_MENU_NM = systMenu.getMENU_NAME();
+
+            this.ATHR_YN = "Y";
             this.ATHR_YN_DESC = "[Y] 권한있음";
-            this.GROP_NM = userGrop.getGROP_NM();
-            this.MENU_NAME = systMenu.getMENU_NAME();
         }
 
         public void updateMenuAuth(GropMenuAthr entity) {

+ 3 - 4
src/main/java/com/its/op/model/entity/database/OperSystMenu.java

@@ -8,10 +8,7 @@ import org.hibernate.annotations.ColumnDefault;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 @DynamicInsert
 @DynamicUpdate
@@ -38,4 +35,6 @@ public class OperSystMenu {
     @ColumnDefault(value = "N")
     private String  DEL_YN;             //	N	CHAR(1)	        Y	'N'		삭제 여부
 
+    @Transient
+    private String  OPER_SYST_NM;
 }

+ 32 - 10
src/main/java/com/its/op/service/database/GropMenuAthrService.java

@@ -33,23 +33,45 @@ public class GropMenuAthrService {
             List<UserGropInfr> userGrops = this.userGropRepo.findAll();
             List<OperSystMenu> systMenus = this.systMenuRepo.findAll();
             List<GropMenuAthr> menuAuths = this.menuAuthRepo.findAll();
+
+            // 메뉴 중에 최상위 메뉴 선택
+            HashMap<String, String> systMenuMap = new HashMap<>();
+            for (OperSystMenu systMenu : systMenus) {
+                if (systMenu.getDEL_YN().equals("N") & systMenu.getMENU_LEVL() == 1) {
+                    // 레벨이 1 인 것이 최상위 메뉴이다, OPERSYST_MENU_ID, OPER_SYST_ID 는 NULL 로 들어가 있다.
+                    systMenuMap.put(systMenu.getOPERSYST_MENU_ID(), systMenu.getMENU_NAME());
+                }
+            }
+
+            // 등록되어 있는 권한 메모리 저장
             HashMap<String, GropMenuAthr> authMap = new HashMap<>();
             for (GropMenuAthr menuAthr : menuAuths) {
                 authMap.put(menuAthr.getGROP_ID() + "*" + menuAthr.getOPERSYST_MENU_ID(), menuAthr);
             }
 
+            // 권한별로 모든 메뉴 생성
             for (UserGropInfr userGrop : userGrops) {
-                if (userGrop.getDEL_YN().equals("N")) {
-                    for (OperSystMenu systMenu : systMenus) {
-                        if (systMenu.getDEL_YN().equals("N")) {
-                            GropMenuAthrDto.GropMenuAthrInfo menuAthr = new GropMenuAthrDto.GropMenuAthrInfo(userGrop, systMenu);
-                            GropMenuAthr auth = authMap.get(userGrop.getGROP_ID() + "*" + systMenu.getOPERSYST_MENU_ID());
-                            if (auth != null) {
-                                menuAthr.updateMenuAuth(auth);
-                            }
-                            result.add(menuAthr);
-                        }
+                if (userGrop.getDEL_YN().equals("Y")) {
+                    continue;
+                }
+
+                // 모든 메뉴에 대해서
+                for (OperSystMenu systMenu : systMenus) {
+                    if (systMenu.getDEL_YN().equals("Y") || systMenu.getMENU_LEVL() == 1) {
+                        // 메뉴레벨이 1인 최상위 메뉴는 제외한다.
+                        continue;
+                    }
+
+                    // 최상위 메뉴명을 업데이트
+                    systMenu.setOPER_SYST_NM(systMenuMap.get(systMenu.getOPER_SYST_ID()));
+                    // 메뉴권한 등록
+                    GropMenuAthrDto.GropMenuAthrInfo menuAthr = new GropMenuAthrDto.GropMenuAthrInfo(userGrop, systMenu);
+                    GropMenuAthr auth = authMap.get(userGrop.getGROP_ID() + "*" + systMenu.getOPERSYST_MENU_ID());
+                    if (auth != null) {
+                        // 메뉴권한이 등록되어 있으면 업데이트
+                        menuAthr.updateMenuAuth(auth);
                     }
+                    result.add(menuAthr);
                 }
             }
         }