From 7c12438408fc7ccd8bb09d662387598b40098af9 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 26 Aug 2025 18:27:10 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/service/impl/UserServiceImpl.java | 79 ++++++++++++++++++++++++++++++---------
1 files changed, 61 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserServiceImpl.java b/src/main/java/com/nq/service/impl/UserServiceImpl.java
index 03d92ad..26bb678 100644
--- a/src/main/java/com/nq/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -2,6 +2,7 @@
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
@@ -16,6 +17,7 @@
import com.nq.pojo.reponse.RUserAssets;
import com.nq.service.*;
import com.nq.utils.UserPointUtil;
+import com.nq.utils.redis.RedisKeyUtil;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.SymmetricCryptoUtil;
@@ -39,6 +41,7 @@
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
@@ -209,7 +212,7 @@
if (user.getIsLogin().intValue() == 1) {
return ServerResponse.createByErrorMsg("登录失败。账户锁定",request);
}
- userAssetsServices.assetsByTypeAndUserId(EStockType.IN.getCode(),user.getId());
+ userAssetsServices.assetsByTypeAndUserId(EStockType.US.getCode(),user.getId());
this.iSiteLoginLogService.saveLog(user, request);
return ServerResponse.createBySuccess(user);
}
@@ -507,9 +510,10 @@
RUserAssets rUserAssets = new RUserAssets();
UserAssets userAssets = userAssetsList.get(i);
// 浮动盈亏
- BigDecimal profitAndLose = userAssets.getProfitAndLoss();
+ String profitAndLose = getProfitAndLose(userId).toString();
BigDecimal amt = userAssets.getAvailableBalance();
- BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney());
+ BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney()).add(new BigDecimal(profitAndLose)).subtract(userAssets.getHandlingChargeWritten());
+// BigDecimal totalAssets = userAssets.getAvailableBalance().add(userAssets.getFreezeMoney()).subtract(userAssets.getCumulativeProfitAndLoss()).add(profitAndLose);
BigDecimal freeMoney = userAssets.getFreezeMoney();
BigDecimal hMoney = userAssets.getHandlingCharge();
BigDecimal hProfitAndLose = userAssets.getCumulativeProfitAndLoss();
@@ -522,7 +526,8 @@
rUserAssets.setHandlingCharge(hMoney.toString());
rUserAssets.setProfitAndLoss(profitAndLose.toString());
rUserAssets.setIsZf(userAssets.getIsZf());
- rUserAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().toString());
+ rUserAssets.setAmountToBeCovered((userAssets.getAmountToBeCovered().add(userAssets.getHandlingChargeWritten()).toString()));
+ rUserAssets.setHandlingChargeWritten(userAssets.getHandlingChargeWritten());
BigDecimal rate = rateServices.currencyRate(
EStockType.getEStockTypeByCode(userAssets.getAccectType()),EStockType.US);
@@ -550,9 +555,9 @@
if(hMoney.compareTo(BigDecimal.ZERO)>0){
handlingChargeUSD =hMoney.multiply(rate);
}
- BigDecimal profitAndLossUSD = profitAndLose;
- if(profitAndLose.compareTo(BigDecimal.ZERO)>0){
- profitAndLossUSD =profitAndLose.multiply(rate);
+ BigDecimal profitAndLossUSD = new BigDecimal(profitAndLose);
+ if(new BigDecimal(profitAndLose).compareTo(BigDecimal.ZERO)>0){
+ profitAndLossUSD =new BigDecimal(profitAndLose).multiply(rate);
}
@@ -565,16 +570,15 @@
rUserAssets.setCumulativeProfitAndLossUSD(cumulativeProfitAndLossUSD.setScale(s,BigDecimal.ROUND_UP).toString());
rUserAssets.setHandlingChargeUSD(handlingChargeUSD.setScale(s,BigDecimal.ROUND_UP).toString());
rUserAssets.setProfitAndLossUSD(profitAndLossUSD.setScale(s,BigDecimal.ROUND_UP).toString());
- rUserAssets.setProfitAndLoss(getProfitAndLose(userId).toString());
- BigDecimal decimal = new BigDecimal(rUserAssets.getTotalMoney()).add(new BigDecimal(rUserAssets.getProfitAndLoss()));
- rUserAssets.setTotalMoney(decimal.toString());
+ rUserAssets.setProfitAndLoss(profitAndLose);
+// BigDecimal decimal = new BigDecimal(rUserAssets.getTotalMoney()).add(new BigDecimal(rUserAssets.getProfitAndLoss()));
+// rUserAssets.setTotalMoney(decimal.toString());
AllProfitAndLose = AllProfitAndLose.add(profitAndLossUSD);
allTotalAssets = allTotalAssets.add(totleMoneyUSD);
allAmt = allAmt.add(availableBalanceUSD);
AllHProfitAndLose = AllHProfitAndLose.add(handlingChargeUSD);
allFreeMoney = allFreeMoney.add(freezeMoneyUSD);
allHMoney = allHMoney.add(handlingChargeUSD);
-
@@ -611,14 +615,13 @@
userPositions = userPositionMapper.
findMyPositionByCodeAndSpell(userId,
"","",
- 0, "IN");
+ 0, "US");
List<UserPositionVO> userPositionVOS = Lists.newArrayList();
if (userPositions.size() > 0) {
for (UserPosition position : userPositions) {
- UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode()));
-
+ UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,priceServices.getNowPrice(position.getStockCode()));
StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
.eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
if(position.getSellOrderId() == null){
@@ -769,7 +772,7 @@
ServerResponse money = iUserService.getMoney(user.getId());
List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
RUserAssets rUserAssets = rUserAssetsList.stream()
- .filter(stock -> "IN".equals(stock.getAccectType()))
+ .filter(stock -> "US".equals(stock.getAccectType()))
.findFirst()
.orElse(null);
@@ -827,8 +830,8 @@
int insertCount = this.userMapper.insert(user);
dbUser = userMapper.selectOne(queryWrapper);
- userAssetsServices.getAvailableBalance(EStockType.IN.getCode(),dbUser.getId() );
- userAssetsServices.availablebalanceChange(EStockType.IN.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"","");
+ userAssetsServices.getAvailableBalance(EStockType.US.getCode(),dbUser.getId() );
+ userAssetsServices.availablebalanceChange(EStockType.US.getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"","");
if (insertCount > 0) {
return ServerResponse.createBySuccessMsg("Success");
}
@@ -853,7 +856,7 @@
ServerResponse money = iUserService.getMoney(user.getId());
List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
RUserAssets rUserAssets = rUserAssetsList.stream()
- .filter(stock -> "IN".equals(stock.getAccectType()))
+ .filter(stock -> "US".equals(stock.getAccectType()))
.findFirst()
.orElse(null);
@@ -1187,5 +1190,45 @@
return ServerResponse.createBySuccess(mapper.selectList(queryWrapper));
}
+ @Override
+ public ServerResponse getWeeklyProfit(HttpServletRequest request) {
+ Integer userId = getCurrentUser(request).getId();
+ if(ObjectUtil.isEmpty(userId)){
+ return ServerResponse.createBySuccess(BigDecimal.ZERO);
+ }
+ List<UserPosition> userPositions = userPositionMapper.selectList(
+ new QueryWrapper<UserPosition>()
+ .eq("user_id", userId)
+ .apply("(sell_order_id IS NOT NULL AND sell_order_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)) " +
+ "OR (sell_order_id IS NULL AND buy_order_time >= DATE_SUB(NOW(), INTERVAL 7 DAY))")
+ );
+ BigDecimal weeklyProfit = BigDecimal.ZERO;
+ if (userPositions.size() > 0) {
+
+ for (UserPosition position : userPositions) {
+ BigDecimal nowPrice = BigDecimal.ZERO;
+ if(null == position.getSellOrderId()){
+ nowPrice = priceServices.getNowPrice(position.getStockCode());
+ }else{
+ nowPrice = position.getSellOrderPrice();
+ }
+ UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,nowPrice);
+
+ StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
+ .eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
+ if(position.getSellOrderId() == null){
+ if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
+ userPositionVO.setProfitAndLose(BigDecimal.ZERO);
+ }else{
+ userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+ }
+ }else{
+ userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+ }
+ weeklyProfit = weeklyProfit.add(userPositionVO.getProfitAndLose());
+ }
+ }
+ return ServerResponse.createBySuccess(weeklyProfit);
+ }
}
--
Gitblit v1.9.3