修改钱包余额
parent
d86d56a90d
commit
3436cedce9
|
@ -0,0 +1,58 @@
|
|||
package com.ruoyi.mybasic.Text;
|
||||
|
||||
/**
|
||||
* @ClassName SpinLockDemo
|
||||
* @Description 描述
|
||||
* @Author WenHao.Sao
|
||||
*/
|
||||
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
||||
/**
|
||||
* 自旋锁
|
||||
*/
|
||||
public class SpinLockDemo {
|
||||
|
||||
AtomicReference<Thread> atomicReference = new AtomicReference<>();
|
||||
public void lock(){
|
||||
// Thread.
|
||||
Thread thread = Thread.currentThread();
|
||||
System.out.println(Thread.currentThread().getName() + "------->swh come in");
|
||||
while (!atomicReference.compareAndSet(null,thread)){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void unLock(){
|
||||
Thread thread = Thread.currentThread();
|
||||
atomicReference.compareAndSet(thread,null);
|
||||
System.out.println(Thread.currentThread().getName()+"------->task over");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpinLockDemo spinLockDemo = new SpinLockDemo();
|
||||
|
||||
new Thread(() -> {
|
||||
spinLockDemo.lock();;
|
||||
//暂停几秒钟线程
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); }
|
||||
spinLockDemo.unLock();
|
||||
}, "A").start();
|
||||
|
||||
//暂停500毫秒 线程A先于B启动
|
||||
try {
|
||||
TimeUnit.MICROSECONDS.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); }
|
||||
new Thread(() -> {
|
||||
spinLockDemo.lock();;
|
||||
//暂停几秒钟线程
|
||||
|
||||
spinLockDemo.unLock();
|
||||
}, "B").start();
|
||||
}
|
||||
}
|
|
@ -26,4 +26,6 @@ public class PurseRequest extends PurseResponse {
|
|||
|
||||
private String orderId;//支付宝订单Id
|
||||
|
||||
private double amountIncome;//收入支出金额
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@ import java.util.Map;
|
|||
* @Description 我的钱包模块接口
|
||||
* @Author WenHao.Sao
|
||||
*/
|
||||
|
||||
/**
|
||||
* 我的钱包小模块接口
|
||||
*/
|
||||
//@CrossOrigin(origins = "*")
|
||||
@RestController
|
||||
@RequestMapping("purse")//purse
|
||||
|
@ -105,11 +109,12 @@ public class PurseControllerTwo {
|
|||
/**
|
||||
* 进行添加H币
|
||||
*/
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
// Long userId = SecurityUtils.getUserId();
|
||||
long userId = 1;
|
||||
PurseResponse purseResponse = purseServiceTwo.purseObject(userId);
|
||||
|
||||
//获取到当前余额
|
||||
Double balanceFee = purseResponse.getBalanceFee();
|
||||
int balanceFee = purseResponse.getBalanceFee();
|
||||
|
||||
//获取前台传入的一个参数
|
||||
double totalAmount = aliPay.getTotalAmount();
|
||||
|
@ -119,7 +124,8 @@ public class PurseControllerTwo {
|
|||
|
||||
purseRequest.setUserId(userId + "");
|
||||
purseRequest.setBalanceFee(balanceFee);
|
||||
purseRequest.setAmount((totalAmountOne));
|
||||
purseRequest.setAmountIncome(totalAmountOne);
|
||||
purseRequest.setStatus(2);
|
||||
//调用修改钱包接口
|
||||
purseServiceTwo.updPurseHBi(purseRequest);
|
||||
|
||||
|
@ -208,13 +214,13 @@ public class PurseControllerTwo {
|
|||
* 消息队列根据消息调用api接口 消息队列根据api接口的返回结果进行不同的操作失败:根据参数中的提现记录id 把对应记录状态改为失败
|
||||
* 成功:根据参数中的充值记录id 把对应记录状态改为成功 用户的余额减少 增加一条收支记录表
|
||||
*/
|
||||
@PostMapping("/withdrawPurse")
|
||||
@PostMapping("/withdrawPurse")//未完成
|
||||
public R<?> withdrawPurse(AliPay aliPay, HttpServletResponse httpResponse){
|
||||
//获取当前用户的userId 里面的余额
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
PurseResponse purseResponse = purseServiceTwo.purseObject(userId);
|
||||
//获取当前用户的余额
|
||||
Double balanceFee = purseResponse.getBalanceFee();
|
||||
int balanceFee = purseResponse.getBalanceFee();
|
||||
//获取前台输入的金额
|
||||
double totalAmount = aliPay.getTotalAmount();
|
||||
//判断需要提现的金额 * 100 跟当前H币的金额
|
||||
|
|
|
@ -19,6 +19,10 @@ import java.util.List;
|
|||
* @Description 描述
|
||||
* @Author WenHao.Sao
|
||||
*/
|
||||
|
||||
/***
|
||||
* 钱包旧
|
||||
*/
|
||||
@Service
|
||||
public class PurseServiceImpl implements PurseService {
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@ import java.util.List;
|
|||
* @Description 描述
|
||||
* @Author WenHao.Sao
|
||||
*/
|
||||
|
||||
/***
|
||||
* 钱包实现层
|
||||
*/
|
||||
@Service
|
||||
public class PurseServiceTwoImpl implements PurseServiceTwo {
|
||||
|
||||
|
@ -26,23 +30,15 @@ public class PurseServiceTwoImpl implements PurseServiceTwo {
|
|||
@Autowired
|
||||
private PurseMapperTwo purseMapperTwo;
|
||||
|
||||
|
||||
/**
|
||||
* 钱包列表
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<PurseRequest> purseListAll() {
|
||||
return purseMapperTwo.purseListAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 进行添加充值记录表
|
||||
* @param purseRequest
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void addPurseLogs(PurseRequest purseRequest) {
|
||||
purseMapperTwo.addPurseLogs(purseRequest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据当前登录的用户userId
|
||||
|
@ -57,6 +53,18 @@ public class PurseServiceTwoImpl implements PurseServiceTwo {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 进行添加充值记录表
|
||||
* @param purseRequest
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void addPurseLogs(PurseRequest purseRequest) {
|
||||
purseMapperTwo.addPurseLogs(purseRequest);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提现接口:
|
||||
* 入参:提现金额 绑定的银行卡id
|
||||
|
@ -83,9 +91,6 @@ public class PurseServiceTwoImpl implements PurseServiceTwo {
|
|||
*/
|
||||
@Override
|
||||
public void purseBalanceChange(PurseRequest purseRequest) {
|
||||
//修改余额
|
||||
// Integer i = purseMapperTwo.updPurse(purseRequest);
|
||||
|
||||
//获取入参的金额
|
||||
double doubleAmount = purseRequest.getAmount();
|
||||
|
||||
|
@ -95,7 +100,7 @@ public class PurseServiceTwoImpl implements PurseServiceTwo {
|
|||
//获取当前用户的余额
|
||||
PurseResponse purseResponse = purseMapperTwo.purseObject(Long.valueOf(userId));
|
||||
//当前用户的余额
|
||||
Double balanceFee = purseResponse.getBalanceFee();
|
||||
int balanceFee = purseResponse.getBalanceFee();
|
||||
//获取到状态是收入还是支出 1:支出 2 收入
|
||||
int status = purseRequest.getStatus();
|
||||
//如果是支出 进行入参金额 和 原有金额 进行判断
|
||||
|
@ -115,6 +120,10 @@ public class PurseServiceTwoImpl implements PurseServiceTwo {
|
|||
purseMapperTwo.addMoneyLogs(moneyLogsRequest);
|
||||
}
|
||||
|
||||
/***
|
||||
* 在充值 里面的一个修改H币方法
|
||||
* @param purseRequest
|
||||
*/
|
||||
@Override
|
||||
public void updPurseHBi(PurseRequest purseRequest) {
|
||||
purseMapperTwo.updPurseHBi(purseRequest);
|
||||
|
|
|
@ -101,25 +101,25 @@
|
|||
|
||||
|
||||
<update id="updPurseHBi">
|
||||
update t_purse set balance_fee = (#{amount} * 100) where userId = #{userId}
|
||||
update t_purse set balance_fee = (#{amount} * 100) where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<select id="purseListAll" resultType="com.ruoyi.mybasic.common.domain.request.PurseRequest">
|
||||
select * from t_purse
|
||||
</select>
|
||||
|
||||
<!-- 添加充值记录表-->
|
||||
<!-- 添加充值收入支出记录表-->
|
||||
<insert id="addPurseLogs">
|
||||
insert into t_money_withdraw
|
||||
insert into t_money_logs
|
||||
(
|
||||
<if test="userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
<if test="statue != null">
|
||||
statue,
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
<if test="amount != null">
|
||||
amount,
|
||||
<if test="amountIncome != null">
|
||||
amount_income,
|
||||
</if>
|
||||
create_time
|
||||
)
|
||||
|
@ -128,11 +128,11 @@
|
|||
<if test="userId != null">
|
||||
#{userId},
|
||||
</if>
|
||||
<if test="statue != null">
|
||||
#{status},
|
||||
<if test="status != null">
|
||||
2,
|
||||
</if>
|
||||
<if test="amount != null">
|
||||
#{amount},
|
||||
<if test="amountIncome != null">
|
||||
(#{amountIncome} / 10 ),
|
||||
</if>
|
||||
now()
|
||||
)
|
||||
|
@ -141,8 +141,7 @@
|
|||
<!-- 修改提现 过后的H币-->
|
||||
<update id="updWithdrawPurse">
|
||||
update t_purse set
|
||||
<if test="userId">
|
||||
|
||||
</if>
|
||||
balance_fee = balance_fee - (#{amount} * 100)
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue