From 570775294c98234595112823964ec22f07a551df Mon Sep 17 00:00:00 2001 From: JoJH Date: Wed, 13 Nov 2024 15:34:10 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A8=EC=86=8D=EC=83=81=ED=83=9C=EC=9D=B4?= =?UTF-8?q?=EB=A0=A5=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/fims/cmmn/CrdnSttsHstryQuery.java | 14 ++- .../fims/cmmn/dao/CrdnSttsHstryMapper.java | 11 +++ .../cmmn/service/bean/CrdnSttsHstryBean.java | 85 +++++++++++++++---- .../mapper/fims/cmmn/crdnSttsHstry-mapper.xml | 3 + 4 files changed, 89 insertions(+), 24 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/CrdnSttsHstryQuery.java b/src/main/java/cokr/xit/fims/cmmn/CrdnSttsHstryQuery.java index df662c7e..1e04eec8 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CrdnSttsHstryQuery.java +++ b/src/main/java/cokr/xit/fims/cmmn/CrdnSttsHstryQuery.java @@ -12,12 +12,12 @@ package cokr.xit.fims.cmmn; */ public class CrdnSttsHstryQuery extends CmmnQuery { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private String sttsHstryId; // 상태 이력 ID - private String crdnId; // 단속 ID - private String crdnSttsCd; // 단속 상태 코드 - private String taskDtlId; // 업무 상세 ID + private String sttsHstryId; // 상태 이력 ID + private String crdnId; // 단속 ID + private String crdnSttsCd; // 단속 상태 코드 + private String taskDtlId; // 업무 상세 ID public String getSttsHstryId() { return ifEmpty(sttsHstryId, () -> null); @@ -25,7 +25,6 @@ public class CrdnSttsHstryQuery extends CmmnQuery { public T setSttsHstryId(String sttsHstryId) { this.sttsHstryId = sttsHstryId; - return self(); } @@ -35,7 +34,6 @@ public class CrdnSttsHstryQuery extends CmmnQuery { public T setCrdnId(String crdnId) { this.crdnId = crdnId; - return self(); } @@ -45,7 +43,6 @@ public class CrdnSttsHstryQuery extends CmmnQuery { public T setCrdnSttsCd(String crdnSttsCd) { this.crdnSttsCd = crdnSttsCd; - return self(); } @@ -55,7 +52,6 @@ public class CrdnSttsHstryQuery extends CmmnQuery { public T setTaskDtlId(String taskDtlId) { this.taskDtlId = taskDtlId; - return self(); } diff --git a/src/main/java/cokr/xit/fims/cmmn/dao/CrdnSttsHstryMapper.java b/src/main/java/cokr/xit/fims/cmmn/dao/CrdnSttsHstryMapper.java index 3d4e7d84..33ec4364 100644 --- a/src/main/java/cokr/xit/fims/cmmn/dao/CrdnSttsHstryMapper.java +++ b/src/main/java/cokr/xit/fims/cmmn/dao/CrdnSttsHstryMapper.java @@ -37,6 +37,17 @@ public interface CrdnSttsHstryMapper extends AbstractMapper { * @param crdnId 단속 ID * @return 지정한 단속 ID의 단속 상태 이력 객체 */ + default DataObject selectCrdnSttsHstryInfo(CrdnSttsHstryQuery req) { + // 기본 정렬 + if (req.getOrderBy() == null) { + req.setOrderBy("CSH.STTS_HSTRY_ID DESC"); + } + + List crdnSttsHstrys = selectCrdnSttsHstrys(req); + + return !crdnSttsHstrys.isEmpty() ? crdnSttsHstrys.get(0) : null; + } + default DataObject selectCrdnSttsHstryInfo(String crdnId, String crdnSttsCd, String useYn) { CrdnSttsHstryQuery req = new CrdnSttsHstryQuery(); diff --git a/src/main/java/cokr/xit/fims/cmmn/service/bean/CrdnSttsHstryBean.java b/src/main/java/cokr/xit/fims/cmmn/service/bean/CrdnSttsHstryBean.java index 01c7e8f0..c13dfa7c 100644 --- a/src/main/java/cokr/xit/fims/cmmn/service/bean/CrdnSttsHstryBean.java +++ b/src/main/java/cokr/xit/fims/cmmn/service/bean/CrdnSttsHstryBean.java @@ -138,6 +138,54 @@ public class CrdnSttsHstryBean extends AbstractBean { return true; } + /**단속 상태 이력 정보를 삭제하고, 하고 단속 대장의 단속상태 정보를 수정한다. + * @param crdnSttsHstry 단속 상태 이력 + * @return 저장 여부 + *
  • 저장됐으면 true
  • + *
  • 그렇지 않으면 false
  • + *
+ */ + public boolean removeHstryUpdateCrdnSttsCd(CrdnSttsHstry crdnSttsHstry) { + // 변수 선언 + int rtnNocs = -1; + + // 단속 ID에 해당하는 단속상태코드의 단속상태이력(TB_CRDN_STTS_HSTRY) 대장을 조회 한다. + CrdnSttsHstryQuery req = new CrdnSttsHstryQuery(); + req.setCrdnId(crdnSttsHstry.getCrdnId()); + req.setUseYn("Y"); + req.setOrderBy("CSH.STTS_HSTRY_ID DESC"); + + DataObject hstryInfo = crdnSttsHstryMapper.selectCrdnSttsHstryInfo(req); + if (hstryInfo == null) { + throw new RuntimeException("단속 상태 이력 자료가 존재하지 않습니다."); // 예외를 발생시켜서 DB Rollback + } + if (!crdnSttsHstry.getCrdnSttsCd().equals(hstryInfo.string("CRDN_STTS_CD"))) { + throw new RuntimeException("현재 단속 상태와 마지막 단속 상태 이력 정보가 다릅니다."); // 예외를 발생시켜서 DB Rollback + } + + // 단속상태이력(TB_CRDN_STTS_HSTRY) 대장을 삭제한다. + crdnSttsHstry.setSttsHstryId(hstryInfo.string("STTS_HSTRY_ID")); // 상태 이력 ID + + rtnNocs = crdnSttsHstryMapper.updateCrdnSttsHstry(crdnSttsHstry); + if (rtnNocs != 1) { + throw new RuntimeException("단속상태이력 대장에 이력 수정에 실패하였습니다."); // 예외를 발생시켜서 DB Rollback + } + + // 단속(TB_CRDN) 대장을 수정한다. + CrdnSttsHstry updtHstry = new CrdnSttsHstry(); + updtHstry.setCrdnId(crdnSttsHstry.getCrdnId()); // 단속 ID + updtHstry.setCrdnSttsCd(hstryInfo.string("BFR_STTS_CD")); // 단속 상태 코드 + updtHstry.setCrdnSttsChgDt(hstryInfo.string("BFR_STTS_CHG_DT")); // 단속 상태 변경 일시 + + rtnNocs = crdnSttsHstryMapper.updateCrdnSttsCd(updtHstry); + if (rtnNocs != 1) { + throw new RuntimeException("단속상태이력 정보 등록 중 오류가 발생하였습니다."); // 예외를 발생시켜서 DB Rollback + } + + return true; + } + + /**단속 상태 이력 정보를 삭제하고, 하고 단속 대장의 단속상태 정보를 수정한다. * @param crdnSttsHstry 단속 상태 이력 * @return 저장 여부 @@ -150,16 +198,19 @@ public class CrdnSttsHstryBean extends AbstractBean { int rtnNocs = -1; // 단속 ID에 해당하는 단속상태코드의 단속상태이력(TB_CRDN_STTS_HSTRY) 대장을 조회 한다. - DataObject crdnSttsHstryInfo = crdnSttsHstryMapper.selectCrdnSttsHstryInfo(crdnId, crdnSttsCd, "Y"); + DataObject hstryInfo = crdnSttsHstryMapper.selectCrdnSttsHstryInfo(crdnId, crdnSttsCd, "Y"); - if (crdnSttsHstryInfo == null) { + if (hstryInfo == null) { throw new RuntimeException("단속상태이력 자료가 존재하지 않습니다."); // 예외를 발생시켜서 DB Rollback } if (!crdnSttsCd.equals("")) { - CrdnSttsHstry crdnSttsHstry = new CrdnSttsHstry(); - crdnSttsHstry.setSttsHstryId(crdnSttsHstryInfo.string("STTS_HSTRY_ID")); - crdnSttsHstry.setUseYn("N"); + CrdnSttsHstry crdnSttsHstry = new CrdnSttsHstry(); + crdnSttsHstry.setSttsHstryId(hstryInfo.string("STTS_HSTRY_ID")); // 상태 이력 ID + if (deltSttsCd.equals("")) { + crdnSttsHstry.setEtcCn(deltEtcCn); // 기타 내용 + } + crdnSttsHstry.setUseYn("N"); // 사용 여부 rtnNocs = crdnSttsHstryMapper.updateCrdnSttsHstry(crdnSttsHstry); if (rtnNocs != 1) { @@ -172,14 +223,14 @@ public class CrdnSttsHstryBean extends AbstractBean { // 단속상태가 의견제출접수(31)가 아니면서, 삭제상태코드가 의견제출삭제(92)나 경찰서이첩삭제(97) 일 경우 if (!crdnSttsCd.equals("31") && "92,97".contains(deltSttsCd)) { // 단속상태이력(TB_CRDN_STTS_HSTRY) 대장에서 의견제출접수(31) 이력을 조회후 사용여부를 미사용("N")으로 수정. - crdnSttsHstryInfo = crdnSttsHstryMapper.selectCrdnSttsHstryInfo(crdnId, "31", "Y"); + hstryInfo = crdnSttsHstryMapper.selectCrdnSttsHstryInfo(crdnId, "31", "Y"); - if (crdnSttsHstryInfo == null) { + if (hstryInfo == null) { throw new RuntimeException("단속상태이력에 의견제출 접수 이력이 존재하지 않습니다."); // 예외를 발생시켜서 DB Rollback } CrdnSttsHstry opnnSttsHstry = new CrdnSttsHstry(); - opnnSttsHstry.setSttsHstryId(crdnSttsHstryInfo.string("STTS_HSTRY_ID")); + opnnSttsHstry.setSttsHstryId(hstryInfo.string("STTS_HSTRY_ID")); opnnSttsHstry.setUseYn("N"); rtnNocs = crdnSttsHstryMapper.updateCrdnSttsHstry(opnnSttsHstry); @@ -189,9 +240,9 @@ public class CrdnSttsHstryBean extends AbstractBean { } CrdnSttsHstry deleteSttsHstry = new CrdnSttsHstry(); - deleteSttsHstry.setCrdnId(crdnSttsHstryInfo.string("CRDN_ID")); - deleteSttsHstry.setBfrSttsCd(crdnSttsHstryInfo.string("CRDN_STTS_CD")); - deleteSttsHstry.setBfrSttsChgDt(crdnSttsHstryInfo.string("REG_DT")); + deleteSttsHstry.setCrdnId(hstryInfo.string("CRDN_ID")); + deleteSttsHstry.setBfrSttsCd(hstryInfo.string("CRDN_STTS_CD")); + deleteSttsHstry.setBfrSttsChgDt(hstryInfo.string("REG_DT")); deleteSttsHstry.setCrdnSttsCd(deltSttsCd); deleteSttsHstry.setEtcCn(deltEtcCn); deleteSttsHstry.setUseYn("N"); @@ -205,11 +256,15 @@ public class CrdnSttsHstryBean extends AbstractBean { if (insertBfrSttsYn) { // 단속상태이력(TB_CRDN_STTS_HSTRY) 대장을 등록한다. CrdnSttsHstry crdnSttsHstry = new CrdnSttsHstry(); - crdnSttsHstry.setCrdnId(crdnSttsHstryInfo.string("CRDN_ID")); - crdnSttsHstry.setBfrSttsCd(deltSttsCd); + crdnSttsHstry.setCrdnId(hstryInfo.string("CRDN_ID")); + if (deltSttsCd.equals("")) { + crdnSttsHstry.setBfrSttsCd(crdnSttsCd); + } else { + crdnSttsHstry.setBfrSttsCd(deltSttsCd); + } crdnSttsHstry.setBfrSttsChgDt(crdnSttsHstry.getCreatedAt()); - crdnSttsHstry.setCrdnSttsCd(crdnSttsHstryInfo.string("BFR_STTS_CD")); - crdnSttsHstry.setCrdnSttsChgDt(crdnSttsHstryInfo.string("BFR_STTS_CHG_DT")); + crdnSttsHstry.setCrdnSttsCd(hstryInfo.string("BFR_STTS_CD")); + crdnSttsHstry.setCrdnSttsChgDt(hstryInfo.string("BFR_STTS_CHG_DT")); crdnSttsHstry.setUseYn("Y"); boolean rtnScs = createHstryUpdateCrdnSttsCd(crdnSttsHstry); diff --git a/src/main/resources/sql/mapper/fims/cmmn/crdnSttsHstry-mapper.xml b/src/main/resources/sql/mapper/fims/cmmn/crdnSttsHstry-mapper.xml index 9c1f67ce..07f3d360 100644 --- a/src/main/resources/sql/mapper/fims/cmmn/crdnSttsHstry-mapper.xml +++ b/src/main/resources/sql/mapper/fims/cmmn/crdnSttsHstry-mapper.xml @@ -130,6 +130,9 @@ /* 단속 상태 이력 수정(crdnSttsHstryMapper.updateCrdnSttsHstry) */ UPDATE TB_CRDN_STTS_HSTRY SET USE_YN = #{useYn} + + , ETC_CN = #{etcCn} + , MDFCN_DT = , MDFR = #{modifiedBy} WHERE STTS_HSTRY_ID = #{sttsHstryId}