코드관리 삭제기능 작업중.

master
강석 최 2021-12-01 18:54:01 +09:00
parent 35a0a27254
commit 0a10167487
13 changed files with 280 additions and 53 deletions

View File

@ -27,6 +27,8 @@ dependencies {
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.5.3'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
@ -35,9 +37,6 @@ dependencies {
implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.4'
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'
// implementation group: 'org.webjars', name: 'bootstrap', version: '5.1.3'
// implementation group: 'org.webjars', name: 'popper.js', version: '2.9.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.5.6'
testImplementation 'org.springframework.security:spring-security-test:5.5.1'
}

View File

@ -3,11 +3,15 @@ package com.dbnt.kcgfilemanager.controller;
import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.service.CommonCodeService;
import lombok.RequiredArgsConstructor;
import org.json.simple.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.http.HttpResponse;
import java.util.List;
@Controller
@ -42,7 +46,47 @@ public class adminController {
@GetMapping("/codeMgt")
public ModelAndView codeMgt(CommonCode commonCode) {
ModelAndView mav = new ModelAndView("admin/codeMgt");
mav.addObject("categoryList", commonCodeService.selectCommonCodeToCategory(commonCode));
mav.addObject("categoryList", commonCodeService.selectCommonCodeCategory(commonCode));
return mav;
}
@GetMapping("/codeValue")
public ModelAndView codeValue(CommonCode commonCode) {
ModelAndView mav = new ModelAndView("admin/codeValue");
mav.addObject("valueList", commonCodeService.selectCommonCodeValue(commonCode));
return mav;
}
@PutMapping("/insertCommonCode")
public void insertCommonCode(HttpServletResponse res, CommonCode commonCode){
res.setCharacterEncoding("UTF-8");
res.setContentType("text/html; charset=UTF-8");
PrintWriter writerJson = null;
JSONObject jsonObject = new JSONObject();
commonCodeService.insertCommonCode(commonCode);
jsonObject.put("codeSq", commonCode.getCodeSq());
jsonObject.put("category", commonCode.getCategory());
jsonObject.put("value", commonCode.getValue());
try {
writerJson = res.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
writerJson.print(jsonObject);
}
@PutMapping("/updateCommonCode")
public void updateCommonCode(HttpServletResponse res, List<CommonCode> commonCodeList){
res.setCharacterEncoding("UTF-8");
res.setContentType("text/html; charset=UTF-8");
PrintWriter writerJson = null;
JSONObject jsonObject = new JSONObject();
System.out.println(commonCodeList.size());
// jsonObject.put("codeSq", commonCode.getCodeSq());
try {
writerJson = res.getWriter();
} catch (IOException e) {
e.printStackTrace();
}
writerJson.print(jsonObject);
}
}

View File

@ -8,5 +8,6 @@ import java.util.List;
@Mapper
public interface CommonCodeMapper {
List<CommonCode> selectCommonCodeToCategory(CommonCode commonCode);
List<CommonCode> selectCommonCodeCategory(CommonCode commonCode);
List<CommonCode> selectCommonCodeValue(CommonCode commonCode);
}

View File

@ -3,12 +3,16 @@ package com.dbnt.kcgfilemanager.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
@Getter
@Setter
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@Entity
@Table(name = "COMMON_CODE")
public class CommonCode {
@ -22,5 +26,7 @@ public class CommonCode {
private String value;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "IS_DELETED")
private String isDeleted;
}

View File

@ -1,6 +1,8 @@
package com.dbnt.kcgfilemanager.model;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
@ -14,6 +16,8 @@ import java.util.Set;
@Getter
@Setter
@NoArgsConstructor
@DynamicInsert
@DynamicUpdate
@Entity
@Table(name = "USER_INFO")
public class UserInfo implements UserDetails{

View File

@ -3,6 +3,7 @@ package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.mapper.CommonCodeMapper;
import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.model.UserInfo;
import com.dbnt.kcgfilemanager.repository.CommonCodeRepository;
import com.dbnt.kcgfilemanager.repository.UserInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
@ -19,8 +20,15 @@ import java.util.List;
public class CommonCodeService {
private final CommonCodeMapper commonCodeMapper;
private final CommonCodeRepository commonCodeRepository;
public List<CommonCode> selectCommonCodeToCategory(CommonCode commonCode) {
return commonCodeMapper.selectCommonCodeToCategory(commonCode);
public List<CommonCode> selectCommonCodeCategory(CommonCode commonCode) {
return commonCodeMapper.selectCommonCodeCategory(commonCode);
}
public List<CommonCode> selectCommonCodeValue(CommonCode commonCode) {
return commonCodeMapper.selectCommonCodeValue(commonCode);
}
public void insertCommonCode(CommonCode commonCode) {
commonCodeRepository.save(commonCode);
}
}

View File

@ -4,11 +4,29 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dbnt.kcgfilemanager.mapper.CommonCodeMapper">
<select id="selectCommonCodeToCategory" resultType="CommonCode" parameterType="CommonCode">
<select id="selectCommonCodeCategory" resultType="CommonCode" parameterType="CommonCode">
SELECT DISTINCT
CATEGORY
FROM COMMON_CODE
WHERE IS_DELETED &lt;> 'Y'
<where>
<if test="isDeleted == null or isDeleted == ''">
AND IS_DELETED = 'N'
</if>
</where>
</select>
<select id="selectCommonCodeValue" resultType="CommonCode" parameterType="CommonCode">
SELECT CODE_SQ,
VALUE,
DESCRIPTION
FROM COMMON_CODE
<where>
<if test="category != null and category != ''">
AND CATEGORY = #{category}
</if>
<if test="isDeleted == null or isDeleted == ''">
AND IS_DELETED = 'N'
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,7 @@
.form-signin{
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}

View File

@ -0,0 +1,128 @@
$(function(){
const commonCodeModal = document.getElementById('commonCodeModal')
commonCodeModal.addEventListener('hidden.bs.modal', function (event) {
formReset();
})
})
$(document).on('change', '#inputSelector', function (){
$("#category").val("");
const categorySelectDiv = $("#categorySelectDiv");
const categoryInputDiv = $("#categoryInputDiv");
categorySelectDiv.children().val("");
categoryInputDiv.children().val("");
if(this.checked){
categorySelectDiv.hide();
categoryInputDiv.show();
}else{
categorySelectDiv.show();
categoryInputDiv.hide();
}
})
$(document).on('change', '#categorySelector, #categoryInput', function (){
$("#category").val(this.value);
})
$(document).on('click', '.categoryTr', function (event){
const checkBox = $(this).find(".categoryCheckBox")[0];
categoryCheckBoxReset();
$("#allValueCheckBox")[0].checked = false;
checkBox.checked = true;
getValues(checkBox.value);
})
$(document).on('click', '.valueTr', function (event) {
if(event.target.className!=="valueCheckBox"){
const checkBox = $(this).find(".valueCheckBox")[0];
checkBox.checked = !checkBox.checked;
}
})
$(document).on('click', '#allValueCheckBox', function (event){
const flag = $("#allValueCheckBox")[0].checked;
$(".valueCheckBox").prop("checked", flag);
})
$(document).on('click', '#saveBtn', function (){
if(valueCheck()){
if(confirm("저장하시겠습니까?")){
const formData = new FormData($("#commonCodeForm")[0]);
$.ajax({
processData: false,
contentType: false,
url : "/admin/insertCommonCode",
type : 'PUT',
data : formData,
dataType: 'json',
success : function(data) {
alert("저장되었습니다.")
$("#closeModalBtn").click();
categoryCheck(data.category);
},
error : function(xhr, status) {
}
})
}
}
})
$(document).on('click', '#deleteCommonCodeBtn', function (){
let commonCodeList = [];
$(".valueCheckBox:checked").each(function (idx, el){
commonCodeList.push({codeSq: el.value, isDeleted:'Y'});
})
$.ajax({
url : "/admin/updateCommonCode",
type : 'PUT',
data : commonCodeList,
dataType: 'json',
success : function(data) {
debugger
},
error : function(xhr, status) {
}
})
})
function getValues(category){
$.ajax({
url: '/admin/codeValue',
data: {category: category},
type: 'GET',
dataType:"html",
success: function(data){
$("#valueDiv").empty().append(data)
},
error:function(){
}
});
}
function categoryCheck(category){
categoryCheckBoxReset();
$(".categoryCheckBox").each(function (idx,el){
if(el.value===category){
el.checked = true;
}
})
getValues(category);
}
function valueCheck(){
const category = $("#category").val();
const value = $("#value").val();
let returnFlag = true;
if(!category){
alert("분류를 선택(또는 입력) 해야합니다.");
returnFlag = false;
}
if(!value){
alert("값이 비어있습니다.");
returnFlag = false;
}
return returnFlag;
}
function categoryCheckBoxReset(){
$(".categoryCheckBox").prop("checked", false);
}
function formReset(){
document.getElementById('commonCodeForm').reset();
}

View File

@ -4,6 +4,9 @@
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
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/admin/codeMgt.js}"></script>
</th:block>
<div layout:fragment="content">
<main>
<h4>코드 관리</h4>
@ -25,20 +28,22 @@
</tr>
</tbody>
<tbody th:if="${categoryList.size()>0}">
<tr th:each="commonCode:${categoryList}">
<tr class="categoryTr" th:each="commonCode:${categoryList}">
<td>
<input type="checkbox">
<input type="checkbox" class="categoryCheckBox" th:value="${commonCode.category}">
</td>
<td>${commonCode.category}</td>
<td th:text="${commonCode.category}"></td>
</tr>
</tbody>
</table>
</div>
<div class="col-7">
<div class="col-7" id="valueDiv">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>
<input type="checkbox" class="valueCheckBox" id="allValueCheckBox">
</th>
<th></th>
<th>설명</th>
</tr>
@ -47,17 +52,6 @@
<tr>
<td colspan="3">분류를 선택해주세요.</td>
</tr>
<!--<tr>
<td>
<input type="checkbox">
</td>
<td>
asdf
</td>
<td>
zxcv
</td>
</tr>-->
</tbody>
</table>
</div>
@ -65,54 +59,57 @@
</div>
<div class="card-footer row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-primary" value="추가" data-bs-toggle="modal" data-bs-target="#addCommonCodeModal">
<input type="button" class="btn btn-danger" value="삭제">
<input type="button" class="btn btn-primary" value="추가" data-bs-toggle="modal" data-bs-target="#commonCodeModal">
<input type="button" class="btn btn-danger" value="삭제" id="deleteCommonCodeBtn">
</div>
</div>
</div>
</div>
</main>
<div class="modal fade" id="addCommonCodeModal" tabindex="-1" aria-labelledby="addCommonCodeModalLabel" aria-hidden="true">
<div class="modal fade" id="commonCodeModal" tabindex="-1" aria-labelledby="commonCodeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addCommonCodeModalLabel">코드 추가</h5>
<h5 class="modal-title" id="commonCodeModalLabel">코드 추가</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="commonCodeForm" action="#" th:action="@{/admin/insertCommonCode}" method="post">
<div class="mb-3 row">
<input type="hidden" name="category">
<input type="hidden" name="category" id="category">
<label class="col-sm-2 col-form-label">분류</label>
<div class="col-sm-5">
<select class="form-select" id="categorySelector" th:attrappend="${categoryList.size()==0?'disabled=':''}">
<div class="col-sm-5" id="categorySelectDiv">
<select class="form-select" id="categorySelector">
<option value="" selected disabled>선택해주세요.</option>
<option th:each="commonCode:${categoryList}" th:value="${commonCode.category}" th:text="${commonCode.category}"></option>
</select>
</div>
<div class="col-sm-5" style="display: none;">
<div class="col-sm-5" id="categoryInputDiv" style="display: none">
<input type="text" id="categoryInput" class="form-control">
</div>
<div class="col-sm-auto">
<input type="checkbox" id="categoryCheckBox">
<label for="categoryCheckBox">직접입력</label>
<div class="col-sm-4">
<input type="checkbox" id="inputSelector">
<label for="inputSelector">직접입력</label>
</div>
</div>
<div class="mb-3 row">
<label for="value" class="col-sm-2 col-form-label"></label>
<div class="col-sm-5">
<input type="text" class="form-control" id="value">
<input type="text" class="form-control" id="value" name="value">
</div>
</div>
<div class="mb-3 row">
<label for="description" class="col-sm-2 col-form-label">설명</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="description">
<input type="text" class="form-control" id="description" name="description">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" id="closeModalBtn">닫기</button>
<button type="button" class="btn btn-primary" id="saveBtn">저장</button>
</div>
</div>
</div>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<table class="table table-striped">
<thead>
<tr>
<th>
<input type="checkbox" id="allValueCheckBox">
</th>
<th></th>
<th>설명</th>
</tr>
</thead>
<tbody>
<tr class="valueTr" th:each="commonCode:${valueList}">
<td>
<input type="checkbox" class="valueCheckBox" th:value="${commonCode.codeSq}">
</td>
<td th:text="${commonCode.value}"></td>
<td th:text="${commonCode.description}"></td>
</tr>
</tbody>
</table>
</html>

View File

@ -7,6 +7,7 @@
<meta charset="UTF-8" />
<title>해양경찰청 파일관리 시스템</title>
<!-- 공통으로 쓰이는 css파일을넣는다.-->
<link rel="stylesheet" th:href="@{/css/common.css}">
<!--bootstrap-->
<!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css">-->

View File

@ -4,16 +4,6 @@
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}">
<th:block layout:fragment="css">
<style>
.form-signin{
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
</style>
</th:block>
<div layout:fragment="content" class="form-signin text-center">
<main>
<!-- Security config의 loginPage("url")와 action url과 동일하게 작성-->