사용자별 권한 설정 작업 완료.

master
강석 최 2021-12-09 18:23:19 +09:00
parent 7d6aecbc7c
commit a244c204f6
16 changed files with 170 additions and 127 deletions

View File

@ -43,4 +43,11 @@ public class BaseController {
ModelAndView mav = new ModelAndView("main");
return mav;
}
@GetMapping("/refreshSession")
public void getSession(HttpSession session){
session.setAttribute("positionList", commonCodeService.selectCommonCodeValue("POSITION"));
session.setAttribute("departmentList", commonCodeService.selectCommonCodeValue("DEPARTMENT"));
session.setAttribute("categoryList", boardCategoryService.selectBoardCategoryAll(null, 1));
}
}

View File

@ -15,7 +15,6 @@ import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;
@RestController
@RequiredArgsConstructor
@ -96,9 +95,9 @@ public class adminController {
}
@GetMapping("/selectCategoryRole")
public ModelAndView selectUserCategoryRole(CategoryRole categoryRole){
public ModelAndView selectCategorySeqListToUser(CategoryRole categoryRole){
ModelAndView mav = new ModelAndView("admin/userCategoryRole");
/*mav.addObject("userCategoryRole", userInfoService.selectUserCategoryRole(categoryRole));*/
mav.addObject("categorySeqList", categoryRoleService.selectCategorySeqListToUser(categoryRole));
return mav;
}

View File

@ -1,8 +0,0 @@
package com.dbnt.kcgfilemanager.mapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BoardCategoryMapper {
}

View File

@ -0,0 +1,12 @@
package com.dbnt.kcgfilemanager.mapper;
import com.dbnt.kcgfilemanager.model.BoardCategory;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CategoryRoleMapper {
List<BoardCategory> selectCategoryListToUser(CategoryRole categoryRole);
}

View File

@ -1,12 +1,11 @@
package com.dbnt.kcgfilemanager.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import java.io.Serializable;
@Getter
@Setter
@ -15,7 +14,7 @@ import javax.persistence.*;
@DynamicInsert
@DynamicUpdate
@Table(name = "CATEGORY_ROLE")
@IdClass(CategoryRoleId.class)
@IdClass(CategoryRole.CategoryRoleId.class)
public class CategoryRole {
@Id
@Column(name = "USER_SEQ", nullable = false)
@ -23,7 +22,17 @@ public class CategoryRole {
@Id
@Column(name = "CATEGORY_SEQ", nullable = false)
private Integer categorySeq;
@Column(name = "CATEGORY_ROLE")
private String categoryRole;
@Embeddable
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class CategoryRoleId implements Serializable {
private Integer userSeq;
private Integer categorySeq;
}
}

View File

@ -1,19 +0,0 @@
package com.dbnt.kcgfilemanager.model;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.IdClass;
import javax.persistence.Table;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CategoryRoleId implements Serializable {
private Integer userSeq;
private Integer categorySeq;
}

View File

@ -1,13 +1,13 @@
package com.dbnt.kcgfilemanager.repository;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.model.CategoryRoleId;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CategoryRoleRepository extends JpaRepository<CategoryRole, CategoryRoleId> {
public interface CategoryRoleRepository extends JpaRepository<CategoryRole, CategoryRole.CategoryRoleId> {
List<CategoryRole> findByUserSeq(Integer userSeq);
void deleteByUserSeq(Integer userSeq);
List<CategoryRole> findByCategorySeq(Integer categorySeq);
}

View File

@ -1,18 +1,22 @@
package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.mapper.BoardCategoryMapper;
import com.dbnt.kcgfilemanager.model.BoardCategory;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.repository.BoardCategoryRepository;
import com.dbnt.kcgfilemanager.repository.CategoryRoleRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@RequiredArgsConstructor
public class BoardCategoryService {
private final BoardCategoryMapper boardCategoryMapper;
private final BoardCategoryRepository boardCategoryRepository;
private final CategoryRoleRepository categoryRoleRepository;
public List<BoardCategory> selectBoardCategory(Integer parentCategory, Integer depth) {
@ -26,8 +30,22 @@ public class BoardCategoryService {
return categoryList;
}
@Transactional
public void insertBoardCategory(List<BoardCategory> categoryList){
boardCategoryRepository.saveAll(categoryList);
Integer parentCategory = categoryList.get(0).getParentCategory();
List<CategoryRole> categoryRoleList = categoryRoleRepository.findByCategorySeq(parentCategory);
List<CategoryRole> addRoleList = new ArrayList<>();
for(CategoryRole role: categoryRoleList){
for(BoardCategory category: categoryList){
CategoryRole categoryRole = new CategoryRole();
categoryRole.setUserSeq(role.getUserSeq());
categoryRole.setCategorySeq(category.getCategorySeq());
categoryRole.setCategoryRole("T");
addRoleList.add(categoryRole);
}
}
categoryRoleRepository.saveAll(addRoleList);
}
public void deleteBoardCategory(Integer categorySeq, Integer depth) {

View File

@ -1,8 +1,11 @@
package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.mapper.CategoryRoleMapper;
import com.dbnt.kcgfilemanager.model.BoardCategory;
import com.dbnt.kcgfilemanager.model.CategoryRole;
import com.dbnt.kcgfilemanager.repository.CategoryRoleRepository;
import lombok.RequiredArgsConstructor;
import org.apache.logging.log4j.util.StringBuilders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -14,11 +17,10 @@ import java.util.List;
@RequiredArgsConstructor
public class CategoryRoleService {
private final CategoryRoleRepository categoryRoleRepository;
private final CategoryRoleMapper categoryRoleMapper;
@Transactional
public void insertCategoryRole(Integer userSeq, List<LinkedHashMap> mapList) {
// List<CategoryRole> categoryRoleList = categoryRoleRepository.findByUserSeq(userSeq);
// categoryRoleRepository.deleteAll(categoryRoleList);
categoryRoleRepository.deleteByUserSeq(userSeq);
List<CategoryRole> categoryRoleList = new ArrayList<>();
for(LinkedHashMap map: mapList){
@ -30,4 +32,14 @@ public class CategoryRoleService {
}
categoryRoleRepository.saveAll(categoryRoleList);
}
public List<Integer> selectCategorySeqListToUser(CategoryRole categoryRole) {
List<CategoryRole> categoryRoleList = categoryRoleRepository.findByUserSeq(categoryRole.getUserSeq());
List<Integer> roleList = new ArrayList<>();
for(CategoryRole userRole: categoryRoleList){
roleList.add(userRole.getCategorySeq());
}
return roleList;
}
}

View File

@ -4,7 +4,7 @@ spring.devtools.livereload.enabled=true
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false
#mariaDB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dbnt.kcgfilemanager.mapper.CategoryRoleMapper">
<select id="selectCategoryListToUser" resultType="BoardCategory" parameterType="CategoryRole">
SELECT B.CATEGORY_SEQ ,
B.DEPTH ,
B.PARENT_CATEGORY ,
B.CATEGORY_NAME
FROM CATEGORY_ROLE A
INNER JOIN BOARD_CATEGORY B ON A.CATEGORY_SEQ = B.CATEGORY_SEQ
WHERE A.USER_SEQ = #{userSeq}
</select>
</mapper>

View File

@ -11,6 +11,9 @@
transform: translate(-50%, -50%);
}
.centerDiv{
max-height: fit-content;
}
/*사이드바 카테고리 트리*/
.btn-toggle:hover, .btn-toggle:focus {
color: rgba(0, 0, 0, .85);

View File

@ -1,11 +1,6 @@
$(function(){
setSearchCondition();
const categorySelectModal = document.getElementById('categorySelectModal');
categorySelectModal.addEventListener('shown.bs.modal', function () {
})
$("#dateSelectorDiv").datepicker({
format: "yyyy-mm-dd",
language: "ko"
@ -117,9 +112,7 @@ $(document).on('click', '#saveCategoryRoleBtn', function (){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(data) {
getCategoryRole($(".userInfoCheckBox:checked").val());
alert("저장되었습니다.");
$("#categorySelectModal").find(".btn-close").click();
},
error : function(xhr, status) {

View File

@ -1,12 +1,69 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<div class="p-3">
<div class="row-cols-6">
권한 목록
<div class="row overflow-auto flex-nowrap" id="categorySelectModalBody">
<th:block th:each="depth1:${session.categoryList}">
<div class="col-auto">
<table class="table table-striped">
<thead>
<tr>
<th>
<input type="checkbox" class="categoryCheckBox parentCategory" th:data-categoryseq="${depth1.categorySeq}"
th:checked="${#lists.contains(categorySeqList, depth1.categorySeq)}">
</th>
<th colspan="3" class="text-center" th:text="${depth1.categoryName}"></th>
</tr>
<tr>
<th></th>
<th>연도</th>
<th>중분류</th>
<th>소분류</th>
</tr>
</thead>
<tbody>
<th:block th:each="depth2:${depth1.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth2.categorySeq}" th:data-parentcategory="${depth2.parentCategory}"
th:checked="${#lists.contains(categorySeqList, depth2.categorySeq)}">
</td>
<td th:text="${depth2.categoryName}"></td>
<td></td>
<td></td>
</tr>
<th:block th:each="depth3:${depth2.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth3.categorySeq}" th:data-parentcategory="${depth3.parentCategory}"
th:checked="${#lists.contains(categorySeqList, depth3.categorySeq)}">
</td>
<td></td>
<td th:text="${depth3.categoryName}"></td>
<td></td>
</tr>
<th:block th:each="depth4:${depth3.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox" th:data-categoryseq="${depth4.categorySeq}"
th:data-parentcategory="${depth4.parentCategory}" th:checked="${#lists.contains(categorySeqList, depth4.categorySeq)}">
</td>
<td></td>
<td></td>
<td th:text="${depth4.categoryName}"></td>
</tr>
</th:block>
</th:block>
</th:block>
</tbody>
</table>
</div>
</th:block>
</div>
<div class="row justify-content-end">
<div class="col-auto">
<button class="btn btn-success" id="roleAddBtn" data-bs-toggle="modal" data-bs-target="#categorySelectModal">편집</button>
<button type="button" class="btn btn-primary" id="saveCategoryRoleBtn">저장</button>
</div>
</div>
</div>

View File

@ -222,79 +222,5 @@
</div>
</div>
</div>
<div class="modal fade" id="categorySelectModal" tabindex="-1" aria-labelledby="categorySelectModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="categorySelectModalLabel">분류 선택</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row overflow-auto flex-nowrap" id="categorySelectModalBody">
<th:block th:each="depth1:${session.categoryList}">
<div class="col-auto">
<table class="table table-striped">
<thead>
<tr>
<th>
<input type="checkbox" class="categoryCheckBox parentCategory" th:data-categoryseq="${depth1.categorySeq}">
</th>
<th colspan="3" class="text-center" th:text="${depth1.categoryName}"></th>
</tr>
<tr>
<th></th>
<th>연도</th>
<th>중분류</th>
<th>소분류</th>
</tr>
</thead>
<tbody>
<th:block th:each="depth2:${depth1.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth2.categorySeq}" th:data-parentcategory="${depth2.parentCategory}">
</td>
<td th:text="${depth2.categoryName}"></td>
<td></td>
<td></td>
</tr>
<th:block th:each="depth3:${depth2.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox parentCategory"
th:data-categoryseq="${depth3.categorySeq}" th:data-parentcategory="${depth3.parentCategory}">
</td>
<td></td>
<td th:text="${depth3.categoryName}"></td>
<td></td>
</tr>
<th:block th:each="depth4:${depth3.childCategoryList}">
<tr>
<td>
<input type="checkbox" class="categoryCheckBox" th:data-categoryseq="${depth4.categorySeq}"
th:data-parentcategory="${depth4.parentCategory}">
</td>
<td></td>
<td></td>
<td th:text="${depth4.categoryName}"></td>
</tr>
</th:block>
</th:block>
</th:block>
</tbody>
</table>
</div>
</th:block>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
<button type="button" class="btn btn-primary" id="saveCategoryRoleBtn">저장</button>
</div>
</div>
</div>
</div>
</div>
</html>

View File

@ -29,15 +29,33 @@
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<!-- 컨텐츠페이지의 스크립트 영역이 들어감 -->
<th:block layout:fragment="script"></th:block>
<th:block sec:authorize="isAuthenticated()">
<script type="text/javascript">
$(function (){
/*세션 체크*/
const positionList = '[[${session.positionList}]]';
const departmentList = '[[${session.departmentList}]]';
const categoryList = '[[${session.categoryList}]]';
if(!positionList && !departmentList && !categoryList){
$.ajax({
url: '/refreshSession',
type: 'GET',
success: function(){location.reload();},
error:function(){}
});
}
})
</script>
</th:block>
</head>
<body class="d-flex flex-column h-100">
<header th:replace="fragments/header :: headerFragment"></header>
<div sec:authorize="isAnonymous()" layout:fragment="content"></div>
<div sec:authorize="isAuthenticated()" class="row mx-0 ">
<div class="col-2">
<div class="col-2 centerDiv">
<div th:replace="fragments/leftMenu :: leftMenuFragment"></div>
</div>
<div class="col-10">
<div class="col-10 centerDiv">
<div layout:fragment="content"></div>
</div>
</div>