package cokr.xit.fims.cvlc.service.bean;

import java.io.File;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import cokr.xit.base.file.FileInfo;
import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.CrdnSttsHstry;
import cokr.xit.fims.cmmn.dao.CrdnPayerHstryMapper;
import cokr.xit.fims.cmmn.dao.CrdnSttsHstryMapper;
import cokr.xit.fims.cmmn.hwp.AddingParagraphBetweenHWPFile;
import cokr.xit.fims.cmmn.hwp.InsertingImageCell;
import cokr.xit.fims.cmmn.service.bean.CrdnSttsHstryBean;
import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery;
import cokr.xit.fims.crdn.dao.CrdnInfoMapper;
import cokr.xit.fims.crdn.dao.CrdnInstMapper;
import cokr.xit.fims.crdn.dao.CrdnUpdtMapper;
import cokr.xit.fims.crdn.dao.GlobalStngMapper;
import cokr.xit.fims.crdn.service.bean.CrdnStngBean;
import cokr.xit.fims.cvlc.CrdnCvlcpt;
import cokr.xit.fims.cvlc.dao.AnswerWordsMapper;
import cokr.xit.fims.cvlc.dao.CrdnCvlcptMapper;
import cokr.xit.fims.cvlc.service.CrdnCvlcptService;
import cokr.xit.fims.excl.dao.LevyExclMapper;
import cokr.xit.fims.excl.service.bean.Excl01Bean;
import cokr.xit.fims.sprt.Sprt;
import cokr.xit.foundation.component.AbstractServiceBean;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.interfaces.disabledparking.service.bean.DisabledParkingBean;
import kr.dogfoot.hwplib.object.HWPFile;
import kr.dogfoot.hwplib.reader.HWPReader;
import kr.dogfoot.hwplib.tool.objectfinder.FieldFinder;
import kr.dogfoot.hwplib.writer.HWPWriter;

@Service("crdnCvlcptService")
public class CrdnCvlcptServiceBean extends AbstractServiceBean implements CrdnCvlcptService {

	@Resource(name="fileBean")
	private FileBean fileBean;

	@Resource(name = "disabledParkingBean")
	private DisabledParkingBean disabledParkingBean;

	@Resource(name="crdnCvlcptMainBean")
	protected CrdnCvlcptMainBean crdnCvlcptMainBean;

	@Resource(name="crdnCvlcptSubBean")
	protected CrdnCvlcptSubBean crdnCvlcptSubBean;

	@Resource(name="crdnStngBean")
	private CrdnStngBean crdnStngBean;

	@Resource(name="excl01Bean")
	private Excl01Bean excl01Bean;

	@Resource(name="levyExclMapper")
	private LevyExclMapper levyExclMapper;

	@Resource(name = "answerWordsMapper")
	private AnswerWordsMapper answerWordsMapper;

	@Resource(name = "crdnCvlcptMapper")
	private CrdnCvlcptMapper crdnCvlcptMapper;

	@Resource(name = "crdnSttsHstryMapper")
	private CrdnSttsHstryMapper crdnSttsHstryMapper;

	@Resource(name = "crdnSttsHstryBean")
	private CrdnSttsHstryBean crdnSttsHstryBean;

	@Resource(name = "crdnPayerHstryMapper")
	private CrdnPayerHstryMapper crdnPayerHstryMapper;

	@Resource(name="crdnInfoMapper")
	private CrdnInfoMapper crdnInfoMapper;

	@Resource(name="crdnInstMapper")
	protected CrdnInstMapper crdnInstMapper;

	@Resource(name="crdnUpdtMapper")
	protected CrdnUpdtMapper crdnUpdtMapper;

	@Resource(name="globalStngMapper")
	protected GlobalStngMapper globalStngMapper;

	@Override
	public List<DataObject> getCivilComplaintList(CrdnQuery query) {
		List<DataObject> dataObjectList = new ArrayList<DataObject>();
        switch (ifEmpty(query.getGridType(), () -> "")) {
	        case "receiptData":
	        	dataObjectList = crdnCvlcptMapper.selectCivilComplaintReceiptDataList(query.setOrderBy("CVLCPT_RCPT_YMD, CRDN_ID"));
	        	break;
	        case "answerTargetData":
	        	dataObjectList = crdnCvlcptMapper.selectCivilComplaintAnswerTargetDataList(query.setOrderBy("CRDN_ID"));
	        	break;
	        default:
	        	dataObjectList = crdnCvlcptMapper.selectCivilComplaintList(query.setOrderBy("CRDN_ID"));
	        	break;
	    }


		return dataObjectList;
	}

	@Override
	public Map<String, String> makeFileFromHwpFormat(CrdnQuery query) {
		String baseFormatFilePath = ("format/cvlcptOrgnl_text.hwp");
		String attachFormatFilePath = ("format/cvlcptOrgnl_photo.hwp");

		DataObject dataObject = crdnCvlcptMainBean.getCivilComplaintOriginalInfo(query);
		SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat ymdHypenFormat = new SimpleDateFormat("yyyy-MM-dd");

		try {

			InputStream baseFormatIS = new ClassPathResource(baseFormatFilePath).getInputStream();

			HWPFile baseFormatFile = HWPReader.fromInputStream(baseFormatIS);

			ArrayList<String> strings = new ArrayList<String>();
			strings.add(dataObject.string("CVLCPT_APLCNT_NM"));
			FieldFinder.setClickHereText(baseFormatFile, "신청자", strings);

			strings = new ArrayList<String>();
			String cvlcptRcptYmd = dataObject.string("CVLCPT_RCPT_YMD");
			cvlcptRcptYmd = ymdHypenFormat.format(ymdFormat.parse(cvlcptRcptYmd));
			strings.add(cvlcptRcptYmd);
			FieldFinder.setClickHereText(baseFormatFile, "접수일자", strings);

			strings = new ArrayList<String>();
			String cvlcptRrcsPrnmntDt = dataObject.string("CVLCPT_PRCS_PRNMNT_DT");
			cvlcptRrcsPrnmntDt = ymdHypenFormat.format(ymdFormat.parse(cvlcptRrcsPrnmntDt));
			strings.add(cvlcptRrcsPrnmntDt);
			FieldFinder.setClickHereText(baseFormatFile, "처리기한", strings);

			strings = new ArrayList<String>();
			strings.add(dataObject.string("CVLCPT_RCPT_NO"));
			FieldFinder.setClickHereText(baseFormatFile, "접수번호", strings);

			strings = new ArrayList<String>();
			strings.add(dataObject.string("CVLCPT_LIST_NO"));
			FieldFinder.setClickHereText(baseFormatFile, "목록번호", strings);

			strings = new ArrayList<String>();
			String cvlcptAplyCn = dataObject.string("CVLCPT_APLY_CN");
			cvlcptAplyCn = CmmnUtil.escapeHTMLEntity(cvlcptAplyCn);
			strings.add(cvlcptAplyCn);
			FieldFinder.setClickHereText(baseFormatFile, "민원내용", strings);

			String currentTime = ymdhmsFormat.format(new Date());
			String year = currentTime.substring(0, 4);
			String month = currentTime.substring(4, 6);
			String day = currentTime.substring(6, 8);

			String formatFileResultRootPath = "files" + File.separator + "result" + File.separator + "print";
			String formatFileResultFolderPath = formatFileResultRootPath
					+ File.separator + year + File.separator + month + File.separator + day;

			File formatFileResultFolder = new File(formatFileResultFolderPath);

			if(!formatFileResultFolder.exists()) {
				formatFileResultFolder.mkdirs();
			}
			String resultHwpPath = formatFileResultFolderPath + File.separator + currentTime + ".hwp";

			HWPWriter.toFile(baseFormatFile, resultHwpPath);

			HWPFile resultFile = HWPReader.fromFile(resultHwpPath);

			String linkTblNm = dataObject.string("LINK_TBL_NM");
			if(!(ifEmpty(linkTblNm, () -> "").equals(""))) {
				FileQuery fileQuery = new FileQuery();

				if(linkTblNm.equals("TB_ESB_INTERFACE")) {
					fileQuery.setInfoType("010");
				} else if(linkTblNm.equals("TB_SAEOL")) {
					fileQuery.setInfoType("020");
				} else {
					throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다.");
				}

				fileQuery.setInfoKeys(dataObject.string("LINK_ID"));

				List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);

				fileInfoList = fileInfoList.stream()
						.filter(fileInfo -> fileInfo.string("MIME_TYPE").startsWith("image"))
						.collect(Collectors.toList());

				if(fileInfoList != null && fileInfoList.size() > 0) {
					int photoCnt = fileInfoList.size();
					int PHOTO_COUNT_PER_PAGE = 4;

					for(int i=0; i < photoCnt; i += PHOTO_COUNT_PER_PAGE) {

						InputStream attachFormatIS = new ClassPathResource(attachFormatFilePath).getInputStream();
						HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS);
						InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "왼쪽위사진", fileInfoList.get(i).string("URL"));
						if(i+1 < photoCnt)
							InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "오른쪽위사진", fileInfoList.get(i+1).string("URL"));
						if(i+2 < photoCnt)
							InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "왼쪽아래사진", fileInfoList.get(i+2).string("URL"));
						if(i+3 < photoCnt)
							InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "오른쪽아래사진", fileInfoList.get(i+3).string("URL"));
						AddingParagraphBetweenHWPFile.fileMerge(attachFormatFile, resultFile);
					}

					HWPWriter.toFile(resultFile, resultHwpPath);
				}
			}

			String downlaodFileName = "민원내역원본_" + currentTime + ".hwp";
			Map<String, String> result = Map.of(
				"filePath", resultHwpPath,
				"fileName", downlaodFileName
			);

			return result;

		} catch (Exception e) {
			throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다.");

		}
	}

	@Override
	public DataObject getCivilComplaintOriginalInfo(CrdnQuery query) {
		return crdnCvlcptMainBean.getCivilComplaintOriginalInfo(query);
	}

	@Override
	public DataObject getAnswerPreview(CrdnQuery query) {
		DataObject dataObject = crdnCvlcptMapper.selectAnswerPreview(query.getCrdnId());

		//저장된 답변이 없으면
		if(ifEmpty(dataObject.string("CVLCPT_PRCS_RSLT_CN"), () -> "").equals("")) {
			String resultWords = crdnCvlcptMainBean.mappingAnswerWords(query.getCrdnId(), query.getCurrentInstitute(), query.getCurrentUserAcnt());
			dataObject.set("CVLCPT_PRCS_RSLT_CN", resultWords);
		}

		return dataObject;
	}

	@Override
	public DataObject getCivilComplaintReceiptInitialDataInfo(CrdnQuery query) {
		//민원조회
		DataObject dataObject = crdnCvlcptMapper.selectCivilComplaintReceiptInitialDataInfo(query);

		//첨부파일 조회
		FileQuery fileQuery = new FileQuery();
		fileQuery.setInfoType(Crdn.INF_TYPE);
		fileQuery.setInfoKeys(query.getCrdnId());
		List<DataObject> fileList = fileBean.getFileList(fileQuery);
		if(fileList != null && !fileList.isEmpty()) {
			dataObject.set("fileList", fileList);
		}

		//동영상 존재 여부 확인
		dataObject.set("videoExist", "N");
		String linkTblNm = dataObject.string("LINK_TBL_NM");
		if(!linkTblNm.equals("")) {

			if(linkTblNm.equals("TB_ESB_INTERFACE")) {
				fileQuery.setInfoType("010");
			} else if(linkTblNm.equals("TB_SAEOL")) {
				fileQuery.setInfoType("020");
			} else {
				throw new RuntimeException("파일 조회 중 오류가 발생하였습니다.");
			}

			fileQuery.setInfoKeys(dataObject.string("LINK_ID"));
			List<DataObject> linkFileList = fileBean.getFileList(fileQuery);
			if(linkFileList != null && !linkFileList.isEmpty()) {
				for(int i=0; i < linkFileList.size(); i++) {
					String mimeType = linkFileList.get(i).string("MIME_TYPE");
					if(Arrays.asList(Sprt.VIDEO_MIME_TYPE).contains(mimeType)) {
						dataObject.set("videoExist", "Y");
					}
				}
			}
		}

		return dataObject;
	}

	@Override
	public boolean sendBackCivilComplaintInfo(String crdnId) {
		boolean saved = false;

		DataObject crdnInfo = crdnInfoMapper.selectCrdnInfo(crdnId);

		saved = crdnCvlcptSubBean.executelevyExcl("sendBack", crdnId);
		if(!saved) {
			throw new RuntimeException("반송 처리 중 서손처리에 실패하였습니다.");
		}

		boolean isFirstBorn = crdnInfo.string("CRDN_REG_SE_CD").equals("02");
		boolean isNotYetTransmit = !Arrays.asList(new String[]{"04","05","06"}).contains(crdnInfo.string("CVLCPT_TRSM_CD"));

		//자동등록된 연계자료이며, 전송 작업 처리 전 자료에 대해 민원 정보를 업데이트한다.
		if (isFirstBorn && isNotYetTransmit) {

			CrdnCvlcpt crdnCvlcpt = new CrdnCvlcpt();
			crdnCvlcpt.setCvlcptLinkId(crdnInfo.string("CVLCPT_LINK_ID"));
			crdnCvlcpt.setCvlcptPrcsCd("01");

			boolean retSuccess = crdnCvlcptMapper.updateCvlcptProcessSectionForSendBack(crdnCvlcpt) == 1 ? true : false;

			if (!retSuccess) {
				throw new RuntimeException("반송 처리 중 단속민원답변 수정에 실패하였습니다.");
			}

			boolean result = crdnCvlcptMainBean.insertTransmitInfo(true, crdnInfo.string("CVLCPT_LINK_ID"));
			if (!result) {
				throw new RuntimeException("반송 처리 중 전송자료 등록에 실패하였습니다.");
			}
		}

		return saved;
	}

	@Override
	public boolean updateCvlcptProcessSection(Map<String, Object> nonQueryRequest, CrdnCvlcpt crdnCvlcpt, Crdn crdn, List<FileInfo> newFileInfoList) {
		boolean saved = false;

		DataObject crdnInfo = crdnInfoMapper.selectCrdnInfo(crdn.getCrdnId());
		String acceptType = (String)ifEmpty(nonQueryRequest.get("acceptType"), "");

		saved = crdnCvlcptSubBean.updateSubInfo(nonQueryRequest, crdn, newFileInfoList);
		if(!saved) {
			throw new RuntimeException("민원자료 저장 중 오류가 발생하였습니다.");
		}
		crdnCvlcpt.setCvlcptLinkId(crdnInfo.string("CVLCPT_LINK_ID"));

		boolean isFirstBorn = crdnInfo.string("CRDN_REG_SE_CD").equals("02");
		boolean isNotYetTransmit = !Arrays.asList(new String[]{"04","05","06"}).contains(crdnInfo.string("CVLCPT_TRSM_CD"));

		//자동등록된 연계자료이며, 전송 작업 처리 전 자료에 대해 민원 정보를 업데이트한다.
		if (isFirstBorn && isNotYetTransmit) {

			boolean retSuccess = false;
			// 답변내용 초기화
			retSuccess = crdnCvlcptMainBean.initCvlcptPrcsRsltCn(crdnCvlcpt.getCvlcptLinkId());
			if (!retSuccess) {
				throw new RuntimeException("민원자료 저장 중 단속민원 대장의 민원처리결과내용 초기화에 실패하였습니다.");
			}

			String newCvlcptPrcsCd = "";
			String newCvlcptTrsmCd = "";

			String ansRsnCd = "";
			if(acceptType.equals("someAccept") || acceptType.equals("nonAccept")) { //일부수용,불수용
				ansRsnCd = crdn.getLevyExclRsnCd();
			} else {
				ansRsnCd = "3"+crdn.getVltnCd();
			}

			CrdnQuery crdnQuery = new CrdnQuery();
			crdnQuery.setSggCd(crdn.getSggCd());
			crdnQuery.setTaskSeCd(crdn.getTaskSeCd());
			crdnQuery.setAnsRsnCd(ansRsnCd);
			if(crdn.getVltnCd().equals("01") && ifEmpty(crdnCvlcpt.getDstrbncYn(), () -> "").equals("Y")) {
				crdnQuery.setDstrbncYn("Y");
			}

			// 민원 답변 문구(TB_CVLCPT_ANS_WORDS) 대장 조회
			DataObject infoCvlcptAnsWords = answerWordsMapper.selectCvlcptAnswerWordsInfo(crdnQuery);

			if(acceptType.equals("someAccept") || acceptType.equals("nonAccept")) { //일부수용,불수용
				// 비부과(서손)사유가 민원 답변대상인가? 민원 답변 문구(TB_CVLCPT_ANS_WORDS) 대장에 답변 사유 코드가 존재한다면..
				if (infoCvlcptAnsWords != null) {
					newCvlcptPrcsCd = "04";									// 민원 처리 코드 - 불수용(과태료 부과제외)
					newCvlcptTrsmCd = "01";									// 민원 전송 코드 - 전송 대상
				} else  {
					newCvlcptPrcsCd = "07";									// 민원 처리 코드 - 비부과(서손)사유가 답변 미대상
					newCvlcptTrsmCd = "03";									// 민원 전송 코드 - 비부과(서손)사유가 전송 미대상
				}
			} else { //수용일 때

				newCvlcptPrcsCd = "02";									// 민원 처리 코드 - 수용
				newCvlcptTrsmCd = "01";									// 민원 전송 코드 - 전송 대상
			}

	        crdnCvlcpt.setCvlcptPrcsCd(newCvlcptPrcsCd);									// 민원 처리 코드

	        if (acceptType.equals("someAccept")) {
	        	crdnCvlcpt.setCvlcptPrcsSumry("과태료 계고");			// 민원 처리 요약
	        } else if(acceptType.equals("accept")) {
	        	crdnCvlcpt.setCvlcptPrcsSumry("과태료부과");			// 민원 처리 요약
	        } else if(acceptType.equals("nonAccept")) {
	        	crdnCvlcpt.setCvlcptPrcsSumry("과태료 미부과");			// 민원 처리 요약
	        }

	        crdnCvlcpt.setCvlcptTrsmCd(newCvlcptTrsmCd);									// 민원 전송 코드
			//민원처리정보 변경
			retSuccess = crdnCvlcptMainBean.updateCvlcptPrcsSe(true, crdnCvlcpt);

			if (!retSuccess) {
				throw new RuntimeException("민원자료 저장 중 단속민원답변 수정에 실패하였습니다.");
			}
		}

		return saved;
	}

	@Override
	public boolean copyCvlcptCrdnInfo(String crdnId) {
		return crdnCvlcptSubBean.copyCvlcptCrdnInfo(crdnId);
	}

	@Override
	public boolean updateAnswerContent(CrdnCvlcpt crdnCvlcpt) {

		int effected = crdnCvlcptMapper.updateAnswerContent(crdnCvlcpt);
		if(effected != 1) {
			throw new RuntimeException("답변 내용 저장에 실패하였습니다.");
		}

		return true;

	}

	@Override
	public boolean updateAnswerTargetProcessStatus(String processType, String currentUserInstitute, String currentUserAcnt, String[] crdnIDs) {

		List<DataObject> targetDataList = crdnCvlcptMapper.selectAnswerTargetList(crdnIDs);

		for(int i=0; i < targetDataList.size(); i++) {

			//단속상태 변경(차적조회완료 -> 부과대상)
			if(targetDataList.get(i).string("CRDN_STTS_CD").equals("21")) {
				CrdnSttsHstry crdnSttsHstry = new CrdnSttsHstry();
				crdnSttsHstry.setCrdnId(targetDataList.get(i).string("CRDN_ID"));
				crdnSttsHstry.setBfrSttsCd(targetDataList.get(i).string("CRDN_STTS_CD"));
				crdnSttsHstry.setBfrSttsChgDt(targetDataList.get(i).string("CRDN_STTS_CHG_DT"));
				crdnSttsHstry.setCrdnSttsCd("22");
				crdnSttsHstry.setTaskDtlId(targetDataList.get(i).string("CRDN_ID"));
				crdnSttsHstry.setEtcCn("민원답변등록");
				boolean retSuccess = crdnSttsHstryBean.createHstryUpdateCrdnSttsCd(crdnSttsHstry);
				if (!retSuccess) {
					throw new RuntimeException("민원 전송 상태 변경 중 단속상태코드 변경에 실패하였습니다.");
				}
			}

			CrdnCvlcpt crdnCvlcpt = new CrdnCvlcpt();
			crdnCvlcpt.setCvlcptLinkId(targetDataList.get(i).string("CVLCPT_LINK_ID"));
			if(processType.equals("answerExecute")) {
				crdnCvlcpt.setCvlcptTrsmCd("04");
				if(ifEmpty(targetDataList.get(i).string("CVLCPT_PRCS_RSLT_CN"), () -> "").equals("")) {
					String answerWords = crdnCvlcptMainBean.mappingAnswerWords(targetDataList.get(i).string("CRDN_ID"), currentUserInstitute, currentUserAcnt);
					crdnCvlcpt.setCvlcptPrcsRsltCn(answerWords);
				}
			} else if(processType.equals("answerComplete")){
				crdnCvlcpt.setCvlcptTrsmCd("09");
			} else {
				throw new RuntimeException("민원 전송 상태 변경에 실패하였습니다.");
			}

			int effected = crdnCvlcptMapper.updateAnswerTargetTransmitStatus(crdnCvlcpt);
			if(effected != 1) {
				throw new RuntimeException("민원 전송 상태 변경 중 오류가 발생하였습니다.");
			}

			if(processType.equals("answerExecute")) {
				boolean result = crdnCvlcptMainBean.insertTransmitInfo(false, targetDataList.get(i).string("CVLCPT_LINK_ID"));
				if (!result) {
					throw new RuntimeException("민원 전송 상태 변경 중 전송자료 등록에 실패하였습니다.");
				}
			}
		}

		return true;
	}

	@Override
	public Map<String, Object> getCvlcptAnswerWordsInfo(CrdnQuery crdnQuery) {
		Map<String,Object> wordsStngInfo = new HashMap<String, Object>();

		DataObject basic = crdnCvlcptMainBean.selectCvlcptAnswerBasicWordsInfo(crdnQuery);
		List<DataObject> levyCaseList = crdnCvlcptMainBean.selectAnswerBodyWordsList(crdnQuery,"3");
		List<DataObject> warningCaseList = crdnCvlcptMainBean.selectAnswerBodyWordsList(crdnQuery,"2");
		List<DataObject> nonlevyCaseList = crdnCvlcptMainBean.selectAnswerBodyWordsList(crdnQuery,"1");

		wordsStngInfo.put("basic", basic);
		wordsStngInfo.put("levyCaseList", levyCaseList);
		wordsStngInfo.put("warningCaseList", warningCaseList);
		wordsStngInfo.put("nonlevyCaseList", nonlevyCaseList);

		return wordsStngInfo;
	}

	@Override
	public boolean saveAnswerWordsInfo(String saveData, CrdnCvlcpt crdnCvlcpt) {
		boolean saved = false;
		if(saveData.equals("basic")) {
			saved = crdnCvlcptMainBean.saveAnswerBasicWordsInfo(crdnCvlcpt);
		}
		if(saveData.equals("body")) {
			saved = crdnCvlcptMainBean.saveAnswerBodyWordsInfo(crdnCvlcpt);
		}
		return saved;
	}

	@Override
	public boolean removeCvlcptAnswerWordsInfo(String ansWordsId) {
		CrdnCvlcpt crdnCvlcpt = new CrdnCvlcpt();
		crdnCvlcpt.setAnsWordsId(ansWordsId);
		return answerWordsMapper.deleteCvlcptAnswerWordsInfo(crdnCvlcpt) == 1 ? true : false;
	}

	@Override
	public List<DataObject> getWarningWordsList(CrdnQuery crdnQuery) {
		return crdnCvlcptSubBean.selectWarningWordsList(crdnQuery);
	}

	@Override
	public boolean saveWarningWordsInfo(CrdnCvlcpt crdnCvlcpt) {
		return crdnCvlcptSubBean.saveWarningWordsInfo(crdnCvlcpt);
	}

	@Override
	public List<DataObject> getDmndDataList(CrdnQuery query) {
		return crdnCvlcptMainBean.selectDmndDataList(query);
	}

	@Override
	public boolean createDmndDataInfo(CrdnCvlcpt crdnCvlcpt) {
		return crdnCvlcptMainBean.createDmndDataInfo(crdnCvlcpt);
	}

	@Override
	public boolean removeDmndDataInfo(String... indivIDs) {
		return crdnCvlcptMainBean.removeDmndDataInfo(indivIDs);
	}

	@Override
	public boolean executeDisabledTagInfoInquire(String... crdnIDs) {
		int i=0;

		HashMap<String, Boolean> vehicleResultMap = new HashMap<String, Boolean>();

		for(; i<crdnIDs.length; i++){

			DataObject crdnInfo = crdnInfoMapper.selectCrdnInfo(crdnIDs[i]);
			String vhrno = crdnInfo.string("VHRNO");

			if(ifEmpty(vhrno, () -> "").equals("")) {
				continue;
			}

			if(!vehicleResultMap.containsKey(vhrno)) {

				DataObject inquireResult = disabledParkingBean.getParkingInfo(crdnInfo.string("VHRNO"));

				String parkingPsblYn = inquireResult.string("PARKING_PSBL_YN");
				String bohunParkingPsblYn = inquireResult.string("BOHUN_PARKING_PSBL_YN");

				boolean resulstYn = false;
				if(parkingPsblYn.equals("Y") || bohunParkingPsblYn.equals("Y")) {
					resulstYn = true;
				}
				vehicleResultMap.put(vhrno, resulstYn);
			}

			boolean result = vehicleResultMap.get(vhrno);
			if(result) {

				boolean saved = crdnCvlcptSubBean.executelevyExcl("inquireTag", crdnInfo.string("CRDN_ID"));
				if(!saved) {
					throw new RuntimeException("서손처리에 실패하였습니다.");
				}

				boolean isFirstBorn = crdnInfo.string("CRDN_REG_SE_CD").equals("02");
				boolean isNotYetTransmit = !Arrays.asList(new String[]{"04","05","06"}).contains(crdnInfo.string("CVLCPT_TRSM_CD"));


				//자동등록된 연계자료이며, 전송 작업 처리 전 자료에 대해 민원 정보를 업데이트한다.
				if (isFirstBorn && isNotYetTransmit) {

					CrdnCvlcpt crdnCvlcpt = new CrdnCvlcpt();
					crdnCvlcpt.setCvlcptLinkId(crdnInfo.string("CVLCPT_LINK_ID"));
					crdnCvlcpt.setCvlcptPrcsCd("04");
					crdnCvlcpt.setCvlcptPrcsSumry("과태료 미부과");

					CrdnQuery crdnQuery = new CrdnQuery();
					crdnQuery.setSggCd(crdnInfo.string("SGG_CD"));
					crdnQuery.setTaskSeCd("DPV");
					crdnQuery.setAnsRsnCd("103");

					// 민원 답변 문구(TB_CVLCPT_ANS_WORDS) 대장 조회
					DataObject infoCvlcptAnsWords = answerWordsMapper.selectCvlcptAnswerWordsInfo(crdnQuery);
					if(infoCvlcptAnsWords == null) {
						crdnCvlcpt.setCvlcptTrsmCd("03");
					} else {
						crdnCvlcpt.setCvlcptTrsmCd("01");
					}

					boolean retSuccess = crdnCvlcptMainBean.updateCvlcptPrcsSe(false, crdnCvlcpt);

					if (!retSuccess) {
						throw new RuntimeException("서손처리 중 단속민원답변 상태 수정에 실패하였습니다.");
					}

				}

			} else {
				Crdn crdn = new Crdn();
				crdn.setCrdnId(crdnInfo.string("CRDN_ID"));
				boolean saved = crdnUpdtMapper.updateTagInfo(crdn) == 1 ? true : false;
				if(!saved) {
					throw new RuntimeException("표지조회처리 중 표지확인여부 변경에 실패하였습니다.");
				}
			}
		}

		return i > 0 ? true : false;
	}

}
