From 83059987ace49ac7aa15b168a9dbc18201669fa7 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Wed, 18 Oct 2023 10:43:39 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A8=EC=86=8D=EC=97=B0=EA=B3=84=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=20=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crdn/parsing/LayoutDiscriminator.java | 126 +++++++++++++++++- .../xit/fims/crdn/parsing/LayoutParser.java | 10 +- .../xit/fims/crdn/web/Crdn05Controller.java | 4 + .../WEB-INF/jsp/fims/crdn/crdn05020-info.jsp | 1 + 4 files changed, 138 insertions(+), 3 deletions(-) diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutDiscriminator.java b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutDiscriminator.java index 1cce75df..a8461a2d 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutDiscriminator.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutDiscriminator.java @@ -1,14 +1,136 @@ package cokr.xit.fims.crdn.parsing; +import java.util.Iterator; import java.util.List; +import java.util.function.BiFunction; +import org.apache.commons.io.FilenameUtils; import org.springframework.web.multipart.MultipartFile; public class LayoutDiscriminator { public static LayoutDescriptor choice(MultipartFile[] fileList, List candidates) { - // TODO - return null; + + BiFunction filter = (validType, thisValue) -> { + for(Iterator it = candidates.iterator(); it.hasNext();){ + LayoutDescriptor descriptor = it.next(); + + switch (validType) { + case "fileGroupIsThis": { + if(!descriptor.getFileGroup().equals(thisValue)){ + it.remove(); + } + break; + } + case "notUseThisFileNameSeperator": { + if(descriptor.getFileNameSeperator().equals(thisValue)){ + it.remove(); + } + break; + } + case "fileNameLengthIsThis": { + if(descriptor.getFileNameLength() != null) { + if(!descriptor.getFileNameLength().equals(thisValue)){ + it.remove(); + } + } + break; + } + case "fileNameLengthIsNotFixed": { + if(descriptor.getFileNameLength() != null){ + it.remove(); + } + break; + } + } + } + + return candidates.size(); + }; + + boolean hasTxt = false; //txt파일 포함 여부 + boolean hasJpg = false; //jpg파일 포함 여부 + boolean hasUnderbar = false; //파일명에 언더바 포함 여부 + boolean hasComma = false; //파일명에 콤마 포함 여부 + boolean sameAllFileNameLength = true; //모든 파일명 길이 동일 여부 + + int fileNameLengthTemp = 0; + for(int i=0;i < fileList.length; i++) { + + String fileName = fileList[i].getOriginalFilename(); + String extension = FilenameUtils.getExtension(fileName); + String noExtensionName= FilenameUtils.removeExtension(fileName); + + if(fileNameLengthTemp == 0) { + fileNameLengthTemp = fileName.length(); + } + + int fileNameLength = fileName.length(); + if(fileNameLength != fileNameLengthTemp) { + sameAllFileNameLength = false; + } + + if(extension.toUpperCase().equals("TXT")) { + hasTxt = true; + } + if(extension.toUpperCase().equals("JPG")) { + hasJpg = true; + } + + if(noExtensionName.contains("_")) { + hasUnderbar = true; + } + if(noExtensionName.contains(",")) { + hasComma = true; + } + } + + // + String fileGroup = ""; + if(hasTxt) { + fileGroup = "TXT"; + } else if(hasJpg) { + fileGroup = "JPG"; + } else { + fileGroup = "BIN"; + } + + if(filter.apply("fileGroupIsThis", fileGroup) == 1) { + return candidates.get(0); + } + + if(!hasUnderbar) { + if(filter.apply("notUseThisSeperator", "_") == 1) { + return candidates.get(0); + } + } + + if(!hasComma) { + if(filter.apply("notUseThisFileNameSeperator", ",") == 1) { + return candidates.get(0); + } + } + + if(sameAllFileNameLength) { + MultipartFile sample = fileList[0]; + int nameLength = sample.getOriginalFilename().length(); + if(filter.apply("fileNameLengthIsThis", Integer.toString(nameLength)) == 1) { + return candidates.get(0); + } + } else { + if(filter.apply("fileNameLengthIsNotFixed", "") == 1) { + return candidates.get(0); + } + } + + + + + if(candidates.size() != 1) { + throw new RuntimeException("파일의 레이아웃 서식을 구분할 수 없습니다."); + } + + return candidates.get(0); } } diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java index 6d796812..e57b9d35 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/LayoutParser.java @@ -23,9 +23,17 @@ import net.minidev.json.parser.ParseException; abstract public class LayoutParser { - protected DataObject before = new DataObject(); protected int tempGroupSeq = 1; + public int getTempGroupSeq() { + return this.tempGroupSeq; + } + public void setTempGroupSeq(int tempGroupSeq) { + this.tempGroupSeq = tempGroupSeq; + } + + protected DataObject before = new DataObject(); + protected String groupingType; protected Need need; 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 9001d7df..13e6281e 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn05Controller.java @@ -252,6 +252,8 @@ public class Crdn05Controller extends ApplicationController { throw new RuntimeException("연계파일 레이아웃 정보 조회에 실패하였습니다."); } + + int nextTempGroupSeq = 1; for(int i=0; i < layoutDescriptors.size(); i++) { String workPath = layoutDescriptors.get(i).getLinkFileLocation(); @@ -269,6 +271,7 @@ public class Crdn05Controller extends ApplicationController { case "JPG": parser = new OnlyImageParser(); break; case "BIN": parser = new SingleFileParser(); break; } + parser.setTempGroupSeq(nextTempGroupSeq); parser.addCommonCode(codeInfo); parser.setDescriptor(layoutDescriptors.get(i)); @@ -276,6 +279,7 @@ public class Crdn05Controller extends ApplicationController { if(!fileList.isEmpty()) { List parsedDataList = parser.parsing(fileList); allParsedDataList.addAll(parsedDataList); + nextTempGroupSeq = parser.getTempGroupSeq() + 1; } } 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 6a1032ea..03635e4c 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 @@ -264,6 +264,7 @@ $(document).ready(function(){ data : formData, success : (resp) => { if(resp.saved){ + $("#uploadFiles--${pageName}").val(""); $P.searchFileList(); } else { dialog.alert("파일 업로드에 실패하였습니다.");