단속연계파일등록 수정(중복파일제거)

main
이범준 1 year ago
parent 32dabc9e8e
commit c4383e1c2b

@ -1,6 +1,15 @@
package cokr.xit.fims.cmmn; package cokr.xit.fims.cmmn;
import java.io.File; 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 { public class CmmnUtil {
@ -124,4 +133,42 @@ public class CmmnUtil {
return delCnt; return delCnt;
} }
/**
* .
* @param root
* @return
*/
public static void removeDuplicateFileName(String root) {
try {
List<Path> fileList = Files.walk(Paths.get(root)).filter(Files::isRegularFile).toList();
Map<String, List<Path>> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName()));
Iterator<String> keys = byFileName.keySet().iterator();
while( keys.hasNext() ){
String key = keys.next();
List<Path> 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();
}
}
} }

@ -22,6 +22,7 @@ import cokr.xit.base.file.web.FileInfoFactory;
import cokr.xit.base.user.ManagedUser; import cokr.xit.base.user.ManagedUser;
import cokr.xit.base.user.dao.UserMapper; import cokr.xit.base.user.dao.UserMapper;
import cokr.xit.base.web.ApplicationController; 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.FTPUtil;
import cokr.xit.fims.cmmn.ftp.RemoteSystemInfo; import cokr.xit.fims.cmmn.ftp.RemoteSystemInfo;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
@ -175,6 +176,8 @@ public class Crdn05Controller extends ApplicationController {
mav.addObject("saved", saved); mav.addObject("saved", saved);
return mav; return mav;
} }
CmmnUtil.removeDuplicateFileName(workPath);
} }
saved = true; saved = true;
@ -221,6 +224,7 @@ public class Crdn05Controller extends ApplicationController {
return mav; return mav;
} }
CmmnUtil.removeDuplicateFileName(workPath);
saved = true; saved = true;
mav.addObject("saved", saved); mav.addObject("saved", saved);

@ -3,10 +3,18 @@
<c:set var="pageKorName" scope="request">단속 파일 등록</c:set> <c:set var="pageKorName" scope="request">단속 파일 등록</c:set>
<div class="d-flex" style="flex-flow:column"> <div class="d-flex" style="flex-flow:column">
<div class="d-flex flex-row justify-content-evenly"> <div class="d-flex flex-row justify-content-evenly">
<div class="card" style="min-width:1400px;width:1400px;height:100px;"> <div class="card" style="min-width:1400px;width:1400px;height:80px;">
<form id="frmFirst--${pageName}" method="post" enctype="multipart/form-data"> <form id="frmFirst--${pageName}" method="post" enctype="multipart/form-data">
<div class="row g-1"> <div class="row g-1">
<div class="col-md-4"> <div class="col-md-12">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="direct--${pageName}">
<label class="form-check-label" for="direct--${pageName}">로컬파일업로드</label>
</div>
</div>
</div>
<div class="row g-1">
<div class="col-md-12 d-flex align-items-center flex-nowrap">
<label for="taskSeCd--${pageName}" <label for="taskSeCd--${pageName}"
class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">과태료업무</label> class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">과태료업무</label>
<select id="taskSeCd--${pageName}" name="taskSeCd" class="form-select" disabled> <select id="taskSeCd--${pageName}" name="taskSeCd" class="form-select" disabled>
@ -16,21 +24,15 @@
>${item.value}</option> >${item.value}</option>
</c:forEach> </c:forEach>
</select> </select>
</div> <span id="uploadFilesArea" hidden>
<div class="col-md-4"> <label for="uploadFiles--${pageName}"
<span class="d-flex justify-content-end float-end ms-auto me-4"> class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">파일</label>
<button type="button" id="btnSearch--${pageName}" class="btn btn-primary">조회</button> <input type="file" id="uploadFiles--${pageName}" name="uploadFiles"
multiple="multiple" class="form-control"/>
</span> </span>
</div> <span class="d-flex justify-content-end float-start ms-4">
<div class="col-md-4 d-flex align-items-center flex-nowrap"> <button type="button" id="btnSearch--${pageName}" class="btn btn-primary">조회</button>
<button type="button" id="btnFileUpload--${pageName}" class="btn btn-primary" hidden>업로드</button>
</div>
<div class="col-md-12 d-flex align-items-center flex-nowrap">
<label for="uploadFiles--${pageName}"
class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">파일</label>
<input type="file" id="uploadFiles--${pageName}" name="uploadFiles" multiple="multiple" class="form-control"/>
<span class="d-flex justify-content-end float-end ms-auto me-4">
<button type="button" id="btnFileUpload--${pageName}" class="btn btn-primary">업로드</button>
</span> </span>
</div> </div>
</div> </div>
@ -248,13 +250,13 @@ $(document).ready(function(){
//로컬파일업로드 //로컬파일업로드
$P.uploadLocalFile = () => { $P.uploadLocalFile = () => {
if($("#localFile--${pageName}").val() == ""){ if($("#uploadFiles--${pageName}").val() == ""){
dialog.alert("파일이 없습니다."); dialog.alert("파일이 없습니다.");
return; return;
} }
var formData = new FormData(document.getElementById("frmFirst--${pageName}")); var formData = new FormData(document.getElementById("frmFirst--${pageName}"));
formData.append("taskSeCd", "${taskSeCd}");
ajax.post({ ajax.post({
url : wctx.url("/${taskSeCd}/crdn/crdn05/020/importFileFromClient.do"), url : wctx.url("/${taskSeCd}/crdn/crdn05/020/importFileFromClient.do"),
@ -458,6 +460,18 @@ $(document).ready(function(){
$("#btnDelete--${pageName}").on("click", function(){ $P.deleteFile(); }); $("#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([]); $P.parsedInfoControl.setData([]);
}); });

Loading…
Cancel
Save