|
|
@ -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,65 +36,62 @@ 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());
|
|
|
|
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
|
|
|
|
|
|
|
|
tempGroupSeq++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataObjectList.add(dataObject);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dataObjectList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//파일내용
|
|
|
|
@Override
|
|
|
|
String fileCn0 = "";
|
|
|
|
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void analyzeFileContent(DataObject dataObject, File file) {
|
|
|
|
try {
|
|
|
|
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"));
|
|
|
|
if(descriptor.getContentSeperator().equals("byte")) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
contentSplit = this.smartSplit(textConent, jsonArray);
|
|
|
|
e.printStackTrace();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
contentSplit = this.smartSplit(textConent, descriptor.getContentSeperator());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String fileCn = "";
|
|
|
|
for(int i=0; i<jsonArray.size(); i++) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
fileCn = new String(fileCn0.getBytes("ISO-8859-1"), "EUC-KR");
|
|
|
|
JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
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));
|
|
|
|
String imgContent = org.apache.commons.io.IOUtils.toString(imageReader).substring(this.getSumByte(jsonArray));
|
|
|
|
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();
|
|
|
|
Encoder encoder = Base64.getEncoder();
|
|
|
|
|
|
|
|
|
|
|
@ -100,19 +99,20 @@ public class SingleFileParser extends LayoutParser {
|
|
|
|
String jpgName = "";
|
|
|
|
String jpgName = "";
|
|
|
|
boolean jpgIn = false;
|
|
|
|
boolean jpgIn = false;
|
|
|
|
int jpgNum = 0;
|
|
|
|
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 jpgStart = (i != imgContent.length()-1) && (imgContent.charAt(i) == 0xFF && imgContent.charAt(i+1) == 0xD8);
|
|
|
|
boolean jpgEnd = (i != 0) && (fileAreaText.charAt(i-1) == 0xFF && fileAreaText.charAt(i) == 0xD9);
|
|
|
|
boolean jpgEnd = (i != 0) && (imgContent.charAt(i-1) == 0xFF && imgContent.charAt(i) == 0xD9);
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgStart) {
|
|
|
|
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;
|
|
|
|
jpgIn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgIn) {
|
|
|
|
if(jpgIn) {
|
|
|
|
jpgString += fileAreaText.charAt(i);
|
|
|
|
jpgString += imgContent.charAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(jpgIn && jpgEnd) {
|
|
|
|
if(jpgIn && jpgEnd) {
|
|
|
@ -137,21 +137,12 @@ public class SingleFileParser extends LayoutParser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
dataObject.put("TEMP_GROUP_ID", tempGroupSeq);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
tempGroupSeq++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataObjectList.add(dataObject);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return dataObjectList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|