|
|
@ -1,23 +1,25 @@
|
|
|
|
package cokr.xit.fims.crdn.parsing;
|
|
|
|
package cokr.xit.fims.crdn.parsing;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Base64;
|
|
|
|
import java.util.Base64;
|
|
|
|
import java.util.Base64.Decoder;
|
|
|
|
import java.util.Base64.Decoder;
|
|
|
|
import java.util.Base64.Encoder;
|
|
|
|
import java.util.Base64.Encoder;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import cokr.xit.base.file.FileInfo;
|
|
|
|
import cokr.xit.base.file.FileInfo;
|
|
|
|
import cokr.xit.fims.cmmn.CmmnUtil;
|
|
|
|
import cokr.xit.fims.cmmn.CmmnUtil;
|
|
|
|
import cokr.xit.foundation.data.DataObject;
|
|
|
|
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 {
|
|
|
|
public class SingleFileParser extends LayoutParser {
|
|
|
|
|
|
|
|
|
|
|
@ -34,109 +36,11 @@ public class SingleFileParser extends LayoutParser {
|
|
|
|
dataObject.put("FILE_GROUP_TYPE", "BIN");
|
|
|
|
dataObject.put("FILE_GROUP_TYPE", "BIN");
|
|
|
|
|
|
|
|
|
|
|
|
File file = item.toFile();
|
|
|
|
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");
|
|
|
|
this.setFileDefaultInfo(dataObject, file);
|
|
|
|
dataObject.put("FILE_LAST_MODIFIED", sdf.format(new Date(file.lastModified())));
|
|
|
|
|
|
|
|
dataObject.put("FILE_SIZE", file.length()+" byte");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataObject.put("FILE_EXTENSION","");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0;
|
|
|
|
this.analyzeFileContent(dataObject, file);
|
|
|
|
if(!isUserUpload) {
|
|
|
|
|
|
|
|
dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//파일내용
|
|
|
|
|
|
|
|
String fileCn0 = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileCn0 = Files.readString(item, Charset.forName("ISO-8859-1"));
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fileCn = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fileCn = new String(fileCn0.getBytes("ISO-8859-1"), "EUC-KR");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Encoder encoder = Base64.getEncoder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String jpgString = "";
|
|
|
|
|
|
|
|
String jpgName = "";
|
|
|
|
|
|
|
|
boolean jpgIn = false;
|
|
|
|
|
|
|
|
int jpgNum = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < fileAreaText.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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
jpgIn = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgIn) {
|
|
|
|
|
|
|
|
jpgString += fileAreaText.charAt(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgIn && jpgEnd) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpgNum++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpgString = new String(encoder.encode(jpgString.getBytes(Charset.forName("ISO-8859-1"))));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgNum == 1){
|
|
|
|
|
|
|
|
dataObject.put("CAR_IMAGE", jpgString);
|
|
|
|
|
|
|
|
dataObject.put("CAR_IMAGE_NM", jpgName);
|
|
|
|
|
|
|
|
} else if(jpgNum == 2){
|
|
|
|
|
|
|
|
dataObject.put("PLATE_IMAGE", jpgString);
|
|
|
|
|
|
|
|
dataObject.put("PLATE_IMAGE_NM", jpgName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dataObject.put("MOVING_IMAGE"+(jpgNum-2), jpgString);
|
|
|
|
|
|
|
|
dataObject.put("MOVING_IMAGE"+(jpgNum-2)+"_NM", jpgName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
jpgString = "";
|
|
|
|
|
|
|
|
jpgIn = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
|
|
|
|
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
|
|
|
|
tempGroupSeq++;
|
|
|
|
tempGroupSeq++;
|
|
|
@ -152,6 +56,93 @@ public class SingleFileParser extends LayoutParser {
|
|
|
|
return true;
|
|
|
|
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 = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(descriptor.getContentSeperator().equals("byte")) {
|
|
|
|
|
|
|
|
contentSplit = this.smartSplit(textConent, jsonArray);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
contentSplit = this.smartSplit(textConent, descriptor.getContentSeperator());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String imgContent = org.apache.commons.io.IOUtils.toString(imageReader).substring(this.getSumByte(jsonArray));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Encoder encoder = Base64.getEncoder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String jpgString = "";
|
|
|
|
|
|
|
|
String jpgName = "";
|
|
|
|
|
|
|
|
boolean jpgIn = false;
|
|
|
|
|
|
|
|
int jpgNum = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < imgContent.length(); i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = "" + 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 += imgContent.charAt(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgIn && jpgEnd) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpgNum++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jpgString = new String(encoder.encode(jpgString.getBytes(Charset.forName("ISO-8859-1"))));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgNum == 1){
|
|
|
|
|
|
|
|
dataObject.put("CAR_IMAGE", jpgString);
|
|
|
|
|
|
|
|
dataObject.put("CAR_IMAGE_NM", jpgName);
|
|
|
|
|
|
|
|
} else if(jpgNum == 2){
|
|
|
|
|
|
|
|
dataObject.put("PLATE_IMAGE", jpgString);
|
|
|
|
|
|
|
|
dataObject.put("PLATE_IMAGE_NM", jpgName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dataObject.put("MOVING_IMAGE"+(jpgNum-2), jpgString);
|
|
|
|
|
|
|
|
dataObject.put("MOVING_IMAGE"+(jpgNum-2)+"_NM", jpgName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
jpgString = "";
|
|
|
|
|
|
|
|
jpgIn = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static FileInfo base64ToFileInfo(String fileName, String base64str, int sortOrder) {
|
|
|
|
public static FileInfo base64ToFileInfo(String fileName, String base64str, int sortOrder) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Decoder decoder = Base64.getDecoder();
|
|
|
|
Decoder decoder = Base64.getDecoder();
|
|
|
|