세션의 공통코드 관리방식 수정.

사용자별 메뉴 링크 세션 저장.
강석 최 2022-09-02 16:14:09 +09:00
parent dcdc141dc2
commit 4db0486939
12 changed files with 149 additions and 95 deletions

View File

@ -8,7 +8,10 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
@ -40,9 +43,21 @@ public class CodeMgtService{
return codeCatgList;
}
public List<CodeMgt> selectCommonCodeList() {
public Map<String, List<CodeMgt>> getCommonCode() {
//return codeMgtRepository.findByUseChkOrderByItemCdAsc("T");
return codeMgtRepository.findByOrderByItemCdAsc();
List<CodeCatg> categoryList = codeCatgRepository.findAll();
List<CodeMgt> codeList = codeMgtRepository.findByOrderByItemCdAsc();
Map<String, List<CodeMgt>> categoryMap = new HashMap<>();
for(CodeCatg category: categoryList){
List<CodeMgt> childList = new ArrayList<>();
for(CodeMgt code: codeList){
if(code.getCategoryCd().equals(category.getCategoryCd())){
childList.add(code);
}
}
categoryMap.put(category.getCategoryCd(), childList);
}
return categoryMap;
}
public List<CodeMgt> selectCodeMgtList(String categoryCd) {

View File

@ -74,9 +74,21 @@ public class SecurityConfig{
).hasRole(Role.SUB_ADMIN.name()) // SUB_ADMIN만 접근 허용
.antMatchers("/login").permitAll() // 로그인 페이지는 권한 없이 접근 허용
.and() // 로그인 설정
.formLogin() .loginPage("/login") // Custom login form 사용
.formLogin().loginPage("/login") // Custom login form 사용
.failureUrl("/login-error") // 로그인 실패 시 이동
.defaultSuccessUrl("/") // 로그인 성공 시 redirect 이동
.defaultSuccessUrl("/") // 로그인 성공 시 이동
/*.failureHandler((request, response, exception) -> {
}) // 로그인 실패시 동작 수행
.successHandler((request, response, authentication) -> {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request,response);
if(savedRequest != null){
String targetUrl = savedRequest.getRedirectUrl();
new DefaultRedirectStrategy().sendRedirect(request,response,targetUrl);
}else{
new DefaultRedirectStrategy().sendRedirect(request,response,"/");
}
}) // 로그인 성공시 동작 수행.*/
.and() // 로그아웃 설정
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) // 로그아웃 시 URL 재정의
.logoutSuccessUrl("/") // 로그아웃 성공 시 redirect 이동

View File

@ -36,15 +36,17 @@ public class BaseController {
}else{
loginUser.setOrganCdList(organConfigService.selectOrganListWhereUserOgCd(loginUser.getOgCd()));
session.setAttribute("menuList", menuMgtService.selectAccessMenuListWhereUserSeq(loginUser.getUserSeq()));
session.setAttribute("commonCodeList", codeMgtService.selectCommonCodeList());
session.setAttribute("commonCode", codeMgtService.getCommonCode());
mav = new ModelAndView("redirect:/dashboard");
}
return mav;
}
@GetMapping("/refreshSession")
public void getSession(HttpSession session){
session.setAttribute("commonCodeList", codeMgtService.selectCommonCodeList());
public void getSession(@AuthenticationPrincipal UserInfo loginUser, HttpSession session){
loginUser.setOrganCdList(organConfigService.selectOrganListWhereUserOgCd(loginUser.getOgCd()));
session.setAttribute("menuList", menuMgtService.selectAccessMenuListWhereUserSeq(loginUser.getUserSeq()));
session.setAttribute("commonCode", codeMgtService.getCommonCode());
}
@GetMapping("/login")

View File

@ -1,6 +1,5 @@
package com.dbnt.faisp.menuMgt;
import com.dbnt.faisp.authMgt.model.AccessConfig;
import com.dbnt.faisp.menuMgt.mapper.MenuMgtMapper;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import com.dbnt.faisp.menuMgt.repository.MenuMgtRepository;
@ -8,8 +7,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Service
@RequiredArgsConstructor
@ -87,24 +85,80 @@ public class MenuMgtService {
public List<MenuMgt> selectAccessMenuListWhereUserSeq(Integer userSeq) {
List<MenuMgt> accessMenuList =menuMgtMapper.selectAccessMenuListWhereUserSeq(userSeq);
List<MenuMgt> menuList = new ArrayList<>();
for(MenuMgt menuMgt: accessMenuList){
boolean savedFlag = false;
for(MenuMgt savedMenu: menuList){
if(savedChk(menuMgt.getCat1Cd(), savedMenu.getCat1Cd())){
savedFlag = true;
break;
}
}
if(!savedFlag){
MenuMgt topMenu = new MenuMgt();
menuList.add(topMenu);
Set<String> cat1Set = new HashSet<>();
Set<String> cat2Set = new HashSet<>();
Set<String> cat3Set = new HashSet<>();
for(MenuMgt accessMenu: accessMenuList){
cat1Set.add(accessMenu.getCat1Cd());
cat2Set.add(accessMenu.getCat1Cd()+accessMenu.getCat2Cd());
if(!accessMenu.getCat3Cd().isEmpty()){
cat3Set.add(accessMenu.getCat1Cd()+accessMenu.getCat2Cd()+accessMenu.getCat3Cd());
}
}
return menuList;
}
private boolean savedChk(String catCd1, String catCd2){
return catCd1.equals(catCd2);
List<MenuMgt> firstMenuList = new ArrayList<>();
Iterator<String> cat1Itr = cat1Set.iterator();
while(cat1Itr.hasNext()){
String cat1Cd = cat1Itr.next();
MenuMgt firstMenu = new MenuMgt();
List<MenuMgt> secondMenuList = new ArrayList<>();
firstMenu.setCat1Cd(cat1Cd);
Iterator<String> cat2Itr = cat2Set.iterator();
while(cat2Itr.hasNext()){
String cat2Cd = cat2Itr.next();
if(cat2Cd.contains(cat1Cd)){
MenuMgt secondMenu = new MenuMgt();
List<MenuMgt> thirdMenuList = new ArrayList<>();
secondMenu.setCat2Cd(cat2Cd.replace(cat1Cd, ""));
Iterator<String> cat3Itr = cat3Set.iterator();
while(cat3Itr.hasNext()){
String cat3Cd = cat3Itr.next();
if(cat3Cd.contains(cat2Cd)){
MenuMgt thirdMenu = new MenuMgt();
thirdMenu.setCat3Cd(cat3Cd.replace(cat2Cd, ""));
for(MenuMgt accessMenu: accessMenuList){
if(accessMenu.getCat1Cd().equals(cat1Cd)
&& accessMenu.getCat2Cd().equals(secondMenu.getCat2Cd())
&& accessMenu.getCat3Cd().equals(thirdMenu.getCat3Cd())){
thirdMenu.setMenuUrl(accessMenu.getMenuUrl());
break;
}
}
thirdMenuList.add(thirdMenu);
}
}
if(thirdMenuList.size()>0){
thirdMenuList.sort((o1, o2) -> {
String cat3_1 = o1.getCat3Cd();
String cat3_2 = o2.getCat3Cd();
return cat3_1.compareTo(cat3_2);
});
secondMenu.setChildList(thirdMenuList);
}else{
for(MenuMgt accessMenu: accessMenuList){
if(accessMenu.getCat1Cd().equals(cat1Cd)
&& accessMenu.getCat2Cd().equals(secondMenu.getCat2Cd())){
secondMenu.setMenuUrl(accessMenu.getMenuUrl());
break;
}
}
}
secondMenuList.add(secondMenu);
}
}
secondMenuList.sort((o1, o2) -> {
String cat2_1 = o1.getCat2Cd();
String cat2_2 = o2.getCat2Cd();
return cat2_1.compareTo(cat2_2);
});
firstMenu.setChildList(secondMenuList);
firstMenuList.add(firstMenu);
}
firstMenuList.sort((o1, o2) -> {
String cat1_1 = o1.getCat1Cd();
String cat1_2 = o2.getCat1Cd();
return cat1_1.compareTo(cat1_2);
});
return firstMenuList;
}
}

View File

@ -33,10 +33,6 @@ public class MenuMgt extends BaseModel {
@Column(name = "approval_chk")
private String approvalChk;
@Transient
private String menuCd;
@Transient
private String menuNm;
@Transient
private List<MenuMgt> childList;

View File

@ -16,12 +16,12 @@
<tbody>
<tr th:each="accessConfig:${userInfo.accessConfigList}">
<input type="hidden" class="menuKey" th:value="${accessConfig.menuKey}">
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('CAT1')}">
<th:block th:if="${commonCode.itemCd eq accessConfig.cat1Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('CAT2')}">
<th:block th:if="${commonCode.itemCd eq accessConfig.cat2Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
@ -29,7 +29,7 @@
<th:block th:if="${#strings.isEmpty(accessConfig.cat3Cd)}">
<td></td>
</th:block>
<th:block th:unless="${#strings.isEmpty(accessConfig.cat3Cd)}" th:each="commonCode:${session.commonCodeList}">
<th:block th:unless="${#strings.isEmpty(accessConfig.cat3Cd)}" th:each="commonCode:${session.commonCode.get('CAT3')}">
<th:block th:if="${commonCode.itemCd eq accessConfig.cat3Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
@ -63,12 +63,12 @@
<tbody>
<tr th:each="approvalConfig:${userInfo.approvalConfigList}">
<input type="hidden" class="menuKey" th:value="${approvalConfig.menuKey}">
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('CAT1')}">
<th:block th:if="${commonCode.itemCd eq approvalConfig.cat1Cd}">
<td th:text="${commonCode.itemValue}">.</td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('CAT2')}">
<th:block th:if="${commonCode.itemCd eq approvalConfig.cat2Cd}">
<td th:text="${commonCode.itemValue}">.</td>
</th:block>
@ -76,7 +76,7 @@
<th:block th:if="${#strings.isEmpty(approvalConfig.cat3Cd)}">
<td></td>
</th:block>
<th:block th:unless="${#strings.isEmpty(approvalConfig.cat3Cd)}" th:each="commonCode:${session.commonCodeList}">
<th:block th:unless="${#strings.isEmpty(approvalConfig.cat3Cd)}" th:each="commonCode:${session.commonCode.get('CAT3')}">
<th:block th:if="${commonCode.itemCd eq approvalConfig.cat3Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>

View File

@ -28,20 +28,16 @@
<div class="col-auto">
<select class="form-select form-select-sm" name="ogCd">
<option value="">관서 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='OG'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ogCd==commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('OG')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ogCd==commonCode.itemCd}"></option>
</th:block>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm" name="ofcCd">
<option value="">부서 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='OFC'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ofcCd==commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('OFC')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ofcCd==commonCode.itemCd}"></option>
</th:block>
</select>
</div>
@ -79,12 +75,12 @@
<td>
<input type="checkbox" class="userInfoCheckBox" th:value="${userInfo.userSeq}">
</td>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('OG')}">
<th:block th:if="${commonCode.itemCd == userInfo.ogCd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('OFC')}">
<th:block th:if="${commonCode.itemCd == userInfo.ofcCd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>

View File

@ -15,10 +15,8 @@
<div class="col-sm-6">
<select class="form-select form-select-sm" id="cat1Cd" name="cat1Cd">
<option value="">대분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT1'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat1Cd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT1')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat1Cd}"></option>
</th:block>
</select>
</div>
@ -28,10 +26,8 @@
<div class="col-sm-6">
<select class="form-select form-select-sm" id="cat2Cd" name="cat2Cd">
<option value="">중분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT2'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat2Cd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT2')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat2Cd}"></option>
</th:block>
</select>
</div>
@ -41,10 +37,8 @@
<div class="col-sm-6">
<select class="form-select form-select-sm" id="cat3Cd" name="cat3Cd">
<option value="">소분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT3'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat3Cd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT3')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd==menuMgt.cat3Cd}"></option>
</th:block>
</select>
</div>

View File

@ -28,30 +28,24 @@
<div class="col-auto">
<select class="form-select form-select-sm" name="cat1Cd">
<option value="">대분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd eq 'CAT1'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat1Cd eq commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT1')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat1Cd eq commonCode.itemCd}"></option>
</th:block>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm" name="cat2Cd">
<option value="">중분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd eq 'CAT2'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat2Cd eq commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT2')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat2Cd eq commonCode.itemCd}"></option>
</th:block>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm" name="cat3Cd">
<option value="">소분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd eq 'CAT3'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat3Cd eq commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('CAT3')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.cat3Cd eq commonCode.itemCd}"></option>
</th:block>
</select>
</div>
@ -89,17 +83,17 @@
<td>
<input type="checkbox" class="menuCheckBox" th:value="${menuMgt.menuKey}">
</td>
<th:block th:if="${menuMgt.cat1RowspanCnt ne 0}" th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${menuMgt.cat1RowspanCnt ne 0}" th:each="commonCode:${session.commonCode.get('CAT1')}">
<th:block th:if="${commonCode.itemCd eq menuMgt.cat1Cd}">
<td th:text="${commonCode.itemValue}" th:rowspan="${menuMgt.cat1RowspanCnt}"></td>
</th:block>
</th:block>
<th:block th:if="${menuMgt.cat2RowspanCnt ne 0}" th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${menuMgt.cat2RowspanCnt ne 0}" th:each="commonCode:${session.commonCode.get('CAT2')}">
<th:block th:if="${commonCode.itemCd eq menuMgt.cat2Cd}">
<td th:text="${commonCode.itemValue}" th:rowspan="${menuMgt.cat2RowspanCnt}"></td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:each="commonCode:${session.commonCode.get('CAT3')}">
<th:block th:if="${commonCode.itemCd eq menuMgt.cat3Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>

View File

@ -49,20 +49,16 @@
<div class="col-auto">
<select class="form-select form-select-sm" name="ogCd">
<option value="">관서 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='OG'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ogCd==commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('OG')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ogCd==commonCode.itemCd}"></option>
</th:block>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm" name="ofcCd">
<option value="">부서 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='OFC'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ofcCd==commonCode.itemCd}"></option>
</th:block>
<th:block th:each="commonCode:${session.commonCode.get('OFC')}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.ofcCd==commonCode.itemCd}"></option>
</th:block>
</select>
</div>

View File

@ -8,18 +8,13 @@
<!--<span class="fs-4">해양경찰청 파일관리 시스템</span>-->
</a>
<ul class="nav nav-pills flex-column my-3" sec:authorize="isAuthenticated()">
<li><a href="#" class="nav-link link-dark">외사정보관리</a></li>
<li><a href="#" class="nav-link link-dark">외사수사관리</a></li>
<li><a href="#" class="nav-link link-dark">외사방첩관리</a></li>
<li><a href="#" class="nav-link link-dark">외사대상목표</a></li>
<li><a href="#" class="nav-link link-dark">정보예산관리</a></li>
<li><a href="#" class="nav-link link-dark">외사장비</a></li>
<li><a href="#" class="nav-link link-dark">첩보수집활동</a></li>
<li><a href="#" class="nav-link link-dark">외사첩보망</a></li>
<li><a href="#" class="nav-link link-dark">외사모니터링</a></li>
<li><a href="#" class="nav-link link-dark">외사통계</a></li>
<li><a href="#" class="nav-link link-dark">외사경찰</a></li>
<li><a href="#" class="nav-link link-dark">민간통역인</a></li>
<li th:each="firstMenu:${session.menuList}">
<th:block th:each="cat1Code:${session.commonCode.get('CAT1')}">
<th:block th:if="${cat1Code.itemCd eq firstMenu.cat1Cd}">
<a href="#" class="nav-link link-dark" th:text="${cat1Code.itemValue}"></a>
</th:block>
</th:block>
</li>
</ul>
</div>
</html>

View File

@ -37,8 +37,8 @@
<script type="text/javascript">
$(function (){
/*세션 체크*/
const commonCodeList = '[[${session.commonCodeList}]]';
if(!commonCodeList) {
const menuList = '[[${session.menuList}]]';
if(!menuList) {
sessionReload()
}
})