d9006870c2c293ad55e5a07e281e84b1bd605925
[epayment/food_payapi.git] /
1 package com.supwisdom.dlpay.api.service.impl
2
3 import com.supwisdom.dlpay.agent.citizencard.YnrccUtil
4 import com.supwisdom.dlpay.api.bean.YnrccChkfileBean
5 import com.supwisdom.dlpay.api.dao.TransactionChkdtlDao
6 import com.supwisdom.dlpay.api.dao.TransactionChkfileDao
7 import com.supwisdom.dlpay.api.domain.TTransactionChkdtl
8 import com.supwisdom.dlpay.api.domain.TTransactionChkfile
9 import com.supwisdom.dlpay.api.service.TransactionReconciliationService
10 import com.supwisdom.dlpay.exception.TransactionCheckException
11 import com.supwisdom.dlpay.framework.dao.BusinessparaDao
12 import com.supwisdom.dlpay.framework.service.SystemUtilService
13 import com.supwisdom.dlpay.framework.tenant.TenantContext
14 import com.supwisdom.dlpay.framework.util.TradeErrorCode
15 import com.supwisdom.dlpay.util.ConstantUtil
16 import org.springframework.beans.factory.annotation.Autowired
17 import org.springframework.stereotype.Service
18
19 @Service
20 class TransactionReconciliationServiceImpl : TransactionReconciliationService {
21     @Autowired
22     private lateinit var transactionChkfileDao: TransactionChkfileDao
23     @Autowired
24     private lateinit var transactionChkdtlDao: TransactionChkdtlDao
25     @Autowired
26     private lateinit var systemUtilService: SystemUtilService
27     @Autowired
28     private lateinit var businessparaDao: BusinessparaDao
29
30     override fun getTransactionChkfile(accdate: String, sourcetype: String): TTransactionChkfile? {
31         return transactionChkfileDao.getByAccdateAndSourcetype(accdate, sourcetype)
32     }
33
34     override fun doInitTransactionChkfile(accdate: String, sourcetype: String): TTransactionChkfile {
35         return transactionChkfileDao.getByAccdateAndSourcetype(accdate, sourcetype).let {
36             if (it != null) {
37                 if (ConstantUtil.CHKFILE_STATUS_INIT != it.status)
38                     throw TransactionCheckException(TradeErrorCode.BUSINESS_DEAL_ERROR, "accdate=$accdate,sourcetype=$sourcetype 的chkfile已经存在")
39                 it
40             } else {
41                 transactionChkfileDao.save(TTransactionChkfile().apply {
42                     this.accdate = accdate
43                     this.sourcetype = sourcetype
44                     this.status = ConstantUtil.CHKFILE_STATUS_INIT
45                     this.result = ConstantUtil.CHKFILE_RESULT_NONE
46                     this.remark = null
47                     this.othercnt = 0
48                     this.otheramt = 0.00
49                     this.localcnt = 0
50                     this.localamt = 0.00
51                     this.lastsaved = systemUtilService.sysdatetime.sysdate
52                     this.tenantid = TenantContext.getTenantSchema()
53                 }) //保存init对账文件
54             }
55         }
56     }
57
58     override fun saveOrUpdateTransactionChkfile(chkfile: TTransactionChkfile) {
59         transactionChkfileDao.save(chkfile)
60     }
61
62     override fun saveYnrccTransactionChkDtl(chkfile: TTransactionChkfile, bean: YnrccChkfileBean): TTransactionChkdtl {
63         return transactionChkdtlDao.save(TTransactionChkdtl().apply {
64             this.chkfileId = chkfile.id
65             this.accdate = chkfile.accdate
66             this.sourcetype = chkfile.sourcetype
67             this.recordno = bean.recordno
68             this.amount = bean.amount / 100.0
69             this.otherRefno = bean.agentrefno
70             this.localRefno = bean.refno
71             this.otherAccdate = bean.agentdate
72             this.transtype = bean.flag
73             this.otherStatus = bean.status
74             this.remark = null
75             this.extdata = bean.summary
76             this.chkresult = ConstantUtil.CHKDTL_CHKRESULT_UNCHECK
77             this.resolved = null
78             this.lastsaved = systemUtilService.sysdatetime.sysdate
79             this.tenantid = TenantContext.getTenantSchema()
80         })
81     }
82
83     override fun doBatchSaveYnrccTransactionChkDtl(chkfile: TTransactionChkfile, list: ArrayList<YnrccChkfileBean>): Boolean {
84         for (bean in list) {
85             saveYnrccTransactionChkDtl(chkfile, bean)
86         }
87         return true
88     }
89
90     override fun doSuccessTransactionChkfile(chkfile: TTransactionChkfile, remark: String) {
91         val suminfo = transactionChkdtlDao.getTransactionSumInfo(chkfile.accdate, chkfile.sourcetype)
92         chkfile.status = ConstantUtil.CHKFILE_STATUS_UNCHECK
93         chkfile.remark = remark
94         chkfile.othercnt = suminfo.totalcnt ?: 0
95         chkfile.otheramt = suminfo.totalamt ?: 0.0
96         transactionChkfileDao.save(chkfile)
97         businessparaDao.updateBusinessparaValue(YnrccUtil.YNRCC_BILLS_DOWNLOAD_LASTDATE, chkfile.accdate) //更新下载对账单日期
98     }
99
100 }