整理
diff --git a/src/main/java/com/supwisdom/dlpay/consume/dao/AccountDao.java b/src/main/java/com/supwisdom/dlpay/consume/dao/AccountDao.java
index 6efee29..948b525 100644
--- a/src/main/java/com/supwisdom/dlpay/consume/dao/AccountDao.java
+++ b/src/main/java/com/supwisdom/dlpay/consume/dao/AccountDao.java
@@ -4,6 +4,7 @@
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Lock;
 import org.springframework.data.jpa.repository.Query;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.persistence.LockModeType;
 
@@ -12,4 +13,6 @@
   @Lock(LockModeType.PESSIMISTIC_WRITE)
   @Query("select a from taccount a where a.accno = ?1")
   TAccount getByAccnoForUpdate(String accno);
+
+  TAccount findByUserid(String userid);
 }
diff --git a/src/main/java/com/supwisdom/dlpay/consume/domain/TPerson.java b/src/main/java/com/supwisdom/dlpay/consume/domain/TPerson.java
index bc08331..a347bb9 100644
--- a/src/main/java/com/supwisdom/dlpay/consume/domain/TPerson.java
+++ b/src/main/java/com/supwisdom/dlpay/consume/domain/TPerson.java
@@ -19,6 +19,9 @@
   @Column(name = "SEX", length = 10)
   private String sex;
 
+  @Column(name = "STATUS",nullable = false, length = 10)
+  private String status;
+
   @Column(name = "IDTYPE", length = 20)
   private String idtype;
 
@@ -52,10 +55,10 @@
   public TPerson() {
   }
 
-  public TPerson(String userid, String name, String sex, String idtype, String idno, String country, String nation, String email, String tel, String mobile, String addr, String zipcode, String lastsaved) {
-    this.userid = userid;
+  public TPerson(String name, String sex, String status, String idtype, String idno, String country, String nation, String email, String tel, String mobile, String addr, String zipcode, String lastsaved) {
     this.name = name;
     this.sex = sex;
+    this.status = status;
     this.idtype = idtype;
     this.idno = idno;
     this.country = country;
@@ -92,6 +95,14 @@
     this.sex = sex;
   }
 
+  public String getStatus() {
+    return status;
+  }
+
+  public void setStatus(String status) {
+    this.status = status;
+  }
+
   public String getIdtype() {
     return idtype;
   }
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java
index eac1aa2..e7a7a99 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java
@@ -25,4 +25,6 @@
 
   @Query(value = "select t.SHOPACCNO as accno from TB_SHOPACC t left join TB_SHOPACCBAL a on t.SHOPACCNO=a.SHOPACCNO where a.SHOPACCNO is null and t.opendate>=:settday ", nativeQuery = true)
   List<AccnoBean> getNewAddShopacc(@RequestParam("settday") String settday);
+
+  TShopacc findByShopid(Integer shopid);
 }
diff --git a/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java b/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java
index 8465572..63eee64 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/util/TradeDict.java
@@ -40,4 +40,11 @@
   public static final String SUBJNO_SHOP = "2004";
   public static final String SUBJNO_ACCOUNT = "220201";
 
+
+  /**
+   * 支付方式
+   * */
+  public static final String PAYTYPE_CASH="cash";
+  public static final String PAYTYPE_BALANCE="balance";
+
 }
diff --git a/src/main/java/com/supwisdom/dlpay/framework/util/TradeErrorCode.java b/src/main/java/com/supwisdom/dlpay/framework/util/TradeErrorCode.java
index 1cc2119..6c89ce0 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/util/TradeErrorCode.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/util/TradeErrorCode.java
@@ -7,29 +7,47 @@
   /**
    * 10000 开始表示交易数据错误
    */
-  public static final int INPUT_DATA_ERROR = 100000;
+  public static final int INPUT_DATA_ERROR = 10000;
+
+
+  /**
+   * 账户不存在
+   * */
+  public static final int ACCOUNT_NOT_EXISTS = 10001;
+
   /**
    * 账户余额不足
    */
-  public static final int SHORT_BALANCE_ERROR = 100001;
+  public static final int SHORT_BALANCE_ERROR = 10002;
 
   /**
    * 个人账户状态异常
    */
-  public static final int PERSON_STATUS_ERROR = 100002;
+  public static final int PERSON_STATUS_ERROR = 10003;
 
   /**
    * 交易记录不存在
    */
-  public static final int TRANSACTION_NOT_EXISTS = 100003;
+  public static final int TRANSACTION_NOT_EXISTS = 10004;
 
   /**
    * 交易状态已完成
    */
-  public static final int TRANSACTION_IS_FINISHED = 100004;
+  public static final int TRANSACTION_IS_FINISHED = 10005;
 
   /**
    * 交易已冲正
    */
-  public static final int TRANSACTION_HAS_CANCELED = 100005;
+  public static final int TRANSACTION_HAS_CANCELED = 10006;
+  /**
+   * 商户不存在
+   * */
+  public static final int SHOP_NOT_EXISTS = 10007;
+
+  /**
+   * 商户不存在
+   * */
+  public static final int SUBJECT_NOT_EXISTS = 10008;
+
+
 }
diff --git a/src/main/java/com/supwisdom/dlpay/framework/util/Tradetype.java b/src/main/java/com/supwisdom/dlpay/framework/util/Tradetype.java
new file mode 100644
index 0000000..af8646f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/util/Tradetype.java
@@ -0,0 +1,6 @@
+package com.supwisdom.dlpay.framework.util;
+
+public enum Tradetype {
+  RECHARGE, //充值
+  CONSUME   //消费
+}
diff --git a/src/main/kotlin/com/supwisdom/dlpay/consume/comsume_builder.kt b/src/main/kotlin/com/supwisdom/dlpay/consume/comsume_builder.kt
index f6bdadd..75b8e1b 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/consume/comsume_builder.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/consume/comsume_builder.kt
@@ -11,6 +11,7 @@
 import com.supwisdom.dlpay.framework.domain.TTranstype
 import com.supwisdom.dlpay.framework.util.TradeDict
 import com.supwisdom.dlpay.framework.util.TradeErrorCode
+import com.supwisdom.dlpay.framework.util.Tradetype
 
 class AccountHolder<T> private constructor(val accountId: String, val idType: Int) {
     companion object {
@@ -42,7 +43,7 @@
     fun <T> get(): T {
         return when (idType) {
             IDTYPE_PERSON -> builder.accountUtil.readAccount(accountId)
-            IDTYPE_SHOP -> builder.accountUtil.readShopAcc(accountId)
+            IDTYPE_SHOP -> builder.accountUtil.readShopAcc(accountId.toInt())
             IDTYPE_SUBJECT -> builder.accountUtil.readSubject(accountId)
             IDTYPE_TRANSTYPE -> builder.accountUtil.readTranstype(accountId.toInt())
             else -> throw TransactionCheckException(TradeErrorCode.INPUT_DATA_ERROR, "账户类型未知type<$idType>")
@@ -66,6 +67,7 @@
 
     // 输入参数,调用接口时指定的参数值
     lateinit var person: TPerson
+    lateinit var tradetype:Tradetype
 
     var transDate = ""
     var transTime = ""
@@ -75,22 +77,20 @@
     var overdraft = false
     var description = ""
 
-    /**
-     * 学工号,一卡通商户号 -- 第三方支付一卡通使用
-     * */
-    var stuempno = ""
-    var yktshopid = ""
-
 
     // 内部参数,不需要调用者处理
     val details = mutableListOf<TransDetail>()
     var amount: Double = 0.0
     lateinit var accountUtil: AccountUtilServcie
 
+    /**
+     * 支付方式
+     * */
+    var paytype = ""
+    var payinfo = ""
 
-    fun setPerson(per: TPerson): PersonTransBuilder {
+    fun setOwner(per: TPerson) {
         this.person = per
-        return this
     }
 
     fun enableOverdraft(b: Boolean = false): PersonTransBuilder {
@@ -104,22 +104,39 @@
         return this
     }
 
-    fun setStuempno(s: String): PersonTransBuilder {
-        this.stuempno = s
+    fun selectPaytype(paytype: String, payinfo: String): PersonTransBuilder {
+        this.paytype = paytype
+        this.payinfo = payinfo
         return this
     }
 
-    fun setYktshopid(s: String): PersonTransBuilder {
-        this.yktshopid = s
-        return this
+    fun chooseTradetype(tradetype: Tradetype) {
+        this.tradetype = tradetype
     }
 
     private fun prepareData() {
+        if (null == this.person) {
+            throw TransactionCheckException(TradeErrorCode.INPUT_DATA_ERROR, "未指定交易用户")
+        }
+
         amount = 0.0
+        if(this.details.size<1){
+            throw TransactionCheckException(TradeErrorCode.INPUT_DATA_ERROR, "未指定交易明细")
+        }
         amount = this.details.sumByDouble { it.amount }
+
+
+
+
+
     }
 
     private fun preCheckAccount() {
+
+        when(person.status){
+            TradeDict.STATUS_CLOSED -> throw TransactionCheckException(TradeErrorCode.PERSON_STATUS_ERROR, "用户已注销")
+            TradeDict.STATUS_LOCKED -> throw TransactionCheckException(TradeErrorCode.PERSON_STATUS_ERROR, "用户已冻结锁定")
+        }
     }
 
     fun <T, U> addDetail(debit: AccountHolder<T>, credit: AccountHolder<U>,
@@ -176,7 +193,10 @@
     fun done(service: PersonBalancePayService, isFinished: Boolean): TUserdtl {
         prepareData()
         preCheckAccount()
-        return service.process(this)
+        return when (isFinished) {
+            true -> service.process(this)
+            false -> service.init(this)
+        }
     }
 
     /**
@@ -185,19 +205,10 @@
      * @param status - 完成交易状态,见 TradeDict.DTL_STATUS_FAIL
      */
     fun done(paydtl: TUserdtl, status: String, service: PersonBalancePayService): TUserdtl {
-        prepareData()
-        when (status) {
-            TradeDict.DTL_STATUS_INIT -> {
-                return service.init(this)
-            }
-            TradeDict.DTL_STATUS_WIP -> {
-                return service.wip(paydtl, this)
-            }
-        }
-        TODO("add process")
+        return service.finish(paydtl, status, this)
     }
 
     fun done(refno: String, status: String, service: PersonBalancePayService): TUserdtl {
-        TODO("add process")
+        return service.finish(refno, status, this)
     }
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/supwisdom/dlpay/consume/service/impl/pay_service_impl.kt b/src/main/kotlin/com/supwisdom/dlpay/consume/service/impl/pay_service_impl.kt
index 3422dee..547a472 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/consume/service/impl/pay_service_impl.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/consume/service/impl/pay_service_impl.kt
@@ -8,11 +8,11 @@
 import com.supwisdom.dlpay.consume.service.AccountUtilServcie
 import com.supwisdom.dlpay.consume.service.PersonBalancePayService
 import com.supwisdom.dlpay.exception.TransactionProcessException
+import com.supwisdom.dlpay.framework.dao.ShopaccDao
+import com.supwisdom.dlpay.framework.dao.SubjectDao
 import com.supwisdom.dlpay.framework.domain.TShopacc
 import com.supwisdom.dlpay.framework.domain.TSubject
 import com.supwisdom.dlpay.framework.domain.TTranstype
-import com.supwisdom.dlpay.framework.service.SystemUtilService
-import com.supwisdom.dlpay.framework.util.TradeDict
 import com.supwisdom.dlpay.framework.util.TradeErrorCode
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
@@ -22,33 +22,61 @@
 
 @Service
 class AccountUtilServcieImpl : AccountUtilServcie {
+    @Autowired
+    lateinit var accountDao: AccountDao
+
+    @Autowired
+    lateinit var shopaccDao: ShopaccDao
+
+    @Autowired
+    lateinit var subjectDao: SubjectDao
+
 
     override fun readAccountForUpdate(userid: String, nowait: Boolean): TAccount {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+       //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return accountDao.findByUserid(userid);
     }
 
     override fun readAccount(userid: String): TAccount {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        accountDao.findByUserid(userid).let {
+            if (null != it) {
+                return it
+            }
+            throw TransactionProcessException(TradeErrorCode.ACCOUNT_NOT_EXISTS, "账户<$userid>不存在")
+        }
     }
 
-    override fun readShopAccForUpdate(shopId: String, nowait: Boolean): TShopacc {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    override fun readShopAccForUpdate(shopId: Int, nowait: Boolean): TShopacc {
+       // TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return shopaccDao.findByShopid(shopId)
     }
 
-    override fun readShopAcc(shopId: String): TShopacc {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+    override fun readShopAcc(shopId: Int): TShopacc {
+        shopaccDao.findByShopid(shopId).let {
+            if (null != it) {
+                return it
+            }
+            throw TransactionProcessException(TradeErrorCode.SHOP_NOT_EXISTS, "商户<$shopId>不存在")
+        }
     }
 
     override fun readSubjectForUpdate(subjno: String, nowait: Boolean): TSubject {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return subjectDao.getOne(subjno);
     }
 
     override fun readSubject(subjno: String): TSubject {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        subjectDao.getOne(subjno).let {
+            if (null != it) {
+                return it
+            }
+            throw TransactionProcessException(TradeErrorCode.SUBJECT_NOT_EXISTS, "科目<$subjno>不存在")
+        }
     }
 
     override fun readTranstype(transtype: Int): TTranstype {
-        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+        return TTranstype();
     }
 }
 
@@ -58,9 +86,6 @@
     lateinit var userdtlDao: UserdtlDao
 
     @Autowired
-    lateinit var systemUtilService: SystemUtilService
-
-    @Autowired
     lateinit var accountDao: AccountDao
 
     @PersistenceContext
@@ -75,15 +100,7 @@
     }
 
     override fun init(builder: PersonTransBuilder): TUserdtl {
-        val userdtl = TUserdtl()
-        val refno = systemUtilService.refno
-        val systemtime = systemUtilService.sysdatetime
-        userdtl.refno = refno
-        userdtl.amount = builder.amount
-        userdtl.createtime = systemtime.hostdatetime
-        userdtl.status = TradeDict.DTL_STATUS_INIT
-        userdtlDao.save(userdtl)
-        return userdtl
+        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
     }
 
     override fun wip(paydtl: TUserdtl, builder: PersonTransBuilder): TUserdtl {
@@ -106,4 +123,6 @@
             throw TransactionProcessException(TradeErrorCode.TRANSACTION_NOT_EXISTS, "交易参考号<$refno>不存在")
         }
     }
+
+
 }
\ No newline at end of file
diff --git a/src/main/kotlin/com/supwisdom/dlpay/consume/service/pay_service.kt b/src/main/kotlin/com/supwisdom/dlpay/consume/service/pay_service.kt
index 0c4a6c6..d3d9933 100644
--- a/src/main/kotlin/com/supwisdom/dlpay/consume/service/pay_service.kt
+++ b/src/main/kotlin/com/supwisdom/dlpay/consume/service/pay_service.kt
@@ -12,8 +12,8 @@
     fun readAccountForUpdate(userid: String, nowait: Boolean): TAccount
     fun readAccount(userid: String): TAccount
 
-    fun readShopAccForUpdate(shopId: String, nowait: Boolean): TShopacc
-    fun readShopAcc(shopId: String): TShopacc
+    fun readShopAccForUpdate(shopId: Int, nowait: Boolean): TShopacc
+    fun readShopAcc(shopId: Int): TShopacc
 
     fun readSubjectForUpdate(subjno: String, nowait: Boolean): TSubject
     fun readSubject(subjno: String): TSubject