diff --git a/admin/admin-service-impl/src/main/resources/mapper/AdminRoleMapper.xml b/admin/admin-service-impl/src/main/resources/mapper/AdminRoleMapper.xml index f677b8a50..8faa8f3af 100644 --- a/admin/admin-service-impl/src/main/resources/mapper/AdminRoleMapper.xml +++ b/admin/admin-service-impl/src/main/resources/mapper/AdminRoleMapper.xml @@ -16,6 +16,7 @@ FROM admin a, admin_role ar WHERE a.id = #{adminId} AND a.id = ar.admin_id + AND ar.deleted = 0 diff --git a/build_admin.sh b/build_admin.sh deleted file mode 100644 index 0a5a3ea81..000000000 --- a/build_admin.sh +++ /dev/null @@ -1 +0,0 @@ -mvn clean package -am -DskipTests \ No newline at end of file diff --git a/build_order.sh b/build_order.sh deleted file mode 100644 index dcefb1672..000000000 --- a/build_order.sh +++ /dev/null @@ -1 +0,0 @@ -mvn clean package -pl order/order-application -am -DskipTests \ No newline at end of file diff --git a/build_product.sh b/build_product.sh deleted file mode 100644 index d8762854f..000000000 --- a/build_product.sh +++ /dev/null @@ -1 +0,0 @@ -mvn clean package -pl product/product-application -am -DskipTests \ No newline at end of file diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java new file mode 100644 index 000000000..6cea83c63 --- /dev/null +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java @@ -0,0 +1,43 @@ +package cn.iocoder.common.framework.constant; + +/** + * 通用状态枚举 + */ +public enum CommonStatusEnum { + + ENABLE(1, "开启"), + DISABLE(2, "关闭"); + + /** + * 状态值 + */ + private Integer value; + /** + * 状态名 + */ + private String name; + + CommonStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public CommonStatusEnum setValue(Integer value) { + this.value = value; + return this; + } + + public String getName() { + return name; + } + + public CommonStatusEnum setName(String name) { + this.name = name; + return this; + } + +} \ No newline at end of file diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/HttpUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/HttpUtil.java index 4cd649b6e..418db24aa 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/HttpUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/HttpUtil.java @@ -18,4 +18,25 @@ public class HttpUtil { return authorization.substring(index + 7).trim(); } + public static String getIp(HttpServletRequest request) { + // 基于 X-Forwarded-For 获得 + String ip = request.getHeader("X-Forwarded-For"); + if (!StringUtils.isEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + // 多次反向代理后会有多个ip值,第一个 ip 才是真实 ip + int index = ip.indexOf(","); + if (index != -1) { + return ip.substring(0, index); + } else { + return ip; + } + } + // 基于 X-Real-IP 获得 + ip = request.getHeader("X-Real-IP"); + if (!StringUtils.isEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { + return ip; + } + // 默认方式 + return request.getRemoteAddr(); + } + } \ No newline at end of file diff --git a/common/common-framework/target/classes/cn/iocoder/common/framework/util/HttpUtil.class b/common/common-framework/target/classes/cn/iocoder/common/framework/util/HttpUtil.class index b9d62df2b..e9841d099 100644 Binary files a/common/common-framework/target/classes/cn/iocoder/common/framework/util/HttpUtil.class and b/common/common-framework/target/classes/cn/iocoder/common/framework/util/HttpUtil.class differ diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java deleted file mode 100644 index d8e45ca55..000000000 --- a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/PayController.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.iocoder.mall.pay.application.controller; - -import cn.iocoder.mall.pay.api.PayService; -import com.alibaba.dubbo.config.annotation.Reference; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/pay") -public class PayController { - - @Reference(validation = "true") - private PayService payService; - -} diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayDemoController.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayDemoController.java new file mode 100644 index 000000000..5af8b5736 --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayDemoController.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.pay.application.controller.users; + +import cn.iocoder.common.framework.util.HttpUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.pay.api.PayTransactionService; +import cn.iocoder.mall.pay.api.bo.PayTransactionBO; +import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO; +import com.alibaba.dubbo.config.annotation.Reference; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; + +/** + * 示例 Controller + */ +@RestController +@RequestMapping("users/demo") +public class PayDemoController { + + @Reference(validation = "true") + private PayTransactionService payTransactionService; + + @PostMapping("/create_order") + public void createOrder(HttpServletRequest request) { + // 创建业务订单 + // ... + + // 调用【支付服务】,创建交易订单 + PayTransactionCreateDTO payTransactionCreateDTO = new PayTransactionCreateDTO() + .setAppId("1024") + .setCreateIp(HttpUtil.getIp(request)) + .setOrderId("1") + .setOrderSubject("商品名" ) + .setOrderDescription("商品描述") + .setOrderMemo("商品备注") + .setPrice(10) + .setExpireTime(new Date()); + CommonResult result = payTransactionService.createTransaction(payTransactionCreateDTO); + Assert.isTrue(result.isSuccess(), "一定会成功的"); + } + +} \ No newline at end of file diff --git a/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayTransactionController.java b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayTransactionController.java new file mode 100644 index 000000000..e1285f418 --- /dev/null +++ b/pay/pay-application/src/main/java/cn/iocoder/mall/pay/application/controller/users/PayTransactionController.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.pay.application.controller.users; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.pay.api.PayTransactionService; +import com.alibaba.dubbo.config.annotation.Reference; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("users/transaction") // TODO 芋艿,理论来说,是用户无关的。这里先酱紫先~ +public class PayTransactionController { + + @Reference(validation = "true") + private PayTransactionService payService; + + @PostMapping("/submit") // TODO api 注释 + public CommonResult submit() { // TODO 1. params 2. result + return null; + } + +} \ No newline at end of file diff --git a/pay/pay-service-api/pom.xml b/pay/pay-service-api/pom.xml index 6e8532fa4..42799e634 100644 --- a/pay/pay-service-api/pom.xml +++ b/pay/pay-service-api/pom.xml @@ -10,6 +10,14 @@ 4.0.0 pay-service-api + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + compile + + \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java deleted file mode 100644 index 4556d0495..000000000 --- a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayService.java +++ /dev/null @@ -1,4 +0,0 @@ -package cn.iocoder.mall.pay.api; - -public interface PayService { -} diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayTransactionService.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayTransactionService.java new file mode 100644 index 000000000..046b26a28 --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/PayTransactionService.java @@ -0,0 +1,15 @@ +package cn.iocoder.mall.pay.api; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.pay.api.bo.PayTransactionBO; +import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO; + +public interface PayTransactionService { + + CommonResult createTransaction(PayTransactionCreateDTO payTransactionCreateDTO); + + CommonResult submitTransaction(); // TODO 1. params 2. result + + CommonResult cancelTransaction(); // TODO 1. params 2. result + +} \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/PayTransactionBO.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/PayTransactionBO.java new file mode 100644 index 000000000..1ef08264a --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/bo/PayTransactionBO.java @@ -0,0 +1,242 @@ +package cn.iocoder.mall.pay.api.bo; + +import java.util.Date; + +/** + * 支付交易 BO + */ +public class PayTransactionBO { + + /** + * 编号,自增 + */ + private Integer id; + /** + * 应用编号 + */ + private String appId; + /** + * 发起交易的 IP + */ + private String createIp; + /** + * 业务线的订单编号 + * + * 1. 使用 String 的原因是,业务线可能使用 String 做为编号 + * 2. 每个 appId 下,orderId 唯一 + */ + private String orderId; + /** + * 订单商品名 + */ + private String orderSubject; + /** + * 订单商品描述 + */ + private String orderDescription; + /** + * 订单备注 + */ + private String orderMemo; + /** + * 支付金额,单位:分。 + */ + private Integer price; + /** + * 订单状态 + * + * @see cn.iocoder.mall.pay.api.constant.PayTransactionStatusEnum + */ + private Integer status; + /** + * 交易过期时间 + */ + private Date expireTime; + /** + * 回调业务线完成时间 + */ + private Date finishTime; + + /** + * 成功支付的交易拓展编号 + */ + private Integer extensionId; + /** + * 支付成功的支付渠道 + * + * @see cn.iocoder.mall.pay.api.constant.PayChannelEnum + */ + private Integer payChannel; + /** + * 第三方支付成功的时间 + */ + private Date paymentTime; + /** + * 收到第三方系统通知的时间 + * + * 一般情况下,即第三方系统的异步通知 + */ + private Date notifyTime; + /** + * 第三方的流水号 + */ + private String tradeNo; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public PayTransactionBO setId(Integer id) { + this.id = id; + return this; + } + + public String getAppId() { + return appId; + } + + public PayTransactionBO setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getCreateIp() { + return createIp; + } + + public PayTransactionBO setCreateIp(String createIp) { + this.createIp = createIp; + return this; + } + + public String getOrderId() { + return orderId; + } + + public PayTransactionBO setOrderId(String orderId) { + this.orderId = orderId; + return this; + } + + public String getOrderSubject() { + return orderSubject; + } + + public PayTransactionBO setOrderSubject(String orderSubject) { + this.orderSubject = orderSubject; + return this; + } + + public String getOrderDescription() { + return orderDescription; + } + + public PayTransactionBO setOrderDescription(String orderDescription) { + this.orderDescription = orderDescription; + return this; + } + + public String getOrderMemo() { + return orderMemo; + } + + public PayTransactionBO setOrderMemo(String orderMemo) { + this.orderMemo = orderMemo; + return this; + } + + public Integer getPrice() { + return price; + } + + public PayTransactionBO setPrice(Integer price) { + this.price = price; + return this; + } + + public Integer getStatus() { + return status; + } + + public PayTransactionBO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getExpireTime() { + return expireTime; + } + + public PayTransactionBO setExpireTime(Date expireTime) { + this.expireTime = expireTime; + return this; + } + + public Date getFinishTime() { + return finishTime; + } + + public PayTransactionBO setFinishTime(Date finishTime) { + this.finishTime = finishTime; + return this; + } + + public Integer getExtensionId() { + return extensionId; + } + + public PayTransactionBO setExtensionId(Integer extensionId) { + this.extensionId = extensionId; + return this; + } + + public Integer getPayChannel() { + return payChannel; + } + + public PayTransactionBO setPayChannel(Integer payChannel) { + this.payChannel = payChannel; + return this; + } + + public Date getPaymentTime() { + return paymentTime; + } + + public PayTransactionBO setPaymentTime(Date paymentTime) { + this.paymentTime = paymentTime; + return this; + } + + public Date getNotifyTime() { + return notifyTime; + } + + public PayTransactionBO setNotifyTime(Date notifyTime) { + this.notifyTime = notifyTime; + return this; + } + + public String getTradeNo() { + return tradeNo; + } + + public PayTransactionBO setTradeNo(String tradeNo) { + this.tradeNo = tradeNo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public PayTransactionBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + +} \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannel.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannelEnum.java similarity index 87% rename from pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannel.java rename to pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannelEnum.java index 0939b203c..0325e6bb7 100644 --- a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannel.java +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayChannelEnum.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.pay.api.constant; /** * 支付通道 */ -public enum PayChannel { +public enum PayChannelEnum { WEIXIN_APP(100, "wx", "微信 App 支付"), WEIXIN_PUB(100, "wx", "微信 JS API 支付"), @@ -23,7 +23,7 @@ public enum PayChannel { */ private String name; - PayChannel(Integer id, String code, String name) { + PayChannelEnum(Integer id, String code, String name) { this.id = id; this.code = code; this.name = name; @@ -40,4 +40,5 @@ public enum PayChannel { public String getName() { return name; } + } \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java index b51cd16f3..827a35eb3 100644 --- a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayErrorCodeEnum.java @@ -7,7 +7,13 @@ package cn.iocoder.mall.pay.api.constant; */ public enum PayErrorCodeEnum { - // ========== PAY 模块 ========== + // ========== APP 模块 ========== + PAY_APP_NOT_FOUND(1004000000, "App 不存在"), + PAY_APP_IS_DISABLE(1004000001, "App 已经被禁用"), + + // ========== TRANSACTION 模块 ========== + + ; private final int code; diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionNotifyStatusEnum.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionNotifyStatusEnum.java new file mode 100644 index 000000000..0d85e7efa --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionNotifyStatusEnum.java @@ -0,0 +1,38 @@ +package cn.iocoder.mall.pay.api.constant; + +/** + * 支付交易通知状态枚举 + */ +public enum PayTransactionNotifyStatusEnum { + + WAITING(1, "等待通知"), + SUCCESS(2, "通知成功"), + FAILURE(3, "通知失败"), // 多次尝试,彻底失败 + REQUEST_SUCCESS(4, "请求成功,但是结果失败"), + REQUEST_FAILURE(5, "请求失败"), + + ; + + /** + * 状态 + */ + private Integer value; + /** + * 名字 + */ + private String name; + + PayTransactionNotifyStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } + +} \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionStatusEnum.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionStatusEnum.java new file mode 100644 index 000000000..9047b1fde --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/constant/PayTransactionStatusEnum.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.pay.api.constant; + +/** + * 支付交易状态枚举 + */ +public enum PayTransactionStatusEnum { + + WAITTING(1, "等待支付"), + SUCCESS(2, "支付成功"), + CANCEL(3, "取消支付"), // 例如说,支付单超时 + ; + + /** + * 状态 + */ + private Integer value; + /** + * 名字 + */ + private String name; + + PayTransactionStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public PayTransactionStatusEnum setValue(Integer value) { + this.value = value; + return this; + } + + public String getName() { + return name; + } + + public PayTransactionStatusEnum setName(String name) { + this.name = name; + return this; + } + +} \ No newline at end of file diff --git a/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/PayTransactionCreateDTO.java b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/PayTransactionCreateDTO.java new file mode 100644 index 000000000..b95d87139 --- /dev/null +++ b/pay/pay-service-api/src/main/java/cn/iocoder/mall/pay/api/dto/PayTransactionCreateDTO.java @@ -0,0 +1,130 @@ +package cn.iocoder.mall.pay.api.dto; + +import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * 支付交易创建 DTO + */ +public class PayTransactionCreateDTO { + + /** + * 应用编号 + */ + @NotEmpty(message = "应用编号不能为空") + private String appId; + /** + * 发起交易的 IP + */ + @NotEmpty(message = "IP 不能为空") + private String createIp; + /** + * 业务线的订单编号 + */ + @NotEmpty(message = "订单号不能为空") + private String orderId; + /** + * 订单商品名 + */ + @NotEmpty(message = "商品名不能为空") + @Size(max = 32, message = "商品名不能超过32") + private String orderSubject; + /** + * 订单商品描述 + */ + @NotEmpty(message = "商品描述不能为空") + @Size(max = 128, message = "商品描述长度不能超过128") + private String orderDescription; + /** + * 订单备注 + */ + @Size(max = 256, message = "商品描述长度不能超过256") + private String orderMemo; + /** + * 支付金额,单位:分。 + */ + @NotNull(message = "金额不能为空") + @DecimalMin(value = "0", inclusive = false, message = "金额必须大于零") + private Integer price; + /** + * 交易过期时间 + */ + @NotNull(message = "交易过期时间不能为空") + private Date expireTime; + + public String getAppId() { + return appId; + } + + public PayTransactionCreateDTO setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getCreateIp() { + return createIp; + } + + public PayTransactionCreateDTO setCreateIp(String createIp) { + this.createIp = createIp; + return this; + } + + public String getOrderId() { + return orderId; + } + + public PayTransactionCreateDTO setOrderId(String orderId) { + this.orderId = orderId; + return this; + } + + public String getOrderSubject() { + return orderSubject; + } + + public PayTransactionCreateDTO setOrderSubject(String orderSubject) { + this.orderSubject = orderSubject; + return this; + } + + public String getOrderDescription() { + return orderDescription; + } + + public PayTransactionCreateDTO setOrderDescription(String orderDescription) { + this.orderDescription = orderDescription; + return this; + } + + public String getOrderMemo() { + return orderMemo; + } + + public PayTransactionCreateDTO setOrderMemo(String orderMemo) { + this.orderMemo = orderMemo; + return this; + } + + public Integer getPrice() { + return price; + } + + public PayTransactionCreateDTO setPrice(Integer price) { + this.price = price; + return this; + } + + public Date getExpireTime() { + return expireTime; + } + + public PayTransactionCreateDTO setExpireTime(Date expireTime) { + this.expireTime = expireTime; + return this; + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/convert/PayTransactionConvert.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/convert/PayTransactionConvert.java new file mode 100644 index 000000000..27b6b0fe6 --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/convert/PayTransactionConvert.java @@ -0,0 +1,21 @@ +package cn.iocoder.mall.pay.convert; + +import cn.iocoder.mall.pay.api.bo.PayTransactionBO; +import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO; +import cn.iocoder.mall.pay.dataobject.PayTransactionDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PayTransactionConvert { + + PayTransactionConvert INSTANCE = Mappers.getMapper(PayTransactionConvert.class); + + @Mappings({}) + PayTransactionDO convert(PayTransactionCreateDTO payTransactionCreateDTO); + + @Mappings({}) + PayTransactionBO convert(PayTransactionDO payTransactionDO); + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayAppMapper.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayAppMapper.java new file mode 100644 index 000000000..c8138b027 --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayAppMapper.java @@ -0,0 +1,12 @@ +package cn.iocoder.mall.pay.dao; + +import cn.iocoder.mall.pay.dataobject.PayAppDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface PayAppMapper { + + PayAppDO selectById(@Param("id") String id); + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayTransactionMapper.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayTransactionMapper.java new file mode 100644 index 000000000..a1ba6e4d2 --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dao/PayTransactionMapper.java @@ -0,0 +1,11 @@ +package cn.iocoder.mall.pay.dao; + +import cn.iocoder.mall.pay.dataobject.PayTransactionDO; +import org.springframework.stereotype.Repository; + +@Repository +public interface PayTransactionMapper { + + void insert(PayTransactionDO entity); + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayAppDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayAppDO.java index 8604cb2e9..3150d82c9 100644 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayAppDO.java +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayAppDO.java @@ -3,7 +3,7 @@ package cn.iocoder.mall.pay.dataobject; import cn.iocoder.common.framework.dataobject.BaseDO; /** - * TODO 支付应用(业务线)DO + * 支付应用(业务线)DO */ public class PayAppDO extends BaseDO { @@ -11,5 +11,53 @@ public class PayAppDO extends BaseDO { * 应用编号 */ private String id; + /** + * 应用名 + */ + private String name; + /** + * 异步通知地址 + */ + private String notifyUrl; + /** + * 状态 + */ + private Integer status; + + public String getId() { + return id; + } + + public PayAppDO setId(String id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public PayAppDO setName(String name) { + this.name = name; + return this; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public PayAppDO setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + return this; + } + + public Integer getStatus() { + return status; + } + + public PayAppDO setStatus(Integer status) { + this.status = status; + return this; + } } \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayNotifyAppLogDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayNotifyAppLogDO.java deleted file mode 100644 index 7eb38d46a..000000000 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayNotifyAppLogDO.java +++ /dev/null @@ -1,7 +0,0 @@ -package cn.iocoder.mall.pay.dataobject; - -/** - * - */ -public class PayNotifyAppLogDO { -} diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayRepeatTransactionDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayRepeatTransactionDO.java index 04bb30132..23660a7d3 100644 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayRepeatTransactionDO.java +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayRepeatTransactionDO.java @@ -2,6 +2,8 @@ package cn.iocoder.mall.pay.dataobject; /** * TODO 重复支付的交易 + * + * 可能不靠这个表,而是差错处理。 */ public class PayRepeatTransactionDO { } diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionDO.java index 8398b64fe..0556f0da4 100644 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionDO.java +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionDO.java @@ -33,15 +33,6 @@ public class PayTransactionDO extends BaseDO { * 2. 每个 appId 下,orderId 唯一 */ private String orderId; - /** - * 订单状态 - * - * 0 : 等待支付 - * 1 : 待付款完成 - * 2 : 该笔交易已关闭 TODO 交易关闭,是不是订单系统触发 - * -1 : 支付失败 TODO 怎么触发 - */ - private Integer orderStatus; /** * 订单商品名 */ @@ -60,16 +51,38 @@ public class PayTransactionDO extends BaseDO { * TODO 暂时不考虑货币类型。 */ private Integer price; + /** + * 订单状态 + * + * @see cn.iocoder.mall.pay.api.constant.PayTransactionStatusEnum + */ + private Integer status; /** * 交易过期时间 */ - private Integer expireTime; + private Date expireTime; + /** + * 回调业务线完成时间 + */ + private Date finishTime; + // TODO return url - // TODO notify url + /** + * 异步通知地址 + */ + private String notifyUrl; + /** + * 成功支付的交易拓展编号 + * + * @see PayTransactionExtensionDO#getId() + */ + private Integer extensionId; /** * 支付成功的支付渠道 + * + * @see cn.iocoder.mall.pay.api.constant.PayChannelEnum */ private Integer payChannel; /** @@ -123,12 +136,12 @@ public class PayTransactionDO extends BaseDO { return this; } - public Integer getOrderStatus() { - return orderStatus; + public Integer getStatus() { + return status; } - public PayTransactionDO setOrderStatus(Integer orderStatus) { - this.orderStatus = orderStatus; + public PayTransactionDO setStatus(Integer status) { + this.status = status; return this; } @@ -150,15 +163,6 @@ public class PayTransactionDO extends BaseDO { return this; } - public Integer getExpireTime() { - return expireTime; - } - - public PayTransactionDO setExpireTime(Integer expireTime) { - this.expireTime = expireTime; - return this; - } - public Date getPaymentTime() { return paymentTime; } @@ -212,4 +216,40 @@ public class PayTransactionDO extends BaseDO { this.orderMemo = orderMemo; return this; } + + public Date getExpireTime() { + return expireTime; + } + + public PayTransactionDO setExpireTime(Date expireTime) { + this.expireTime = expireTime; + return this; + } + + public Date getFinishTime() { + return finishTime; + } + + public PayTransactionDO setFinishTime(Date finishTime) { + this.finishTime = finishTime; + return this; + } + + public Integer getExtensionId() { + return extensionId; + } + + public PayTransactionDO setExtensionId(Integer extensionId) { + this.extensionId = extensionId; + return this; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public PayTransactionDO setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + return this; + } } \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionExtensionDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionExtensionDO.java index 43cc8f3c2..b396db16c 100644 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionExtensionDO.java +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionExtensionDO.java @@ -21,14 +21,10 @@ public class PayTransactionExtensionDO extends BaseDO { private Integer payChannel; /** * 生成传输给第三方的订单号 + * + * 唯一索引 */ private String transactionCode; - /** - * 发起调用的次数 - * - * TODO 芋艿,需要去请教下 - */ - private Integer callNum; /** * 扩展内容 * @@ -39,6 +35,13 @@ public class PayTransactionExtensionDO extends BaseDO { * 发起交易的 IP */ private String createIp; + /** + * 状态 + * + * @see cn.iocoder.mall.pay.api.constant.PayTransactionStatusEnum + * 注意,只包含上述枚举的 WAITTING 和 SUCCESS + */ + private Integer status; public Integer getId() { return id; @@ -76,15 +79,6 @@ public class PayTransactionExtensionDO extends BaseDO { return this; } - public Integer getCallNum() { - return callNum; - } - - public PayTransactionExtensionDO setCallNum(Integer callNum) { - this.callNum = callNum; - return this; - } - public String getExtensionData() { return extensionData; } @@ -103,4 +97,13 @@ public class PayTransactionExtensionDO extends BaseDO { return this; } + public Integer getStatus() { + return status; + } + + public PayTransactionExtensionDO setStatus(Integer status) { + this.status = status; + return this; + } + } \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyLogDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyLogDO.java new file mode 100644 index 000000000..3320eab8c --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyLogDO.java @@ -0,0 +1,67 @@ +package cn.iocoder.mall.pay.dataobject; + +import cn.iocoder.common.framework.dataobject.BaseDO; + +/** + * 支付交易通知 App 的日志 DO + * + * 通过该表,记录通知 App 时,产生的日志 + */ +public class PayTransactionNotifyLogDO extends BaseDO { + + /** + * 日志编号,自增 + */ + private Integer id; + /** + * 请求参数 + */ + private String request; + /** + * 响应结果 + */ + private String response; + /** + * 状态 + * + * @see cn.iocoder.mall.pay.api.constant.PayTransactionNotifyStatusEnum + */ + private Integer status; + + public Integer getId() { + return id; + } + + public PayTransactionNotifyLogDO setId(Integer id) { + this.id = id; + return this; + } + + public String getRequest() { + return request; + } + + public PayTransactionNotifyLogDO setRequest(String request) { + this.request = request; + return this; + } + + public String getResponse() { + return response; + } + + public PayTransactionNotifyLogDO setResponse(String response) { + this.response = response; + return this; + } + + public Integer getStatus() { + return status; + } + + public PayTransactionNotifyLogDO setStatus(Integer status) { + this.status = status; + return this; + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyTaskDO.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyTaskDO.java new file mode 100644 index 000000000..d4c4364eb --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/dataobject/PayTransactionNotifyTaskDO.java @@ -0,0 +1,139 @@ +package cn.iocoder.mall.pay.dataobject; + +import cn.iocoder.common.framework.dataobject.BaseDO; + +import java.util.Date; + +/** + * 支付交易通知 App 的任务 DO + */ +public class PayTransactionNotifyTaskDO extends BaseDO { + + /** + * 编号,自增 + */ + private Integer id; + /** + * 交易编号 + * + * {@link PayTransactionDO#getId()} + */ + private Integer transactionId; + /** + * 交易拓展编号 + * + * {@link PayTransactionExtensionDO#getId()} + */ + private Integer transactionExtensionId; + /** + * 应用编号 + */ + private String appId; + /** + * 应用订单编号 + */ + private String orderId; + /** + * 通知状态 + * + * @see cn.iocoder.mall.pay.api.constant.PayTransactionNotifyStatusEnum + */ + private Integer status; + /** + * 最后一次通知时间 + */ + private Date lastNotifyTime; + /** + * 当前通知次数 + */ + private Integer notifyTimes; + /** + * 最大可通知次数 + */ + private Integer maxNotifyTimes; + + // TODO notify url + + + public Integer getTransactionId() { + return transactionId; + } + + public PayTransactionNotifyTaskDO setTransactionId(Integer transactionId) { + this.transactionId = transactionId; + return this; + } + + public String getAppId() { + return appId; + } + + public PayTransactionNotifyTaskDO setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getOrderId() { + return orderId; + } + + public PayTransactionNotifyTaskDO setOrderId(String orderId) { + this.orderId = orderId; + return this; + } + + public Integer getStatus() { + return status; + } + + public PayTransactionNotifyTaskDO setStatus(Integer status) { + this.status = status; + return this; + } + + public Date getLastNotifyTime() { + return lastNotifyTime; + } + + public PayTransactionNotifyTaskDO setLastNotifyTime(Date lastNotifyTime) { + this.lastNotifyTime = lastNotifyTime; + return this; + } + + public Integer getNotifyTimes() { + return notifyTimes; + } + + public PayTransactionNotifyTaskDO setNotifyTimes(Integer notifyTimes) { + this.notifyTimes = notifyTimes; + return this; + } + + public Integer getMaxNotifyTimes() { + return maxNotifyTimes; + } + + public PayTransactionNotifyTaskDO setMaxNotifyTimes(Integer maxNotifyTimes) { + this.maxNotifyTimes = maxNotifyTimes; + return this; + } + + public Integer getId() { + return id; + } + + public PayTransactionNotifyTaskDO setId(Integer id) { + this.id = id; + return this; + } + + public Integer getTransactionExtensionId() { + return transactionExtensionId; + } + + public PayTransactionNotifyTaskDO setTransactionExtensionId(Integer transactionExtensionId) { + this.transactionExtensionId = transactionExtensionId; + return this; + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/scheduler/PayNotifyAppJob.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/scheduler/PayNotifyAppJob.java new file mode 100644 index 000000000..91f6745cc --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/scheduler/PayNotifyAppJob.java @@ -0,0 +1,12 @@ +package cn.iocoder.mall.pay.scheduler; + +/** + * TODO + */ +public class PayNotifyAppJob { + + // TODO 需要考虑下是基于 MQ 还是 Job + // TODO 通知频率 + // TODO rpc 泛化回调 + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayAppServiceImpl.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayAppServiceImpl.java new file mode 100644 index 000000000..7bdee653f --- /dev/null +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayAppServiceImpl.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.pay.service; + +import cn.iocoder.common.framework.constant.CommonStatusEnum; +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.pay.api.constant.PayErrorCodeEnum; +import cn.iocoder.mall.pay.dao.PayAppMapper; +import cn.iocoder.mall.pay.dataobject.PayAppDO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class PayAppServiceImpl { + + @Autowired + private PayAppMapper payAppMapper; + + public CommonResult validPayApp(String appId) { + PayAppDO payAppDO = payAppMapper.selectById(appId); + // 校验是否存在 + if (payAppDO == null) { + return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_APP_NOT_FOUND.getCode()); + } + // 校验是否禁用 + if (CommonStatusEnum.DISABLE.getValue().equals(payAppDO.getStatus())) { + return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_APP_IS_DISABLE.getCode()); + } + return CommonResult.success(payAppDO); + } + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java index 8d4a9c82f..5ba872134 100644 --- a/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java +++ b/pay/pay-service-impl/src/main/java/cn/iocoder/mall/pay/service/PayServiceImpl.java @@ -1,9 +1,44 @@ package cn.iocoder.mall.pay.service; -import cn.iocoder.mall.pay.api.PayService; +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.pay.api.PayTransactionService; +import cn.iocoder.mall.pay.api.bo.PayTransactionBO; +import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO; +import cn.iocoder.mall.pay.dao.PayTransactionMapper; +import cn.iocoder.mall.pay.dataobject.PayAppDO; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service @com.alibaba.dubbo.config.annotation.Service(validation = "true") -public class PayServiceImpl implements PayService { -} +public class PayServiceImpl implements PayTransactionService { + + @Autowired + private PayTransactionMapper payTransactionMapper; + @Autowired + private PayAppServiceImpl payAppService; + + @Override + public CommonResult createTransaction(PayTransactionCreateDTO payTransactionCreateDTO) { + // 校验 App + CommonResult appResult = payAppService.validPayApp(payTransactionCreateDTO.getAppId()); + if (appResult.isError()) { + return CommonResult.error(appResult); + } + // 插入 PayTransactionDO + return null; + } + + @Override + public CommonResult submitTransaction() { + return null; + } + + @Override + public CommonResult cancelTransaction() { + return null; + } + + + +} \ No newline at end of file diff --git a/pay/pay-service-impl/src/main/resources/mapper/PayAppMapper.xml b/pay/pay-service-impl/src/main/resources/mapper/PayAppMapper.xml new file mode 100644 index 000000000..b581aae1f --- /dev/null +++ b/pay/pay-service-impl/src/main/resources/mapper/PayAppMapper.xml @@ -0,0 +1,37 @@ + + + + + + id, name, status, create_time + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/publish_admin.sh b/publish_admin.sh deleted file mode 100644 index a9a2ca64c..000000000 --- a/publish_admin.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -sh build_admin.sh -scp admin/admin-application/target/admin-application-1.0-SNAPSHOT.jar runner@192.168.88.10:/work2/project/admin \ No newline at end of file