From 68b9175323a2f9b40ffcc48bb01af1d8279e5d01 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 22 Aug 2025 10:21:51 +0800
Subject: [PATCH] 平仓返回保证金修改
---
src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java | 102 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 64 insertions(+), 38 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java b/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
index 9b5cdf0..027f2a9 100644
--- a/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -5,13 +5,9 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
-import com.nq.Repository.ExchangeRateRepository;
import com.nq.common.ResponseCode;
import com.nq.common.ServerResponse;
-import com.nq.dao.StockSubscribeMapper;
-import com.nq.dao.UserAssetsMapper;
-import com.nq.dao.UserMapper;
-import com.nq.dao.UserStockSubscribeMapper;
+import com.nq.dao.*;
import com.nq.enums.EStockType;
import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
@@ -60,10 +56,6 @@
ISiteProductService iSiteProductService;
@Autowired
IUserService iUserService;
- @Autowired
- ISiteSettingService iSiteSettingService;
- @Autowired
- TradingHourServiceImpl tradingHourService;
@Resource
IUserAssetsServices iUserAssetsServices;
@@ -72,7 +64,7 @@
UserAssetsMapper userAssetsMapper;
@Autowired
- ExchangeRateRepository exchangeRateRepository;
+ MoneyLogMapper moneyLogMapper;
/**
* 用户新股申购
@@ -92,6 +84,9 @@
if (model.getNewCode() != null) {
StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>()
.eq("newlist_id", model.getNewlistId()));
+ if (stockSubscribe == null) {
+ return ServerResponse.createByErrorMsg("新的股票代码不存在",request);
+ }
//判断购买新股需不需要密钥
if(StringUtils.isNotEmpty(stockSubscribe.getPassword()) && !stockSubscribe.getPassword().equals(model.getPassword())){
return ServerResponse.createByErrorMsg("密钥输入错误",request);
@@ -117,10 +112,10 @@
return ServerResponse.createByErrorMsg("最多可申购:" + stockSubscribe.getOrderNumber(), request);
}
- BigDecimal sumPrice = stockSubscribe.getPrice().multiply(new BigDecimal(model.getApplyNums()));
+ /*BigDecimal sumPrice = stockSubscribe.getPrice().multiply(new BigDecimal(model.getApplyNums()));
if(userAssets.getAvailableBalance().compareTo(sumPrice) < 0){
return ServerResponse.createByErrorMsg("账户余额不足", request);
- }
+ }*/
Date currentDate = new Date();
if(currentDate.before(stockSubscribe.getSubscriptionTime())){
@@ -139,9 +134,6 @@
if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定",request);
}
- if (stockSubscribe == null) {
- return ServerResponse.createByErrorMsg("新的股票代码不存在",request);
- }
model.setApplyNums((int) (model.getApplyNums()*stockSubscribe.getLever()));
@@ -152,6 +144,15 @@
}else{
bound = new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice());
}
+ //如果不是墨西哥币需要转换金额
+ if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
+ bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound);
+ }
+ if(userAssets.getAvailableBalance().compareTo(bound) < 0){
+ return ServerResponse.createByErrorMsg("账户余额不足", request);
+ }
+
+ String before = userAssets.getAvailableBalance().toString();
if(stockSubscribe.getType() == 1){
model.setUserId(user.getId());
model.setNewName(stockSubscribe.getName());
@@ -168,10 +169,6 @@
userStockSubscribe.setNewStockId(stockSubscribe.getNewlistId());
ret = userStockSubscribeMapper.insert(userStockSubscribe);
- //如果不是墨西哥币需要转换金额
- if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
- bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound);
- }
BigDecimal subtract = userAssets.getAvailableBalance().subtract(bound);
if(subtract.compareTo(BigDecimal.ZERO) >= 0){
userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(bound));
@@ -182,7 +179,19 @@
userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().add(subtract.abs()));
}
userAssetsMapper.updateById(userAssets);
-
+ //交易记录MEX
+ MoneyLog moneyLog = new MoneyLog();
+ EUserAssets eUserAssets = EUserAssets.BUY;
+ moneyLog.setDescs(eUserAssets.getDesc());
+ moneyLog.setBeFore(before);
+ moneyLog.setAfter(userAssets.getAvailableBalance().toString());
+ moneyLog.setAmount(bound.negate().toString());
+ moneyLog.setAccectType(EStockType.MX.getCode());
+ moneyLog.setType(eUserAssets.getCode());
+ moneyLog.setUserId(user.getId()+"");
+ moneyLog.setSymbol(EStockType.MX.getSymbol());
+ moneyLog.setCreateTime(new Date());
+ moneyLogMapper.insert(moneyLog);
if (ret > 0) {
return ServerResponse.createBySuccessMsg("申购成功",request);
} else {
@@ -272,10 +281,12 @@
return ServerResponse.createByErrorMsg("客户资金账户不存在");
}
int applyNumber = userStockSubscribe.getApplyNums() - model.getApplyNumber();
+ BigDecimal refundPrice = BigDecimal.ZERO;
+ String before = userAssets.getAvailableBalance().toString();
if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) <= 0){
if(applyNumber > 0){
//需要退回的资金
- BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
+ refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
//如果不是墨西哥币需要转换金额
if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
@@ -285,7 +296,7 @@
}
}else{
if(applyNumber > 0){
- BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
+ refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
//如果不是墨西哥币需要转换金额
if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
@@ -299,6 +310,21 @@
userAssets.setAvailableBalance(subtract);
}
}
+ }
+ //如果退回资金 add交易记录MEX
+ if (refundPrice.compareTo(BigDecimal.ZERO) > 0) {
+ MoneyLog moneyLog = new MoneyLog();
+ EUserAssets eUserAssets = EUserAssets.BUY_RT;
+ moneyLog.setDescs(eUserAssets.getDesc());
+ moneyLog.setBeFore(before);
+ moneyLog.setAfter(userAssets.getAvailableBalance().toString());
+ moneyLog.setAmount(refundPrice.toString());
+ moneyLog.setAccectType(EStockType.MX.getCode());
+ moneyLog.setType(eUserAssets.getCode());
+ moneyLog.setUserId(userAssets.getUserId()+"");
+ moneyLog.setSymbol(EStockType.MX.getSymbol());
+ moneyLog.setCreateTime(new Date());
+ moneyLogMapper.insert(moneyLog);
}
ret = userStockSubscribeMapper.update1(model);
userAssetsMapper.updateById(userAssets);
@@ -473,26 +499,26 @@
String header = request.getHeader(property);
if (header != null) {
User user = iUserService.getCurrentRefreshUser(request);
-
List<UserStockSubscribeVo> userStockSubscribe = this.userStockSubscribeMapper.getListByParam(user.getId(), type, status);
- /*if (type==null||type.equals("")){
- userStockSubscribe = this.userStockSubscribeMapper.selectList(new QueryWrapper<>(new UserStockSubscribe()).eq("user_id", user.getId()).orderByDesc("add_time"));
- }else{
- userStockSubscribe = this.userStockSubscribeMapper.selectList(new QueryWrapper<>(new UserStockSubscribe()).eq("user_id", user.getId()).eq("type", type).orderByDesc("add_time"));
- }*/
-
- List<UserStockSubscribeVo> list = new ArrayList<>();
- for (UserStockSubscribeVo userStockSubscribe1 : userStockSubscribe) {
- StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe())
- .eq("newlist_id", userStockSubscribe1.getNewStockId()));
- if (stockSubscribe != null) {
- list.add(userStockSubscribe1);
- }
- }
- return ServerResponse.createBySuccess(list);
+ return ServerResponse.createBySuccess(userStockSubscribe);
}
return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
}
+
+ @Override
+ public ServerResponse getOneSubscribeByUserIdPage(int pageNum,int pageSize,String type, Integer status, HttpServletRequest request) {
+ String property = PropertiesUtil.getProperty("user.cookie.name");
+ String header = request.getHeader(property);
+ if (header != null) {
+ User user = iUserService.getCurrentRefreshUser(request);
+ PageHelper.startPage(pageNum, pageSize);
+ List<UserStockSubscribeVo> userStockSubscribe = this.userStockSubscribeMapper.getListByParam(user.getId(), type, status);
+ PageInfo<UserStockSubscribeVo> pageInfo = new PageInfo<>(userStockSubscribe);
+ return ServerResponse.createBySuccess(pageInfo);
+ }
+ return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录");
+ }
+
/**
* 新股申购-用户提交金额
*/
--
Gitblit v1.9.3