Parcourir la source

정산 확정

marseyes il y a 2 ans
Parent
commit
6e4242a748

+ 0 - 5
src/main/java/com/oqpo/api/mapper/loanmng/UnpaidMngMapper.java

@@ -7,7 +7,6 @@ import com.oqpo.api.entity.settmng.PgKiccPayPtclEntity;
7 7
 import com.oqpo.api.entity.settmng.StlMgntBaseInfoEntity;
8 8
 import com.oqpo.api.entity.settmng.StlMgntDtlPtclEntity;
9 9
 import com.oqpo.api.web.dto.request.GridRequest;
10
-import com.oqpo.api.web.dto.request.loanmng.EasypayPaymentRequest;
11 10
 import org.apache.ibatis.annotations.Mapper;
12 11
 import org.apache.ibatis.annotations.Param;
13 12
 
@@ -30,10 +29,6 @@ public interface UnpaidMngMapper {
30 29
 
31 30
     int insertPgKiccPayPtcl(@Param("userId") String userId, PgKiccPayPtclEntity entity) throws Exception;
32 31
 
33
-    int updateStlMgntBaseInfo4Rcpt(@Param("userId") String userId, StlMgntBaseInfoEntity entity) throws Exception;
34
-
35 32
     int updateLoanMgntBaseInfo4UnpaidPay(@Param("userId") String userId, LoanMgntBaseInfoEntity entity) throws Exception;
36 33
 
37
-    int selectTotalUnpaidAmt(EasypayPaymentRequest easypayPaymentRequest) throws Exception;
38
-
39 34
 }

+ 8 - 7
src/main/java/com/oqpo/api/service/loanmng/EasypayPaymentService.java

@@ -9,13 +9,12 @@ import com.oqpo.api.entity.oper.UserMngEntity;
9 9
 import com.oqpo.api.entity.settmng.PgKiccBaseInfoEntity;
10 10
 import com.oqpo.api.entity.settmng.PgKiccPayPtclEntity;
11 11
 import com.oqpo.api.entity.settmng.StlMgntBaseInfoEntity;
12
-import com.oqpo.api.entity.stinfo.BrandEntity;
13 12
 import com.oqpo.api.enums.*;
14 13
 import com.oqpo.api.exception.GlobalException;
15 14
 import com.oqpo.api.mapper.loanmng.DsptMngMapper;
16 15
 import com.oqpo.api.mapper.loanmng.UnpaidMngMapper;
17 16
 import com.oqpo.api.mapper.oper.UserMngMapper;
18
-import com.oqpo.api.mapper.stinfo.BrandMapper;
17
+import com.oqpo.api.mapper.sttlmng.SttlReqMapper;
19 18
 import com.oqpo.api.service.CommonService;
20 19
 import com.oqpo.api.util.DateUtil;
21 20
 import com.oqpo.api.util.StringUtil;
@@ -44,10 +43,10 @@ public class EasypayPaymentService extends CommonService {
44 43
     private UserMngMapper userMngMapper;
45 44
 
46 45
     @Autowired
47
-    private BrandMapper brandMapper;
46
+    private DsptMngMapper dsptMngMapper;
48 47
 
49 48
     @Autowired
50
-    private DsptMngMapper dsptMngMapper;
49
+    private SttlReqMapper sttlReqMapper;
51 50
 
52 51
     @Value("${kicc.gateway}")
53 52
     private String kiccGatewayUrl;
@@ -611,9 +610,11 @@ public class EasypayPaymentService extends CommonService {
611 610
         // easypayPaymentRequest.setR_amount(Long.parseLong(r_amount));
612 611
         List<EasypayPaymentReqData> reqDataList = easypayPaymentRequest.getReqDataList();
613 612
         for (EasypayPaymentReqData reqData : reqDataList) {
614
-            StlMgntBaseInfoEntity stlEntity = new StlMgntBaseInfoEntity();
615
-            stlEntity.setSttlMgntUnqNo(reqData.getSttlMgntUnqNo()); // 정산관리고유번호
616
-            unpaidMngMapper.updateStlMgntBaseInfo4Rcpt(userId, stlEntity);
613
+            StlMgntBaseInfoEntity stlEntity = sttlReqMapper.selectStlMgntBaseInfo(reqData.getSttlMgntUnqNo());
614
+            long rcptAmt = stlEntity.getRcptAmt() + Long.parseLong(r_amount); // 수납금액
615
+            stlEntity.setRcptYn(rcptAmt >= stlEntity.getSttlReqAmt() ? "Y" : "N");
616
+            stlEntity.setRcptAmt(rcptAmt);
617
+            sttlReqMapper.updateStlMgntBaseInfo4Rcpt(userId, stlEntity);
617 618
         }
618 619
     }
619 620
 

+ 20 - 22
src/main/java/com/oqpo/api/service/sttlmng/SttlStateService.java

@@ -82,36 +82,33 @@ public class SttlStateService extends CommonService {
82 82
     @Transactional
83 83
     public void endSttl(String userId, SttlConfirmRequest sttlConfirmRequest) throws Exception {
84 84
         // 정산기본정보 조회
85
-        StlMgntBaseInfoEntity entity = sttlReqMapper.selectStlMgntBaseInfo(sttlConfirmRequest.getSttlMgntUnqNo());
85
+        StlMgntBaseInfoEntity stlEntity = sttlReqMapper.selectStlMgntBaseInfo(sttlConfirmRequest.getSttlMgntUnqNo());
86 86
 
87 87
         // 정산관리기본정보 - 정산상태코드 변경
88
-        entity.setSttlStCd(SttlStCd.STTL_CONFIRM.getCd());
89
-        entity.setSttlDt(DateUtil.getCurrentDate());
90
-        entity.setSttlAmt(entity.getSttlReqAmt()); // 정산요청금액을 정산금액으로 지정한다.
91
-        sttlReqMapper.updateStlMgntBaseInfo4SttlConfirm(userId, entity);
88
+        stlEntity.setSttlStCd(SttlStCd.STTL_CONFIRM.getCd());
89
+        stlEntity.setSttlDt(DateUtil.getCurrentDate());
90
+        stlEntity.setSttlAmt(stlEntity.getSttlReqAmt()); // 정산요청금액을 정산금액으로 지정한다.
91
+        sttlReqMapper.updateStlMgntBaseInfo4SttlConfirm(userId, stlEntity);
92 92
 
93
-        if ("N".equals(entity.getRcptYn())) { // 수납여부가 N인 경우
93
+        if ("N".equals(stlEntity.getRcptYn())) { // 수납여부가 N인 경우
94 94
             // 매장의 계좌잔액이 있은 경우 정산지급 처리를 한다.
95 95
             // 매장 계좌잔액 조회
96
-            LoanMgntBaseInfoEntity loanEntity = dsptMngMapper.selectLoanMgntBaseInfo(entity.getBrandId(), entity.getStoreId());
96
+            LoanMgntBaseInfoEntity loanEntity = dsptMngMapper.selectLoanMgntBaseInfo(stlEntity.getBrandId(), stlEntity.getStoreId());
97 97
             if (loanEntity.getAcctBal() > 0) {
98
-                // 계좌잔액이 정산요청금액 이상인 경우 정산요청금액을 지급처리하고 정산 데이터는 수납처리한다.
99
-                // 계좌잔액이 정산요청금액 미만인 경우 계좌잔액을 지급처리하고 정산 데이터는 일부 수납처리한다. (미납금 발생)
100
-                String rcptYn; // 수납완료여부
101
-                long rcptAmt = 0; // 수납금액
102
-                if (loanEntity.getAcctBal() >= entity.getSttlReqAmt()) {
103
-                    rcptAmt = entity.getSttlReqAmt();
104
-                    rcptYn = "Y";
98
+                // 계좌잔액이 미납금액 이상인 경우 미납금액을 지급처리하고 정산 데이터는 수납처리한다.
99
+                // 계좌잔액이 미납금액 미만인 경우 계좌잔액을 지급처리하고 정산 데이터는 일부 수납처리한다. (미납금 발생)
100
+                long trscAmt = 0; // 수납금액
101
+                if (loanEntity.getAcctBal() >= stlEntity.getUnpaidAmt()) {
102
+                    trscAmt = stlEntity.getUnpaidAmt();
105 103
                 } else {
106
-                    rcptAmt = loanEntity.getAcctBal();
107
-                    rcptYn = "N";
104
+                    trscAmt = loanEntity.getAcctBal();
108 105
                 }
109 106
 
110 107
                 // 1. 여신관리기본정보 처리
111 108
                 long trscBfBal = loanEntity.getAcctBal();
112
-                long trscAfBal = loanEntity.getAcctBal() - rcptAmt;
109
+                long trscAfBal = loanEntity.getAcctBal() - trscAmt;
113 110
                 loanEntity.setAcctBal(trscAfBal); // 계좌잔액
114
-                loanEntity.setUseAmtTotal(loanEntity.getUseAmtTotal() - rcptAmt); // 사용금액합계 감소
111
+                loanEntity.setUseAmtTotal(loanEntity.getUseAmtTotal() - trscAmt); // 사용금액합계 감소
115 112
                 sttlReqMapper.updateLoanMgntBaseInfo4SttlReqProc(userId, loanEntity);
116 113
 
117 114
                 // 2. 여신관리상세이력
@@ -122,15 +119,16 @@ public class SttlStateService extends CommonService {
122 119
                 hstEntity.setDpstPayDvsn(DpstPayDvsn.PAYMENT.getCd());
123 120
                 hstEntity.setMediaDvsn(MediaDvsn.SETTLMENT.getCd());
124 121
                 hstEntity.setPayType(PayType.STTL_PAY.getCd());
125
-                hstEntity.setTrscAmt(rcptAmt); // 거래금액
122
+                hstEntity.setTrscAmt(trscAmt); // 거래금액
126 123
                 hstEntity.setTrscBfBal(trscBfBal); // 거래전잔액
127 124
                 hstEntity.setTrscAfBal(trscAfBal); // 거래후잔액
128 125
                 dsptMngMapper.insertLoanMgntDtlHst(userId, hstEntity);
129 126
 
130 127
                 // 3. 정산관리기본정보 수납처리
131
-                entity.setRcptYn(rcptYn); // 수납여부
132
-                entity.setRcptAmt(entity.getRcptAmt() + rcptAmt); // 수납금액
133
-                sttlReqMapper.updateStlMgntBaseInfo4Rcpt(userId, entity);
128
+                long rcptAmt = stlEntity.getRcptAmt() + trscAmt; // 수납금액
129
+                stlEntity.setRcptYn(rcptAmt >= stlEntity.getSttlReqAmt() ? "Y" : "N");
130
+                stlEntity.setRcptAmt(rcptAmt);
131
+                sttlReqMapper.updateStlMgntBaseInfo4Rcpt(userId, stlEntity);
134 132
             }
135 133
         }
136 134
     }

+ 7 - 0
src/main/java/com/oqpo/api/util/DateUtil.java

@@ -763,6 +763,13 @@ public class DateUtil {
763 763
         return format.format(cal.getTime());
764 764
     }
765 765
 
766
+    public static Date addSeconds(Date date, Integer seconds) {
767
+        Calendar cal = Calendar.getInstance();
768
+        cal.setTime(date);
769
+        cal.add(Calendar.SECOND, seconds);
770
+        return cal.getTime();
771
+    }
772
+
766 773
     public static void main(String args[]) {
767 774
         System.out.println(Integer.parseInt(DateUtil.getCurrentMinTime().substring(0, 2)));
768 775
         System.out.println(Integer.parseInt("0420"));

+ 0 - 11
src/main/resources/mybatis/sqlmaps/loanmng/UnpaidMng.xml

@@ -197,17 +197,6 @@
197 197
              NOW(), #{userId}, NOW(), #{userId})
198 198
     </insert>
199 199
 
200
-    <update id="updateStlMgntBaseInfo4Rcpt" >
201
-        /* UnpaidMngMapper.updateStlMgntBaseInfo4Rcpt */
202
-        UPDATE stl_mgnt_base_info SET
203
-            rcpt_yn = 'Y',                                                          /* 수납여부 */
204
-            rcpt_dt = DATE_FORMAT(NOW(),'%Y%m%d'),                                  /* 수납일자 */
205
-            rcpt_amt = sttl_req_amt,                                                /* 수납금액 : 정산요청금액을 지정한다. */
206
-            sys_chg_dttm = NOW(),
207
-            sys_chg_id = #{userId}
208
-        WHERE sttl_mgnt_unq_no = #{entity.sttlMgntUnqNo}
209
-    </update>
210
-
211 200
     <update id="updateLoanMgntBaseInfo4UnpaidPay" >
212 201
         /* UnpaidMngMapper.updateLoanMgntBaseInfo4UnpaidPay */
213 202
         UPDATE loan_mgnt_base_info SET

+ 1 - 1
src/main/resources/mybatis/sqlmaps/sttlmng/SttlReq.xml

@@ -175,7 +175,7 @@
175 175
             A.sttl_req_amt,                         /* 정산요청금액 */
176 176
             A.sttl_amt,                             /* 정산확정금액 */
177 177
             IFNULL(A.rcpt_amt, 0) AS rcpt_amt,      /* 수납금액 */
178
-            case when B.LOAN_DVSN = 'LD02' then A.sttl_amt - IFNULL(A.rcpt_amt, 0) ELSE 0 END AS unpaid_amt, /* 미납금액 */ 
178
+            CASE WHEN B.LOAN_DVSN = 'LD02' THEN IFNULL(A.sttl_amt, A.sttl_req_amt) - IFNULL(A.rcpt_amt, 0) ELSE 0 END AS unpaid_amt, /* 미납금액 */
179 179
             A.sttl_reg_mgr_nm, A.sttl_reg_mgr_id,
180 180
             A.sttl_rjct_rsn,
181 181
             A.rcpt_yn, DATE_FORMAT(A.rcpt_dt, '%Y.%m.%d') AS rcpt_dt,   /* 수납여부/수납일자 */

+ 1 - 1
src/main/resources/mybatis/sqlmaps/sttlmng/SttlState.xml

@@ -15,7 +15,7 @@
15 15
             A.sttl_req_amt,         /* 정산요청금액 */
16 16
             A.sttl_amt,             /* 정산확정금액 */
17 17
             A.rcpt_amt,             /* 수납금액 */
18
-            case when B.LOAN_DVSN = 'LD02' then A.sttl_amt - IFNULL(A.rcpt_amt, 0) ELSE 0 END AS unpaid_amt, /* 미납금액 */ 
18
+            CASE WHEN B.LOAN_DVSN = 'LD02' THEN IFNULL(A.sttl_amt, A.sttl_req_amt) - IFNULL(A.rcpt_amt, 0) ELSE 0 END AS unpaid_amt, /* 미납금액 */
19 19
             A.sttl_reg_mgr_nm, A.sttl_reg_mgr_id,
20 20
             B.loan_dvsn, FN_CODE_NM('LOAN_DVSN', B.loan_dvsn) AS loan_dvsn_nm
21 21
         FROM stl_mgnt_base_info A