From 85037c73f8b16f4258a2af354cd162247700ffde Mon Sep 17 00:00:00 2001
From: peternameyakj <908253177@qq.com>
Date: Sun, 14 Jul 2024 18:35:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/6-29' into 6-29
---
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java | 53 ++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index de70f90..9eb87e6 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -1,5 +1,6 @@
package com.nq.service.impl;
+import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nq.dao.*;
@@ -37,6 +38,9 @@
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -119,6 +123,10 @@
@Autowired
IStockConfigServices iStockConfigServices;
+
+ @Autowired
+ UserPositionCheckDzService userPositionCheckDzService;
+
@Transactional
@@ -1178,7 +1186,7 @@
if (userStockSubscribe == null) {
return ServerResponse.createByErrorMsg("无该申购记录");
}
- StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("code", userStockSubscribe.getNewCode()).eq("type",userStockSubscribe.getType()));
+ StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("newlist_id", userStockSubscribe.getNewStockId()));
if (userStockSubscribe == null) {
return ServerResponse.createByErrorMsg("该新股不存在");
}
@@ -1196,8 +1204,10 @@
userPosition.setStockCode(stock.getStockCode());
userPosition.setStockSpell(stock.getStockSpell());
userPosition.setStockName(userStockSubscribe.getNewName());
- userPosition.setStockGid(stockSubscribe.getStockType() + userStockSubscribe.getNewCode());
-
+ StringBuffer gid = new StringBuffer();
+ gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():"");
+ gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild");
+ userPosition.setStockGid(gid.toString());
userPosition.setBuyOrderId(GeneratePosition.getPositionId());
userPosition.setBuyOrderTime(new Date());
userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice());
@@ -1253,6 +1263,7 @@
return ServerResponse.createByErrorMsg("新股转持仓失败");
}
userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(userPosition.getOrderTotalPrice()));
+ userAssets.setFreezeMoney(userAssets.getFreezeMoney()!=null?userAssets.getFreezeMoney().setScale(2,BigDecimal.ROUND_UP):null);
userAssetsMapper.updateById(userAssets);
if (ret > 0) {
userStockSubscribe.setStatus(5);
@@ -1538,7 +1549,7 @@
* @return
*/
@Transactional
- public synchronized ServerResponse buyDz(String stockCode, String password, Integer num, HttpServletRequest request) throws Exception {
+ public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request) throws Exception {
/*实名认证开关开启*/
SiteProduct siteProduct = iSiteProductService.getProductSetting();
User user = this.iUserService.getCurrentRefreshUser(request);
@@ -1553,8 +1564,8 @@
if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
}
- StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("stock_code", stockCode));
- if (!Objects.equals(stockDz.getPassword(), password)) {
+ StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", dzId));
+ if (StringUtils.isNotEmpty(stockDz.getPassword()) && !Objects.equals(stockDz.getPassword(), password)) {
return ServerResponse.createByErrorMsg("密码错误", request);
}
if (stockDz.getIsLock() != 0) {
@@ -1566,7 +1577,8 @@
if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){
return ServerResponse.createByErrorMsg("不在内幕交易时间之内", request);
}
- BigDecimal nowPrice = priceServices.getNowPrice(stockCode).multiply(stockDz.getDiscount());
+// BigDecimal nowPrice = priceServices.getNowPrice(stockDz.getStockCode()).multiply(stockDz.getDiscount());
+ BigDecimal nowPrice = stockDz.getNowPrice();
if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
return ServerResponse.createByErrorMsg("股票价格0,请重试", request);
@@ -1575,11 +1587,29 @@
return ServerResponse.createByErrorMsg("最小购买数据" + stockDz.getStockNum(), request);
}
BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num.intValue()));
- BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
- BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
+ BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
+ BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
if (buyAmt.compareTo(availableBalance) > 0) {
return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
}
+
+ //判断审核开关
+ if(stockDz.getSwitchType() == 1){
+ UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt);
+ UserPositionCheckDz userPositionCheckDz = Convert.convert(UserPositionCheckDz.class, userPosition);
+ userPositionCheckDz.setDzId(dzId);
+ userPositionCheckDzService.save(userPositionCheckDz);
+ return ServerResponse.createBySuccess("购买成功,等待审核", request);
+ }
+
+ // 创建UserPosition对象
+ UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt);
+ userPositionMapper.insert(userPosition);
+ userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"","");
+ return ServerResponse.createBySuccess("购买成功", request);
+ }
+
+ private UserPosition getUserPosition(Integer num, User user, StockDz stockDz, BigDecimal nowPrice, Stock stock, BigDecimal buyAmt) {
UserPosition userPosition = new UserPosition();
userPosition.setPositionType(3);
userPosition.setPositionSn(KeyUtils.getUniqueKey());
@@ -1608,11 +1638,8 @@
userPosition.setAllProfitAndLose(all_profit_and_lose);
userPosition.setOrderStayDays(Integer.valueOf(0));
userPosition.setOrderStayFee(new BigDecimal("0"));
-
userPosition.setOrderSpread(BigDecimal.ZERO);
- userPositionMapper.insert(userPosition);
- userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"","");
- return ServerResponse.createBySuccess("购买成功", request);
+ return userPosition;
}
@Override
--
Gitblit v1.9.3