Commit 1d1861a9 authored by Administrator's avatar Administrator

创建项目

parent 5f70e1fe
......@@ -29,6 +29,7 @@
<mapping class="cn.quant.baa.pay.jpa.entity.CustomerEntity"/>
<mapping class="cn.quant.baa.pay.jpa.entity.AccountEntity"/>
<mapping class="cn.quant.baa.pay.jpa.entity.PayHistoryEntity"/>
<mapping class="cn.quant.baa.pay.jpa.entity.PayGoodsDetailEntity"/>
<!-- Drop and re-create the database schema on startup -->
<!--
......
......@@ -51,6 +51,7 @@ public class AcquirerBuilder {
PayFeatureIds featureIds = new PayFeatureIds();
featureIds.setPayChanCode(entity.getPayChanCode());
featureIds.setAccessCode(entity.getAccessCode());
PayFeatureEntity feature = (PayFeatureEntity) bigTable.get(PayFeatureEntity.class, featureIds);
BeanUtils.copyProperties(feature, profile);
profile.setAccessCode(entity.getAccessCode());
......
......@@ -17,6 +17,13 @@ public enum MessageEnum {
ILLEGAL_REQ_DISC_AMT("2000000"),
ILLEGAL_REQ_CASH_AMT("2000000"),
ILLEGAL_REQ_CREDIT_AMT("2000000"),
ILLEGAL_REQ_GOODS_NO("2000000"),
ILLEGAL_REQ_GOODS_NAME("2000000"),
ILLEGAL_REQ_GOODS_QUANTITY("2000000"),
ILLEGAL_REQ_GOODS_PRICE("2000000"),
ILLEGAL_REQ_GOODS_DISC("2000000"),
ILLEGAL_REQ_GOODS_AMT("2000000"),
ILLEGAL_REQ_GOODS_ATTACH("2000000"),
EXIST_ORDER("300"),
......
......@@ -2,6 +2,7 @@ package cn.quant.baa.pay.jpa.entity;
import cn.quant.baa.pay.context.TransactionSession;
import cn.quant.baa.pay.dict.*;
import cn.quant.baa.pay.model.GoodsDetail;
import cn.quant.baa.pay.model.MerchantAcquirerProfile;
import cn.quant.baa.pay.model.PayRequestData;
import cn.quant.spring.util.DateUtils;
......@@ -49,7 +50,7 @@ public class EntityBuilder {
return account;
}
public static PayHistoryEntity history(MerchantAcquirerProfile profile, AccountEntity account, PayHistoryIds ids, PayRequestData data
public static PayHistoryEntity history(AccountEntity account, PayHistoryIds ids, long historyId, PayRequestData data, MerchantAcquirerProfile profile
, TransactionSession session) {
BigDecimal discount = new BigDecimal(data.getDiscounts());
......@@ -82,7 +83,7 @@ public class EntityBuilder {
entity.setPayMethod(PayMethod.DRST);
entity.setPostCashAmount(cash);
entity.setPostCreditAmount(credit);
entity.setPartitionKey(session.partitionKey(accountId));
entity.setPartitionKey(account.getPartitionKey());
entity.setRequestId(session.getRequestId());
entity.setRequestTime(session.getRequestTime());
entity.setShopName(data.getShopName());
......@@ -90,7 +91,7 @@ public class EntityBuilder {
entity.setStatisticsCode("RPAY");
entity.setStatusCode(StatusCode.PEND);
entity.setSubject(data.getSubject());
entity.setTransactionId(session.nextId());
entity.setTransactionId(historyId);
entity.setTxnAmount(amount);
entity.setTxnDate(session.getBusinessLocalDate());
entity.setTxnTime(session.getBusinessLocalTime());
......@@ -106,4 +107,24 @@ public class EntityBuilder {
return entity;
}
public static PayGoodsDetailEntity goodsDetail(long goodsId, long historyId, GoodsDetail detail) {
BigDecimal amount = new BigDecimal(detail.getAmount());
BigDecimal discount = new BigDecimal(detail.getDiscounts());
BigDecimal price = new BigDecimal(detail.getPrice());
int qiantity = Integer.parseInt(detail.getQuantity(), 10);
PayGoodsDetailEntity entity = new PayGoodsDetailEntity();
entity.setAttachText(detail.getAttach());
entity.setDiscAmount(discount);
entity.setTxnAmount(amount);
entity.setTransactionId(historyId);
entity.setGoodsId(goodsId);
entity.setGoodsName(detail.getGoodsName());
entity.setGoodsOrderNo(detail.getGoodsNo());
entity.setPrice(price);
entity.setQuantity(qiantity);
return entity;
}
}
......@@ -23,11 +23,20 @@ public class PayFeatureEntity extends DescriptionEntity implements Serializable
@Column(name = "ACCESS_TYPE", nullable = false, length = 3)
private AccessType accessType;
@Column(name = "ACCESS_METHOD", nullable = false, length = 255)
private String accessMethod;
@Column(name = "VERSION", nullable = false, length = 4)
private String version;
@Column(name = "ACCESS_PATH", nullable = true, length = 255)
private String accessPath;
@Column(name = "PAY_ACCESS", nullable = false, length = 255)
private String payAccess;
@Column(name = "REFUND_ACCESS", nullable = false, length = 255)
private String refundAccess;
@Column(name = "CHECK_ACCESS", nullable = false, length = 255)
private String checkAccess;
public PayFeatureIds getIds() {
return ids;
......@@ -45,6 +54,14 @@ public class PayFeatureEntity extends DescriptionEntity implements Serializable
this.accessType = accessType;
}
public String getAccessMethod() {
return accessMethod;
}
public void setAccessMethod(String accessMethod) {
this.accessMethod = accessMethod;
}
public String getVersion() {
return version;
}
......@@ -53,12 +70,28 @@ public class PayFeatureEntity extends DescriptionEntity implements Serializable
this.version = version;
}
public String getAccessPath() {
return accessPath;
public String getPayAccess() {
return payAccess;
}
public void setPayAccess(String payAccess) {
this.payAccess = payAccess;
}
public String getRefundAccess() {
return refundAccess;
}
public void setRefundAccess(String refundAccess) {
this.refundAccess = refundAccess;
}
public String getCheckAccess() {
return checkAccess;
}
public void setAccessPath(String accessPath) {
this.accessPath = accessPath;
public void setCheckAccess(String checkAccess) {
this.checkAccess = checkAccess;
}
@Override
......@@ -78,9 +111,12 @@ public class PayFeatureEntity extends DescriptionEntity implements Serializable
public String toString() {
final StringBuilder sb = new StringBuilder("PayFeatureEntity{");
sb.append("ids=").append(ids);
sb.append(", accessType='").append(accessType).append('\'');
sb.append(", accessType=").append(accessType);
sb.append(", accessMethod='").append(accessMethod).append('\'');
sb.append(", version='").append(version).append('\'');
sb.append(", accessPath='").append(accessPath).append('\'');
sb.append(", payAccess='").append(payAccess).append('\'');
sb.append(", refundAccess='").append(refundAccess).append('\'');
sb.append(", checkAccess='").append(checkAccess).append('\'');
sb.append(',').append(super.toString());
sb.append('}');
return sb.toString();
......
package cn.quant.baa.pay.jpa.entity;
import cn.quant.baa.pay.dict.AccessCode;
import cn.quant.baa.pay.dict.AccessType;
import cn.quant.spring.data.jpa.entity.EntityPrimaryIds;
import cn.quant.spring.util.StringUtils;
......
package cn.quant.baa.pay.jpa.entity;
import cn.quant.spring.data.jpa.entity.PartitionEntity;
import cn.quant.spring.util.StringUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Objects;
/**
* Created by Administrator on 2021/8/30 0030.
*/
@Entity
@Table(name = "pay_goods_detail")
public class PayGoodsDetailEntity extends PartitionEntity implements Serializable {
public final static String CLASS_NAME = PayGoodsDetailEntity.class.getSimpleName();
private static final long serialVersionUID = -2783909112856789454L;
@Id
@Column(name = "GOODS_ID", nullable = false, updatable = false)
private Long goodsId;
@Column(name = "TRANSACTION_ID", nullable = false, updatable = false)
private Long transactionId;
@Column(name = "GOODS_ORDER_NO", nullable = false, updatable = false, length = 64)
private String goodsOrderNo;
@Column(name = "GOODS_NAME", nullable = false, updatable = false, length = 512)
private String goodsName;
@Column(name = "QUANTITY", nullable = false, updatable = false)
private Integer quantity;
@Column(name = "PRICE", nullable = false, updatable = false, precision = 2)
private BigDecimal price;
@Column(name = "DISC_AMOUNT", nullable = false, updatable = false, precision = 2)
private BigDecimal discAmount;
@Column(name = "TXN_AMOUNT", nullable = false, updatable = false, precision = 2)
private BigDecimal txnAmount;
@Column(name = "ATTACH_TEXT", nullable = true, length = 512)
private String attachText;
public Long getGoodsId() {
return goodsId;
}
public void setGoodsId(Long goodsId) {
this.goodsId = goodsId;
}
public Long getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
this.transactionId = transactionId;
}
public String getGoodsOrderNo() {
return goodsOrderNo;
}
public void setGoodsOrderNo(String goodsOrderNo) {
this.goodsOrderNo = goodsOrderNo;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getDiscAmount() {
return discAmount;
}
public void setDiscAmount(BigDecimal discAmount) {
this.discAmount = discAmount;
}
public BigDecimal getTxnAmount() {
return txnAmount;
}
public void setTxnAmount(BigDecimal txnAmount) {
this.txnAmount = txnAmount;
}
public String getAttachText() {
return attachText;
}
public void setAttachText(String attachText) {
this.attachText = attachText;
}
@Override
public String persistenceKey() {
return StringUtils.toDelimitedString(CLASS_NAME, goodsId);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PayGoodsDetailEntity that = (PayGoodsDetailEntity) o;
return Objects.equals(goodsId, that.goodsId);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("PayGoodsDetailEntity{");
sb.append("goodsId=").append(goodsId);
sb.append(", transactionId=").append(transactionId);
sb.append(", goodsOrderNo='").append(goodsOrderNo).append('\'');
sb.append(", goodsName='").append(goodsName).append('\'');
sb.append(", quantity=").append(quantity);
sb.append(", price=").append(price);
sb.append(", discAmount=").append(discAmount);
sb.append(", txnAmount=").append(txnAmount);
sb.append(", attachText='").append(attachText).append('\'');
sb.append(',').append(super.toString());
sb.append('}');
return sb.toString();
}
}
package cn.quant.baa.pay.jpa.repository;
import cn.quant.baa.pay.jpa.entity.AccountEntity;
import cn.quant.baa.pay.jpa.entity.AccountIds;
import cn.quant.baa.pay.jpa.entity.PayGoodsDetailEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by Administrator on 2021/8/22 0022.
*/
@Repository
public interface PayGoodsDetailRepository extends JpaRepository<PayGoodsDetailEntity, Long> {
}
package cn.quant.baa.pay.model;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.constraints.*;
import java.io.Serializable;
/**
......@@ -14,46 +13,59 @@ public class GoodsDetail implements Serializable{
/**
* 商品ID
*/
@Size(min = 6, max = 64)
private String goodsId;
@NotNull(message = "ILLEGAL_REQ_GOODS_NO")
@Size(min = 6, max = 64, message = "ILLEGAL_REQ_GOODS_NO")
private String goodsNo;
/**
* 商品名
*/
@NotNull(message = "ILLEGAL_REQ_GOODS_NAME")
@Size(min = 3, max = 512, message = "ILLEGAL_REQ_GOODS_NAME")
private String goodsName;
/**
* 数量
*/
@NotNull(message = "ILLEGAL_REQ_GOODS_QUANTITY")
@Max(value = 30000, message = "ILLEGAL_REQ_GOODS_QUANTITY")
@Min(value = 1, message = "ILLEGAL_REQ_GOODS_QUANTITY")
private String quantity;
/**
* 商品单价
*/
@NotNull(message = "ILLEGAL_REQ_GOODS_PRICE")
@DecimalMin(value = "0.00")
private String price;
/**
* 优惠金额
*/
@NotNull(message = "ILLEGAL_REQ_GOODS_DISC")
@DecimalMin(value = "0.00")
private String discounts;
/**
* 实付金额
*/
@NotNull(message = "ILLEGAL_REQ_GOODS_AMT")
@DecimalMin(value = "0.01")
private String amount;
/**
* 附加信息
*/
@Size(max = 512, message = "ILLEGAL_REQ_GOODS_ATTACH")
private String attach;
public String getGoodsId() {
return goodsId;
public String getGoodsNo() {
return goodsNo;
}
public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
public void setGoodsNo(String goodsNo) {
this.goodsNo = goodsNo;
}
public String getGoodsName() {
......@@ -107,7 +119,7 @@ public class GoodsDetail implements Serializable{
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("GoodsDetail{");
sb.append("goodsId='").append(goodsId).append('\'');
sb.append("goodsNo='").append(goodsNo).append('\'');
sb.append(", goodsName='").append(goodsName).append('\'');
sb.append(", quantity=").append(quantity);
sb.append(", price='").append(price).append('\'');
......
......@@ -38,13 +38,12 @@ public class MerchantAcquirerProfile implements Serializable{
//feature
private AccessCode accessCode;
private AccessType accessType;
private String accessMethod;
private String version;
private String accessPath;
private String payAccess;
private String refundAccess;
private String checkAccess;
private String descText;
//APP
......@@ -161,6 +160,14 @@ public class MerchantAcquirerProfile implements Serializable{
this.accessType = accessType;
}
public String getAccessMethod() {
return accessMethod;
}
public void setAccessMethod(String accessMethod) {
this.accessMethod = accessMethod;
}
public String getVersion() {
return version;
}
......@@ -169,12 +176,28 @@ public class MerchantAcquirerProfile implements Serializable{
this.version = version;
}
public String getAccessPath() {
return accessPath;
public String getPayAccess() {
return payAccess;
}
public void setPayAccess(String payAccess) {
this.payAccess = payAccess;
}
public String getRefundAccess() {
return refundAccess;
}
public void setRefundAccess(String refundAccess) {
this.refundAccess = refundAccess;
}
public String getCheckAccess() {
return checkAccess;
}
public void setAccessPath(String accessPath) {
this.accessPath = accessPath;
public void setCheckAccess(String checkAccess) {
this.checkAccess = checkAccess;
}
public String getDescText() {
......@@ -264,8 +287,11 @@ public class MerchantAcquirerProfile implements Serializable{
sb.append(", payPublicKey='").append(payPublicKey).append('\'');
sb.append(", accessCode=").append(accessCode);
sb.append(", accessType=").append(accessType);
sb.append(", accessMethod='").append(accessMethod).append('\'');
sb.append(", version='").append(version).append('\'');
sb.append(", accessPath='").append(accessPath).append('\'');
sb.append(", payAccess='").append(payAccess).append('\'');
sb.append(", refundAccess='").append(refundAccess).append('\'');
sb.append(", checkAccess='").append(checkAccess).append('\'');
sb.append(", descText='").append(descText).append('\'');
sb.append(", institutionId='").append(institutionId).append('\'');
sb.append(", productId='").append(productId).append('\'');
......
package cn.quant.baa.pay.service;
import cn.quant.baa.pay.component.Sequencer;
import cn.quant.baa.pay.context.TransactionSession;
import cn.quant.baa.pay.dict.AcctTypeId;
import cn.quant.baa.pay.dict.CurrencyCode;
import cn.quant.baa.pay.dict.StatusCode;
import cn.quant.baa.pay.jpa.entity.AccountEntity;
import cn.quant.baa.pay.jpa.entity.AccountIds;
import cn.quant.baa.pay.jpa.entity.EntityBuilder;
import cn.quant.baa.pay.jpa.repository.AccountRepository;
import cn.quant.baa.pay.model.AssertUtils;
import cn.quant.spring.IllegalParameterException;
import cn.quant.spring.NullException;
import cn.quant.spring.context.ContextLoader;
import cn.quant.spring.context.ServerApplicationContext;
import cn.quant.spring.util.DateUtils;
import cn.quant.spring.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.Set;
import static cn.quant.baa.pay.Constant.MINI_LOCAL_DATE;
import static cn.quant.baa.pay.dict.MessageEnum.*;
/**
* Created by Administrator on 2021/8/25 0025.
*/
......
......@@ -2,10 +2,7 @@ package cn.quant.baa.pay.service;
import cn.quant.baa.pay.config.MerchantAcquirerBuilder;
import cn.quant.baa.pay.context.TransactionSession;
import cn.quant.baa.pay.jpa.entity.AccountEntity;
import cn.quant.baa.pay.jpa.entity.EntityBuilder;
import cn.quant.baa.pay.jpa.entity.PayHistoryEntity;
import cn.quant.baa.pay.jpa.entity.PayHistoryIds;
import cn.quant.baa.pay.jpa.entity.*;
import cn.quant.baa.pay.model.AssertUtils;
import cn.quant.baa.pay.model.GoodsDetail;
import cn.quant.baa.pay.model.MerchantAcquirerProfile;
......@@ -17,6 +14,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.LinkedList;
import java.util.List;
import static cn.quant.baa.pay.dict.MessageEnum.*;
/**
......@@ -49,16 +49,33 @@ public class TransactionService extends BusinessService {
AssertUtils.throwMessage(ACQUIRER_NOSUCH, chanId);
}
String mchId = data.getMchId();
if (!mchId.equals(profile.getPayAppId())) {
AssertUtils.throwMessage(ACQUIRER_NOMATCH, chanId, mchId);
}
String institutionId = profile.getInstitutionId();
String productId = profile.getProductId();
String buyerId = data.getBuyerId();
TransactionSession session = TransactionSession.session();
prepare(institutionId, productId, buyerId, session);
AccountEntity account = session.getAccount();
long historyId = session.nextId();
Integer partitionKey = account.getPartitionKey();
GoodsDetail[] goodsDetails = data.getGoodsDetail();
List<PayGoodsDetailEntity> details = new LinkedList<>();
for (GoodsDetail detail : goodsDetails) {
validate(detail);
PayGoodsDetailEntity detailEntity = EntityBuilder.goodsDetail(session.nextId(), historyId, detail);
detailEntity.setPartitionKey(partitionKey);
details.add(detailEntity);
}
String mchId = data.getMchId();
if (!mchId.equals(profile.getPayAppId())) {
AssertUtils.throwMessage(ACQUIRER_NOMATCH, chanId, mchId);
}
String outTradeNo = data.getOutTradeNo();
PayHistoryIds ids = new PayHistoryIds();
ids.setInstitutionId(institutionId);
......@@ -66,19 +83,10 @@ public class TransactionService extends BusinessService {
ids.setExternalOrderNo(outTradeNo);
check(ids, session);
GoodsDetail[] goodsDetail = data.getGoodsDetail();
String buyerId = data.getBuyerId();
prepare(institutionId, productId, buyerId, session);
AccountEntity account = session.getAccount();
PayHistoryEntity history = EntityBuilder.history(profile, account, ids, data, session);
PayHistoryEntity history = EntityBuilder.history(account, ids, historyId, data, profile, session);
session.pushEntity(history);
session.pushEntity(details);
session.commit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment