diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownFactory.java b/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownFactory.java new file mode 100644 index 00000000..9b46bab3 --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownFactory.java @@ -0,0 +1,30 @@ +package kr.xit.fims.biz.cmm.extr; + +import kr.xit.fims.biz.ec.model.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 CctvBusOnlyCrackDownFactory extends ExtrInterfaceDataFactory{ + private CctvCrackdownDTO.BusOnly dto; + + @Override + public CctvCrackdownDTO.BusOnly parseData(CctvCrackdownDTO.Request reqDto) { + return CctvCrackdownDTO.BusOnly.builder() + .carModel("dkkdkd").build(); + } + + // @Override + // public CctvCrackdownDTO.BusOnly createDTO() { + // return CctvCrackdownDTO.BusOnly.builder() + // .carModel("dkkdkd").build(); + // } + +} diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownService.java b/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownService.java new file mode 100644 index 00000000..8ca43a6f --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/CctvBusOnlyCrackDownService.java @@ -0,0 +1,93 @@ +package kr.xit.fims.biz.cmm.extr; + +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 org.apache.commons.collections4.ListUtils; +import org.apache.commons.io.IOUtils; +import org.springframework.web.multipart.MultipartFile; + +import kr.xit.fims.biz.ec.model.CctvCrackdownDTO; +import kr.xit.framework.support.exception.BizRuntimeException; +import kr.xit.framework.support.util.constants.MessageKey; +import lombok.Builder; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Builder +public class CctvBusOnlyCrackDownService implements IExtrStrategyService { + + // private final IEcCctvCrackdownMapper mapper; + // private final IEcCtznSttemntMapper ctznSttemntMapper; + // + // private final ICmmFileService cmmFileService; + + private final CctvCrackdownDTO.Request reqDTO; + private final CctvCrackdownDTO.BusOnly 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 + } + // data set + // CctvCrackdownDTO.ExtrlRegltCntc extrRegltDTO = getExtrlRegltCntcDTO(txtNames[0], records); + // extrRegltDTO.setSysCode(getUserInfo().getOrgnztId()); + // extrRegltDTO.setInsttCode(getUserInfo().getPstinstCode()); + // + // if(records.size() >= 3){ + // extrRegltDTO.setRegltSeCode(FimsConst.RegltSeCode.CCTV_DRV.getCode()); + // }else{ + // extrRegltDTO.setRegltSeCode(FimsConst.RegltSeCode.CCTV_FIX.getCode()); + // } + // // 외부연계 데이타 생성 + // //mapper.insertEcExtrlRegltCntc(extrRegltDTO); + // + // // CCTV image 저장 + // List cpListMf = new ArrayList<>(mfList); + // cpListMf.remove(0); + // cmmFileService.saveFiles(getFileMst(extrRegltDTO.getRegltSeCode(), extrRegltDTO.getExtrlRegltCntcId()), cpListMf); + } + } + + @Override + public void saveReglt() { + dto.setGpsX("xxxxxxxxx");; + } + + public void saveErpp() { + dto.setGpsY("yyyyyyyyyyy"); + } +} 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 new file mode 100644 index 00000000..981a4ba0 --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceDataFactory.java @@ -0,0 +1,14 @@ +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/ExtrInterfaceService.java b/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceService.java new file mode 100644 index 00000000..812a9a8a --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/ExtrInterfaceService.java @@ -0,0 +1,43 @@ +package kr.xit.fims.biz.cmm.extr; + +import kr.xit.fims.biz.ec.model.CctvCrackdownDTO; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ExtrInterfaceService implements IExtrInterfaceService{ + + @Override + public void processSave(IExtrStrategyService service){ + service.saveInterfaceData(); + } + + @Override + public void processReglt(IExtrStrategyService service){ + service.saveReglt(); + } + + @Override + public void processErpp(IExtrStrategyService service){ + service.saveErpp(); + } + + public static void main(String[] args) { + ExtrInterfaceDataFactory factory = new CctvBusOnlyCrackDownFactory(); + CctvCrackdownDTO.BusOnly dto = factory.parseInterfaceData(CctvCrackdownDTO.Request.builder().build()); + log.debug("{}", dto); + + ExtrInterfaceService eds = new ExtrInterfaceService(); + + + IExtrStrategyService strategy = new CctvBusOnlyCrackDownService(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/cmm/extr/IExtrInterfaceService.java b/src/main/java/kr/xit/fims/biz/cmm/extr/IExtrInterfaceService.java new file mode 100644 index 00000000..5a7edd6b --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/IExtrInterfaceService.java @@ -0,0 +1,18 @@ +package kr.xit.fims.biz.cmm.extr; + +import kr.xit.framework.biz.cmm.model.XitLoginVO; +import kr.xit.framework.core.utils.XitCmmnUtil; + +public interface IExtrInterfaceService { + + void processSave(IExtrStrategyService service); + + void processReglt(IExtrStrategyService service); + + + void processErpp(IExtrStrategyService service); + + default XitLoginVO getUserInfo(){ + return XitCmmnUtil.getUserInfo(); + } +} diff --git a/src/main/java/kr/xit/fims/biz/cmm/extr/IExtrStrategyService.java b/src/main/java/kr/xit/fims/biz/cmm/extr/IExtrStrategyService.java new file mode 100644 index 00000000..c2d6252b --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/IExtrStrategyService.java @@ -0,0 +1,14 @@ +package kr.xit.fims.biz.cmm.extr; + +import kr.xit.framework.biz.cmm.model.XitLoginVO; +import kr.xit.framework.core.utils.XitCmmnUtil; + +public interface IExtrStrategyService { + void saveInterfaceData(); + void saveReglt(); + void saveErpp(); + + default XitLoginVO getUserInfo(){ + return XitCmmnUtil.getUserInfo(); + } +} 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 new file mode 100644 index 00000000..5d3a9c73 --- /dev/null +++ b/src/main/java/kr/xit/fims/biz/cmm/extr/strategypattern.drawio @@ -0,0 +1 @@ + \ No newline at end of file