From 0a10167487ce30646454aef3a3133cc54e1fad50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=84=9D=20=EC=B5=9C?= Date: Wed, 1 Dec 2021 18:54:01 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EA=B8=B0=EB=8A=A5=20=EC=9E=91=EC=97=85?= =?UTF-8?q?=EC=A4=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +- .../controller/adminController.java | 50 ++++++- .../mapper/CommonCodeMapper.java | 3 +- .../dbnt/kcgfilemanager/model/CommonCode.java | 6 + .../dbnt/kcgfilemanager/model/UserInfo.java | 4 + .../service/CommonCodeService.java | 12 +- .../mybatisMapper/CommonCodeMapper.xml | 22 ++- src/main/resources/static/css/common.css | 7 + src/main/resources/static/js/admin/codeMgt.js | 128 ++++++++++++++++++ .../resources/templates/admin/codeMgt.html | 61 ++++----- .../resources/templates/admin/codeValue.html | 24 ++++ .../resources/templates/layout/layout.html | 1 + src/main/resources/templates/login.html | 10 -- 13 files changed, 280 insertions(+), 53 deletions(-) create mode 100644 src/main/resources/static/css/common.css create mode 100644 src/main/resources/static/js/admin/codeMgt.js create mode 100644 src/main/resources/templates/admin/codeValue.html diff --git a/build.gradle b/build.gradle index 616e864..61e71c8 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java index 5a84faf..0006aa1 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java @@ -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 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); + } } diff --git a/src/main/java/com/dbnt/kcgfilemanager/mapper/CommonCodeMapper.java b/src/main/java/com/dbnt/kcgfilemanager/mapper/CommonCodeMapper.java index a6b041e..18e5996 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/mapper/CommonCodeMapper.java +++ b/src/main/java/com/dbnt/kcgfilemanager/mapper/CommonCodeMapper.java @@ -8,5 +8,6 @@ import java.util.List; @Mapper public interface CommonCodeMapper { - List selectCommonCodeToCategory(CommonCode commonCode); + List selectCommonCodeCategory(CommonCode commonCode); + List selectCommonCodeValue(CommonCode commonCode); } diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/CommonCode.java b/src/main/java/com/dbnt/kcgfilemanager/model/CommonCode.java index fa9f460..bb1a5d4 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/CommonCode.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/CommonCode.java @@ -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; } diff --git a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java index 134e9ec..57891a5 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java +++ b/src/main/java/com/dbnt/kcgfilemanager/model/UserInfo.java @@ -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{ diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java b/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java index 41cd359..2d2b6f3 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java @@ -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 selectCommonCodeToCategory(CommonCode commonCode) { - return commonCodeMapper.selectCommonCodeToCategory(commonCode); + public List selectCommonCodeCategory(CommonCode commonCode) { + return commonCodeMapper.selectCommonCodeCategory(commonCode); + } + public List selectCommonCodeValue(CommonCode commonCode) { + return commonCodeMapper.selectCommonCodeValue(commonCode); + } + public void insertCommonCode(CommonCode commonCode) { + commonCodeRepository.save(commonCode); } } diff --git a/src/main/resources/mybatisMapper/CommonCodeMapper.xml b/src/main/resources/mybatisMapper/CommonCodeMapper.xml index f161bf7..6bdc674 100644 --- a/src/main/resources/mybatisMapper/CommonCodeMapper.xml +++ b/src/main/resources/mybatisMapper/CommonCodeMapper.xml @@ -4,11 +4,29 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - SELECT DISTINCT CATEGORY FROM COMMON_CODE - WHERE IS_DELETED <> 'Y' + + + AND IS_DELETED = 'N' + + + \ No newline at end of file diff --git a/src/main/resources/static/css/common.css b/src/main/resources/static/css/common.css new file mode 100644 index 0000000..6827921 --- /dev/null +++ b/src/main/resources/static/css/common.css @@ -0,0 +1,7 @@ + +.form-signin{ + width: 100%; + max-width: 330px; + padding: 15px; + margin: auto; +} \ No newline at end of file diff --git a/src/main/resources/static/js/admin/codeMgt.js b/src/main/resources/static/js/admin/codeMgt.js new file mode 100644 index 0000000..3179824 --- /dev/null +++ b/src/main/resources/static/js/admin/codeMgt.js @@ -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(); +} \ No newline at end of file diff --git a/src/main/resources/templates/admin/codeMgt.html b/src/main/resources/templates/admin/codeMgt.html index a830542..fc6a8de 100644 --- a/src/main/resources/templates/admin/codeMgt.html +++ b/src/main/resources/templates/admin/codeMgt.html @@ -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}"> + + +

코드 관리

@@ -25,20 +28,22 @@ - + - + - ${commonCode.category} +
-
+
- + @@ -47,17 +52,6 @@ -
+ + 설명
분류를 선택해주세요.
@@ -65,54 +59,57 @@
-