From 996c4b473b6f070d76146941c9fcbccb32b0d2fc Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Mon, 5 Jun 2023 13:30:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EB=B2=84=EC=8A=A4=EC=9E=A5?= =?UTF-8?q?=EC=B0=A9=ED=98=95=20=ED=8C=8C=EC=9D=BC=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extr/CctvBusInstallCrackDownFactory.java | 24 --- .../cmm/extr/ExtrInterfaceDataFactory.java | 14 -- .../fims/biz/cmm/extr/strategypattern.drawio | 1 - .../biz/cmm/service/ExtrInterfaceService.java | 18 -- .../biz/cmm/service/ExtrStrategyService.java | 14 -- .../CctvBusInstallCrackDownServiceBean.java | 78 --------- .../bean/ExtrInterfaceServiceBean.java | 47 ------ .../bean/EcCctvCrackdownServiceBean.java | 3 +- .../util/ExtnlBusInstallInterfaceUtils.java | 155 ++++++++++++++++++ .../biz/util/ExtnlInterfaceUtils.java | 148 +---------------- 10 files changed, 160 insertions(+), 342 deletions(-) delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusInstallCrackDownFactory.java delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceDataFactory.java delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/extr/strategypattern.drawio delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/service/ExtrInterfaceService.java delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/service/ExtrStrategyService.java delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/service/bean/CctvBusInstallCrackDownServiceBean.java delete mode 100644 src/main/java/kr/xit/fims/biz/cmm/service/bean/ExtrInterfaceServiceBean.java create mode 100644 src/main/java/kr/xit/fims/biz/ec/util/ExtnlBusInstallInterfaceUtils.java diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusInstallCrackDownFactory.java b/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusInstallCrackDownFactory.java deleted file mode 100644 index 2b6269f5..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusInstallCrackDownFactory.java +++ /dev/null @@ -1,24 +0,0 @@ -package kr.xit.fims.biz.cmm.extr; - -import kr.xit.fims.biz.ec.CctvCrackdownDTO; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@EqualsAndHashCode(callSuper = true) -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -public class CctvBusInstallCrackDownFactory extends ExtrInterfaceDataFactory{ - private CctvCrackdownDTO.BusInstall dto; - - @Override - public CctvCrackdownDTO.BusInstall parseData(CctvCrackdownDTO.Request reqDto) { - return CctvCrackdownDTO.BusInstall.builder() - .carModel("dkkdkd").build(); - } - -} diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceDataFactory.java b/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceDataFactory.java deleted file mode 100644 index 981a4ba0..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceDataFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package kr.xit.fims.biz.cmm.extr; - -public abstract class ExtrInterfaceDataFactory { - //private T t; - - public T parseInterfaceData(E e){ - return this.parseData(e); - //return this.createDTO(); - } - - public abstract T parseData(E e); - - //public abstract T createDTO(); -} diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/strategypattern.drawio b/src/main/java/kr/xit/fims/biz/cmm/extr/strategypattern.drawio deleted file mode 100644 index c8a7c02a..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/extr/strategypattern.drawio +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/main/java/kr/xit/fims/biz/cmm/service/ExtrInterfaceService.java b/src/main/java/kr/xit/fims/biz/cmm/service/ExtrInterfaceService.java deleted file mode 100644 index 30a9f9f4..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/service/ExtrInterfaceService.java +++ /dev/null @@ -1,18 +0,0 @@ -package kr.xit.fims.biz.cmm.service; - -import kr.xit.fims.framework.biz.cmm.XitLoginVO; -import kr.xit.fims.framework.core.utils.XitCmmnUtil; - -public interface ExtrInterfaceService { - - void processSave(ExtrStrategyService service); - - void processReglt(ExtrStrategyService service); - - - void processErpp(ExtrStrategyService service); - - default XitLoginVO getUserInfo(){ - return XitCmmnUtil.getUserInfo(); - } -} diff --git a/src/main/java/kr/xit/fims/biz/cmm/service/ExtrStrategyService.java b/src/main/java/kr/xit/fims/biz/cmm/service/ExtrStrategyService.java deleted file mode 100644 index 54ff23e5..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/service/ExtrStrategyService.java +++ /dev/null @@ -1,14 +0,0 @@ -package kr.xit.fims.biz.cmm.service; - -import kr.xit.fims.framework.biz.cmm.XitLoginVO; -import kr.xit.fims.framework.core.utils.XitCmmnUtil; - -public interface ExtrStrategyService { - void saveInterfaceData(); - void saveReglt(); - void saveErpp(); - - default XitLoginVO getUserInfo(){ - return XitCmmnUtil.getUserInfo(); - } -} diff --git a/src/main/java/kr/xit/fims/biz/cmm/service/bean/CctvBusInstallCrackDownServiceBean.java b/src/main/java/kr/xit/fims/biz/cmm/service/bean/CctvBusInstallCrackDownServiceBean.java deleted file mode 100644 index 606d821c..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/service/bean/CctvBusInstallCrackDownServiceBean.java +++ /dev/null @@ -1,78 +0,0 @@ -package kr.xit.fims.biz.cmm.service.bean; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import kr.xit.fims.biz.cmm.service.ExtrStrategyService; -import org.apache.commons.collections4.ListUtils; -import org.apache.commons.io.IOUtils; -import org.springframework.web.multipart.MultipartFile; - -import kr.xit.fims.biz.ec.CctvCrackdownDTO; -import kr.xit.fims.framework.support.exception.BizRuntimeException; -import kr.xit.fims.framework.support.util.constants.MessageKey; -import lombok.Builder; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Builder -public class CctvBusInstallCrackDownServiceBean implements ExtrStrategyService { - - // private final IEcCctvCrackdownMapper mapper; - // private final IEcCtznSttemntMapper ctznSttemntMapper; - // - // private final ICmmFileService cmmFileService; - - private final CctvCrackdownDTO.Request reqDTO; - private final CctvCrackdownDTO.BusInstall dto; - - @Override - public void saveInterfaceData() { - // 단속정보메타 1 + 이미지파일 4 = 5개로 구성 - if(reqDTO.getFiles().size() % 5 != 0){ - throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, "단속정보[파일]가 부정확 합니다\n다시 확인해 주세요."); - } - final Comparator comp = (mf1, mf2) -> String.CASE_INSENSITIVE_ORDER.compare(mf1.getOriginalFilename(), mf2.getOriginalFilename()); - List sortedFileList = reqDTO.getFiles().stream() - .sorted(comp) - .collect(Collectors.toList()); - - //Arrays.copyOfRange(sortedFileList.toArray(), 0, 4); - - List> listByMd = ListUtils.partition(sortedFileList, 5); - - for(int idx = 0; idx < listByMd.size(); idx++){ - List mfList = listByMd.get(idx); - - MultipartFile mf = mfList.get(0); - String[] txtNames = mf.getOriginalFilename().split("[.]"); - if(txtNames.length != 2 || !Objects.equals("txt", txtNames[1].toLowerCase())) - throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, String.format("[%s]%s", txtNames[0], "의 단속정보[파일]가 없습니다.")); - - //String[] mdInfos = txtNames[0].split("_"); - - // meta정보 read - List records = new ArrayList<>(); - try(InputStream inputStream = mf.getInputStream();){ - records.addAll(IOUtils.readLines(inputStream, "euc-kr")); - } catch (IOException e) { - // handle exception - } - - } - } - - @Override - public void saveReglt() { - dto.setGpsX("xxxxxxxxx");; - } - - public void saveErpp() { - dto.setGpsY("yyyyyyyyyyy"); - } -} diff --git a/src/main/java/kr/xit/fims/biz/cmm/service/bean/ExtrInterfaceServiceBean.java b/src/main/java/kr/xit/fims/biz/cmm/service/bean/ExtrInterfaceServiceBean.java deleted file mode 100644 index eda3301a..00000000 --- a/src/main/java/kr/xit/fims/biz/cmm/service/bean/ExtrInterfaceServiceBean.java +++ /dev/null @@ -1,47 +0,0 @@ -package kr.xit.fims.biz.cmm.service.bean; - -import kr.xit.fims.biz.cmm.extr.CctvBusInstallCrackDownFactory; -import kr.xit.fims.biz.cmm.extr.ExtrInterfaceDataFactory; -import kr.xit.fims.biz.cmm.service.ExtrInterfaceService; -import kr.xit.fims.biz.cmm.service.ExtrStrategyService; -import kr.xit.fims.biz.ec.CctvCrackdownDTO; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class ExtrInterfaceServiceBean implements ExtrInterfaceService { - - @Override - public void processSave(ExtrStrategyService service){ - service.saveInterfaceData(); - } - - @Override - public void processReglt(ExtrStrategyService service){ - service.saveReglt(); - } - - @Override - public void processErpp(ExtrStrategyService service){ - service.saveErpp(); - } - - public static void main(String[] args) { - ExtrInterfaceDataFactory factory = new CctvBusInstallCrackDownFactory(); - CctvCrackdownDTO.BusInstall dto = factory.parseInterfaceData(CctvCrackdownDTO.Request.builder().build()); - log.debug("{}", dto); - - ExtrInterfaceServiceBean eds = new ExtrInterfaceServiceBean(); - - - ExtrStrategyService strategy = new CctvBusInstallCrackDownServiceBean(CctvCrackdownDTO.Request.builder().build(), dto); - - -eds.processSave(strategy); - log.debug("{}", dto); - - eds.processReglt(strategy); - log.debug("{}", dto); - eds.processErpp(strategy); - log.debug("{}", dto); - } -} diff --git a/src/main/java/kr/xit/fims/biz/ec/service/bean/EcCctvCrackdownServiceBean.java b/src/main/java/kr/xit/fims/biz/ec/service/bean/EcCctvCrackdownServiceBean.java index 799aa22a..dddc745f 100644 --- a/src/main/java/kr/xit/fims/biz/ec/service/bean/EcCctvCrackdownServiceBean.java +++ b/src/main/java/kr/xit/fims/biz/ec/service/bean/EcCctvCrackdownServiceBean.java @@ -12,6 +12,7 @@ import java.util.stream.Collectors; import cokr.xit.foundation.component.AbstractServiceBean; import kr.xit.fims.biz.ec.service.EcCctvCrackdownService; +import kr.xit.fims.biz.ec.util.ExtnlBusInstallInterfaceUtils; import kr.xit.fims.framework.biz.cmm.dao.XitFrameCodeMapper; import kr.xit.fims.framework.biz.cmm.service.XitFrameCodeService; import org.apache.commons.collections4.ListUtils; @@ -188,7 +189,7 @@ public class EcCctvCrackdownServiceBean extends AbstractServiceBean implements E //for(FolderReqDTO.FileInfo fi: dto.getFileInfoList()) { dto.getFileInfoList().forEach((fi) -> { CctvCrackdownDTO.BusInstall busInstallDTO = new CctvCrackdownDTO.BusInstall(); - ExtnlInterfaceUtils.parseFileBusinstallToObject(busInstallDTO, filePath + "/" + fi.getFileNm(), + ExtnlBusInstallInterfaceUtils.parseFileBusinstallToObject(busInstallDTO, filePath + "/" + fi.getFileNm(), uploadRoot + uploadTempPath); String sggCd = xitFrameCodeService.instCdToSggCd(getUserInfo().getNsttCd()); diff --git a/src/main/java/kr/xit/fims/biz/ec/util/ExtnlBusInstallInterfaceUtils.java b/src/main/java/kr/xit/fims/biz/ec/util/ExtnlBusInstallInterfaceUtils.java new file mode 100644 index 00000000..94af523e --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/ec/util/ExtnlBusInstallInterfaceUtils.java @@ -0,0 +1,155 @@ +package kr.xit.fims.biz.ec.util; + +import kr.xit.fims.biz.ec.CctvCrackdownDTO; +import kr.xit.fims.framework.biz.util.ExtnlInterfaceUtils; +import kr.xit.fims.framework.support.exception.BizRuntimeException; +import kr.xit.fims.framework.support.util.CommUtils; +import kr.xit.fims.framework.support.util.constants.MessageKey; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; + +public class ExtnlBusInstallInterfaceUtils { + + /** + *
+     * 버스장착형 파일 parsing
+     * @param dto CctvCrackdownDTO.BusInstall DTO
+     * @param fullFilePath 버스장착형 파일 full file path info
+     * @param tempDir 파싱시 임시로 사용할 directory
+     * 
+ */ + public static void parseFileBusinstallToObject(CctvCrackdownDTO.BusInstall dto, final String fullFilePath, final String tempDir) { + String tempPath = tempDir + "/" + CommUtils.getStringFromUUID(); + + try(RandomAccessFile raf = new RandomAccessFile(fullFilePath,"r")) { + long fileSize = raf.length(); + byte[] buff = null; + long pos = 0; + + // 텍스트size : 1 ~ 7(7) + dto.setTextSize(ExtnlInterfaceUtils.readBuff(raf, pos, 7)); + pos += 7; + + // 단속장비 : 8 ~ 12(5) + dto.setRegltEquip(ExtnlInterfaceUtils.readBuff(raf, pos, 5)); + pos += 5; + + // 차량속도 : 13 ~ 15(3) + dto.setCarSpeed(ExtnlInterfaceUtils.readBuff(raf, pos, 3)); + pos += 3; + + // 차종 : 16 ~ 16(1) - 미사용 + dto.setCarModel(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // 도로코드 : 17 ~ 17(1) - 미사용 + dto.setRoadCode(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // 단속일자 : 18 ~ 25(8) + dto.setCrdnYmd(ExtnlInterfaceUtils.readBuff(raf, pos, 8)); + pos += 8; + + // 단속시간 : 26 ~ 31(6) + dto.setRegltTime(ExtnlInterfaceUtils.readBuff(raf, pos, 6)); + pos += 6; + + // 차량번호 : 32 ~ 43(12) + dto.setVhrno(ExtnlInterfaceUtils.readBuff(raf, pos, 12, "euc-kr")); + pos += 12; + + // 번호판 X 좌표 : 44 ~ 47(4) + dto.setCarNumXPos(ExtnlInterfaceUtils.readBuff(raf, pos, 4)); + pos += 4; + + // 번호판 Y 좌표 : 48 ~ 51(4) + dto.setCarNumYPos(ExtnlInterfaceUtils.readBuff(raf, pos, 4)); + pos += 4; + + // 번호판 Width : 52 ~ 55(4) + dto.setCarNumWidth(ExtnlInterfaceUtils.readBuff(raf, pos, 4)); + pos += 4; + + // 번호판 Height : 56 ~ 59(4) + dto.setCarNumHeight(ExtnlInterfaceUtils.readBuff(raf, pos, 4)); + pos += 4; + + // (미사용) : 60 ~ 60(1) + dto.setSkipFld(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // 위반구분(미사용) : 61 ~ 61(1) + dto.setVioltDiv(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // 위반종류(미사용) : 62 ~ 62(1) + dto.setVioltKind(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // GPS X 좌표 : 62 ~ 84(23) + dto.setGpsX(ExtnlInterfaceUtils.readBuff(raf, pos, 23)); + pos += 23; + + // GPS Y 좌표 : 85 ~ 107(23) + dto.setGpsY(ExtnlInterfaceUtils.readBuff(raf, pos, 23)); + pos += 23; + + // 사진매수(미사용) : 108 ~ 109(2) + dto.setImgCnt(ExtnlInterfaceUtils.readBuff(raf, pos, 2)); + pos += 2; + + // tlcType(미사용) : 110 ~ 110(1) + dto.setTlcType(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // movingType(미사용) : 111 ~ 111(1) + dto.setMovingType(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // tlcColor(미사용) : 112 ~ 112(1) + dto.setTlcColor(ExtnlInterfaceUtils.readBuff(raf, pos, 1)); + pos += 1; + + // car image + int imgSize = Integer.parseInt(ExtnlInterfaceUtils.readBuff(raf, pos, 7)); + pos += 7; + dto.getBusinstallImgList().add(ExtnlInterfaceUtils.getImgMultipartFile(raf, pos, imgSize, "car.jpg", tempPath)); + pos += imgSize; + + // plate image : car number + imgSize = Integer.parseInt(ExtnlInterfaceUtils.readBuff(raf, pos, 7)); + pos += 7; + dto.getBusinstallImgList().add(ExtnlInterfaceUtils.getImgMultipartFile(raf, pos, imgSize, "carNum.jpg", tempPath)); + pos += imgSize; + + // moving image + int idx = 1; + do{ + imgSize = Integer.parseInt(ExtnlInterfaceUtils.readBuff(raf, pos, 7)); + pos += 7; + dto.getBusinstallImgList().add(ExtnlInterfaceUtils.getImgMultipartFile(raf, pos, imgSize, String.format("%s%d%s","moving", idx, ".jpg"), tempPath)); + pos += imgSize; + idx++; + } while(fileSize > pos); + + //FIXME: moving image수 체크 : 불필요 하면 삭제 + // dto.getImgCnt() - moving image count 이므로, car image and carNum image (2개) 제외한 수량으로 check + if(Integer.parseInt(dto.getImgCnt()) != dto.getBusinstallImgList().size() - 2){ + String errMsg = String.format("버스장착형 단속이미지 정보[이미지수: %d, 실제이미지: %d]가 부정확 합니다[%s]", Integer.parseInt(dto.getImgCnt()), dto.getBusinstallImgList().size() - 2, fullFilePath); + throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, errMsg); + } + + }catch(IOException e){ + throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, e.getMessage()); + + }finally { + File f = new File(tempPath); + if(f.exists()) { + //noinspection ResultOfMethodCallIgnored + f.delete(); + } + } + } +} diff --git a/src/main/java/kr/xit/fims/framework/biz/util/ExtnlInterfaceUtils.java b/src/main/java/kr/xit/fims/framework/biz/util/ExtnlInterfaceUtils.java index 53919726..f23240b0 100644 --- a/src/main/java/kr/xit/fims/framework/biz/util/ExtnlInterfaceUtils.java +++ b/src/main/java/kr/xit/fims/framework/biz/util/ExtnlInterfaceUtils.java @@ -25,146 +25,7 @@ import java.util.List; @Slf4j public class ExtnlInterfaceUtils { - /** - *
-     * 버스장착형 파일 parsing
-     * @param dto CctvCrackdownDTO.BusInstall DTO
-     * @param fullFilePath 버스장착형 파일 full file path info
-     * @param tempDir 파싱시 임시로 사용할 directory
-     * 
- */ - public static void parseFileBusinstallToObject(CctvCrackdownDTO.BusInstall dto, final String fullFilePath, final String tempDir) { - String tempPath = tempDir + "/" + CommUtils.getStringFromUUID(); - - try(RandomAccessFile raf = new RandomAccessFile(fullFilePath,"r")) { - long fileSize = raf.length(); - byte[] buff = null; - long pos = 0; - - // 텍스트size : 1 ~ 7(7) - dto.setTextSize(readBuff(raf, pos, 7)); - pos += 7; - - // 단속장비 : 8 ~ 12(5) - dto.setRegltEquip(readBuff(raf, pos, 5)); - pos += 5; - - // 차량속도 : 13 ~ 15(3) - dto.setCarSpeed(readBuff(raf, pos, 3)); - pos += 3; - - // 차종 : 16 ~ 16(1) - 미사용 - dto.setCarModel(readBuff(raf, pos, 1)); - pos += 1; - - // 도로코드 : 17 ~ 17(1) - 미사용 - dto.setRoadCode(readBuff(raf, pos, 1)); - pos += 1; - - // 단속일자 : 18 ~ 25(8) - dto.setCrdnYmd(readBuff(raf, pos, 8)); - pos += 8; - - // 단속시간 : 26 ~ 31(6) - dto.setRegltTime(readBuff(raf, pos, 6)); - pos += 6; - - // 차량번호 : 32 ~ 43(12) - dto.setVhrno(readBuff(raf, pos, 12, "euc-kr")); - pos += 12; - - // 번호판 X 좌표 : 44 ~ 47(4) - dto.setCarNumXPos(readBuff(raf, pos, 4)); - pos += 4; - - // 번호판 Y 좌표 : 48 ~ 51(4) - dto.setCarNumYPos(readBuff(raf, pos, 4)); - pos += 4; - - // 번호판 Width : 52 ~ 55(4) - dto.setCarNumWidth(readBuff(raf, pos, 4)); - pos += 4; - - // 번호판 Height : 56 ~ 59(4) - dto.setCarNumHeight(readBuff(raf, pos, 4)); - pos += 4; - - // (미사용) : 60 ~ 60(1) - dto.setSkipFld(readBuff(raf, pos, 1)); - pos += 1; - - // 위반구분(미사용) : 61 ~ 61(1) - dto.setVioltDiv(readBuff(raf, pos, 1)); - pos += 1; - - // 위반종류(미사용) : 62 ~ 62(1) - dto.setVioltKind(readBuff(raf, pos, 1)); - pos += 1; - - // GPS X 좌표 : 62 ~ 84(23) - dto.setGpsX(readBuff(raf, pos, 23)); - pos += 23; - - // GPS Y 좌표 : 85 ~ 107(23) - dto.setGpsY(readBuff(raf, pos, 23)); - pos += 23; - - // 사진매수(미사용) : 108 ~ 109(2) - dto.setImgCnt(readBuff(raf, pos, 2)); - pos += 2; - - // tlcType(미사용) : 110 ~ 110(1) - dto.setTlcType(readBuff(raf, pos, 1)); - pos += 1; - - // movingType(미사용) : 111 ~ 111(1) - dto.setMovingType(readBuff(raf, pos, 1)); - pos += 1; - - // tlcColor(미사용) : 112 ~ 112(1) - dto.setTlcColor(readBuff(raf, pos, 1)); - pos += 1; - - // car image - int imgSize = Integer.parseInt(readBuff(raf, pos, 7)); - pos += 7; - dto.getBusinstallImgList().add(getImgMultipartFile(raf, pos, imgSize, "car.jpg", tempPath)); - pos += imgSize; - - // plate image : car number - imgSize = Integer.parseInt(readBuff(raf, pos, 7)); - pos += 7; - dto.getBusinstallImgList().add(getImgMultipartFile(raf, pos, imgSize, "carNum.jpg", tempPath)); - pos += imgSize; - - // moving image - int idx = 1; - do{ - imgSize = Integer.parseInt(readBuff(raf, pos, 7)); - pos += 7; - dto.getBusinstallImgList().add(getImgMultipartFile(raf, pos, imgSize, String.format("%s%d%s","moving", idx, ".jpg"), tempPath)); - pos += imgSize; - idx++; - } while(fileSize > pos); - - //FIXME: moving image수 체크 : 불필요 하면 삭제 - // dto.getImgCnt() - moving image count 이므로, car image and carNum image (2개) 제외한 수량으로 check - if(Integer.parseInt(dto.getImgCnt()) != dto.getBusinstallImgList().size() - 2){ - String errMsg = String.format("버스장착형 단속이미지 정보[이미지수: %d, 실제이미지: %d]가 부정확 합니다[%s]", Integer.parseInt(dto.getImgCnt()), dto.getBusinstallImgList().size() - 2, fullFilePath); - throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, errMsg); - } - - }catch(IOException e){ - throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, e.getMessage()); - }finally { - File f = new File(tempPath); - if(f.exists()) { - //noinspection ResultOfMethodCallIgnored - f.delete(); - } - } - } /** * 성공시 null, 실패시 NtriDTO.PhotoFileError return @@ -307,7 +168,7 @@ public class ExtnlInterfaceUtils { return null; } - private static String readBuff(RandomAccessFile raf, Long startPos, int readLength){ + public static String readBuff(RandomAccessFile raf, Long startPos, int readLength){ try { raf.seek(startPos); byte[] buff = new byte[readLength]; @@ -319,7 +180,7 @@ public class ExtnlInterfaceUtils { } - private static String readBuff(RandomAccessFile raf, long startPos, int readLength, String encoding){ + public static String readBuff(RandomAccessFile raf, long startPos, int readLength, String encoding){ try { raf.seek(startPos); byte[] buff = new byte[readLength]; @@ -331,7 +192,7 @@ public class ExtnlInterfaceUtils { } - private static MultipartFile getImgMultipartFile(RandomAccessFile raf, long startPos, int imgSize, String imgName, String tempPath){ + public static MultipartFile getImgMultipartFile(RandomAccessFile raf, long startPos, int imgSize, String imgName, String tempPath){ try { raf.seek(startPos); byte[] buff = new byte[imgSize]; @@ -344,9 +205,6 @@ public class ExtnlInterfaceUtils { } - public static void main(String[] args) { - - } }