시군구 테이블 백업 기능 추가

main
이범준 9 months ago
parent 1413c15a79
commit a4d0587d2f

@ -1,11 +1,19 @@
package cokr.xit;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import cokr.xit.backup.Backup;
import cokr.xit.backup.service.bean.BackupBean;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.web.AbstractController;
@Controller
@ -13,9 +21,56 @@ public class MainController extends AbstractController {
@Autowired
private RequestMappingHandlerMapping requestHandlers;
@Resource(name = "backupBean")
private BackupBean backupBean;
@GetMapping(name="홈", value={"/", "/index.do"})
public ModelAndView mainPage() {
return new ModelAndView("index");
}
@GetMapping(name="시군구 추가/삭제 메인", value="/sggAddDelMain.do")
public ModelAndView sggAddDelMain() {
ModelAndView mav = new ModelAndView();
mav.setViewName("sgg/sggAddDelMain");
mav.addObject("pageName","sggAddDelMain");
return mav;
}
@GetMapping(name="백업 테이블 및 실사용 테이블 자료 조회", value="/backup/list.do")
public ModelAndView getBackupList(String backupTable, String originalTable, String pkName) {
ModelAndView mav = new ModelAndView("jsonView");
List<DataObject> originalDataList = backupBean.getAllList(originalTable, pkName);
List<DataObject> backupDataList = backupBean.getAllList(backupTable, originalTable, pkName);
mav.addObject("originalDataList", originalDataList);
mav.addObject("backupDataList", backupDataList);
return mav;
}
@PostMapping(name="백업 테이블 자료를 사용 테이블로 복사", value="/backup/activate.do")
public ModelAndView add(Backup backup) {
ModelAndView mav = new ModelAndView("jsonView");
boolean saved = backupBean.activate(backup);
mav.addObject("saved", saved);
return mav;
}
@PostMapping(name="사용 테이블 자료 삭제 및 백업", value="/backup/deactivate.do")
public ModelAndView del(Backup backup) {
ModelAndView mav = new ModelAndView("jsonView");
boolean saved = backupBean.deactivate(backup);
mav.addObject("saved", saved);
return mav;
}
}

@ -0,0 +1,16 @@
package cokr.xit.backup;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Backup {
String originalTable;
String backupTable;
String pkName;
String[] pks;
}

@ -0,0 +1,25 @@
package cokr.xit.backup.dao;
import java.util.List;
import java.util.Map;
import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
import cokr.xit.backup.Backup;
import cokr.xit.foundation.component.AbstractMapper;
import cokr.xit.foundation.data.DataObject;
@Mapper("backupMapper")
public interface BackupMapper extends AbstractMapper {
List<DataObject> selectAllList(Map<String, String> map);
int insertOriginalData(Backup backup);
int deleteOriginalData(Backup backup);
int insertBackupData(Backup backup);
int deleteBackupData(Backup backup);
}

@ -0,0 +1,53 @@
package cokr.xit.backup.service.bean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import cokr.xit.backup.Backup;
import cokr.xit.backup.dao.BackupMapper;
import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.data.DataObject;
@Component("backupBean")
public class BackupBean extends AbstractComponent {
@Resource(name = "backupMapper")
private BackupMapper backupMapper;
public List<DataObject> getAllList(String originalTable, String pkName) {
Map<String,String> map = new HashMap<String,String>();
map.put("originalTable", originalTable);
map.put("pkName", pkName);
return backupMapper.selectAllList(map);
}
public List<DataObject> getAllList(String backupTable, String originalTable, String pkName) {
Map<String,String> map = new HashMap<String,String>();
map.put("originalTable", originalTable);
map.put("backupTable", backupTable);
map.put("pkName", pkName);
return backupMapper.selectAllList(map);
}
public boolean activate(Backup backup) {
return backupMapper.insertOriginalData(backup) > 0;
}
public boolean deactivate(Backup backup) {
backupMapper.deleteBackupData(backup);
int result1 = backupMapper.insertBackupData(backup);
int result2 = backupMapper.deleteOriginalData(backup);
return ((result1 != 0) && (result1 == result2));
}
}

@ -0,0 +1,51 @@
<?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="cokr.xit.backup.dao.BackupMapper">
<select id="selectAllList" parameterType="map">
<choose>
<when test="backupTable != null">
SELECT *
FROM ${backupTable}
WHERE ${pkName} NOT IN (
SELECT ${pkName}
FROM ${originalTable}
)
</when>
<otherwise>
SELECT *
FROM ${originalTable}
</otherwise>
</choose>
ORDER BY ${pkName}
</select>
<insert id="insertOriginalData" parameterType="cokr.xit.backup.Backup">
INSERT
INTO ${originalTable}
SELECT *
FROM ${backupTable}
WHERE ${pkName} IN (<foreach collection="pks" item="pk" separator=",">#{pk}</foreach>)
</insert>
<delete id="deleteBackupData" parameterType="cokr.xit.backup.Backup">
DELETE
FROM ${backupTable}
WHERE ${pkName} IN (<foreach collection="pks" item="pk" separator=",">#{pk}</foreach>)
</delete>
<insert id="insertBackupData" parameterType="cokr.xit.backup.Backup">
INSERT
INTO ${backupTable}
SELECT *
FROM ${originalTable}
WHERE ${pkName} IN (<foreach collection="pks" item="pk" separator=",">#{pk}</foreach>)
</insert>
<delete id="deleteOriginalData" parameterType="cokr.xit.backup.Backup">
DELETE
FROM ${originalTable}
WHERE ${pkName} IN (<foreach collection="pks" item="pk" separator=",">#{pk}</foreach>)
</delete>
</mapper>

@ -54,6 +54,27 @@
});
});
$("#btnForSgg").on("click", function(){
$.ajax({
type : "GET",
ContentType : "text/html;charset=UTF-8",
url : "/sggAddDelMain.do",
data: {},
success: (resp) => {
console.log(resp);
dialog.open({
id: "sggAddDelDialog",
title: "시군구 추가,삭제",
content: resp ,
size: "fullscreen",
init:() => {}
});
}
});
});
$(function(){
});

@ -0,0 +1,190 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<form id="frmEdit--${pageName}">
<div class="d-flex flex-row justify-content-evenly">
<div class="card" style="width:500px;">
<h3>시군구 백업</h3>
<div class="card-datatable text-nowrap">
<div id="backupSgg-DataTables_Table_0_wrapper--${pageName}" class="dataTables_wrapper dt-bootstrap5 no-footer">
<div id="backupSgg-table-responsive--${pageName}" class="table-responsive"
style="overflow-x: scroll;height:500px;overflow-y: scroll;">
<table id="backupSgg-DataTables_Table_0--${pageName}"
class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
<thead class="sticky-thead">
<tr data-key="{SGG_CD}">
<th style="width: 50px;"></th>
<th style="width: 140px;" >시군구코드</th>
<th style="width: 300px;" >시군구명</th>
<th class="cmn dummy-th"></th>
</tr>
</thead>
<tbody id="backupSggTbody--${pageName}">
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="card" style="width:100px;">
<div style="display: flex;flex-direction: column;justify-content: space-evenly;height: 100%;">
<button type="button" id="btnAdd-${pageName}">추가 &gt;&gt;</button>
<button type="button" id="btnDel-${pageName}">&lt;&lt; 삭제</button>
</div>
</div>
<div class="card" style="width:500px;">
<h3>시군구</h3>
<div class="card-datatable text-nowrap">
<div id="originalSgg-DataTables_Table_0_wrapper--${pageName}" class="dataTables_wrapper dt-bootstrap5 no-footer">
<div id="originalSgg-table-responsive--${pageName}" class="table-responsive"
style="overflow-x: scroll;height:500px;overflow-y: scroll;">
<table id="originalSgg-DataTables_Table_0--${pageName}"
class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
<thead class="sticky-thead">
<tr data-key="{SGG_CD}">
<th style="width: 50px;"></th>
<th style="width: 140px;" >시군구코드</th>
<th style="width: 300px;" >시군구명</th>
<th class="cmn dummy-th"></th>
</tr>
</thead>
<tbody id="originalSggTbody--${pageName}">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</form>
<template id="sggRow--${pageName}">
<tr data-key="{SGG_CD}">
<td onclick="{onclick}" ondblclick="{ondblclick}" class="text-center cmn">
<input type="checkbox" value="{SGG_CD}" />
</td>
<td onclick="{onclick}" ondblclick="{ondblclick}" class="text-center cmn">{SGG_CD}</td>
<td onclick="{onclick}" ondblclick="{ondblclick}" class="text-center cmn">{SGG_NM}</td>
<td class="dummy-td cmn"></td>
</tr>
</template>
<template id="sggNotFound--${pageName}">
<tr>
<td valign="top" colspan="14" class="dataTables_empty text-center">
정보를 찾지 못했습니다.
</td>
</tr>
</template>
<script>
var originalDataset = new Dataset({
keymapper : info => info ? info.SGG_CD : ""
});
var backupDataset = new Dataset({
keymapper : info => info ? info.SGG_CD : ""
});
function fnRenderBackupAndOriginal(list,tbodyId,dataset){
$("#"+tbodyId).html("");
if(list != null && list.length > 0){
dataset.setData(list);
} else {
dataset.setData([]);
}
var empty = dataset.empty;
var notFound = [document.getElementById("sggNotFound--${pageName}").innerHTML];
var found = document.getElementById("sggRow--${pageName}").innerHTML;
var replacer = (str, dataItem) => str.replace(/{onclick}/gi, "");
var trs = empty ? notFound : dataset.inStrings(found, replacer);
$("#"+tbodyId).html(trs.join());
}
function getBackupAndOriginalDataList(){
ajax.get({
url : wctx.url("backup/list.do"),
data : {
originalTable : "TB_SGG",
backupTable : "TB_SGG_ORG",
pkName : "SGG_CD"
},
success : (resp) => {
fnRenderBackupAndOriginal(resp.originalDataList,"originalSggTbody--${pageName}", originalDataset);
fnRenderBackupAndOriginal(resp.backupDataList,"backupSggTbody--${pageName}", backupDataset);
}
});
}
$("#btnAdd-${pageName}").on("click", function(){
var checked = $("#backupSggTbody--${pageName}").find("input[type='checkbox']:checked");
if(checked.length < 1){
return;
}
var arr = [];
checked.each(function(){
arr.push(this.value);
});
ajax.post({
url : wctx.url("backup/activate.do"),
data : {
originalTable : "TB_SGG",
backupTable : "TB_SGG_ORG",
pkName : "SGG_CD",
pks : arr.join(",")
},
success : (resp) => {
if(resp.saved){
getBackupAndOriginalDataList();
}
}
});
});
$("#btnDel-${pageName}").on("click", function(){
var checked = $("#originalSggTbody--${pageName}").find("input[type='checkbox']:checked");
if(checked.length < 1){
return;
}
var arr = [];
checked.each(function(){
arr.push(this.value);
});
ajax.post({
url : wctx.url("backup/deactivate.do"),
data : {
originalTable : "TB_SGG",
backupTable : "TB_SGG_ORG",
pkName : "SGG_CD",
pks : arr.join(",")
},
success : (resp) => {
if(resp.saved){
getBackupAndOriginalDataList();
}
}
});
});
$(document).ready(function(){
getBackupAndOriginalDataList();
});
</script>

@ -215,7 +215,9 @@
$("#sinmungoTbody--${pageName}").html("");
var list = resp.list;
var originalDataList = resp.originalDataList;
var backupDataList = resp.backupDataList;
if(list != null && list.length > 0){
sinmungoDataset.setData(list);
} else {
@ -224,16 +226,13 @@
var empty = sinmungoDataset.empty;
var notFound = [document.getElementById("sinmungoNotFound--${pageName}").innerHTML];
var found = document.getElementById("sinmungoRow--${pageName}").innerHTML;
var replacer = (str, dataItem) => str
.replace(/{onclick}/gi, "fnClickSinmungoList('" + dataItem.getValue("SINMUNGO_INNER_KEY") + "');");
var notFound = [document.getElementById("sggNotFound--${pageName}").innerHTML];
var found = document.getElementById("sggRow--${pageName}").innerHTML;
var replacer = (str, dataItem) => str.replace(/{onclick}/gi, "");
var trs = empty ? notFound : sinmungoDataset.inStrings(found, replacer);
$("#sinmungoTbody--${pageName}").html(trs.join());
$("#sinmungoTbody--${pageName}").find("tr").find("td").eq(0).click();
}
});
});

Loading…
Cancel
Save