From a865704685173fafacff039ba21aa4c6f2120a98 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Wed, 27 Sep 2023 14:25:56 +0900 Subject: [PATCH] =?UTF-8?q?ftp=20=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/cmmn/ftp/FTPUtil.java | 11 ++- .../cokr/xit/fims/crdn/parsing/HiteCom.java | 2 +- .../java/cokr/xit/fims/crdn/parsing/Ino.java | 2 +- .../xit/fims/crdn/parsing/ParsingUtil.java | 6 +- .../crdn/service/bean/ImportServiceBean.java | 4 +- .../xit/fims/crdn/web/Crdn05Controller.java | 79 ++++++++++++------- .../WEB-INF/jsp/fims/crdn/crdn05020-info.jsp | 44 +++++------ 7 files changed, 87 insertions(+), 61 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java index f2f5c1b4..b63dca27 100644 --- a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java @@ -14,6 +14,9 @@ import org.apache.commons.net.ftp.FTPReply; public class FTPUtil { public static boolean fileDown(RemoteSystemInfo rs, String remoteWorkPath, String downloadRoot) { + File f = new File(downloadRoot + remoteWorkPath); + f.mkdirs(); + FTPClient client = null; try { @@ -100,6 +103,7 @@ public class FTPUtil { } } catch (Exception e) { + e.printStackTrace(); throw new RuntimeException("오류 발생"); } finally { // ftp 커넥션이 연결되어 있으면 종료한다. @@ -108,7 +112,7 @@ public class FTPUtil { client.disconnect(); } } catch (Throwable e) { - e.printStackTrace(); + throw new RuntimeException("오류 발생"); } } @@ -127,8 +131,8 @@ public class FTPUtil { if (!file.isFile()) { // 디렉토리리면 함수의 재귀적 방식으로 하위 탐색을 시작한다. - if (!getFileList(client, fileSeparator, work + file.getName() + fileSeparator, files, directories)) { - return false; + if(!getFileList(client, fileSeparator, work + file.getName() + fileSeparator, files, directories)) { + return false; } // directories 리스트에 디렉토리 경로를 추가한다. @@ -147,6 +151,7 @@ public class FTPUtil { } } catch (IOException e) { + e.printStackTrace(); throw new RuntimeException(); } diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/HiteCom.java b/src/main/java/cokr/xit/fims/crdn/parsing/HiteCom.java index 854bfb6f..5c29f269 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/HiteCom.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/HiteCom.java @@ -124,7 +124,7 @@ public class HiteCom implements EquipmentEnterprise { tempGroupSeq++; dataObject.put("TEMP_GROUP_ID", tempGroupSeq); - dataObject.put("ENT_TYPE", "HITECOM"); + dataObject.put("ENT_TYPE", "hitecom"); dataObjectList.add(dataObject); }); diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/Ino.java b/src/main/java/cokr/xit/fims/crdn/parsing/Ino.java index 278ded5e..4382178f 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/Ino.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/Ino.java @@ -91,7 +91,7 @@ public class Ino implements EquipmentEnterprise { } dataObject.put("TEMP_GROUP_ID", tempGroupSeq); - dataObject.put("ENT_TYPE", "INO"); + dataObject.put("ENT_TYPE", "ino"); dataObjectList.add(dataObject); before = dataObject; }); diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/ParsingUtil.java b/src/main/java/cokr/xit/fims/crdn/parsing/ParsingUtil.java index 25f05c80..d2d4620e 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/ParsingUtil.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/ParsingUtil.java @@ -11,13 +11,13 @@ public class ParsingUtil { public static String getWorkDirectoryPath(String institute, String taskSeCd, String entType, String equipmentType) { String workPath = ""; - if(entType.equals("INO")) { + if(entType.equals("ino")) { workPath = "files"+File.separator+"tempForIno"; } - if(entType.equals("KNL")) { + if(entType.equals("knl")) { workPath = "files"+File.separator+"tempForKnl"; } - if(entType.equals("HITECOM")) { + if(entType.equals("hitecom")) { workPath = "files"+File.separator+"tempForHitecom"; } diff --git a/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java b/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java index 0591bddc..b34c9c22 100644 --- a/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java +++ b/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java @@ -91,7 +91,7 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ List fileInfoList = new ArrayList(); - if(entType.equals("INO")) { + if(entType.equals("ino")) { crdn.setCrdnInptSeCd("11"); crdn.setVltnCd("01"); @@ -133,7 +133,7 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ } - if(entType.equals("KNL")) { + if(entType.equals("knl")) { crdn.setCrdnInptSeCd("12"); crdn.setVltnCd("01"); diff --git a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java index 8e78e461..cb941e09 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java @@ -1,5 +1,6 @@ package cokr.xit.fims.crdn.web; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -20,6 +21,8 @@ import cokr.xit.base.code.CommonCode; import cokr.xit.base.file.FileInfo; import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.base.web.ApplicationController; +import cokr.xit.fims.cmmn.ftp.FTPUtil; +import cokr.xit.fims.cmmn.ftp.RemoteSystemInfo; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.dao.CrdnInstMapper; @@ -129,10 +132,10 @@ public class Crdn05Controller extends ApplicationController { String entType = hReq.getParameter("entType"); EquipmentEnterprise enterprise = null; switch(entType){ - case "INO": enterprise = new Ino(); break; - case "KNL": enterprise = new Knl(); break; - case "HITECOM": enterprise = new HiteCom(); break; - case "XIT": enterprise = new XitRecommend(); break; + case "ino": enterprise = new Ino(); break; + case "knl": enterprise = new Knl(); break; + case "hitecom": enterprise = new HiteCom(); break; + case "xit": enterprise = new XitRecommend(); break; //case "": enterprise = new (); break; } @@ -141,24 +144,31 @@ public class Crdn05Controller extends ApplicationController { String equipmentType = hReq.getParameter("equipmentType"); String workPath = ParsingUtil.getWorkDirectoryPath(institute, taskSeCd, entType, equipmentType); - - //ftp G클라우드 - - - //RemoteSystemInfo rs = new RemoteSystemInfo(); - //rs.setIp("211.119.124.9"); - //rs.setId("xituser"); - //rs.setPw("xituser!@"); - //rs.setOsType("linux"); - - //String remoteWorkPath = File.separator + "applications" - // + File.separator + "tempForFTPTest" - // + File.separator + "ino" - // + File.separator; + File workDir = new File(workPath); + workDir.mkdirs(); + + RemoteSystemInfo rs = new RemoteSystemInfo(); + rs.setIp("211.119.124.9"); + rs.setId("xituser"); + rs.setPw("xituser!@"); + rs.setOsType("linux"); + + String remoteWorkPath = File.separator + "applications" + + File.separator + "tempForFTPTest" + + File.separator + entType + + File.separator; try { - //boolean result = FTPUtil.fileDown(rs, remoteWorkPath, workPath); + boolean result = FTPUtil.fileDown(rs, remoteWorkPath, workPath); + if(!result) { + saved = false; + mav.addObject("saved", saved); + return mav; + } } catch (Exception e) { e.printStackTrace(); + saved = false; + mav.addObject("saved", saved); + return mav; } saved = true; @@ -177,10 +187,10 @@ public class Crdn05Controller extends ApplicationController { String entType = hReq.getParameter("entType"); EquipmentEnterprise enterprise = null; switch(entType){ - case "INO": enterprise = new Ino(); break; - case "KNL": enterprise = new Knl(); break; - case "HITECOM": enterprise = new HiteCom(); break; - case "XIT": enterprise = new XitRecommend(); break; + case "ino": enterprise = new Ino(); break; + case "knl": enterprise = new Knl(); break; + case "hitecom": enterprise = new HiteCom(); break; + case "xit": enterprise = new XitRecommend(); break; //case "": enterprise = new (); break; } @@ -189,8 +199,19 @@ public class Crdn05Controller extends ApplicationController { String equipmentType = hReq.getParameter("equipmentType"); String workPath = ParsingUtil.getWorkDirectoryPath(institute, taskSeCd, entType, equipmentType); - //TODO : - + File workDir = new File(workPath); + workDir.mkdirs(); + try { + for(int i=0; i < uploadFiles.length; i++) { + File newFile = new File(workPath+File.separator+uploadFiles[i].getOriginalFilename()); + uploadFiles[i].transferTo(newFile); + } + } catch (Exception e) { + saved = false; + mav.addObject("saved", saved); + return mav; + } + saved = true; mav.addObject("saved", saved); return mav; } @@ -205,10 +226,10 @@ public class Crdn05Controller extends ApplicationController { String entType = hReq.getParameter("entType"); EquipmentEnterprise enterprise = null; switch(entType){ - case "INO": enterprise = new Ino(); break; - case "KNL": enterprise = new Knl(); break; - case "HITECOM": enterprise = new HiteCom(); break; - case "XIT": enterprise = new XitRecommend(); break; + case "ino": enterprise = new Ino(); break; + case "knl": enterprise = new Knl(); break; + case "hitecom": enterprise = new HiteCom(); break; + case "xit": enterprise = new XitRecommend(); break; //case "": enterprise = new (); break; } diff --git a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp index 1e7e0d5a..289f4173 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp @@ -4,7 +4,7 @@
-
+
- - + @@ -263,10 +263,10 @@ $(document).ready(function(){ $("#table-responsive--${pageName}").find("."+$P.entType).find("tbody").setCurrentRow(dataKey); } - if(item.data.ENT_TYPE == "INO"){ + if(item.data.ENT_TYPE == "ino"){ var src = item.data.FILE_PATH; $P.renderImage(src); - } else if(item.data.ENT_TYPE == "HITECOM"){ + } else if(item.data.ENT_TYPE == "hitecom"){ var srcArr = [ "data:image/jpg;base64,"+item.data.CAR_IMAGE, "data:image/jpg;base64,"+item.data.PLATE_IMAGE @@ -292,10 +292,10 @@ $(document).ready(function(){ } if($("#entType--${pageName}").val() == "unkown" - || $("#entType--${pageName}").val() == "KNL" - || $("#entType--${pageName}").val() == "GASAN" - || $("#entType--${pageName}").val() == "ELISOFT" - || $("#entType--${pageName}").val() == "XIT" + || $("#entType--${pageName}").val() == "knl" + || $("#entType--${pageName}").val() == "gasan" + || $("#entType--${pageName}").val() == "elisoft" + || $("#entType--${pageName}").val() == "xit" ){ dialog.alert("해당 업체 연계는 현재 준비중입니다."); return false; @@ -339,13 +339,13 @@ $(document).ready(function(){ return; } + + var formData = new FormData(document.getElementById("frmFirst--${pageName}")); + ajax.post({ url : wctx.url("/${taskSeCd}/crdn/crdn05/020/importFileFromClient.do"), - data : { - taskSeCd : $("#taskSeCd--${pageName}").val(), - entType : $("#entType--${pageName}").val(), - equipmentType : $("#equipmentType--${pageName}").val() - }, + contentType : false, processData : false, + data : formData, success : (resp) => { if(resp.saved){ $P.searchFileList(); @@ -363,9 +363,9 @@ $(document).ready(function(){ $P.parsedInfoControl.setData([]); - if($("#entType--${pageName}").val() == "INO"){ + if($("#entType--${pageName}").val() == "ino"){ $P.entType = "ino"; - } else if($("#entType--${pageName}").val() == "HITECOM"){ + } else if($("#entType--${pageName}").val() == "hitecom"){ $P.entType = "hitecom"; } else { $P.entType = "";