parent
c772da6716
commit
7d423c8ed2
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.common.framework.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MathUtil {
|
||||
|
||||
/**
|
||||
* 随机对象
|
||||
*/
|
||||
private static final Random RANDOM = new Random(); // TODO 后续优化
|
||||
|
||||
/**
|
||||
* 随机[min, max]范围内的数字
|
||||
*
|
||||
* @param min 随机开始
|
||||
* @param max 随机结束
|
||||
* @return 数字
|
||||
*/
|
||||
public static int random(int min, int max) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
if (min > max) {
|
||||
int temp = min;
|
||||
min = max;
|
||||
max = temp;
|
||||
}
|
||||
// 随即开始
|
||||
int diff = max - min + 1;
|
||||
return RANDOM.nextInt(diff) + min;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.ReferenceConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
import com.alibaba.dubbo.rpc.service.GenericService;
|
||||
|
||||
public class DubboGenericInvokerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationConfig application = new ApplicationConfig();
|
||||
application.setName("api-generic-consumer");
|
||||
|
||||
RegistryConfig registry = new RegistryConfig();
|
||||
registry.setAddress("zookeeper://127.0.0.1:2181");
|
||||
|
||||
application.setRegistry(registry);
|
||||
|
||||
ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
|
||||
// 弱类型接口名
|
||||
reference.setInterface("cn.iocoder.mall.pay.api.PayDemoService");
|
||||
// 声明为泛化接口
|
||||
reference.setGeneric(true);
|
||||
|
||||
reference.setApplication(application);
|
||||
|
||||
// 用com.alibaba.dubbo.rpc.service.GenericService可以替代所有接口引用
|
||||
GenericService genericService = reference.get();
|
||||
|
||||
String name = (String) genericService.$invoke("updatePaySuccess", new String[]{String.class.getName()}, new Object[]{"1"});
|
||||
System.out.println(name);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package cn.iocoder.mall.pay.api;
|
||||
|
||||
public interface PayDemoService {
|
||||
|
||||
String updatePaySuccess(String orderId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.mall.pay.client;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 交易支付成功结果
|
||||
*/
|
||||
public class TransactionPaySuccessBO {
|
||||
|
||||
/**
|
||||
* 生成传输给第三方的订单号
|
||||
*
|
||||
* 唯一索引
|
||||
*/
|
||||
private String transactionCode;
|
||||
/**
|
||||
* 第三方的流水号
|
||||
*/
|
||||
private String tradeNo;
|
||||
/**
|
||||
* 第三方支付成功的时间
|
||||
*/
|
||||
private Date paymentTime;
|
||||
|
||||
public String getTransactionCode() {
|
||||
return transactionCode;
|
||||
}
|
||||
|
||||
public TransactionPaySuccessBO setTransactionCode(String transactionCode) {
|
||||
this.transactionCode = transactionCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTradeNo() {
|
||||
return tradeNo;
|
||||
}
|
||||
|
||||
public TransactionPaySuccessBO setTradeNo(String tradeNo) {
|
||||
this.tradeNo = tradeNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getPaymentTime() {
|
||||
return paymentTime;
|
||||
}
|
||||
|
||||
public TransactionPaySuccessBO setPaymentTime(Date paymentTime) {
|
||||
this.paymentTime = paymentTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,11 +1,17 @@
|
||||
package cn.iocoder.mall.pay.dao;
|
||||
|
||||
import cn.iocoder.mall.pay.dataobject.PayTransactionExtensionDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PayTransactionExtensionMapper {
|
||||
|
||||
void insert(PayTransactionExtensionDO payTransactionExtensionDO);
|
||||
void insert(PayTransactionExtensionDO entity);
|
||||
|
||||
int update(@Param("entity") PayTransactionExtensionDO entity,
|
||||
@Param("whereStatus") Integer whereStatus);
|
||||
|
||||
PayTransactionExtensionDO selectByTransactionCode(@Param("transactionCode") String transactionCode);
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package cn.iocoder.mall.pay.dao;
|
||||
|
||||
import cn.iocoder.mall.pay.dataobject.PayTransactionNotifyTaskDO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PayTransactionNotifyTaskMapper {
|
||||
|
||||
void insert(PayTransactionNotifyTaskDO entity);
|
||||
|
||||
int update(PayTransactionNotifyTaskDO entity);
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.pay.service;
|
||||
|
||||
import cn.iocoder.mall.pay.api.PayDemoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@com.alibaba.dubbo.config.annotation.Service
|
||||
public class PayDemoServiceImpl implements PayDemoService {
|
||||
|
||||
@Override
|
||||
public String updatePaySuccess(String orderId) {
|
||||
return "你好呀";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.mall.pay.dao.PayTransactionExtensionMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, transaction_id, pay_channel, transaction_code, extension_data,
|
||||
create_ip, status, create_time
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="PayTransactionExtensionDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO transaction_extension (
|
||||
transaction_id, pay_channel, transaction_code, extension_data,
|
||||
create_ip, status
|
||||
) VALUES (
|
||||
#{transactionId}, #{payChannel}, #{transactionCode}, #{extensionData},
|
||||
#{createIp}, #{status}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE transaction_extension
|
||||
<set>
|
||||
<if test="entity.extensionData != null">
|
||||
, extension_data = #{entity.extensionData}
|
||||
</if>
|
||||
<if test="entity.status != null">
|
||||
, status = #{entity.status}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{entity.id}
|
||||
<if test="whereStatus != null">
|
||||
AND status = #{whereStatus}
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<select id="selectByTransactionCode" parameterType="String" resultType="PayTransactionExtensionDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM transaction_extension
|
||||
WHERE transaction_code = #{transactionCode}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.mall.pay.dao.PayTransactionMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, app_id, create_ip, order_id, order_subject,
|
||||
order_description, order_memo, price, status, expire_time,
|
||||
finish_time, notify_url, extension_id, pay_channel, payment_time,
|
||||
notify_time, trade_no, create_time
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="PayTransactionDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO transaction (
|
||||
app_id, create_ip, order_id, order_subject,
|
||||
order_description, order_memo, price, status, expire_time,
|
||||
finish_time, notify_url, extension_id, pay_channel, payment_time,
|
||||
notify_time, trade_no, create_time
|
||||
) VALUES (
|
||||
#{appId}, #{createIp}, #{orderId}, #{orderSubject},
|
||||
#{orderDescription}, #{orderMemo}, #{price}, #{status}, #{expireTime},
|
||||
#{finishTime}, #{notifyUrl}, #{extensionId}, #{payChannel}, #{paymentTime},
|
||||
#{notifyTime}, #{tradeNo}, #{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE transaction
|
||||
<set>
|
||||
<if test="entity.status != null">
|
||||
, status = #{entity.status}
|
||||
</if>
|
||||
<if test="entity.extensionId != null">
|
||||
, extension_id = #{entity.extensionId}
|
||||
</if>
|
||||
<if test="entity.payChannel != null">
|
||||
, pay_channel = #{entity.payChannel}
|
||||
</if>
|
||||
<if test="entity.paymentTime != null">
|
||||
, payment_time = #{entity.paymentTime}
|
||||
</if>
|
||||
<if test="entity.notifyTime != null">
|
||||
, notify_time = #{entity.notifyTime}
|
||||
</if>
|
||||
<if test="entity.tradeNo != null">
|
||||
, trade_no = #{entity.tradeNo}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{entity.id}
|
||||
<if test="whereStatus != null">
|
||||
AND status = #{whereStatus}
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<select id="selectByAppIdAndOrderId" resultType="PayTransactionDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM transaction
|
||||
WHERE app_id = #{appId}
|
||||
AND order_id = #{orderId}
|
||||
</select>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="PayTransactionDO">
|
||||
SELECT
|
||||
<include refid="FIELDS"/>
|
||||
FROM transaction
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.mall.pay.dao.PayTransactionNotifyTaskMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, transaction_id, transaction_extension_id, app_id, order_id,
|
||||
status, last_Notify_time, notify_times, max_notify_times, create_time
|
||||
</sql>
|
||||
|
||||
<insert id="insert" parameterType="PayTransactionNotifyTaskDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO transaction_notify_task (
|
||||
transaction_id, transaction_extension_id, app_id, order_id,
|
||||
status, last_notify_time, notify_times, max_notify_times
|
||||
) VALUES (
|
||||
#{transactionId}, #{transactionExtensionId}, #{appId}, #{orderId},
|
||||
#{status}, #{lastNotifyTime}, #{notifyTimes}, #{maxNotifyTimes}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="PayTransactionNotifyTaskDO">
|
||||
UPDATE transaction_notify_task
|
||||
<set>
|
||||
<if test="status != null">
|
||||
, status = #{status}
|
||||
</if>
|
||||
<if test="lastNotifyTime != null">
|
||||
, last_notify_time = #{lastNotifyTime}
|
||||
</if>
|
||||
<if test="notifyTimes != null">
|
||||
, notify_times = #{notifyTimes}
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!--<select id="selectByTransactionCode" parameterType="String" resultType="PayTransactionExtensionDO">-->
|
||||
<!--SELECT-->
|
||||
<!--<include refid="FIELDS"/>-->
|
||||
<!--FROM transaction_extension-->
|
||||
<!--WHERE transaction_code = #{transactionCode}-->
|
||||
<!--LIMIT 1-->
|
||||
<!--</select>-->
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in new issue