시군구 테이블 백업 기능 추가
parent
1413c15a79
commit
a4d0587d2f
@ -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>
|
@ -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}">추가 >></button>
|
||||
<button type="button" id="btnDel-${pageName}"><< 삭제</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>
|
Loading…
Reference in New Issue