단속연계파일 레이아웃 판단 기능 추가

main
이범준 1 year ago
parent a9219d0779
commit 83059987ac

@ -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<LayoutDescriptor> candidates) {
// TODO
return null;
BiFunction<String, String, Integer> filter = (validType, thisValue) -> {
for(Iterator<LayoutDescriptor> 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);
}
}

@ -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;

@ -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<DataObject> parsedDataList = parser.parsing(fileList);
allParsedDataList.addAll(parsedDataList);
nextTempGroupSeq = parser.getTempGroupSeq() + 1;
}
}

@ -264,6 +264,7 @@ $(document).ready(function(){
data : formData,
success : (resp) => {
if(resp.saved){
$("#uploadFiles--${pageName}").val("");
$P.searchFileList();
} else {
dialog.alert("파일 업로드에 실패하였습니다.");

Loading…
Cancel
Save