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 e8a682b0..06c0012b 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/AttachedTxtParser.java @@ -5,13 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.commons.io.FilenameUtils; import cokr.xit.foundation.data.DataObject; import net.minidev.json.JSONArray; @@ -20,65 +14,12 @@ import net.minidev.json.parser.JSONParser; public class AttachedTxtParser extends LayoutParser{ - private DataObject before = new DataObject(); - private int tempGroupSeq = 1; - - @Override - public List parsing(List fileList) { - - //파일명으로 정렬(파싱 전) - List sortedFileList = fileList.stream() - .sorted((item1, item2) -> item1.toFile().getName().compareTo(item2.toFile().getName())) - .collect(Collectors.toList()); - - List dataObjectList = new ArrayList<>(); - - sortedFileList.forEach(item -> { - DataObject dataObject = this.createParsedDataObject(); - dataObject.put("FILE_GROUP_TYPE", "TXT"); - - File file = item.toFile(); - - this.setFileDefaultInfo(dataObject, file); - - String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME")); - - this.analyzeFileName(dataObject, noExtensionName); - - this.refineValue(dataObject); - - this.analyzeFileContent(dataObject, file); - - this.refineValue(dataObject); - - 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; + public AttachedTxtParser(){ + this.groupingType = "TXT"; + this.need = new Need(true,false,true); } @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; - } - } - public void analyzeFileContent(DataObject dataObject, File file) { try { @@ -130,19 +71,6 @@ public class AttachedTxtParser extends LayoutParser{ 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 단속정보 + */ + public List parsing(List fileList){ + List dataObjectList = new ArrayList<>(); + + //파일명으로 정렬(파싱 전) + List sortedFileList = fileList.stream() + .sorted((item1, item2) -> item1.toFile().getName().compareTo(item2.toFile().getName())) + .collect(Collectors.toList()); + + sortedFileList.forEach(item -> { + DataObject dataObject = this.createParsedDataObject(); + dataObject.put("FILE_GROUP_TYPE", this.groupingType); + File file = item.toFile(); + this.setFileDefaultInfo(dataObject, file); + + if(this.need.fileNameAnalyze) { + String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME")); + this.analyzeFileName(dataObject, noExtensionName); + this.refineValue(dataObject); + } + + if(this.need.contentAnalyze) { + this.analyzeFileContent(dataObject, file); + this.refineValue(dataObject); + } + + //단속구분코드 보정 + 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"); + } + } + } + + if(descriptor.getTaskSeCd().equals("BPV")) { + if(descriptor.getEnterpriseName().equals("hitecom")) { + dataObject.put("CRDN_SE_CD", "07"); + } + } + + if(!before.isEmpty()) { + if(this.need.checkChangeCrackdown) { + boolean isChangeTempGroup = this.isChangeCrackdown(dataObject, before); + if(isChangeTempGroup) { + tempGroupSeq++; + } + } else { + tempGroupSeq++; + } + } + + dataObject.put("TEMP_GROUP_ID", tempGroupSeq); + dataObjectList.add(dataObject); + before = dataObject; + }); + + return dataObjectList; + } + /**파일에서 파일관련 기본정보를 추출한다.
* @param dataObject 정보, File 파일 * @return @@ -93,19 +178,53 @@ abstract public class LayoutParser { } } - /**장비 단속 연계 파일에서 단속정보를 추출한다.
- * @param fileList 연계파일리스트 - * @return 단속정보 + /**파일명을 분석한다.
+ * @param dataObject + * @return */ - abstract public List parsing(List fileList); + public void analyzeFileName(DataObject dataObject, String noExtensionName) { - /**현재 연계 파일의 정보가 이전 연계 파일의 정보와 다른 단속건인지 판단한다.
- * @param currentItem 현재 연계 파일 정보, beforeItem 이전 연계 파일 정보 - * @return 개별 단속자료 여부 + String fileNameItmesJSONString = descriptor.getFileNameItmes(); + + try { + JSONParser jsonParser = new JSONParser(-1); + JSONArray jsonArray = (JSONArray)jsonParser.parse(fileNameItmesJSONString); + + String[] fileNameSplit = {}; + if(descriptor.getFileNameSeperator().equals("byte")) { + + fileNameSplit = this.smartSplit(noExtensionName, jsonArray); + + } else { + + fileNameSplit = this.smartSplit(noExtensionName, descriptor.getFileNameSeperator()); + } + + for(int i=0; i i) { + dataObject.put(key, fileNameSplit[i]); + } else { + dataObject.put(key, ""); + } + } + + } catch (ParseException e) { + e.printStackTrace(); + } + + } + + /**파일내용을 분석한다.
+ * @param dataObject + * @return */ - abstract public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem); + abstract public void analyzeFileContent(DataObject dataObject, File file); - /**파싱된 데이터를 정제한다.
+ /**파일명이나 파일내용을 파싱한 후 데이터를 정제한다.
* @param dataObject * @return */ @@ -186,44 +305,39 @@ abstract public class LayoutParser { } } - /**파일명을 분석한다.
- * @param dataObject - * @return + /**현재 연계 파일의 정보가 이전 연계 파일의 정보와 다른 단속건인지 판단한다.
+ * @param currentItem 현재 연계 파일 정보, beforeItem 이전 연계 파일 정보 + * @return 개별 단속자료 여부 */ - public void analyzeFileName(DataObject dataObject, String noExtensionName) { - - String fileNameItmesJSONString = descriptor.getFileNameItmes(); - - try { - JSONParser jsonParser = new JSONParser(-1); - JSONArray jsonArray = (JSONArray)jsonParser.parse(fileNameItmesJSONString); - - String[] fileNameSplit = {}; - if(descriptor.getFileNameSeperator().equals("byte")) { - - fileNameSplit = this.smartSplit(noExtensionName, jsonArray); - - } else { - - fileNameSplit = this.smartSplit(noExtensionName, descriptor.getFileNameSeperator()); + public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) { + boolean isSameItemChange = false; + String sameItems = descriptor.getSameItemsInFileGroup(); + String[] sameItemsSplit = sameItems.split(","); + for(int i=0; i < sameItemsSplit.length; i++) { + if(!currentItem.string(sameItemsSplit[i]).equals(beforeItem.string(sameItemsSplit[i]))) { + isSameItemChange = true; } + } + if(isSameItemChange) { + return true; + } - for(int i=0; i i) { - dataObject.put(key, fileNameSplit[i]); - } else { - dataObject.put(key, ""); + if(increaseType.equals("number")){ + if(currentItem.number(increaseItem).intValue() <= beforeItem.number(increaseItem).intValue()) { + return true; + } + } else if(increaseType.equals("alphabet")) { + if(currentItem.string(increaseItem).charAt(0) <= beforeItem.string(increaseItem).charAt(0)) { + return true; } } - - } catch (ParseException e) { - e.printStackTrace(); } + return false; } /**파일명이나 파일내용을 특정 구분자로 자른다.
@@ -264,6 +378,10 @@ abstract public class LayoutParser { return result; } + /**레이아웃 설정 정보의 byte를 합계를 반환한다.
+ * @param jsonArray 레이아웃 설정정보 + * @return + */ public int getSumByte(JSONArray jsonArray){ int result = 0; for(int i=0; i parsing(List fileList) { - - List dataObjectList = new ArrayList<>(); - - //파일명으로 정렬(파싱 전) - List sortedFileList = fileList.stream() - .sorted((item1, item2) -> item1.toFile().getName().compareTo(item2.toFile().getName())) - .collect(Collectors.toList()); - - sortedFileList.forEach(item -> { - DataObject dataObject = this.createParsedDataObject(); - - dataObject.put("FILE_GROUP_TYPE", "JPG"); - - File file = item.toFile(); - - this.setFileDefaultInfo(dataObject, file); - - String noExtensionName = FilenameUtils.removeExtension(dataObject.string("FILE_NAME")); - - this.analyzeFileName(dataObject, noExtensionName); - - this.refineValue(dataObject); - - 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; + public OnlyImageParser(){ + this.groupingType = "JPG"; + this.need = new Need(true,false,true); } @Override - public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) { - - if(!currentItem.string("VHRNO").equals(beforeItem.string("VHRNO"))) { - return true; - } - - if(!currentItem.string("PHOTO_CNT").equals(beforeItem.string("PHOTO_CNT"))) { - return true; - } + public void analyzeFileContent(DataObject dataObject, File file) { - if(currentItem.number("PHOTO_TYPE_CD").intValue() <= beforeItem.number("PHOTO_TYPE_CD").intValue()) { - return true; - } - - return false; } + } 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 fd67a958..1f1ad4a3 100644 --- a/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java +++ b/src/main/java/cokr/xit/fims/crdn/parsing/SingleFileParser.java @@ -7,12 +7,9 @@ import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; -import java.nio.file.Path; -import java.util.ArrayList; import java.util.Base64; import java.util.Base64.Decoder; import java.util.Base64.Encoder; -import java.util.List; import cokr.xit.base.file.FileInfo; import cokr.xit.fims.cmmn.CmmnUtil; @@ -23,41 +20,16 @@ import net.minidev.json.parser.JSONParser; public class SingleFileParser extends LayoutParser { - private int tempGroupSeq = 1; - - @Override - public List parsing(List fileList) { - - List dataObjectList = new ArrayList<>(); - - fileList.forEach(item -> { - DataObject dataObject = this.createParsedDataObject(); - - dataObject.put("FILE_GROUP_TYPE", "BIN"); - - File file = item.toFile(); - - this.setFileDefaultInfo(dataObject, file); - - this.analyzeFileContent(dataObject, file); - - this.refineValue(dataObject); - - dataObject.put("TEMP_GROUP_ID", tempGroupSeq); - tempGroupSeq++; - - dataObjectList.add(dataObject); - }); - - return dataObjectList; + public SingleFileParser(){ + this.groupingType = "BIN"; + this.need = new Need(false,true,false); } + /**파일내용을 분석한다.
+ * @param dataObject + * @return + */ @Override - public boolean isChangeCrackdown(DataObject currentItem, DataObject beforeItem) { - return true; - } - - public void analyzeFileContent(DataObject dataObject, File file) { try { JSONParser jsonParser = new JSONParser(-1); @@ -90,6 +62,7 @@ public class SingleFileParser extends LayoutParser { } } + //이미지 영역 파싱 BufferedReader imageReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("ISO-8859-1"))); @@ -128,17 +101,9 @@ public class SingleFileParser extends LayoutParser { 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); - } + dataObject.put("B64IMAGE"+(jpgNum), jpgString); + dataObject.put("B64IMAGE"+(jpgNum)+"_NM", jpgName); + jpgString = ""; jpgIn = false; } @@ -149,7 +114,10 @@ public class SingleFileParser extends LayoutParser { } } - + /** 베이스64문자열 이미지로 fileInfo를 생성한다.
+ * @param fileName 파일명, base64str 베이스64문자열, sortOrder 파일순서 + * @return fileInfo 파일정보 + */ public static FileInfo base64ToFileInfo(String fileName, String base64str, int sortOrder) { try { Decoder decoder = Base64.getDecoder(); diff --git a/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java b/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java index 04cfdb2a..24f47e5a 100644 --- a/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java +++ b/src/main/java/cokr/xit/fims/crdn/service/bean/ImportServiceBean.java @@ -90,167 +90,59 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ Crdn crdn = new Crdn(); crdn.setCrdnRegSeCd("07"); crdn.setTaskSeCd(taskSeCd); + crdn.setSggCd(globalStngMapper.selectSggCdForCurrentUser()); - List fileInfoList = new ArrayList(); - - // - if(fileGroupType.equals("JPG")) { + Map dividedInfo = this.divideInformation(linkFileInfoList, fileGroupType); - //1. 연계파일정보를 단속 엔티티로 변환 - DataObject bgngData = linkFileInfoList.stream() - .min(Comparator.comparing(item -> new BigInteger(item.string("CRDN_TIMESTAMP")))) - .orElseThrow(); - - DataObject endData = linkFileInfoList.stream() - .max(Comparator.comparing(item -> new BigInteger(item.string("CRDN_TIMESTAMP")))) - .orElseThrow(); + DataObject metaFileInfo = (DataObject) dividedInfo.get("metaInfo"); + List imageFileInfoList = (List) dividedInfo.get("imageInfo"); + DataObject bgngData = (DataObject) dividedInfo.get("bgngData"); + DataObject endData = (DataObject) dividedInfo.get("endData"); - crdn.setCrdnBgngTm(bgngData.string("CRDN_TM")); - crdn.setCrdnEndTm(endData.string("CRDN_TM")); + //1. 연계파일정보를 단속 엔티티로 변환 + this.crdnTimeRangeSet(crdn, bgngData, endData); - DataObject linkFileInfo = endData; + String entType = metaFileInfo.string("LINK_ENT_NM"); + if(entType.equals("ino")) crdn.setCrdnInptSeCd("11"); + else if(entType.equals("knl")) crdn.setCrdnInptSeCd("12"); + else crdn.setCrdnInptSeCd("15"); - String entType = linkFileInfo.string("LINK_ENT_NM"); - if(entType.equals("ino")) crdn.setCrdnInptSeCd("11"); - else if(entType.equals("knl")) crdn.setCrdnInptSeCd("12"); - else crdn.setCrdnInptSeCd("15"); - crdn.setCrdnInptSeCd("11"); + if(metaFileInfo.string("VLTN_CD").equals("")) { crdn.setVltnCd("01"); - crdn.setSggCd(globalStngMapper.selectSggCdForCurrentUser()); - crdn.setVhrno(linkFileInfo.string("VHRNO")); - crdn.setCrdnYmd(linkFileInfo.string("CRDN_YMD")); - crdn.setCrdnTm(linkFileInfo.string("CRDN_TM")); - crdn.setGpsX(linkFileInfo.string("GPS_X")); - crdn.setGpsY(linkFileInfo.string("GPS_Y")); - crdn.setCrdnStdgNm(linkFileInfo.string("CRDN_STDG_NM")); - crdn.setCrdnPlc(linkFileInfo.string("CRDN_PLC")); - crdn.setCrdnRoadNm(linkFileInfo.string("CRDN_ROAD_NM")); - - //linkFileInfo.string("EQPMNT_CD"); - - List files = new ArrayList<>(); - for (DataObject linkFileInfo0 : linkFileInfoList) { - files.add(new File(linkFileInfo0.string("FILE_PATH"))); - } - - fileInfoList = new FileInfoFactory().createFileInfos(null, files); - for (int iLoop = 0; iLoop < fileInfoList.size(); iLoop++) { - fileInfoList.get(iLoop).setName("image"+iLoop+"."+FilenameUtils.getExtension(fileInfoList.get(iLoop).getName())); - } - + } else { + crdn.setVltnCd(metaFileInfo.string("VLTN_CD")); + } + if(metaFileInfo.string("CRDN_SPAREA_CD").equals("")) { + crdn.setCrdnSpareaCd("00"); + } else { + crdn.setCrdnSpareaCd(metaFileInfo.string("CRDN_SPAREA_CD")); } - //XIT권장포맷 - if(fileGroupType.equals("TXT")) { - - //1. 연계파일정보를 단속 엔티티로 변환 - crdn.setSggCd(globalStngMapper.selectSggCdForCurrentUser()); - - DataObject metaFileInfo = null; - for (DataObject linkFileInfo0 : linkFileInfoList) { - if(linkFileInfo0.string("FILE_EXTENSION").toUpperCase().equals("TXT")) { - metaFileInfo = linkFileInfo0; - } - } - - String entType = metaFileInfo.string("LINK_ENT_NM"); - if(entType.equals("ino")) crdn.setCrdnInptSeCd("11"); - else if(entType.equals("knl")) crdn.setCrdnInptSeCd("12"); - else crdn.setCrdnInptSeCd("15"); - - crdn.setVltnCd("01"); - - crdn.setCrdnSeCd(metaFileInfo.string("CRDN_SE_CD")); - crdn.setCrdnYmd(metaFileInfo.string("CRDN_YMD")); - crdn.setCrdnTm(metaFileInfo.string("CRDN_TM")); - crdn.setVhrno(metaFileInfo.string("VHRNO")); - crdn.setGpsX(metaFileInfo.string("GPS_X")); - crdn.setGpsY(metaFileInfo.string("GPS_Y")); + crdn.setVhrno(metaFileInfo.string("VHRNO")); + crdn.setCrdnYmd(metaFileInfo.string("CRDN_YMD")); + crdn.setCrdnTm(metaFileInfo.string("CRDN_TM")); + if(crdn.getCrdnBgngTm() == null) { crdn.setCrdnBgngTm(metaFileInfo.string("CRDN_BGNG_TM")); crdn.setCrdnEndTm(metaFileInfo.string("CRDN_END_TM")); - crdn.setCrdnPlc(metaFileInfo.string("CRDN_PLC")); - - if(metaFileInfo.string("CRDN_SPAREA_NM").equals("어린이보호구역")) { - crdn.setCrdnSpareaCd("01"); - } else { - crdn.setCrdnSpareaCd("00"); - } - crdn.setCrdnStdgNm(metaFileInfo.string("CRDN_STDG_NM")); - - //metaFileInfo.string("VLTN_NM"); - //metaFileInfo.string("EQPMNT_CD"); - - List files = new ArrayList<>(); - for (DataObject linkFileInfo0 : linkFileInfoList) { - if(!linkFileInfo0.string("FILE_EXTENSION").toUpperCase().equals("TXT")) { - files.add(new File(linkFileInfo0.string("FILE_PATH"))); - } - } - - fileInfoList = new FileInfoFactory().createFileInfos(null, files); - for (int iLoop = 0; iLoop < fileInfoList.size(); iLoop++) { - fileInfoList.get(iLoop).setName("image"+iLoop+"."+FilenameUtils.getExtension(fileInfoList.get(iLoop).getName())); - } - } - // - if(fileGroupType.equals("BIN")) { + crdn.setGpsX(metaFileInfo.string("GPS_X")); + crdn.setGpsY(metaFileInfo.string("GPS_Y")); + crdn.setCrdnPlc(metaFileInfo.string("CRDN_PLC")); + crdn.setCrdnRoadNm(metaFileInfo.string("CRDN_ROAD_NM")); + crdn.setCrdnStdgNm(metaFileInfo.string("CRDN_STDG_NM")); - //1. 연계파일정보를 단속 엔티티로 변환 - if(linkFileInfoList.size() != 1) { - resultMap.put("saved", false); - resultMap.put("failReason", "그룹핑 오류"); - return resultMap; - } - DataObject linkFileInfo = linkFileInfoList.get(0); - - String entType = linkFileInfo.string("LINK_ENT_NM"); - if(entType.equals("ino")) crdn.setCrdnInptSeCd("11"); - else if(entType.equals("knl")) crdn.setCrdnInptSeCd("12"); - else crdn.setCrdnInptSeCd("15"); + crdn.setCrdnSeCd(metaFileInfo.string("CRDN_SE_CD")); + crdn.setMoscX(metaFileInfo.string("MOSC_X")); + crdn.setMoscY(metaFileInfo.string("MOSC_Y")); + //metaFileInfo.string("EQPMNT_CD"); + //metaFileInfo.string("PLATE_WIDTH"); + //metaFileInfo.string("PLATE_HEIGHT"); - crdn.setVltnCd("01"); - - crdn.setCrdnSeCd("07"); - - crdn.setSggCd(globalStngMapper.selectSggCdForCurrentUser()); - crdn.setVhrno(linkFileInfo.string("VHRNO")); - crdn.setCrdnYmd(linkFileInfo.string("CRDN_YMD")); - crdn.setCrdnTm(linkFileInfo.string("CRDN_TM")); - crdn.setGpsX(linkFileInfo.string("GPS_X")); - crdn.setGpsY(linkFileInfo.string("GPS_Y")); - crdn.setMoscX(linkFileInfo.string("MOSC_X")); - crdn.setMoscY(linkFileInfo.string("MOSC_Y")); - - //linkFileInfo.string("EQPMNT_CD"); - //linkFileInfo.string("PLATE_WIDTH"); - //linkFileInfo.string("PLATE_HEIGHT"); - - try { - FileInfo FileInfo1 = SingleFileParser.base64ToFileInfo(linkFileInfo.string("CAR_IMAGE_NM"), linkFileInfo.string("CAR_IMAGE"), 1); - fileInfoList.add(FileInfo1); - FileInfo FileInfo2 = SingleFileParser.base64ToFileInfo(linkFileInfo.string("PLATE_IMAGE_NM"), linkFileInfo.string("PLATE_IMAGE"), 2); - fileInfoList.add(FileInfo2); - - int otherPhotoCnt = linkFileInfo.number("PHOTO_CNT").intValue() - 2; - for(int i=1; i <= otherPhotoCnt; i++){ - String fileName = linkFileInfo.string("MOVING_IMAGE"+i+"_NM"); - String b64str = linkFileInfo.string("MOVING_IMAGE"+i); - FileInfo FileInfo = SingleFileParser.base64ToFileInfo(fileName, b64str, i + 2); - fileInfoList.add(FileInfo); - } - - } catch (Exception e) { - throw new RuntimeException(e); - } - - - } - + List fileInfoList = this.parsedDataInfoToFileInfo(imageFileInfoList, fileGroupType); //2. 차적 조회 @@ -287,4 +179,145 @@ public class ImportServiceBean extends AbstractServiceBean implements ImportServ return resultMap; } + + /**파싱된 데이터 목록을 메타정보, 이미지정보목록, 최초단속자료, 최종단속자료로 분리한다.
+ * @param linkFileInfoList 연계파일정보목록, fileGroupType 연계파일그룹형식 + * @return 메타정보, 이미지정보목록, 최초단속자료, 최종단속자료 + */ + public Map divideInformation(List linkFileInfoList, String fileGroupType) { + Map result = new HashMap(); + + DataObject metaFileInfo = null; + List imageFileInfoList = new ArrayList(); + DataObject[] bgngAndEnd = {null, null}; + + if(fileGroupType.equals("TXT")) { + + for (DataObject linkFileInfo : linkFileInfoList) { + if(linkFileInfo.string("FILE_EXTENSION").toUpperCase().equals("TXT")) { + metaFileInfo = linkFileInfo; + } else { + imageFileInfoList.add(linkFileInfo); + } + } + + bgngAndEnd = getBgngDataAndEndData(imageFileInfoList); + + } else if(fileGroupType.equals("JPG")){ + + imageFileInfoList = linkFileInfoList; + + bgngAndEnd = getBgngDataAndEndData(linkFileInfoList); + + if(bgngAndEnd[1] == null) { + metaFileInfo = linkFileInfoList.get(0); + } else { + metaFileInfo = bgngAndEnd[1]; + } + + } else if(fileGroupType.equals("BIN")) { + + metaFileInfo = linkFileInfoList.get(0); + + int otherPhotoCnt = metaFileInfo.number("PHOTO_CNT").intValue(); + for(int i=1; i <= otherPhotoCnt; i++){ + String fileName = metaFileInfo.string("B64IMAGE"+i+"_NM"); + String b64str = metaFileInfo.string("B64IMAGE"+i); + DataObject dataObject = new DataObject(); + dataObject.put("B64IMAGE_NM", fileName); + dataObject.put("B64IMAGE", b64str); + imageFileInfoList.add(dataObject); + } + + } else { + return result; + } + + result.put("metaInfo", metaFileInfo); + result.put("imageInfo", imageFileInfoList); + result.put("bgngData", bgngAndEnd[0]); + result.put("endData", bgngAndEnd[1]); + + return result; + } + + /**단속이미지정보 목록 내에서 최초단속자료와 최종단속자료를 반환한다. 단속일시 정보가 없을 경우 null을 반환한다.
+ * @param imageDataList 단속이미지정보 목록 + * @return 최초단속자료, 최종단속자료 + */ + public DataObject[] getBgngDataAndEndData(List imageDataList) { + DataObject[] bgngAndEnd = {null, null}; + + if(!imageDataList.get(0).get("CRDN_TIMESTAMP").equals("")) { + + DataObject bgngData = imageDataList.stream() + .min(Comparator.comparing(item -> new BigInteger(item.string("CRDN_TIMESTAMP")))) + .orElseThrow(); + + DataObject endData = imageDataList.stream() + .max(Comparator.comparing(item -> new BigInteger(item.string("CRDN_TIMESTAMP")))) + .orElseThrow(); + + bgngAndEnd[0] = bgngData; + bgngAndEnd[1] = endData; + } + + return bgngAndEnd; + } + + /**최초단속정보와 최종단속정보를 기준으로 단속대장의 최초단속시간과 최종단속시간을 설정한다.
+ * @param crdn 단속대장, bgngData 최초단속자료, endData 최종단속자료 + * @return + */ + public void crdnTimeRangeSet(Crdn crdn, DataObject bgngData, DataObject endData) { + if(bgngData != null && endData != null) { + if(!endData.string("CRDN_BGNG_TM").equals("")) { + crdn.setCrdnBgngTm(endData.string("CRDN_BGNG_TM")); + crdn.setCrdnEndTm(endData.string("CRDN_END_TM")); + } else if(!endData.string("CRDN_TM").equals("")){ + crdn.setCrdnBgngTm(bgngData.string("CRDN_TM")); + crdn.setCrdnEndTm(endData.string("CRDN_TM")); + } + } + } + + /**단속이미지정보를 List로 변환한다.
+ * @param imageFileInfoList 단속이미지정보 목록, fileGroupType 연계파일그룹형식 + * @return fileInfo리스트 + */ + public List parsedDataInfoToFileInfo(List imageFileInfoList, String fileGroupType){ + List fileInfoList = new ArrayList(); + + try { + //이미지, 이미지및텍스트 + if(fileGroupType.equals("JPG") || fileGroupType.equals("TXT")) { + + List files = new ArrayList<>(); + for (DataObject imageFileInfo : imageFileInfoList) { + files.add(new File(imageFileInfo.string("FILE_PATH"))); + } + + fileInfoList = new FileInfoFactory().createFileInfos(null, files); + for (int iLoop = 0; iLoop < fileInfoList.size(); iLoop++) { + fileInfoList.get(iLoop).setName("image"+iLoop+"."+FilenameUtils.getExtension(fileInfoList.get(iLoop).getName())); + } + + } else if(fileGroupType.equals("BIN")) { + + for(int i=0; i < imageFileInfoList.size(); i++){ + String fileName = imageFileInfoList.get(i).string("B64IMAGE_NM"); + String b64str = imageFileInfoList.get(i).string("B64IMAGE"); + FileInfo FileInfo = SingleFileParser.base64ToFileInfo(fileName, b64str, (i+1)); + fileInfoList.add(FileInfo); + } + + } + + } catch (Exception e) { + throw new RuntimeException(e); + } + + return fileInfoList; + }; + } \ No newline at end of file diff --git a/src/main/resources/sql/mapper/fims/crdn/global-stng-mapper.xml b/src/main/resources/sql/mapper/fims/crdn/global-stng-mapper.xml index d931300a..a526b703 100644 --- a/src/main/resources/sql/mapper/fims/crdn/global-stng-mapper.xml +++ b/src/main/resources/sql/mapper/fims/crdn/global-stng-mapper.xml @@ -11,6 +11,9 @@ + + + @@ -78,6 +81,9 @@ SELECT A.FILE_LAYOUT_ID , A.FILE_TNOCS , A.LINK_FILE_PATH , A.ENT_NM + , A.SAME_ITEMS + , A.INCREASE_ITEM + , A.INCREASE_TYPE , B.LINK_ENT_NM FROM TB_CRDN_FILE_LAYOUT A LEFT OUTER JOIN TB_FTP_INFO B ON (A.FILE_LAYOUT_ID = B.FILE_LAYOUT_ID) diff --git a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp index 7612775c..91ff3b78 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn05020-info.jsp @@ -205,13 +205,10 @@ $(document).ready(function(){ $("#table-responsive--${pageName}").find("tbody").setCurrentRow(dataKey); if(item.data.FILE_GROUP_TYPE == "BIN"){ - var srcArr = [ - "data:image/jpg;base64,"+item.data.CAR_IMAGE, - "data:image/jpg;base64,"+item.data.PLATE_IMAGE - ]; + var srcArr = []; - for(var i=1; i <= item.data.PHOTO_CNT-2; i++){ - srcArr.push("data:image/jpg;base64," + item.data["MOVING_IMAGE"+i]) + for(var i=1; i <= item.data.PHOTO_CNT; i++){ + srcArr.push("data:image/jpg;base64," + item.data["B64IMAGE"+i]) } $P.renderImage(srcArr);