단속연계파일 파싱 수정

main
이범준 1 year ago
parent c77ff1abec
commit c41039b876

@ -6,10 +6,8 @@ import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -40,37 +38,65 @@ public class AttachedTxtParser extends LayoutParser{
dataObject.put("FILE_GROUP_TYPE", "TXT");
File file = item.toFile();
String filePath = file.getPath();
dataObject.put("FILE_PATH", filePath);
String fileName = file.getName();
dataObject.put("FILE_NAME", fileName);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
dataObject.put("FILE_LAST_MODIFIED", sdf.format(new Date(file.lastModified())));
dataObject.put("FILE_SIZE", file.length()+" byte");
this.setFileDefaultInfo(dataObject, file);
String fileExtension = FilenameUtils.getExtension(fileName);
dataObject.put("FILE_EXTENSION", fileExtension);
String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME"));
boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0;
if(!isUserUpload) {
dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName());
this.analyzeFileName(dataObject, noExtensionName);
this.refineValue(dataObject);
try {
JSONParser jsonParser = new JSONParser(-1);
JSONArray jsonArray = (JSONArray)jsonParser.parse(descriptor.getContentItems());
} catch (Exception e) {
throw new RuntimeException(e);
}
if(!before.isEmpty()) {
boolean isChangeTempGroup = this.isChangeCrackdown(dataObject, before);
if(isChangeTempGroup) {
tempGroupSeq++;
}
}
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
String noExtensionName = FilenameUtils.removeExtension(fileName);
dataObjectList.add(dataObject);
before = dataObject;
});
this.analyzeFileName(dataObject, noExtensionName);
return dataObjectList;
}
this.refineValue(dataObject);
@Override
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
String currentFileNamePrefix = currentItem.string("FILE_NAME").substring(0,25);
String beforeFileNamePrefix = beforeItem.string("FILE_NAME").substring(0,25);
boolean isMetaData = fileExtension.toUpperCase().equals("TXT");
if(currentFileNamePrefix.equals(beforeFileNamePrefix)) {
return false;
} else {
return true;
}
}
public void analyzeFileContent(DataObject dataObject, File file) {
try {
JSONParser jsonParser = new JSONParser(-1);
JSONArray jsonArray = (JSONArray)jsonParser.parse(descriptor.getContentItems());
boolean isMetaData = dataObject.string("FILE_EXTENSION").toUpperCase().equals("TXT");
if(isMetaData) {
@ -82,7 +108,7 @@ public class AttachedTxtParser extends LayoutParser{
int partSplitCursor = 0;
if(!descriptor.getContentSecondSeperator().equals("")) {
contentDivision = smartSplit(content, descriptor.getContentSecondSeperator());
contentDivision = this.smartSplit(content, descriptor.getContentSecondSeperator());
part = contentDivision[contentDivisionIndex];
} else {
part = content;
@ -104,7 +130,7 @@ public class AttachedTxtParser extends LayoutParser{
}
}
String[] partSplit = smartSplit(part, descriptor.getContentSeperator());
String[] partSplit = this.smartSplit(part, descriptor.getContentSeperator());
if(partSplit.length > partSplitCursor) {
dataObject.put(key, partSplit[partSplitCursor]);
@ -136,35 +162,9 @@ public class AttachedTxtParser extends LayoutParser{
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
if(!before.isEmpty()) {
boolean isChangeTempGroup = this.isChangeCrackdown(dataObject, before);
if(isChangeTempGroup) {
tempGroupSeq++;
}
}
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
dataObjectList.add(dataObject);
before = dataObject;
});
return dataObjectList;
}
@Override
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
String currentFileNamePrefix = currentItem.string("FILE_NAME").substring(0,25);
String beforeFileNamePrefix = beforeItem.string("FILE_NAME").substring(0,25);
if(currentFileNamePrefix.equals(beforeFileNamePrefix)) {
return false;
} else {
return true;
} catch (Exception e) {
e.printStackTrace();
}
}

@ -1,13 +1,19 @@
package cokr.xit.fims.crdn.parsing;
import java.io.File;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import org.apache.commons.io.FilenameUtils;
import cokr.xit.base.code.CommonCode;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.foundation.data.DataObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@ -64,6 +70,25 @@ abstract public class LayoutParser {
this.descriptor = descriptor;
}
public void setFileDefaultInfo(DataObject dataObject, File file) {
String filePath = file.getPath();
dataObject.put("FILE_PATH", filePath);
String fileName = file.getName();
dataObject.put("FILE_NAME", fileName);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
dataObject.put("FILE_LAST_MODIFIED", sdf.format(new Date(file.lastModified())));
dataObject.put("FILE_SIZE", file.length()+" byte");
String fileExtension = FilenameUtils.getExtension(fileName);
dataObject.put("FILE_EXTENSION", fileExtension);
boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0;
if(!isUserUpload) {
dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName());
}
}
/** .<br />
* @param fileList
* @return
@ -130,13 +155,15 @@ abstract public class LayoutParser {
JSONParser jsonParser = new JSONParser(-1);
JSONArray jsonArray = (JSONArray)jsonParser.parse(fileNameItmesJSONString);
String[] fileNameSplit = {};
if(descriptor.getFileNameSeperator().equals("byte")) {
//TODO
fileNameSplit = this.smartSplit(noExtensionName, jsonArray);
} else {
String[] fileNameSplit = noExtensionName.split(Matcher.quoteReplacement(descriptor.getFileNameSeperator()));
fileNameSplit = this.smartSplit(noExtensionName, descriptor.getFileNameSeperator());
}
for(int i=0; i<jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
@ -150,8 +177,6 @@ abstract public class LayoutParser {
}
}
}
} catch (ParseException e) {
e.printStackTrace();
}
@ -169,4 +194,37 @@ abstract public class LayoutParser {
return string.split(Matcher.quoteReplacement(sep));
}
}
public String[] smartSplit(String string, JSONArray jsonArray) {
List<Integer> byteNums = new ArrayList();
for(int i=0; i<jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
String key = jsonObject.keySet().iterator().next();
int byteNum = Integer.parseInt((String)jsonObject.get(key));
byteNums.add(byteNum);
}
String[] result = new String[byteNums.size()];
int cursor = 1;
for(int i=0; i<byteNums.size(); i++) {
int byteNum = byteNums.get(i);
result[i] = CmmnUtil.substringByBytes(string, cursor, cursor+(byteNum-1));
cursor += byteNum;
}
return result;
}
public int getSumByte(JSONArray jsonArray){
int result = 0;
for(int i=0; i<jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
String key = jsonObject.keySet().iterator().next();
int byteNum = Integer.parseInt((String)jsonObject.get(key));
result += byteNum;
}
return result;
}
}

@ -2,9 +2,7 @@ package cokr.xit.fims.crdn.parsing;
import java.io.File;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@ -30,27 +28,14 @@ public class OnlyImageParser extends LayoutParser {
sortedFileList.forEach(item -> {
DataObject dataObject = this.createParsedDataObject();
dataObject.put("FILE_GROUP_TYPE", "JPG");
File file = item.toFile();
String filePath = file.getPath();
dataObject.put("FILE_PATH", filePath);
String fileName = file.getName();
dataObject.put("FILE_NAME", fileName);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
dataObject.put("FILE_LAST_MODIFIED", sdf.format(new Date(file.lastModified())));
dataObject.put("FILE_SIZE", file.length()+" byte");
String extension = FilenameUtils.getExtension(fileName);
dataObject.put("FILE_EXTENSION", extension);
boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0;
if(!isUserUpload) {
dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName());
}
this.setFileDefaultInfo(dataObject, file);
String noExtensionName = FilenameUtils.removeExtension(fileName);
String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME"));
this.analyzeFileName(dataObject, noExtensionName);

@ -1,23 +1,25 @@
package cokr.xit.fims.crdn.parsing;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Base64.Encoder;
import java.util.Date;
import java.util.List;
import cokr.xit.base.file.FileInfo;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.foundation.data.DataObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
public class SingleFileParser extends LayoutParser {
@ -34,65 +36,62 @@ public class SingleFileParser extends LayoutParser {
dataObject.put("FILE_GROUP_TYPE", "BIN");
File file = item.toFile();
String filePath = file.getPath();
dataObject.put("FILE_PATH", filePath);
String fileName = file.getName();
dataObject.put("FILE_NAME", fileName);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
dataObject.put("FILE_LAST_MODIFIED", sdf.format(new Date(file.lastModified())));
dataObject.put("FILE_SIZE", file.length()+" byte");
this.setFileDefaultInfo(dataObject, file);
dataObject.put("FILE_EXTENSION","");
boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0;
if(!isUserUpload) {
dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName());
this.analyzeFileContent(dataObject, file);
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
tempGroupSeq++;
dataObjectList.add(dataObject);
});
return dataObjectList;
}
//파일내용
String fileCn0 = "";
@Override
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
return true;
}
public void analyzeFileContent(DataObject dataObject, File file) {
try {
JSONParser jsonParser = new JSONParser(-1);
JSONArray jsonArray = (JSONArray)jsonParser.parse(descriptor.getContentItems());
BufferedReader textReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("EUC-KR")));
String textConent = CmmnUtil.substringByBytes(org.apache.commons.io.IOUtils.toString(textReader), 1, this.getSumByte(jsonArray));
String[] contentSplit = {};
fileCn0 = Files.readString(item, Charset.forName("ISO-8859-1"));
} catch (IOException e) {
e.printStackTrace();
if(descriptor.getContentSeperator().equals("byte")) {
contentSplit = this.smartSplit(textConent, jsonArray);
} else {
contentSplit = this.smartSplit(textConent, descriptor.getContentSeperator());
}
String fileCn = "";
try {
fileCn = new String(fileCn0.getBytes("ISO-8859-1"), "EUC-KR");
} catch (Exception e) {
throw new RuntimeException(e);
for(int i=0; i<jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
String key = jsonObject.keySet().iterator().next();
if(contentSplit.length > i) {
dataObject.put(key, contentSplit[i]);
} else {
dataObject.put(key, "");
}
}
BufferedReader imageReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("ISO-8859-1")));
dataObject.put("TEXT_SIZE", CmmnUtil.substringByBytes(fileCn, 0, 7));
dataObject.put("EQPMNT_CD", CmmnUtil.substringByBytes(fileCn, 8, 12));
dataObject.put("CAR_VELOCITY", CmmnUtil.substringByBytes(fileCn, 13, 15).replaceAll("^0+", "")); //차량속도
dataObject.put("CAR_TYPE", CmmnUtil.substringByBytes(fileCn, 16, 16)); //차종(미사용)
dataObject.put("ROAD_CD", CmmnUtil.substringByBytes(fileCn, 17, 17)); //도로코드(미사용)
dataObject.put("CRDN_YMD", CmmnUtil.substringByBytes(fileCn, 18, 25));
dataObject.put("CRDN_TM", CmmnUtil.substringByBytes(fileCn, 26, 31));
dataObject.put("VHRNO", CmmnUtil.substringByBytes(fileCn, 32, 43).trim());
dataObject.put("MOSC_X", CmmnUtil.substringByBytes(fileCn, 44, 47).replaceAll("^0+", ""));
dataObject.put("MOSC_Y", CmmnUtil.substringByBytes(fileCn, 48, 51).replaceAll("^0+", ""));
dataObject.put("PLATE_WIDTH", CmmnUtil.substringByBytes(fileCn, 52, 55).replaceAll("^0+", "")); //번호판width
dataObject.put("PLATE_HEIGHT", CmmnUtil.substringByBytes(fileCn, 56, 59).replaceAll("^0+", "")); //번호판height
dataObject.put("PLATE_YN", CmmnUtil.substringByBytes(fileCn, 60, 60)); //번호판유무(미사용)
dataObject.put("CRDN_SE", CmmnUtil.substringByBytes(fileCn, 61, 61)); //위반구분(미사용)
dataObject.put("CRDN_TYPE", CmmnUtil.substringByBytes(fileCn, 62, 62)); //위반종류(미사용)
String gpsX = CmmnUtil.substringByBytes(fileCn, 63, 85).replaceAll("^0+", "").replaceAll("0+$", "");
String gpsY = CmmnUtil.substringByBytes(fileCn, 86, 108).replaceAll("^0+", "").replaceAll("0+$", "");
dataObject.put("GPS_X", gpsX.endsWith(".") ? gpsX + "0" : gpsX);
dataObject.put("GPS_Y", gpsY.endsWith(".") ? gpsY + "0" : gpsY);
String photoCnt = CmmnUtil.substringByBytes(fileCn, 109, 110);
dataObject.put("PHOTO_CNT", photoCnt.startsWith("0") ? photoCnt.substring(1,2) : photoCnt);
dataObject.put("TRAFFIC_LIGHT_FORM", CmmnUtil.substringByBytes(fileCn, 111, 111)); //신호등형태(미사용)
dataObject.put("PROGRESS_FORM", CmmnUtil.substringByBytes(fileCn, 112, 112)); //진행형태(미사용)
dataObject.put("TRAFFIC_LIGHT_TYPE", CmmnUtil.substringByBytes(fileCn, 113, 113)); //신호등종류(미사용)
dataObject.put("SOME", CmmnUtil.substringByBytes(fileCn, 113, 113)); //?(미사용)
String fileAreaText = fileCn0.substring(114);
String imgContent = org.apache.commons.io.IOUtils.toString(imageReader).substring(this.getSumByte(jsonArray));
Encoder encoder = Base64.getEncoder();
@ -100,19 +99,20 @@ public class SingleFileParser extends LayoutParser {
String jpgName = "";
boolean jpgIn = false;
int jpgNum = 0;
for (int i = 0; i < fileAreaText.length(); i++) {
for (int i = 0; i < imgContent.length(); i++) {
boolean jpgStart = (i != fileAreaText.length()-1) && (fileAreaText.charAt(i) == 0xFF && fileAreaText.charAt(i+1) == 0xD8);
boolean jpgEnd = (i != 0) && (fileAreaText.charAt(i-1) == 0xFF && fileAreaText.charAt(i) == 0xD9);
boolean jpgStart = (i != imgContent.length()-1) && (imgContent.charAt(i) == 0xFF && imgContent.charAt(i+1) == 0xD8);
boolean jpgEnd = (i != 0) && (imgContent.charAt(i-1) == 0xFF && imgContent.charAt(i) == 0xD9);
if(jpgStart) {
jpgName = "" + fileAreaText.charAt(i-6)+fileAreaText.charAt(i-5)+fileAreaText.charAt(i-4)
+ fileAreaText.charAt(i-3)+fileAreaText.charAt(i-2)+fileAreaText.charAt(i-1);
jpgName = "" + imgContent.charAt(i-6)+imgContent.charAt(i-5)+imgContent.charAt(i-4)
+ imgContent.charAt(i-3)+imgContent.charAt(i-2)+imgContent.charAt(i-1);
jpgIn = true;
}
if(jpgIn) {
jpgString += fileAreaText.charAt(i);
jpgString += imgContent.charAt(i);
}
if(jpgIn && jpgEnd) {
@ -137,21 +137,12 @@ public class SingleFileParser extends LayoutParser {
}
}
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
tempGroupSeq++;
dataObjectList.add(dataObject);
});
return dataObjectList;
} catch (Exception e) {
throw new RuntimeException(e);
}
@Override
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
return true;
}
public static FileInfo base64ToFileInfo(String fileName, String base64str, int sortOrder) {
try {
Decoder decoder = Base64.getDecoder();

Loading…
Cancel
Save