주소구축 기능 추가
parent
9be4006690
commit
6cab1efd7a
@ -0,0 +1,17 @@
|
||||
package externalsystem.juso;
|
||||
|
||||
import cokr.xit.foundation.AbstractEntity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class EstablishJusoRequest extends AbstractEntity {
|
||||
private String driver;
|
||||
private String dbConn;
|
||||
private String dbUserId;
|
||||
private String dbPassword;
|
||||
private String tableSpace;
|
||||
private String tableName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package externalsystem.juso;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class EstablishJusoThread implements Runnable {
|
||||
|
||||
private EstablishJusoRequest vo;
|
||||
|
||||
public EstablishJusoThread(EstablishJusoRequest vo) {
|
||||
this.vo = vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String workDirPath = "files/juso";
|
||||
|
||||
File workDir = new File(workDirPath);
|
||||
String[] txtNames = workDir.list();
|
||||
|
||||
BufferedReader reader = null;
|
||||
|
||||
StringBuffer strSQL = new StringBuffer();
|
||||
strSQL.append("INSERT INTO "+vo.getTableSpace()+"."+vo.getTableName()
|
||||
+" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
|
||||
Connection conn = null;
|
||||
try {
|
||||
|
||||
conn = getConn(vo.getDriver(), vo.getDbConn(),vo.getDbUserId(),vo.getDbPassword());
|
||||
|
||||
for(int i=0; i < txtNames.length; i++) {
|
||||
PreparedStatement ps = conn.prepareStatement(strSQL.toString());
|
||||
reader = new BufferedReader(new InputStreamReader(new FileInputStream(workDir+"/"+txtNames[i]),"MS949"));
|
||||
for(String line = reader.readLine(); line != null; line = reader.readLine()) {
|
||||
if(!line.equals("")) {
|
||||
String[] params = line.split(Pattern.quote("|"), -1);
|
||||
|
||||
for(int j=0; j<params.length;j++) {
|
||||
ps.setString(j, params[j]);
|
||||
}
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
conn.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Connection getConn(String driver, String connInfo, String id, String pw) throws Exception{
|
||||
Class.forName(driver);
|
||||
return DriverManager.getConnection(connInfo, id, pw);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package externalsystem.juso.web;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import cokr.xit.foundation.web.AbstractController;
|
||||
import externalsystem.juso.EstablishJusoRequest;
|
||||
import externalsystem.juso.EstablishJusoThread;
|
||||
import externalsystem.juso.service.JusoService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(name="주소", value="/juso")
|
||||
public class JusoController extends AbstractController {
|
||||
|
||||
@Resource(name="jusoService")
|
||||
private JusoService jusoService;
|
||||
|
||||
@RequestMapping(name="주소구축팝업", value="/establishJusoMain.do")
|
||||
public ModelAndView establishJusoMain(HttpServletRequest req) {
|
||||
|
||||
ModelAndView mav = new ModelAndView("juso/establishJuso-main");
|
||||
mav.addObject("pageName", "establishJusoMain");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@RequestMapping(name="주소파일업로드", value="/fileUpload.do")
|
||||
public ModelAndView fileUpload(HttpServletRequest req, MultipartFile[] txts) {
|
||||
|
||||
String workDirPath = "files/juso";
|
||||
|
||||
File workDir = new File(workDirPath);
|
||||
|
||||
try {
|
||||
if(workDir.exists()) {
|
||||
FileUtils.cleanDirectory(workDir);
|
||||
} else {
|
||||
workDir.mkdirs();
|
||||
}
|
||||
|
||||
for(MultipartFile txt : txts) {
|
||||
String fileName = txt.getOriginalFilename();
|
||||
String newFileFullPath = workDirPath + "/" + fileName;
|
||||
File newFile = new File(newFileFullPath);
|
||||
txt.transferTo(newFile);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ModelAndView mav = new ModelAndView("jsonView");
|
||||
mav.addObject("result", "ok");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@RequestMapping(name="주소구축", value="/establishJuso.do")
|
||||
public ModelAndView establishJuso(HttpServletRequest req, EstablishJusoRequest jusoReq) {
|
||||
|
||||
EstablishJusoThread runnable = new EstablishJusoThread(jusoReq);
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setName("establishJusoThread");
|
||||
thread.start();
|
||||
|
||||
ModelAndView mav = new ModelAndView("jsonView");
|
||||
mav.addObject("result", "ok");
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||
<div style="border: 1px solid black;margin-bottom: 30px;">
|
||||
|
||||
<form id="frmFileInfo--${pageName}" method="post" enctype="multipart/form-data">
|
||||
<strong>주소파일</strong><br/>
|
||||
<input type="file" name="txts" multiple /><br/>
|
||||
<button type="button" id="btnFileUpload--${pageName}">주소파일업로드</button>
|
||||
</form>
|
||||
</div>
|
||||
<div style="border: 1px solid black;">
|
||||
|
||||
<form id="frmDatabaseInfo--${pageName}">
|
||||
db드라이버<input type="text" name="driver"
|
||||
list="driverList--${pageName}" class="w-px-350"/>
|
||||
<br/>
|
||||
db접속정보<input type="text" name="dbConn" placeholder="드라이버:@아이피:포트:서비스명"
|
||||
list="dbConnList--${pageName}" class="w-px-350"/>
|
||||
<br/>
|
||||
db유저아이디<input type="text" name="dbUserId" />
|
||||
<br/>
|
||||
db패스워드<input type="text" name="dbPassword" />
|
||||
<br/>
|
||||
테이블스페이스<input type="text" name="tableSpace" />
|
||||
<br/>
|
||||
테이블명<input type="text" name="tableName" />
|
||||
<br/>
|
||||
</form>
|
||||
|
||||
<button type="button" id="btnEstablishJuso--${pageName}">주소구축</button>
|
||||
|
||||
</div>
|
||||
|
||||
<datalist id="driverList--${pageName}">
|
||||
<option>com.tmax.tibero.jdbc.TbDriver</option>
|
||||
</datalist>
|
||||
|
||||
<datalist id="dbConnList--${pageName}">
|
||||
<option>jdbc:tibero:thin:@211.119.124.22:8629:tibero</option>
|
||||
</datalist>
|
||||
|
||||
<script>
|
||||
$("#btnFileUpload--${pageName}").on("click",function(){
|
||||
|
||||
var formData = new FormData(document.getElementById("frmFileInfo--${pageName}"));
|
||||
|
||||
ajax.post({
|
||||
url: wctx.url("juso/fileUpload.do"),
|
||||
data: formData,
|
||||
contentType : false, processData : false,
|
||||
success: (resp) => {
|
||||
dialog.alert({
|
||||
content : "업로드되었습니다.",
|
||||
init : function(){},
|
||||
onClose : () => {}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#btnEstablishJuso--${pageName}").on("click",function(){
|
||||
var formData = new FormData(document.getElementById("frmDatabaseInfo--${pageName}"));
|
||||
|
||||
ajax.post({
|
||||
url: wctx.url("juso/establishJuso.do"),
|
||||
data: formData,
|
||||
contentType : false, processData : false,
|
||||
success: (resp) => {
|
||||
dialog.alert({
|
||||
content : "주소구축 요청완료.",
|
||||
init : function(){},
|
||||
onClose : () => {}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
Binary file not shown.
Loading…
Reference in New Issue