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;
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("select a from taccount a where a.accno = ?1")
TAccount getByAccnoForUpdate(String accno);
+
+ TAccount findByUserid(String userid);
}
@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;
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;
this.sex = sex;
}
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
public String getIdtype() {
return idtype;
}
@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);
}
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";
+
}
/**
* 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;
+
+
}
--- /dev/null
+package com.supwisdom.dlpay.framework.util;
+
+public enum Tradetype {
+ RECHARGE, //充值
+ CONSUME //消费
+}
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 {
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>")
// 输入参数,调用接口时指定的参数值
lateinit var person: TPerson
+ lateinit var tradetype:Tradetype
var transDate = ""
var transTime = ""
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 {
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>,
fun done(service: PersonBalancePayService, isFinished: Boolean): TUserdtl {
prepareData()
preCheckAccount()
- return service.process(this)
+ return when (isFinished) {
+ true -> service.process(this)
+ false -> service.init(this)
+ }
}
/**
* @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
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
@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();
}
}
@Autowired
lateinit var userdtlDao: UserdtlDao
- @Autowired
- lateinit var systemUtilService: SystemUtilService
-
@Autowired
lateinit var accountDao: AccountDao
}
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 {
throw TransactionProcessException(TradeErrorCode.TRANSACTION_NOT_EXISTS, "交易参考号<$refno>不存在")
}
}
+
+
}
\ No newline at end of file
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