对账修改
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/api/dao/TransactionChkdtlDao.java b/payapi/src/main/java/com/supwisdom/dlpay/api/dao/TransactionChkdtlDao.java
index 51301ce..fb538c8 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/api/dao/TransactionChkdtlDao.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/api/dao/TransactionChkdtlDao.java
@@ -1,6 +1,5 @@
 package com.supwisdom.dlpay.api.dao;
 
-import com.supwisdom.dlpay.api.domain.TPersondtl;
 import com.supwisdom.dlpay.api.domain.TTransactionChkdtl;
 import com.supwisdom.dlpay.framework.data.CountAmountBean;
 import com.supwisdom.dlpay.framework.data.ExistBean;
@@ -39,11 +38,19 @@
   @Query("from TTransactionChkdtl t where t.chkfileId=?1 and t.chkresult='uncheck' order by t.recordno ")
   List<TTransactionChkdtl> getUncheckTransactionChkdtls(String chkfileId);
 
-  @Query("select count(t.id) as existed from TTransactionChkdtl t where t.chkfileId=?1 and t.chkresult='uncheck' ")
-  ExistBean getUncheckCount(String chkfileId);
+  @Query("select count(t.id) as existed from TTransactionChkdtl t where t.chkfileId=?1 and t.chkresult=?2 ")
+  ExistBean getCountByChkresult(String chkfileId, String chkresult);
 
   @Query(value = "select t.refno from TB_PERSONDTL t left join TB_TRANSACTION_CHKDTL a on t.REFNO=a.OTHER_REFNO and a.CHKFILE_ID=:chkfileId " +
       " where t.ACCDATE=:accdate and t.SOURCETYPE=:sourcetype and t.status='success' and a.id is null order by t.refno ", nativeQuery = true)
   List<String> findLocalMoreDtls(@Param("accdate") String accdate, @Param("sourcetype") String sourcetype, @Param("chkfileId") String chkfileId);
 
+  @Query("select count(t.id) as existed from TTransactionChkdtl t where t.chkfileId=?1 and t.chkresult<>'equal' and t.chkresult<>'nocharge' ")
+  ExistBean getErrorCount(String chkfileId);
+
+  @Query("from TTransactionChkdtl t where t.chkresult='nocharge' and t.resolved<>'equal' and t.chkfileId=?1 order by t.recordno ")
+  List<TTransactionChkdtl> getNeedRepairChkdtls(String chkfileId);
+
+  @Query("select count(t.id) as existed from TTransactionChkdtl t where t.chkfileId=?1 and t.and t.resolved<>'equal' ")
+  ExistBean getChkdtlNotEqualCount(String chkfileId);
 }
diff --git a/payapi/src/main/java/com/supwisdom/dlpay/util/ConstantUtil.java b/payapi/src/main/java/com/supwisdom/dlpay/util/ConstantUtil.java
index 7d7e809..8dcf53c 100644
--- a/payapi/src/main/java/com/supwisdom/dlpay/util/ConstantUtil.java
+++ b/payapi/src/main/java/com/supwisdom/dlpay/util/ConstantUtil.java
@@ -39,8 +39,9 @@
    * */
   public static final String CHKFILE_STATUS_INIT = "init"; //初始化
   public static final String CHKFILE_STATUS_UNCHECK = "uncheck"; //待对账
-  public static final String CHKFILE_STATUS_finish = "finish"; //对账完成
-  public static final String CHKFILE_STATUS_ERROR = "error"; //对账异常
+  public static final String CHKFILE_STATUS_CHECKOUT = "checkout"; //校对完成
+  public static final String CHKFILE_STATUS_FINISH = "finish"; //对账完成
+  public static final String CHKFILE_STATUS_ERROR = "error"; //保存数据异常
 
   /**
    * 对账文件结果状态
@@ -48,6 +49,7 @@
   public static final String CHKFILE_RESULT_NONE = "none"; //未对账 -
   public static final String CHKFILE_RESULT_EQUAL = "equal"; //对账一致,平
   public static final String CHKFILE_RESULT_UNEQUAL = "unequal"; //对账不一致,不平
+  public static final String CHKFILE_RESULT_ERROR = "error"; //对账明细有异常
 
   /**
    * 对账明细状态
@@ -58,12 +60,13 @@
   public static final String CHKDTL_CHKRESULT_NOCHARGE = "nocharge"; //支付未记账
   public static final String CHKDTL_CHKRESULT_DIFF = "diff"; //金额不相等
   public static final String CHKDTL_CHKRESULT_ERROR = "error"; //记账日期或支付方式错误
+  public static final String CHKDTL_CHKRESULT_SURPLUS = "surplus"; //本地多余成功流水
 
   /**
    * 对账明细解决状态
    * */
+  public static final String CHKDTL_RESOLVED_NONE = "none"; //已处理
   public static final String CHKDTL_RESOLVED_ADD ="add"; //补账
-  public static final String CHKDTL_RESOLVED_PROCESSED = "processed"; //已处理
   public static final String CHKDTL_RESOLVED_FAIL = "fail"; //补账失败
   public static final String CHKDTL_RESOLVED_EQUAL = "equal";  //一致,相等
   public static final String CHKDTL_RESOLVED_HANGUP="hangup"; //挂起
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_checkfile_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_checkfile_service.kt
index 46ae340..253ef36 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_checkfile_service.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_checkfile_service.kt
@@ -65,7 +65,7 @@
                     ?: transactionReconciliationService.saveInitTransactionChkfile(billDate, checkStatus.sourceType)
 
             if (chkfile.status == ConstantUtil.CHKFILE_STATUS_UNCHECK) {
-                return successDownload("[$billDate]日对账数据入库成功", checkStatus)
+                return successDownload("[$billDate]日对账数据已入库成功", checkStatus)
             }
             val resp = citizencardPayService.getChkfilename(billDate, null)
             when (resp.code) {
@@ -147,7 +147,7 @@
                 BufferedReader(InputStreamReader(stream)).use { reader ->
                     val header = reader.readLine()
                     val fields = header.split(",").mapNotNull { if (it.isNotEmpty()) it else null }
-                    val batchSize = 10000 //每次保存的数目
+                    val batchSize = 5000 //每次保存的数目
                     var failcnt = 0
 
                     val datalist = ArrayList<YnrccChkfileBean>()
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
index 26018f5..05b5b5b 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt
@@ -185,6 +185,7 @@
  *   3. 交易流水不存在(notexist), 表示本地交易流水不存在,影响对账文件表的 result 状态,为error。
  *   4. 支付未记账 ( nocharge) ,表示本地流水未成功,需要补帐
  *   5. 金额不相等(diff), 表示对账明细金额与本地流水不一致, 影响对账文件表的 result 状态,为error。
+ *   6. 本地多流水 (surplus), 表示本地的成功流水在对账单中不存在, 影响对账文件表的 result 状态,为error。
  *   6. 记账日期或支付方式错误 (error) , 其它类型错误,影响对账文件表的 result 状态,为error。
  *
  * 对账明细表(TTransactionChkDtl) 的 result 表示处理结果
@@ -275,62 +276,74 @@
     @Async("sourcetypeCheckTaskExecutor")
     fun reconciliation(checkStatus: TSourceTypeCheckStatus): Future<ExecutorResult> {
         // 3. 完成对账
-        val result = if (!checkStatus.checkStatus) {
-            transactionReconciliationService
-                    .getTransactionChkfile(checkStatus.checkAccdate, checkStatus.sourceType)?.let { chkfile ->
-                        try {
-                            when (doCheckProcess(chkfile, checkStatus).result) {
-                                ConstantUtil.CHKFILE_RESULT_EQUAL -> {
-                                    ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
-                                }
-                                else -> ExecutorResult(checkStatus, FAIL, "对账不平")
-                            }
-                        } catch (ex: Exception) {
-                            ex.printStackTrace()
-                            ExecutorResult(checkStatus, FAIL, "对账异常")
-                        }
-                    } ?: ExecutorResult(checkStatus, FAIL, "未找到[${checkStatus.checkAccdate}]日入库的对账数据")
-        } else if (checkStatus.repairStatus) {
-            // 补帐逻辑
-            ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
-        } else if (checkStatus.settleStatus) {
-            ExecutorResult(checkStatus, SUCCESS, "对账完成,可以结算")
-        } else {
-            ExecutorResult(checkStatus, FAIL, "未找到[${checkStatus.checkAccdate}]日入库的对账数据")
-        }
+        val result =transactionReconciliationService.getTransactionChkfile(checkStatus.checkAccdate, checkStatus.sourceType)?.let { chkfile ->
+            try {
+                doCheckProcess(chkfile, checkStatus) //执行对账过程
+                when (checkStatus.settleStatus) {
+                    true -> ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
+                    false -> ExecutorResult(checkStatus, FAIL, "对账不平")
+                }
+            } catch (ex: Exception) {
+                ex.printStackTrace()
+                ExecutorResult(checkStatus, FAIL, "对账异常")
+            }
+        } ?: ExecutorResult(checkStatus, FAIL, "未找到[${checkStatus.checkAccdate}]日入库的对账数据")
+
+//        val result = if (!checkStatus.checkStatus) {
+//            transactionReconciliationService
+//                    .getTransactionChkfile(checkStatus.checkAccdate, checkStatus.sourceType)?.let { chkfile ->
+//                        try {
+//                            when (doCheckProcess(chkfile, checkStatus).result) {
+//                                ConstantUtil.CHKFILE_RESULT_EQUAL -> {
+//                                    ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
+//                                }
+//                                else -> ExecutorResult(checkStatus, FAIL, "对账不平")
+//                            }
+//                        } catch (ex: Exception) {
+//                            ex.printStackTrace()
+//                            ExecutorResult(checkStatus, FAIL, "对账异常")
+//                        }
+//                    } ?: ExecutorResult(checkStatus, FAIL, "未找到[${checkStatus.checkAccdate}]日入库的对账数据")
+//        } else if (checkStatus.repairStatus) {
+//            // 补帐逻辑
+//            ExecutorResult(checkStatus, SUCCESS, "对账成功,双方一致")
+//        } else if (checkStatus.settleStatus) {
+//            ExecutorResult(checkStatus, SUCCESS, "对账完成,可以结算")
+//        } else {
+//            ExecutorResult(checkStatus, FAIL, "未找到[${checkStatus.checkAccdate}]日入库的对账数据")
+//        }
         return AsyncResult(result)
     }
 
-    fun doCheckProcess(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TTransactionChkfile {
-        // 假设绝大多数记录都是一致的情况下,下面的逻辑采用每1000条批量处理提高性能
-        //统一处理交易一致的记录, 对账 1
+    fun doCheckProcess(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus) {
+        //step1: 假设绝大多数记录都是一致的情况下,下面的逻辑采用每1000条批量处理提高性能,统一处理交易一致的记录
         (0..chkfile.othercnt step 1000).forEach {
             try {
                 transactionReconciliationService.doCheckEqualTransdtls(chkfile, it)
             } catch (e1: Exception) {
             }
         }
-        //剩余的未对账记录逐一对比, 对账 2
-        // 这个规则业务可以处理 "对账1" 中可能漏掉的记录
-        var errorDtl = false
+
+        //step2: 剩余的未对账记录逐一对比, 这个规则业务可以处理 "对账1" 中可能漏掉的记录
         transactionReconciliationService.getUncheckTransactionChkdtls(chkfile.id).forEach {
-            transactionReconciliationService.doCheckTransactionChkdtl(it).also { chkdtl ->
-                if (chkdtl.chkresult != ConstantUtil.CHKDTL_CHKRESULT_NOCHARGE
-                        && chkdtl.chkresult != ConstantUtil.CHKDTL_CHKRESULT_EQUAL) {
-                    errorDtl = true
-                }
-            }
+            transactionReconciliationService.doCheckTransactionChkdtl(it)
         }
 
-        //判断chkdtl是否全部对账完成 , 对账 3
+        //step3: 判断chkdtl是否全部对账完成
         if (transactionReconciliationService.checkUncheckExists(chkfile.id)) {
             throw TransactionException(-2, "存在未对账的明细记录")
         }
-        //判断本地是否有多余成功流水,并保存 , 对账 4
-        transactionReconciliationService.doCheckLocalMoreDtls(chkfile, checkStatus).also {
-            if (it.isNotEmpty()) {
-                errorDtl = true
-            }
+        //step4: 判断本地是否有多余成功流水,并保存
+        try {
+            transactionReconciliationService.doCheckLocalMoreDtls(chkfile)
+        } catch (e1: TransactionException) {
+            //本地数据存在异常
+            checkStatus.checkStatus = false
+            checkStatus.repairStatus = false
+            checkStatus.settleStatus = false
+            checkStatus.remark = e1.message
+            sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
+            return //直接返回
         }
 
         /**
@@ -339,25 +352,25 @@
          * 2. 对"是否可以补帐"的定义是必须"对账完成"
          * 3. 当所有明细完成对账或补帐才能结算
          */
-        return if (!errorDtl) {
-            chkfile.status = ConstantUtil.CHKFILE_STATUS_finish
-            checkStatus.checkStatus = true
-            checkStatus.repairStatus = true
-            checkStatus.settleStatus = false
-            // udpate
-            transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
-            // 调用补帐业务进行补帐处理
+        transactionReconciliationService.doFinishChkfileStatus(chkfile, checkStatus)
 
-            // 完成补帐业务进入结算状态
-            checkStatus.settleStatus = true
-            transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
-
-        } else {
-            chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
-            checkStatus.settleStatus = false
-            checkStatus.repairStatus = false
-            checkStatus.checkStatus = true
-            transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
+        //补账, result为equal或unequal时补帐,error跳过
+        if (chkfile.result in setOf(ConstantUtil.CHKFILE_RESULT_EQUAL, ConstantUtil.CHKFILE_RESULT_UNEQUAL)) {
+            transactionReconciliationService.getNeedRepairChkdtls(chkfile).forEach { chkdtl ->
+                try {
+                    transactionReconciliationService.doRepairTransactionChkdtl(chkdtl) //补账
+                } catch (e2: Exception) {
+                    try {
+                        transactionReconciliationService.saveOrUpdateTransctionChkdtl(chkdtl.apply {
+                            this.resolved = ConstantUtil.CHKDTL_RESOLVED_FAIL
+                            this.remark = e2.message ?: e2.javaClass.name
+                        }) //补账失败,记录错误
+                    } catch (e3: Exception) {
+                    }
+                }
+            }
         }
+
+        transactionReconciliationService.doConfirmChkfileStatus(chkfile, checkStatus)
     }
 }
\ No newline at end of file
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
index 2e2e89a..ad35776 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/impl/transaction_reconciliation_service_impl.kt
@@ -13,6 +13,7 @@
 import com.supwisdom.dlpay.api.service.TransactionReconciliationService
 import com.supwisdom.dlpay.api.service.TransactionServiceProxy
 import com.supwisdom.dlpay.exception.TransactionCheckException
+import com.supwisdom.dlpay.exception.TransactionException
 import com.supwisdom.dlpay.framework.dao.BusinessparaDao
 import com.supwisdom.dlpay.framework.service.SystemUtilService
 import com.supwisdom.dlpay.framework.tenant.TenantContext
@@ -79,7 +80,7 @@
             this.remark = null
             this.extdata = bean.summary
             this.chkresult = ConstantUtil.CHKDTL_CHKRESULT_UNCHECK
-            this.resolved = null
+            this.resolved = ConstantUtil.CHKDTL_RESOLVED_NONE
             this.lastsaved = systemUtilService.sysdatetime.sysdate
             this.tenantid = TenantContext.getTenantSchema()
         })
@@ -184,25 +185,17 @@
             //需要补账
             chkdtl.chkresult = ConstantUtil.CHKDTL_CHKRESULT_NOCHARGE
             chkdtl.resolved = ConstantUtil.CHKDTL_RESOLVED_ADD
-            chkdtl.remark = "本地未入账,需要"
+            chkdtl.remark = "本地未入账,需要补助"
             transactionChkdtlDao.save(chkdtl) //对账明细表更新
         }
     }
 
     override fun checkUncheckExists(chkfileId: String): Boolean {
-        return transactionChkdtlDao.getUncheckCount(chkfileId).existed > 0
+        return transactionChkdtlDao.getCountByChkresult(chkfileId, ConstantUtil.CHKDTL_CHKRESULT_UNCHECK).existed > 0
     }
 
-    private fun updateCheckStatusWhenError(message: String, checkStatus: TSourceTypeCheckStatus,
-                                           chkfile: TTransactionChkfile) {
-        checkStatus.checkStatus = false
-        checkStatus.remark = message
-        chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
-    }
-
-    override fun doCheckLocalMoreDtls(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): List<TTransactionChkdtl> {
-        val result = mutableListOf<TTransactionChkdtl>()
-        transactionChkdtlDao.findLocalMoreDtls(chkfile.accdate, chkfile.sourcetype, chkfile.id)?.also {
+    override fun doCheckLocalMoreDtls(chkfile: TTransactionChkfile): Int {
+        return transactionChkdtlDao.findLocalMoreDtls(chkfile.accdate, chkfile.sourcetype, chkfile.id)?.also {
             it.forEach { refno ->
                 //保存多余的记录
                 transactionMainDao.findByRefno(refno)?.also { transMain ->
@@ -220,54 +213,93 @@
                             else -> transMain.reverseType
                         }
                         this.otherStatus = "unknown"
-                        this.remark = "本地成功流水第三方流水不存在"
+                        this.remark = "本地有成功流水,第三方流水不存在"
                         this.extdata = transMain.personDtl.transdesc
-                        this.chkresult = ConstantUtil.CHKDTL_CHKRESULT_ERROR
+                        this.chkresult = ConstantUtil.CHKDTL_CHKRESULT_SURPLUS
                         this.resolved = ConstantUtil.CHKDTL_RESOLVED_HANGUP
                         this.lastsaved = systemUtilService.sysdatetime.sysdate
                         this.tenantid = chkfile.tenantid
-                    }).also { dtl ->
-                        result.add(dtl)
-                    }//保存本地多出的记录
+                    })//保存本地多出的记录
                 }.also { transMain ->
                     if (transMain == null) {
-                        chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
-                        updateCheckStatusWhenError("交易参考号<$refno>异常,未找到Main记录",
-                                checkStatus, chkfile)
-                        return result
+                        throw TransactionException(-3, "本地存在多余成功流水记录,且交易参考号<$refno>异常,未找到transactionMain记录")
                     }
                 }
             }
-        }?.also {
-            if (it.isNotEmpty()) {
-                chkfile.status = ConstantUtil.CHKFILE_STATUS_ERROR
-                updateCheckStatusWhenError("本地有<${it.size}>条流水不在对账文件中,请联系管理员检查",
-                        checkStatus, chkfile)
+        }?.size ?: 0
+    }
+
+    override fun doFinishChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus) {
+        if (transactionChkdtlDao.getCountByChkresult(chkfile.id, ConstantUtil.CHKDTL_CHKRESULT_UNCHECK).existed > 0) {
+            throw TransactionException(-2, "存在未对账的明细记录")
+        }
+        //明细已全部校对完
+        chkfile.status = ConstantUtil.CHKFILE_STATUS_FINISH
+        checkStatus.checkStatus = true
+        checkStatus.repairStatus = false
+        checkStatus.settleStatus = false
+        if (transactionChkdtlDao.getErrorCount(chkfile.id).existed > 0) {
+            //除了需要补账的错误外有其他异常
+            chkfile.result = ConstantUtil.CHKFILE_RESULT_ERROR
+            chkfile.remark = "校对完成,明细存在对比异常"
+            transactionChkdtlDao.getCountByChkresult(chkfile.id, ConstantUtil.CHKDTL_CHKRESULT_SURPLUS).existed.also {
+                if (null != it && it > 0) {
+                    chkfile.remark = "本地有<${it}>条流水不在对账文件中,请联系管理员检查"
+                }
+            }
+        } else {
+            //仅存在一致或需补账的记录
+            if (transactionChkdtlDao.getCountByChkresult(chkfile.id, ConstantUtil.CHKDTL_CHKRESULT_NOCHARGE).existed > 0) {
+                //存在需补账记录
+                chkfile.result = ConstantUtil.CHKFILE_RESULT_UNEQUAL //不平
+                chkfile.remark = "校对完成,存在需补账的交易记录"
+            } else {
+                chkfile.result = ConstantUtil.CHKFILE_RESULT_EQUAL //一致
+                chkfile.remark = "校对完成,双方交易一致"
             }
         }
-        return result
+        transactionChkfileDao.save(chkfile)
+        sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
+    }
+
+    override fun getNeedRepairChkdtls(chkfile: TTransactionChkfile): List<TTransactionChkdtl> {
+        return transactionChkdtlDao.getNeedRepairChkdtls(chkfile.id) ?: ArrayList<TTransactionChkdtl>(0)
+    }
+
+    override fun doRepairTransactionChkdtl(chkdtl: TTransactionChkdtl): TTransactionChkdtl {
+        transactionService.repair(chkdtl.localRefno, chkdtl.otherAccdate, chkdtl.otherRefno, "补账成功")
+        chkdtl.resolved = ConstantUtil.CHKDTL_RESOLVED_EQUAL
+        chkdtl.remark = "本地未入账,补账成功"
+        return transactionChkdtlDao.save(chkdtl)
+    }
+
+    override fun saveOrUpdateTransctionChkdtl(chkdtl: TTransactionChkdtl){
+        transactionChkdtlDao.save(chkdtl)
     }
 
     override fun doConfirmChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TTransactionChkfile {
-//        if (chkfile.status == ConstantUtil.CHKFILE_STATUS_ERROR) {
-//            chkfile.remark = checkStatus.remark
-//        } else {
-//            val personSumInfo = persondtlDao.getPersondtlSumInfo(chkfile.accdate, chkfile.sourcetype, chkfile.tenantid)
-//            chkfile.localcnt = personSumInfo.totalcnt ?: 0
-//            chkfile.localamt = personSumInfo.totalamt ?: 0.00
-//            chkfile.status = ConstantUtil.CHKFILE_STATUS_finish  //对账结束
-//            if (chkfile.othercnt == chkfile.localcnt && MoneyUtil.moneyEqual(chkfile.otheramt, chkfile.localamt)) {
-//                //fixme: 是否还需判断chkdtl中resolved是否都equal
-//                chkfile.result = ConstantUtil.CHKFILE_RESULT_EQUAL
-//                chkfile.remark = "对账完成,双方一致"
-//                checkStatus.settleStatus = true
-//            } else {
-//                chkfile.result = ConstantUtil.CHKFILE_RESULT_UNEQUAL
-//                chkfile.remark = "对账不平,请查看明细数据"
-//            }
-//            checkStatus.checkStatus = true
-//            checkStatus.remark = "对账完成"
-//        }
+        val personSumInfo = persondtlDao.getPersondtlSumInfo(chkfile.accdate, chkfile.sourcetype, chkfile.tenantid)
+        chkfile.localcnt = personSumInfo.totalcnt ?: 0
+        chkfile.localamt = personSumInfo.totalamt ?: 0.00
+
+        checkStatus.repairStatus = false
+        checkStatus.settleStatus = false
+        checkStatus.remark = chkfile.remark
+        if (chkfile.result in setOf(ConstantUtil.CHKFILE_RESULT_EQUAL, ConstantUtil.CHKFILE_RESULT_UNEQUAL)) {
+            val notEqualCount = transactionChkdtlDao.getChkdtlNotEqualCount(chkfile.id).existed
+            if (notEqualCount == 0 && chkfile.othercnt == chkfile.localcnt && MoneyUtil.moneyEqual(chkfile.otheramt, chkfile.localamt)) {
+                //对平
+                chkfile.remark = when (chkfile.result == ConstantUtil.CHKFILE_RESULT_EQUAL) {
+                    true -> "对账完成,双方交易一致"
+                    else -> "对账完成,补账后双方交易一致"
+                }
+                checkStatus.repairStatus = true
+                checkStatus.settleStatus = true
+                checkStatus.remark = chkfile.remark
+            }else{
+                checkStatus.remark = "对账完成,补账有失败"
+            }
+        }
 
         sourceTypeService.saveOrUpdateSourceTypeCheckStatus(checkStatus)
         return transactionChkfileDao.save(chkfile)
diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/transaction_reconciliation_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/transaction_reconciliation_service.kt
index 9429940..21a16a8 100644
--- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/transaction_reconciliation_service.kt
+++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/service/transaction_reconciliation_service.kt
@@ -47,9 +47,24 @@
     fun checkUncheckExists(chkfileId: String): Boolean
 
     @Transactional(rollbackFor = [Exception::class])
-    fun doCheckLocalMoreDtls(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): List<TTransactionChkdtl>
+    fun doCheckLocalMoreDtls(chkfile: TTransactionChkfile): Int
+
+    @Transactional(rollbackFor = [Exception::class])
+    fun doFinishChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus)
+
+    @Transactional(rollbackFor = [Exception::class], readOnly = true)
+    fun getNeedRepairChkdtls(chkfile: TTransactionChkfile): List<TTransactionChkdtl>
+
+    @Transactional(rollbackFor = [Exception::class])
+    fun doRepairTransactionChkdtl(chkdtl: TTransactionChkdtl): TTransactionChkdtl
+
+    @Transactional(rollbackFor = [Exception::class])
+    fun saveOrUpdateTransctionChkdtl(chkdtl: TTransactionChkdtl)
+
 
     @Transactional(rollbackFor = [Exception::class])
     fun doConfirmChkfileStatus(chkfile: TTransactionChkfile, checkStatus: TSourceTypeCheckStatus): TTransactionChkfile
 
+
+
 }
\ No newline at end of file