From c41039b876bb64f2cd74ad1e0df022093f5d6b55 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Mon, 16 Oct 2023 18:11:07 +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=ED=8C=8C=EC=8B=B1=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fims/crdn/parsing/AttachedTxtParser.java | 164 +++++++-------- .../xit/fims/crdn/parsing/LayoutParser.java | 80 ++++++- .../fims/crdn/parsing/OnlyImageParser.java | 21 +- .../fims/crdn/parsing/SingleFileParser.java | 199 +++++++++--------- 4 files changed, 249 insertions(+), 215 deletions(-) diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java b/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java index 15e9400f..8f14f44f 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java @@ -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,31 +38,17 @@ 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); - - boolean isUserUpload = file.compareTo(new File(descriptor.getLinkFileLocation()+File.separator+fileName)) == 0; - if(!isUserUpload) { - dataObject.put("LINK_ENT_NM", descriptor.getLinkEnterpriseName()); - } - - String noExtensionName = FilenameUtils.removeExtension(fileName); + String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME")); this.analyzeFileName(dataObject, noExtensionName); this.refineValue(dataObject); - boolean isMetaData = fileExtension.toUpperCase().equals("TXT"); + try { JSONParser jsonParser = new JSONParser(-1); @@ -72,70 +56,7 @@ public class AttachedTxtParser extends LayoutParser{ JSONArray jsonArray = (JSONArray)jsonParser.parse(descriptor.getContentItems()); - if(isMetaData) { - - BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),Charset.forName("EUC-KR"))); - String content = org.apache.commons.io.IOUtils.toString(br); - String[] contentDivision = null; - String part = ""; - int contentDivisionIndex = 0; - int partSplitCursor = 0; - - if(!descriptor.getContentSecondSeperator().equals("")) { - contentDivision = smartSplit(content, descriptor.getContentSecondSeperator()); - part = contentDivision[contentDivisionIndex]; - } else { - part = content; - } - - for(int i=0; i contentDivisionIndex) { - part = contentDivision[contentDivisionIndex]; - } else { - part = ""; - } - } - - String[] partSplit = smartSplit(part, descriptor.getContentSeperator()); - - if(partSplit.length > partSplitCursor) { - dataObject.put(key, partSplit[partSplitCursor]); - } else { - dataObject.put(key, ""); - } - partSplitCursor++; - } - - // - if(descriptor.getTaskSeCd().equals("PVS") || descriptor.getTaskSeCd().equals("BPV")) { - if(descriptor.getEnterpriseName().equals("xit")) { - if(!dataObject.string("GPS_X").equals("")) { - dataObject.put("CRDN_SE_CD", "02"); - } else { - dataObject.put("CRDN_SE_CD", "01"); - } - } - } - - this.refineValue(dataObject); - - } else { - for(int i=0; i contentDivisionIndex) { + part = contentDivision[contentDivisionIndex]; + } else { + part = ""; + } + } + + String[] partSplit = this.smartSplit(part, descriptor.getContentSeperator()); + + if(partSplit.length > partSplitCursor) { + dataObject.put(key, partSplit[partSplitCursor]); + } else { + dataObject.put(key, ""); + } + partSplitCursor++; + } + + // + if(descriptor.getTaskSeCd().equals("PVS") || descriptor.getTaskSeCd().equals("BPV")) { + if(descriptor.getEnterpriseName().equals("xit")) { + if(!dataObject.string("GPS_X").equals("")) { + dataObject.put("CRDN_SE_CD", "02"); + } else { + dataObject.put("CRDN_SE_CD", "01"); + } + } + } + + this.refineValue(dataObject); + + } else { + + for(int i=0; i * @param fileList 연계파일리스트 * @return 단속정보 @@ -130,26 +155,26 @@ 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 i) { - dataObject.put(key, fileNameSplit[i]); - } else { - dataObject.put(key, ""); - } + if(fileNameSplit.length > i) { + dataObject.put(key, fileNameSplit[i]); + } else { + dataObject.put(key, ""); } - } } catch (ParseException e) { @@ -169,4 +194,37 @@ abstract public class LayoutParser { return string.split(Matcher.quoteReplacement(sep)); } } + + public String[] smartSplit(String string, JSONArray jsonArray) { + + List byteNums = new ArrayList(); + for(int i=0; i { 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); diff --git a/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java b/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java index e61b17fe..ca4cfb4e 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java @@ -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,109 +36,11 @@ 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()); - } - - //파일내용 - 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; - } - - } + this.analyzeFileContent(dataObject, file); dataObject.put("TEMP_GROUP_ID", tempGroupSeq); tempGroupSeq++; @@ -152,6 +56,93 @@ public class SingleFileParser extends LayoutParser { 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 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) { try { Decoder decoder = Base64.getDecoder();