diff --git a/src/main/java/cokr/xit/MainController.java b/src/main/java/cokr/xit/MainController.java index 4424dcdf..7985301c 100644 --- a/src/main/java/cokr/xit/MainController.java +++ b/src/main/java/cokr/xit/MainController.java @@ -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 originalDataList = backupBean.getAllList(originalTable, pkName); + List 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; + } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/backup/Backup.java b/src/main/java/cokr/xit/backup/Backup.java new file mode 100644 index 00000000..74f541d8 --- /dev/null +++ b/src/main/java/cokr/xit/backup/Backup.java @@ -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; + + +} diff --git a/src/main/java/cokr/xit/backup/dao/BackupMapper.java b/src/main/java/cokr/xit/backup/dao/BackupMapper.java new file mode 100644 index 00000000..b5bbc321 --- /dev/null +++ b/src/main/java/cokr/xit/backup/dao/BackupMapper.java @@ -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 selectAllList(Map map); + + int insertOriginalData(Backup backup); + + int deleteOriginalData(Backup backup); + + int insertBackupData(Backup backup); + + int deleteBackupData(Backup backup); + +} diff --git a/src/main/java/cokr/xit/backup/service/bean/BackupBean.java b/src/main/java/cokr/xit/backup/service/bean/BackupBean.java new file mode 100644 index 00000000..eb137bb9 --- /dev/null +++ b/src/main/java/cokr/xit/backup/service/bean/BackupBean.java @@ -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 getAllList(String originalTable, String pkName) { + Map map = new HashMap(); + map.put("originalTable", originalTable); + map.put("pkName", pkName); + return backupMapper.selectAllList(map); + } + + public List getAllList(String backupTable, String originalTable, String pkName) { + Map map = new HashMap(); + 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)); + } + + + +} diff --git a/src/main/resources/sql/mapper/backup/backup-mapper.xml b/src/main/resources/sql/mapper/backup/backup-mapper.xml new file mode 100644 index 00000000..ae602622 --- /dev/null +++ b/src/main/resources/sql/mapper/backup/backup-mapper.xml @@ -0,0 +1,51 @@ + + + + + + + +INSERT + INTO ${originalTable} +SELECT * + FROM ${backupTable} + WHERE ${pkName} IN (#{pk}) + + + +DELETE + FROM ${backupTable} + WHERE ${pkName} IN (#{pk}) + + + +INSERT + INTO ${backupTable} +SELECT * + FROM ${originalTable} + WHERE ${pkName} IN (#{pk}) + + + +DELETE + FROM ${originalTable} + WHERE ${pkName} IN (#{pk}) + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index a7ebc494..0b9cd3bc 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -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(){ }); diff --git a/src/main/webapp/WEB-INF/jsp/sgg/sggAddDelMain.jsp b/src/main/webapp/WEB-INF/jsp/sgg/sggAddDelMain.jsp new file mode 100644 index 00000000..bbaa75e6 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/sgg/sggAddDelMain.jsp @@ -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"%> +
+
+
+

시군구 백업

+ +
+ +
+ +
+ +
+
+ + +
+
+ +
+

시군구

+ +
+ +
+ +
+ + +
+ + +
+ + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/sinmungo/admin-main.jsp b/src/main/webapp/WEB-INF/jsp/sinmungo/admin-main.jsp index 41084599..488cebc5 100644 --- a/src/main/webapp/WEB-INF/jsp/sinmungo/admin-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/sinmungo/admin-main.jsp @@ -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(); } }); });