diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 727818f8..309aca64 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -1,6 +1,15 @@ package cokr.xit.fims.cmmn; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class CmmnUtil { @@ -124,4 +133,42 @@ public class CmmnUtil { return delCnt; } + + /** + * 폴더 경로에 파일명이 동일한 파일이 여러 개 있을 경우 수정일자가 가장 마지막인 파일만 남기고 삭제한다. + * @param root 경로 + * @return 삭제된 폴더수 + */ + public static void removeDuplicateFileName(String root) { + try { + + List fileList = Files.walk(Paths.get(root)).filter(Files::isRegularFile).toList(); + + Map> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName())); + + Iterator keys = byFileName.keySet().iterator(); + + while( keys.hasNext() ){ + String key = keys.next(); + List sameNameFileList = byFileName.get(key); + if(sameNameFileList.size() < 2) { + continue; + } + + Path latest = sameNameFileList.stream() + .max(Comparator.comparing(item -> item.toFile().lastModified())) + .orElseThrow(); + + for(Path sameNameFile : sameNameFileList) { + if(!sameNameFile.equals(latest)) { + sameNameFile.toFile().delete(); + } + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } } 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 8a482406..9001d7df 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java @@ -22,6 +22,7 @@ import cokr.xit.base.file.web.FileInfoFactory; import cokr.xit.base.user.ManagedUser; import cokr.xit.base.user.dao.UserMapper; import cokr.xit.base.web.ApplicationController; +import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.ftp.FTPUtil; import cokr.xit.fims.cmmn.ftp.RemoteSystemInfo; import cokr.xit.fims.crdn.Crdn; @@ -175,6 +176,8 @@ public class Crdn05Controller extends ApplicationController { mav.addObject("saved", saved); return mav; } + + CmmnUtil.removeDuplicateFileName(workPath); } saved = true; @@ -221,6 +224,7 @@ public class Crdn05Controller extends ApplicationController { return mav; } + CmmnUtil.removeDuplicateFileName(workPath); saved = true; mav.addObject("saved", saved); 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 91ff3b78..6a1032ea 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 @@ -3,10 +3,18 @@ 단속 파일 등록
-
+
-
+
+
+ + +
+
+
+
+
-
-
- - + -
-
- -
-
- - - - + + +
@@ -248,13 +250,13 @@ $(document).ready(function(){ //로컬파일업로드 $P.uploadLocalFile = () => { - if($("#localFile--${pageName}").val() == ""){ + if($("#uploadFiles--${pageName}").val() == ""){ dialog.alert("파일이 없습니다."); return; } - var formData = new FormData(document.getElementById("frmFirst--${pageName}")); + formData.append("taskSeCd", "${taskSeCd}"); ajax.post({ url : wctx.url("/${taskSeCd}/crdn/crdn05/020/importFileFromClient.do"), @@ -458,7 +460,19 @@ $(document).ready(function(){ $("#btnDelete--${pageName}").on("click", function(){ $P.deleteFile(); }); - + $("#direct--${pageName}").on("click", function(){ + if($(this).is(":checked")){ + $("#uploadFilesArea").removeAttr("hidden"); + $("#btnFileUpload--${pageName}").removeAttr("hidden"); + $("#btnSearch--${pageName}").attr("hidden","hidden"); + } else { + $("#uploadFilesArea").attr("hidden","hidden"); + $("#btnFileUpload--${pageName}").attr("hidden","hidden"); + $("#btnSearch--${pageName}").removeAttr("hidden"); + $("#uploadFiles--${pageName}").val(""); + } + }); + $P.parsedInfoControl.setData([]); });