From 3a8764d068b83988fa4c5f61abc4ba359e5aeb29 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 16 Sep 2025 19:45:36 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/service/impl/UserServiceImpl.java | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 203 insertions(+), 33 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserServiceImpl.java b/src/main/java/com/nq/service/impl/UserServiceImpl.java
index afdaf50..ec3756f 100644
--- a/src/main/java/com/nq/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserServiceImpl.java
@@ -1,5 +1,8 @@
package com.nq.service.impl;
+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;
@@ -13,6 +16,9 @@
import com.nq.pojo.*;
import com.nq.pojo.reponse.RUserAssets;
import com.nq.service.*;
+import com.nq.utils.UserPointUtil;
+import com.nq.utils.email.EmailValidator;
+import com.nq.utils.redis.RedisKeyUtil;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.SymmetricCryptoUtil;
@@ -27,18 +33,24 @@
import com.nq.vo.indexposition.IndexPositionVO;
import com.nq.vo.position.PositionProfitVO;
import com.nq.vo.position.PositionVO;
+import com.nq.vo.position.UserPositionVO;
+import com.nq.vo.stock.StockAdminListVO;
import com.nq.vo.stock.StockListVO;
import com.nq.vo.user.UserInfoVO;
import java.math.BigDecimal;
import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.*;
+import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import com.nq.vo.user.UserOut;
+import org.apache.commons.lang3.Conversion;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -99,6 +111,8 @@
@Autowired
StockPoll stockPoll;
+ @Autowired
+ StockSubscribeMapper stockSubscribeMapper;
@Resource
MoneyLogMapper mapper;
@@ -117,8 +131,17 @@
@Autowired
ISiteMessageService iSiteMessageService;
+ @Autowired
+ private ApplyLeverMapper applyLeverMapper;
+ @Autowired
+ private UserPositionMapper userPositionMapper;
+ @Autowired
+ IPriceServices priceServices;
+
+ @Autowired
+ IUserService iUserService;
public ServerResponse reg(String yzmCode, String agentCode, String phone, String userPwd, HttpServletRequest request) {
@@ -126,16 +149,17 @@
StringUtils.isBlank(userPwd) || StringUtils.isBlank(yzmCode)) {
return ServerResponse.createByErrorMsg("注册失败。该参数不能为空",request);
}
+ if(!EmailValidator.isValidEmail(phone)){
+ return ServerResponse.createByErrorMsg("请输入正确的邮箱格式",request);
+ }
-
- String keys = "AliyunSmsCode:" + phone;
+ String keys = "emailCode:" + phone;
String redis_yzm = RedisShardedPoolUtils.get(keys);
log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode);
if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) {
- return ServerResponse.createByErrorMsg("由于验证码不正确,注册失败。过程",request);
+ return ServerResponse.createByErrorMsg("验证码不正确或已过期,注册失败",request);
}
-
AgentUser agentUser = this.iAgentUserService.findByCode(agentCode);
if (agentUser == null) {
@@ -148,7 +172,7 @@
User dbuser = this.userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getPhone,phone).last( " limit 1"));
if (dbuser != null) {
- return ServerResponse.createByErrorMsg("注册失败,手机号已注册",request);
+ return ServerResponse.createByErrorMsg("注册失败,用户名已注册",request);
}
@@ -183,7 +207,7 @@
public ServerResponse login(String phone, String userPwd, HttpServletRequest request) {
if (StringUtils.isBlank(phone) || StringUtils.isBlank(userPwd)) {
- return ServerResponse.createByErrorMsg("手机号码和密码不能为空",request);
+ return ServerResponse.createByErrorMsg("账号和密码不能为空",request);
}
userPwd = SymmetricCryptoUtil.encryptPassword(userPwd);
User user = this.userMapper.login(phone, userPwd);
@@ -191,7 +215,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);
}
@@ -284,9 +308,30 @@
String userJson = RedisShardedPoolUtils.get(loginToken);
User user = (User) JsonUtil.string2Obj(userJson, User.class);
User dbuser = this.userMapper.selectById(user.getId());
+
SiteSetting siteSetting = iSiteSettingService.getSiteSetting();
UserInfoVO userInfoVO = assembleUserInfoVO(dbuser, siteSetting);
+ ApplyLever applyLever = applyLeverMapper.selectOne(new LambdaQueryWrapper<ApplyLever>()
+ .eq(ApplyLever::getUserId, user.getId())
+ .eq(ApplyLever::getState, 1)
+ .orderByDesc(ApplyLever::getCreateTime)
+ .last(" limit 1"));
+ if(null == applyLever || applyLever.getLever().equals("1")){
+ userInfoVO.setSiteLever("1");
+ }else{
+ userInfoVO.setSiteLever(leverSplit(applyLever.getLever()));
+ }
return ServerResponse.createBySuccess(userInfoVO);
+ }
+
+ public String leverSplit(String lever){
+ String levers = "1/2/5/10";
+ String[] parts = levers.split("/");
+ int index = Arrays.asList(parts).indexOf(lever);
+ if (index != -1) {
+ return String.join("/", Arrays.copyOfRange(parts, 0, index + 1));
+ }
+ return null;
}
@@ -468,9 +513,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();
@@ -482,7 +528,9 @@
rUserAssets.setCumulativeProfitAndLoss(hProfitAndLose.toString());
rUserAssets.setHandlingCharge(hMoney.toString());
rUserAssets.setProfitAndLoss(profitAndLose.toString());
-
+ rUserAssets.setIsZf(userAssets.getIsZf());
+ rUserAssets.setAmountToBeCovered((userAssets.getAmountToBeCovered().add(userAssets.getHandlingChargeWritten()).toString()));
+ rUserAssets.setHandlingChargeWritten(userAssets.getHandlingChargeWritten());
BigDecimal rate = rateServices.currencyRate(
EStockType.getEStockTypeByCode(userAssets.getAccectType()),EStockType.US);
@@ -510,9 +558,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);
}
@@ -525,14 +573,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(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);
-
@@ -562,6 +611,41 @@
rUserAssetsList.add(rUserAssets);
return ServerResponse.createBySuccess(rUserAssetsList);
+ }
+
+ public BigDecimal getProfitAndLose(Integer userId){
+ List<UserPosition> userPositions;
+ userPositions = userPositionMapper.
+ findMyPositionByCodeAndSpell(userId,
+ "","",
+ 0, "US");
+
+
+ List<UserPositionVO> userPositionVOS = Lists.newArrayList();
+ if (userPositions.size() > 0) {
+ for (UserPosition position : userPositions) {
+ 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){
+ 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())));
+ }
+
+ userPositionVOS.add(userPositionVO);
+
+ }
+ }
+ BigDecimal profitAndLose = BigDecimal.ZERO;
+ for (UserPositionVO f : userPositionVOS) {
+ profitAndLose = profitAndLose.add(f.getProfitAndLose());
+ }
+ return profitAndLose;
}
@Override
@@ -685,10 +769,24 @@
List<User> users = this.userMapper.listByAgent(realName, phone, searchId, accountType);
List<AgentUserListVO> agentUserListVOS = Lists.newArrayList();
+
for (User user : users) {
+
+ ServerResponse money = iUserService.getMoney(user.getId());
+ List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
+ RUserAssets rUserAssets = rUserAssetsList.stream()
+ .filter(stock -> "US".equals(stock.getAccectType()))
+ .findFirst()
+ .orElse(null);
+
AgentUserListVO agentUserListVO = assembleAgentUserListVO(user, siteSetting
.getForceStopPercent(), siteIndexSetting
.getForceSellPercent(), siteFuturesSetting.getForceSellPercent());
+ if (rUserAssets != null) {
+ agentUserListVO.setUserAmt(rUserAssets.getTotalMoney().equals("0E-8") ? new BigDecimal("0") : new BigDecimal(rUserAssets.getTotalMoney()));
+ agentUserListVO.setFreezeMoney(rUserAssets.getFreezeMoney().equals("0E-8") ? "0" : rUserAssets.getFreezeMoney());
+ agentUserListVO.setAvailableBalance(rUserAssets.getAvailableBalance().equals("0E-8") ? "0" : rUserAssets.getAvailableBalance());
+ }
agentUserListVOS.add(agentUserListVO);
}
@@ -735,8 +833,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");
}
@@ -744,15 +842,45 @@
}
- public ServerResponse listByAdmin(String realName, String phone, Integer agentId, Integer accountType, int pageNum, int pageSize, HttpServletRequest request) {
+ public ServerResponse listByAdmin(String realName, String phone, Integer agentId, Integer accountType, int pageNum, int pageSize, Integer isLock, Integer isLogin, String regTime, Integer isActive, HttpServletRequest request) throws ParseException {
PageHelper.startPage(pageNum, pageSize);
+ SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
+ SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
+ String formattedDateString = null;
+ if (StringUtils.isNotEmpty(regTime)) {
+ formattedDateString = outputFormat.format(inputFormat.parse(regTime));
+ }
+ List<User> users = this.userMapper.listByAdmin(realName, phone, agentId, accountType, isLock, isLogin, formattedDateString, isActive);
+ List<UserOut> userOuts = new ArrayList<>();
- List<User> users = this.userMapper.listByAdmin(realName, phone, agentId, accountType);
+ // 获取用户资产信息并构建返回结果
+ Map<Integer, UserOut> userOutMap = new HashMap<>();
+ for (User user : users) {
+ ServerResponse money = iUserService.getMoney(user.getId());
+ List<RUserAssets> rUserAssetsList = (List<RUserAssets>) money.getData();
+ RUserAssets rUserAssets = rUserAssetsList.stream()
+ .filter(stock -> "US".equals(stock.getAccectType()))
+ .findFirst()
+ .orElse(null);
+
+ UserOut userOut = Convert.convert(UserOut.class, user);
+ if (rUserAssets != null) {
+ userOut.setTotalMoney(rUserAssets.getTotalMoney().equals("0E-8") ? "0" : rUserAssets.getTotalMoney());
+ userOut.setFreezeMoney(rUserAssets.getFreezeMoney().equals("0E-8") ? "0" : rUserAssets.getFreezeMoney());
+ userOut.setAvailableBalance(rUserAssets.getAvailableBalance().equals("0E-8") ? "0" : rUserAssets.getAvailableBalance());
+ userOut.setAmountToBeCovered(rUserAssets.getAmountToBeCovered());
+ }
+
+ userOutMap.put(user.getId(), userOut);
+ userOuts.add(userOut);
+ }
PageInfo pageInfo = new PageInfo(users);
-
+ pageInfo.setList(userOuts);
return ServerResponse.createBySuccess(pageInfo);
}
+
+
public ServerResponse findByUserId(Integer userId) {
@@ -963,7 +1091,9 @@
agentUserListVO.setIsLogin(user.getIsLogin());
agentUserListVO.setRegAddress(user.getRegAddress());
agentUserListVO.setIsActive(user.getIsActive());
-
+ agentUserListVO.setImg1Key(user.getImg1Key());
+ agentUserListVO.setImg2Key(user.getImg2Key());
+ agentUserListVO.setImg3Key(user.getImg3Key());
@@ -994,14 +1124,6 @@
BigDecimal futuresForceLine = futuresForcePercent.multiply(futuresPositionVO.getAllFuturesDepositAmt());
agentUserListVO.setFuturesForceLine(futuresForceLine);
-
-
- UserBank userBank = this.iUserBankService.findUserBankByUserId(user.getId());
- if (userBank != null) {
- agentUserListVO.setBankName(userBank.getBankName());
- agentUserListVO.setBankNo(userBank.getBankNo());
- agentUserListVO.setBankAddress(userBank.getBankAddress());
- }
return agentUserListVO;
}
@@ -1071,5 +1193,53 @@
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);
+ }
+ // 计算7天前的时间
+ Date sevenDaysAgo = Date.from(LocalDateTime.now().minusDays(7).atZone(ZoneId.systemDefault()).toInstant());
+
+ List<UserPosition> userPositions = userPositionMapper.selectList(
+ new QueryWrapper<UserPosition>()
+ .eq("user_id", userId)
+ .and(wrapper -> wrapper
+ .isNotNull("sell_order_id")
+ .ge("sell_order_time", sevenDaysAgo)
+ .or()
+ .isNull("sell_order_id")
+ .ge("buy_order_time", sevenDaysAgo)
+ )
+ );
+ 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