메뉴관리 작업중.

등록, 조회 기능 추가.
강석 최 2022-08-23 18:08:49 +09:00
parent 18557e0329
commit 7854e71f82
15 changed files with 318 additions and 71 deletions

View File

@ -1,4 +1,4 @@
package com.dbnt.faisp;
package com.dbnt.faisp.config;
import lombok.Getter;
import lombok.NoArgsConstructor;

View File

@ -1,4 +1,4 @@
package com.dbnt.faisp;
package com.dbnt.faisp.controller;
import com.dbnt.faisp.userInfo.model.UserInfo;
import com.dbnt.faisp.codeMgt.CodeMgtService;

View File

@ -1,6 +1,7 @@
package com.dbnt.faisp.controller;
import com.dbnt.faisp.menuMgt.MenuMgtService;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
@ -14,10 +15,19 @@ public class MenuMgtController {
private final MenuMgtService menuMgtService;
@GetMapping("/menuMgtPage")
public ModelAndView menuMgtPage() {
public ModelAndView menuMgtPage(MenuMgt menuMgt) {
ModelAndView mav = new ModelAndView("/adminPage/menuMgt/menuMgt");
menuMgt.setQueryInfo();
mav.addObject("menuMgtList", menuMgtService.selectMenuMgtList(menuMgt));
menuMgt.setContentCnt(menuMgtService.selectMenuMgtListCnt(menuMgt));
menuMgt.setPaginationInfo();
mav.addObject("searchParams", menuMgt);
return mav;
}
@PostMapping("/saveMenuMgt")
public String saveMenuMgt(MenuMgt menuMgt){
return menuMgtService.saveMenuMgt(menuMgt);
}
}

View File

@ -1,10 +1,14 @@
package com.dbnt.faisp.menuMgt;
import com.dbnt.faisp.menuMgt.mapper.MenuMgtMapper;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import com.dbnt.faisp.menuMgt.repository.MenuMgtRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import javax.persistence.Transient;
import java.util.List;
@Service
@RequiredArgsConstructor
public class MenuMgtService {
@ -12,5 +16,22 @@ public class MenuMgtService {
private final MenuMgtRepository menuMgtRepository;
private final MenuMgtMapper menuMgtMapper;
public List<MenuMgt> selectMenuMgtList(MenuMgt menuMgt){
return menuMgtMapper.selectMenuMgtList(menuMgt);
}
public Integer selectMenuMgtListCnt(MenuMgt menuMgt){
return menuMgtMapper.selectMenuMgtListCnt(menuMgt);
}
@Transient
public String saveMenuMgt(MenuMgt menuMgt) {
MenuMgt duplMenu = menuMgtRepository.findTopByCat1CdAndCat2CdAndCat3Cd(menuMgt.getCat1Cd(), menuMgt.getCat2Cd(), menuMgt.getCat3Cd());
if(duplMenu!=null){
return duplMenu.getMenuUrl();
}else{
menuMgtRepository.save(menuMgt);
return "";
}
}
}

View File

@ -1,8 +1,14 @@
package com.dbnt.faisp.menuMgt.mapper;
import com.dbnt.faisp.menuMgt.model.MenuMgt;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface MenuMgtMapper {
List<MenuMgt> selectMenuMgtList(MenuMgt menuMgt);
Integer selectMenuMgtListCnt(MenuMgt menuMgt);
}

View File

@ -1,5 +1,6 @@
package com.dbnt.faisp.menuMgt.model;
import com.dbnt.faisp.config.BaseModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@ -15,16 +16,17 @@ import javax.persistence.*;
@DynamicInsert
@DynamicUpdate
@Table(name = "menu_mgt")
public class MenuMgt {
public class MenuMgt extends BaseModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "menu_key")
private String menuKey;
@Column(name = "cat1_nm", nullable = false)
private String cat1Nm;
@Column(name = "cat2_nm", nullable = false)
private String cat2Nm;
@Column(name = "cat3_nm", nullable = false)
private String cat3Nm;
@Column(name = "cat1_cd", nullable = false)
private String cat1Cd;
@Column(name = "cat2_cd", nullable = false)
private String cat2Cd;
@Column(name = "cat3_cd")
private String cat3Cd;
@Column(name = "menu_url", nullable = false)
private String menuUrl;

View File

@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface MenuMgtRepository extends JpaRepository<MenuMgt, Integer> {
MenuMgt findTopByCat1CdAndCat2CdAndCat3Cd(String cat1Cd, String cat2Cd, String cat3Cd);
}

View File

@ -1,6 +1,6 @@
package com.dbnt.faisp.userInfo.model;
import com.dbnt.faisp.BaseModel;
import com.dbnt.faisp.config.BaseModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

View File

@ -22,23 +22,13 @@ spring.datasource.url=jdbc:log4jdbc:postgresql://106.247.244.146:50503/faisp
spring.datasource.username=dbnt0031
spring.datasource.password=dbnt0928!
#mariaDB & log4jdbc
#spring.datasource.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
#spring.datasource.url=ENC(dyWhZaWHoSfJZtAIG3H42B36VasUlkpnnXQ7K1DFIoY+BxgbHAwf9mFSfxoZfn4zU+6uc2n4hK05vDAG2u/oARiQfDZU/y3ATZ8KldP14suXeRHFfnryNGPzEdPzd9Pjd3/HvYOplF+5+B2yUVGawg==)
#spring.datasource.username=ENC(+BM/jvdOdi0MtWj44u1nxA==)
#spring.datasource.password=ENC(njSsOMalmaUC2YKT4jm2GyYSNXc0hZs4)
#spring.datasource.url=jdbc:log4jdbc:mariadb://localhost:3306/kcgFileManager?characterEncoding=UTF-8&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=kcg211228
#jpa
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
# MyBatis
mybatis.mapper-locations: mybatisMapper/**/*.xml
mybatis.mapper-locations: mybatisMapper/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.type-aliases-package=com.dbnt.faisp.model
mybatis.type-aliases-package=com.dbnt.faisp.**.model
logging.level.com.atoz_develop.mybatissample.repository=TRACE

View File

@ -0,0 +1,48 @@
<?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.faisp.menuMgt.mapper.MenuMgtMapper">
<select id="selectMenuMgtList" resultType="MenuMgt" parameterType="MenuMgt">
select cat1_cd as cat1Cd,
cat2_cd as cat2Cd,
cat3_cd as cat3Cd,
menu_url as menuUrl
from menu_mgt
<where>
<if test='cat1Cd != null and cat1Cd != ""'>
and cat1_cd = #{cat1Cd}
</if>
<if test='cat2Cd != null and cat2Cd != ""'>
and cat2_cd = #{cat2Cd}
</if>
<if test='cat3Cd != null and cat3Cd != ""'>
and cat3_cd = #{cat3Cd}
</if>
<if test='menuUrl != null and menuUrl != ""'>
and menu_url = #{menuUrl}
</if>
</where>
order by cat1_cd, cat2_cd, cat3_cd
limit #{rowCnt} offset #{firstIndex}
</select>
<select id="selectMenuMgtListCnt" resultType="int" parameterType="MenuMgt">
select count(*)
from menu_mgt
<where>
<if test='cat1Cd != null and cat1Cd != ""'>
and cat1_cd = #{cat1Cd}
</if>
<if test='cat2Cd != null and cat2Cd != ""'>
and cat2_cd = #{cat2Cd}
</if>
<if test='cat3Cd != null and cat3Cd != ""'>
and cat3_cd = #{cat3Cd}
</if>
<if test='menuUrl != null and menuUrl != ""'>
and menu_url = #{menuUrl}
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,44 @@
$(document).on('click', '#saveMenuBtn', function (){
let valueChk = true;
if(!$("#cat1Cd").val()){
alert("대분류를 선택해주세요.")
valueChk = false;
}
if(!$("#cat2Cd").val()){
alert("중분류를 선택해주세요.")
valueChk = false;
}
if(!$("#menuUrl").val()){
alert("URL을 입력해주세요.")
valueChk = false;
}
if(valueChk && confirm("저장하시겠습니까?")){
contentFade("in");
const formData = new FormData($("#menuEditForm")[0]);
$.ajax({
type : 'POST',
data : formData,
url : "/menuMgt/saveMenuMgt",
processData: false,
contentType: false,
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(result) {
if(result!==""){
alert("url: "+result+"로 저장되어있습니다.")
}else{
location.reload();
alert("저장되었습니다.")
}
contentFade("out");
},
error : function(xhr, status) {
alert("저장에 실패하였습니다.")
contentFade("out");
}
})
}
})

View File

@ -3,7 +3,7 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
<script type="text/javascript" th:src="@{/js/codeMgt/codeMgt.js}"></script>
<script type="text/javascript" th:src="@{/js/codeMgt/menuMgt.js}"></script>
</th:block>
<div layout:fragment="content">
<main class="pt-3">

View File

@ -3,71 +3,124 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
<script type="text/javascript" th:src="@{/js/codeMgt/codeMgt.js}"></script>
<script type="text/javascript" th:src="@{/js/menuMgt/menuMgt.js}"></script>
</th:block>
<div layout:fragment="content">
<main class="pt-3">
<h4>메뉴 관리</h4>
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<div class="row mx-0">
<div class="col-12 card text-center">
<div class="card-body">
<div class="row">
<div class="col-10">
<div class="row justify-content-end">
<button class="col-auto btn btn-success mx-3 my-2" id="codeSaveBtn">저장</button>
</div>
<div class="row justify-content-end px-3 py-1">
<div class="col-auto">
<select class="form-select form-select-sm">
<option>대분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT1'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"></option>
</th:block>
</th:block>
<option></option>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm">
<option>중분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT2'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"></option>
</th:block>
</th:block>
</select>
</div>
<div class="col-auto">
<select class="form-select form-select-sm">
<option>소분류 선택</option>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.categoryCd=='CAT3'}">
<option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"></option>
</th:block>
</th:block>
</select>
</div>
<div class="col-auto">
<input type="text" class="form-control form-control-sm" placeholder="url">
</div>
<button class="btn btn-sm btn-primary col-auto" id="searchBtn">검색</button>
</div>
<div class="row justify-content-start">
<div class="col-6">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<table class="table table-striped" id="categoryTable">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>분류코드</th>
<th>분류명</th>
<th>설명</th>
<th>대분류</th>
<th>중분류</th>
<th>소분류</th>
<th>url</th>
</tr>
</thead>
<tbody class="overflow-scroll">
<tbody>
<tr class="userInfoTr" th:each="menuMgt:${menuMgtList}">
<td>
<input type="checkbox" class="userInfoCheckBox" th:value="${menuMgt.menuKey}">
</td>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.itemCd == menuMgt.cat1Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.itemCd == menuMgt.cat2Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
</th:block>
<th:block th:each="commonCode:${session.commonCodeList}">
<th:block th:if="${commonCode.itemCd == menuMgt.cat3Cd}">
<td th:text="${commonCode.itemValue}"></td>
</th:block>
</th:block>
<th:block th:if="${#strings.isEmpty(menuMgt.cat3Cd)}">
<td></td>
</th:block>
<td th:text="${menuMgt.menuUrl}"></td>
</tr>
</tbody>
</table>
</div>
<div class="row justify-content-center">
<button class="btn btn-sm btn-outline-primary col-auto" id="categoryAddBtn"><i class="bi bi-plus-lg"></i></button>
</div>
</div>
</div>
</div>
<div class="col-4" id="valueDiv">
<div class="card">
<div class="card-body">
<div class="row">
<table class="table table-striped" id="itemTable">
<thead>
<tr>
<th></th>
<th>하위코드</th>
<th></th>
<th>사용</th>
</tr>
</thead>
<tbody class="overflow-scroll">
</tbody>
<tfoot>
<tr id="emptyTr"><td colspan="4">분류를 선택해주세요.</td></tr>
</tfoot>
</table>
</div>
<div class="row justify-content-center" id="itemBtnRow" style="display: none">
<button class="btn btn-sm btn-outline-primary col-auto" id="itemAddBtn"><i class="bi bi-plus-lg"></i></button>
<div class="row justify-content-between">
<div class="col-auto"></div>
<div class="col-auto">
<nav aria-label="Page navigation">
<ul class="pagination">
<th:block th:if="${searchParams.pageIndex>3}">
<li class="page-item" th:data-pageindex="${(searchParams.pageIndex)-3}">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
</th:block>
<th:block th:each="num : ${#numbers.sequence(searchParams.startNum, searchParams.endNum)}">
<li class="page-item" th:data-pageindex="${num}" th:classappend="${searchParams.pageIndex==num?'active':''}">
<a class="page-link" href="#" th:text="${num}"></a>
</li>
</th:block>
<th:block th:if="${searchParams.maxNum>searchParams.endNum+2}">
<li class="page-item" th:data-pageindex="${(searchParams.pageIndex)+3}">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</th:block>
</ul>
</nav>
</div>
<div class="col-auto">
<input type="button" class="btn btn-success" value="메뉴 추가" data-bs-toggle="modal" data-bs-target="#menuEditModal">
</div>
</div>
</div>
</div>
@ -77,5 +130,71 @@
</div>
</div>
</main>
<div class="modal fade" id="menuEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="menuEditModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="menuEditModalLabel">메뉴 추가</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="menuEditForm" action="#" method="post">
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<div class="row mb-3">
<label for="cat1Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">대분류</label>
<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}"></option>
</th:block>
</th:block>
</select>
</div>
</div>
<div class="row mb-3">
<label for="cat2Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">중분류</label>
<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}"></option>
</th:block>
</th:block>
</select>
</div>
</div>
<div class="row mb-3">
<label for="cat3Cd" class="col-sm-4 col-form-label col-form-label-sm text-center">소분류</label>
<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}"></option>
</th:block>
</th:block>
</select>
</div>
</div>
<div class="row mb-3">
<label for="menuUrl" class="col-sm-4 col-form-label col-form-label-sm text-center">URL</label>
<div class="col-sm-6">
<input type="text" class="form-control form-control-sm" id="menuUrl" name="menuUrl">
</div>
</div>
</form>
</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="saveMenuBtn">저장</button>
</div>
</div>
</div>
</div>
</div>
</html>

View File

@ -12,7 +12,7 @@
<div>
<ul class="nav nav-pills" sec:authorize="hasRole('ROLE_ADMIN')">
<li class="nav-item"><a href="/codeMgt/codeMgtPage" class="nav-link p-1 link-dark">코드관리</a></li>
<li class="nav-item"><a href="#" class="nav-link p-1 link-dark">메뉴관리</a></li>
<li class="nav-item"><a href="/menuMgt/menuMgtPage" class="nav-link p-1 link-dark">메뉴관리</a></li>
<li class="nav-item"><a href="#" class="nav-link p-1 link-dark">외사경찰관리</a></li>
<li class="nav-item"><a href="#" class="nav-link p-1 link-dark">권한설정</a></li>
<li class="nav-item"><a href="#" class="nav-link p-1 link-dark">사용자로그</a></li>

View File

@ -35,6 +35,13 @@
<th:block layout:fragment="script"></th:block>
<th:block sec:authorize="isAuthenticated()">
<script type="text/javascript">
$(function (){
/*세션 체크*/
const commonCodeList = '[[${session.commonCodeList}]]';
if(!commonCodeList) {
sessionReload()
}
})
</script>
</th:block>
</head>