1
zj
2024-10-24 b537f97886c51d59818a788f641a9b16b510d62e
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -8,9 +11,13 @@
import com.nq.config.StockPoll;
import com.nq.dao.*;
import com.nq.enums.EStockType;
import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
import com.nq.pojo.reponse.RUserAssets;
import com.nq.service.*;
import com.nq.utils.DateTimeUtil;
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;
import com.nq.utils.ip.IpUtils;
@@ -24,17 +31,22 @@
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.Arrays;
import java.util.Date;
import java.util.List;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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;
@@ -46,7 +58,7 @@
public class UserServiceImpl implements IUserService {
    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    @Resource
    UserMapper userMapper;
    @Autowired
@@ -55,8 +67,18 @@
    @Autowired
    ISiteLoginLogService iSiteLoginLogService;
    @Autowired
    @Resource
    StockOptionMapper stockOptionMapper;
    @Autowired
    IUserService userService;
    @Autowired
    IRateServices rateServices;
    @Autowired
    IUserAssetsServices userAssetsServices;
    @Autowired
    StockMapper stockMapper;
@@ -64,9 +86,9 @@
    IUserPositionService iUserPositionService;
    @Autowired
    IUserBankService iUserBankService;
    @Autowired
    @Resource
    AgentUserMapper agentUserMapper;
    @Autowired
    @Resource
    SiteTaskLogMapper siteTaskLogMapper;
    @Autowired
    IStockOptionService iStockOptionService;
@@ -84,6 +106,15 @@
    ISiteIndexSettingService iSiteIndexSettingService;
    @Autowired
    StockPoll stockPoll;
    @Autowired
    StockSubscribeMapper stockSubscribeMapper;
    @Resource
    MoneyLogMapper mapper;
    @Resource
    IUserPositionService userPositionService;
    @Resource
    SiteAmtTransLogMapper siteAmtTransLogMapper;
    @Autowired
@@ -92,17 +123,27 @@
    ISiteFuturesSettingService iSiteFuturesSettingService;
    @Autowired
    IStockFuturesService iStockFuturesService;
    @Resource
    StockFuturesMapper stockFuturesMapper;
    @Resource
    StockIndexMapper stockIndexMapper;
    @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) {
        if (StringUtils.isBlank(agentCode) || StringUtils.isBlank(phone) ||
                StringUtils.isBlank(userPwd) || StringUtils.isBlank(yzmCode)) {
            return ServerResponse.createByErrorMsg("Registration failed. The parameter cannot be empty");
            return ServerResponse.createByErrorMsg("注册失败。该参数不能为空",request);
        }
@@ -111,22 +152,22 @@
        log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode);
        if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) {
            return ServerResponse.createByErrorMsg("Registration failed because the verification code is incorrect. Procedure");
            return ServerResponse.createByErrorMsg("由于验证码不正确,注册失败。过程",request);
        }
        AgentUser agentUser = this.iAgentUserService.findByCode(agentCode);
        if (agentUser == null) {
            return ServerResponse.createByErrorMsg("Registration failed because the agent does not exist");
            return ServerResponse.createByErrorMsg("由于代理不存在,注册失败",request);
        }
        if (agentUser.getIsLock().intValue() == 1) {
            return ServerResponse.createByErrorMsg("Registration failed. The agent is locked");
            return ServerResponse.createByErrorMsg("注册失败。代理被锁定",request);
        }
        User dbuser = this.userMapper.findByPhone(phone);
        User dbuser = this.userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getPhone,phone).last( " limit 1"));
        if (dbuser != null) {
            return ServerResponse.createByErrorMsg("Registration failed, the mobile phone number has been registered");
            return ServerResponse.createByErrorMsg("注册失败,手机号已注册",request);
        }
@@ -149,52 +190,36 @@
        user.setIsLogin(Integer.valueOf(0));
        user.setUserAmt(new BigDecimal("0"));
        user.setEnableAmt(new BigDecimal("0"));
        user.setUserIndexAmt(new BigDecimal("0"));
        user.setEnableIndexAmt(new BigDecimal("0"));
        user.setUserFutAmt(new BigDecimal("0"));
        user.setEnableFutAmt(new BigDecimal("0"));
        user.setSumBuyAmt(new BigDecimal("0"));
        user.setSumChargeAmt(new BigDecimal("0"));
        user.setDjzj(new BigDecimal("0"));
        int insertCount = this.userMapper.insert(user);
        if (insertCount > 0) {
            log.info("用户注册成功 手机 {} , ip = {} 地址 = {}", new Object[]{phone, uip, uadd});
            return ServerResponse.createBySuccessMsg("Registration successful. Please login");
        }
        return ServerResponse.createBySuccessMsg("Registration error, please try again");
        return ServerResponse.createBySuccessMsg("注册错误,请重试",request);
    }
    public ServerResponse login(String phone, String userPwd, HttpServletRequest request) {
        if (StringUtils.isBlank(phone) || StringUtils.isBlank(userPwd)) {
            return ServerResponse.createByErrorMsg("The mobile phone number and password cannot be empty");
            return ServerResponse.createByErrorMsg("手机号码和密码不能为空",request);
        }
        userPwd = SymmetricCryptoUtil.encryptPassword(userPwd);
        User user = this.userMapper.login(phone, userPwd);
        if (user != null) {
            if (user.getIsLogin().intValue() == 1) {
                return ServerResponse.createByErrorMsg("Login failed. Account locked");
                return ServerResponse.createByErrorMsg("登录失败。账户锁定",request);
            }
            log.info("用户{}登陆成功, 登陆状态{} ,交易状态{}", new Object[]{user.getId(), user.getIsLogin(), user.getIsLock()});
            userAssetsServices.assetsByTypeAndUserId(EStockType.IN.getCode(),user.getId());
            this.iSiteLoginLogService.saveLog(user, request);
            return ServerResponse.createBySuccess(user);
        }
        return ServerResponse.createByErrorMsg("Login failed, the user name and password are incorrect");
        return ServerResponse.createByErrorMsg("登录失败,用户名和密码错误",request);
    }
    public User getCurrentUser(HttpServletRequest request) {
        String property = PropertiesUtil.getProperty("user.cookie.name");
//        System.out.println(property);
        String loginToken = request.getHeader(property);
        if (loginToken == null) {
            return null;
@@ -217,24 +242,21 @@
        if (user == null) {
            return null;
        } else {
            return this.userMapper.selectByPrimaryKey(user.getId());
            return this.userMapper.selectById(user.getId());
        }
    }
    public ServerResponse addOption(String code, HttpServletRequest request) {
        User user = getCurrentUser(request);
        if (user == null) {
            return ServerResponse.createBySuccessMsg("Please log in first");
        }
        String stockcode = code;
        StockOption dboption = this.stockOptionMapper.findMyOptionIsExistByCode(user.getId(), stockcode);
        if (dboption != null) {
            return ServerResponse.createByErrorMsg("Failed to add the selected stock because it already exists");
            return ServerResponse.createByErrorMsg("未能添加所选股票,因为它已经存在",request );
        }
        //期货逻辑
        Stock stock = this.stockMapper.findStockByCode(code);
        if (stock == null) {
            return ServerResponse.createByErrorMsg("Add failed, stock does not exist");
            return ServerResponse.createByErrorMsg("添加失败,库存不存在",request );
        }
        StockOption stockOption = new StockOption();
        stockOption.setUserId(user.getId());
@@ -247,47 +269,30 @@
        int insertCount = this.stockOptionMapper.insert(stockOption);
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("Adding self-selected stocks succeeded");
            return ServerResponse.createBySuccessMsg("添加自选股票成功",request );
        }
        return ServerResponse.createByErrorMsg("Failed to add, please try again");
        return ServerResponse.createByErrorMsg("添加失败,请重试",request );
    }
    public ServerResponse delOption(String code, HttpServletRequest request) {
        User user = getCurrentUser(request);
        if (user == null) {
            return ServerResponse.createBySuccessMsg("Please log in first");
        }
        String stockcode = code;
        if (code.contains("hf")) {
            stockcode = code.split("_")[1].toString();
        }
        stockcode = stockcode.replace("sh", "").replace("sz", "").replace("bj", "");
        StockOption dboption = this.stockOptionMapper.findMyOptionIsExistByCode(user.getId(), stockcode);
        if (dboption == null) {
            return ServerResponse.createByErrorMsg("Failed to delete because the self-selected stock does not exist");
            return ServerResponse.createByErrorMsg("删除失败,因为自选股票不存在",request);
        }
        int delCount = this.stockOptionMapper.deleteByPrimaryKey(dboption.getId());
        if (delCount > 0) {
            return ServerResponse.createBySuccessMsg("Deleting self-selected stocks succeeded. Procedure");
            return ServerResponse.createBySuccessMsg("删除自选成功",request);
        }
        return ServerResponse.createByErrorMsg("Failed to delete, please try again");
        return ServerResponse.createByErrorMsg("删除自选失败",request);
    }
    public ServerResponse isOption(String code, HttpServletRequest request) {
        User user = getCurrentUser(request);
        if (user == null) {
            return ServerResponse.createBySuccessMsg("Please log in first");
        }
        String stockcode = code;
        if (code.contains("hf")) {
            stockcode = code.split("_")[1].toString();
        }
        stockcode = stockcode.replace("sh", "").replace("sz", "").replace("bj", "");
        return this.iStockOptionService.isOption(user.getId(), stockcode);
    }
@@ -297,33 +302,51 @@
        String loginToken = request.getHeader(cookie_name);
        String userJson = RedisShardedPoolUtils.get(loginToken);
        User user = (User) JsonUtil.string2Obj(userJson, User.class);
        User dbuser = this.userMapper.selectByPrimaryKey(user.getId());
        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;
    }
    public ServerResponse updatePwd(String oldPwd, String newPwd, HttpServletRequest request) {
        if (StringUtils.isBlank(oldPwd) || StringUtils.isBlank(newPwd)) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
            return ServerResponse.createByErrorMsg("该参数不能为空",request);
        }
        User user = getCurrentRefreshUser(request);
        if (user == null) {
            return ServerResponse.createBySuccessMsg("Please log in first");
        }
        oldPwd = SymmetricCryptoUtil.encryptPassword(oldPwd);
        if (!oldPwd.equals(user.getUserPwd())) {
            return ServerResponse.createByErrorMsg("Password error");
            return ServerResponse.createByErrorMsg("密码错误",request);
        }
        user.setUserPwd(SymmetricCryptoUtil.encryptPassword(newPwd));
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("Modified successfully");
            return ServerResponse.createBySuccessMsg("修改成功",request);
        }
        return ServerResponse.createByErrorMsg("Modification failure");
        return ServerResponse.createByErrorMsg("修改失败",request);
    }
@@ -358,7 +381,7 @@
        }
        user.setUserPwd(SymmetricCryptoUtil.encryptPassword(newPwd));
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccess("Password changed successfully!");
        }
@@ -367,10 +390,6 @@
    public ServerResponse update(User user) {
        log.info("#####修改用户信息####,用户总资金 = {} 可用资金 = {}", user
                .getUserAmt(), user.getEnableAmt());
        log.info("#####修改用户信息####,用户index总资金 = {} index可用资金 = {}", user
                .getUserIndexAmt(), user.getEnableIndexAmt());
        if (user.getAgentId() != null) {
            AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(user.getAgentId());
            if (agentUser != null) {
@@ -380,7 +399,7 @@
        if (user.getUserPwd() != null && !user.getUserPwd().equals("")) {
            user.setUserPwd(SymmetricCryptoUtil.encryptPassword(user.getUserPwd()));
        }
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("Modified successfully");
        }
@@ -392,18 +411,16 @@
        if (StringUtils.isBlank(realName) ||
                StringUtils.isBlank(idCard)) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
            return ServerResponse.createByErrorMsg("该参数不能为空",request);
        }
        User user = getCurrentRefreshUser(request);
        if (user == null) {
            return ServerResponse.createByErrorMsg("Please log in!");
        }
        if (((0 != user.getIsActive().intValue())) & ((3 != user.getIsActive().intValue()))) {
            return ServerResponse.createByErrorMsg("The current status cannot be authenticated");
            return ServerResponse.createByErrorMsg("当前状态无法验证",request);
        }
        user.setImg1Key(img1key);
        user.setImg2Key(img2key);
        user.setNickName(realName);
        user.setRealName(realName);
        user.setIdCard(idCard);
@@ -411,14 +428,12 @@
        user.setIsActive(Integer.valueOf(1));
        log.info("##### 用户认证 ####,用户总资金 = {} 可用资金 = {}", user
                .getUserAmt(), user.getEnableAmt());
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("Real name authentication");
            return ServerResponse.createBySuccessMsg("实名认证",request);
        }
        return ServerResponse.createByErrorMsg("Real-name authentication failed. Procedure");
        return ServerResponse.createByErrorMsg("实名认证失败",request);
    }
@@ -440,37 +455,206 @@
        BigDecimal exranRate = iSiteSettingService.getSiteSetting().getExchangeRate();
        if (type == 1) {
            if (user.getUserIndexAmt().compareTo(new BigDecimal(amt)) == -1) {
                return ServerResponse.createByErrorMsg("US available in the financing account");
            }
            userIndexAmt = user.getUserAmt().subtract(new BigDecimal(amt));
            enableIndexAmt = user.getEnableAmt().subtract(new BigDecimal(amt));
            BigDecimal usdt = new BigDecimal(amt).multiply(exranRate).setScale(2, RoundingMode.UP);
            userAmt = user.getUserIndexAmt().add(usdt);
            enableAmt = user.getEnableIndexAmt().add(usdt);
        } else if (2 == type) {
            if (user.getEnableAmt().compareTo(new BigDecimal(amt)) == -1) {
                return ServerResponse.createByErrorMsg("US available in the financing account");
            }
            userAmt = user.getUserAmt().subtract(new BigDecimal(amt));
            enableAmt = user.getEnableAmt().subtract(new BigDecimal(amt));
            BigDecimal usdt = new BigDecimal(amt).divide(exranRate).setScale(2, RoundingMode.UP);
            userIndexAmt = user.getUserIndexAmt().add(usdt);
            enableIndexAmt = user.getEnableIndexAmt().add(usdt);
        }
        user.setUserAmt(userAmt);
        user.setEnableAmt(enableAmt);
        user.setUserIndexAmt(userIndexAmt);
        user.setEnableIndexAmt(enableIndexAmt);
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            saveAmtTransLog(user, type, amt);
            return ServerResponse.createBySuccessMsg("Transfer successful");
        }
        return ServerResponse.createByErrorMsg("Transfer failure");
    }
    @Override
    public ServerResponse getMoney(HttpServletRequest request) {
        return  getMoney(getCurrentUser(request).getId());
    }
    @Override
    public ServerResponse getMoney(Integer userId) {
        List<UserAssets>  userAssetsList =   userAssetsServices.assetsByUserId(userId);
        List<RUserAssets>  rUserAssetsList = new ArrayList<>();
        int s= 4;
        /**
         *  浮动盈亏
         * */
        BigDecimal AllProfitAndLose = BigDecimal.ZERO;
        /**
         *  总资产
         * */
        BigDecimal allTotalAssets = BigDecimal.ZERO;
        /**
         *  总可用余额
         * */
        BigDecimal allAmt = BigDecimal.ZERO;
        /**
         *  累计盈亏
         * */
        BigDecimal AllHProfitAndLose = BigDecimal.ZERO;
        /**
         *  总冻结资产
         * */
        BigDecimal allFreeMoney = BigDecimal.ZERO;
        /**
         *  总手续费
         * */
        BigDecimal allHMoney = BigDecimal.ZERO;
        for (int i = 0; i <userAssetsList.size() ; i++) {
            RUserAssets rUserAssets  = new RUserAssets();
            UserAssets userAssets = userAssetsList.get(i);
            // 浮动盈亏
            String profitAndLose = getProfitAndLose(userId).toString();
            BigDecimal amt = userAssets.getAvailableBalance();
            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();
            rUserAssets.setId(userAssets.getId());
            rUserAssets.setTotalMoney((totalAssets.toString()));
            rUserAssets.setAccectType(userAssets.getAccectType());
            rUserAssets.setAvailableBalance(amt.toString());
            rUserAssets.setFreezeMoney(freeMoney.toString());
            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);
           BigDecimal  availableBalanceUSD = amt;
           if(amt.compareTo(BigDecimal.ZERO)>0){
               availableBalanceUSD = amt.multiply(rate);
           }
            BigDecimal  freezeMoneyUSD = freeMoney;
           if(freeMoney.compareTo(BigDecimal.ZERO)>0){
               freezeMoneyUSD  = freeMoney.multiply(rate);
           }
            BigDecimal  totleMoneyUSD = totalAssets;
            if(totalAssets.compareTo(BigDecimal.ZERO)>0){
                totleMoneyUSD  = totleMoneyUSD.multiply(rate);
            }
            BigDecimal  cumulativeProfitAndLossUSD = hProfitAndLose;
            if(hProfitAndLose.compareTo(BigDecimal.ZERO)>0){
                cumulativeProfitAndLossUSD = hProfitAndLose.multiply(rate);
            }
            BigDecimal  handlingChargeUSD = hMoney;
            if(hMoney.compareTo(BigDecimal.ZERO)>0){
                handlingChargeUSD  =hMoney.multiply(rate);
            }
            BigDecimal  profitAndLossUSD = new BigDecimal(profitAndLose);
            if(new BigDecimal(profitAndLose).compareTo(BigDecimal.ZERO)>0){
                profitAndLossUSD  =new BigDecimal(profitAndLose).multiply(rate);
            }
            rUserAssets.setAvailableBalanceUSD(availableBalanceUSD.setScale(s,BigDecimal.ROUND_UP).toString());
            rUserAssets.setFreezeMoneyUSD(freezeMoneyUSD.setScale(s,BigDecimal.ROUND_UP).toString());
            rUserAssets.setTotalMoneyUSD(totleMoneyUSD.setScale(s,BigDecimal.ROUND_UP).toString());
            rUserAssets.setSymbol(EStockType.getEStockTypeByCode(userAssets.getAccectType()).getSymbol1());
            rUserAssets.setSymbolCode(EStockType.getEStockTypeByCode(userAssets.getAccectType()).getSymbol());
            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);
            rUserAssetsList.add(rUserAssets);
        }
        RUserAssets rUserAssets  = new RUserAssets();
        rUserAssets.setAccectType("ALL");
        rUserAssets.setProfitAndLoss(AllProfitAndLose.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setProfitAndLossUSD(AllProfitAndLose.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setHandlingCharge(allHMoney.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setHandlingChargeUSD(allHMoney.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setCumulativeProfitAndLoss(AllHProfitAndLose.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setCumulativeProfitAndLossUSD(AllHProfitAndLose.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setTotalMoney(allTotalAssets.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setTotalMoneyUSD(allTotalAssets.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setAvailableBalance(allAmt.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setAvailableBalanceUSD(allAmt.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setFreezeMoney(allFreeMoney.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setFreezeMoneyUSD(allFreeMoney.setScale(s,BigDecimal.ROUND_DOWN).toString());
        rUserAssets.setSymbol("$");
        rUserAssets.setSymbolCode("USD");
        rUserAssetsList.add(rUserAssets);
        return ServerResponse.createBySuccess(rUserAssetsList);
    }
    public BigDecimal getProfitAndLose(Integer userId){
        List<UserPosition> userPositions;
        userPositions = userPositionMapper.
                findMyPositionByCodeAndSpell(userId,
                        "","",
                        0, "IN");
        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
    public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest request) {
        User user =  userService.getCurrentUser(request);
        UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId());
        BigDecimal amtBig = new BigDecimal(amt);
        if(formAssets.getAvailableBalance().compareTo(amtBig)<0){
            return ServerResponse.createByErrorMsg("余额不足",request);
        }
        userAssetsServices.availablebalanceChange(fromType,user.getId(), EUserAssets.TRANSFER,amtBig.negate(),fromType+"/"+toType,"");
        amtBig = rateServices.currencyRate(EStockType.getEStockTypeByCode(fromType),EStockType.getEStockTypeByCode(toType)).multiply(amtBig);
        userAssetsServices.availablebalanceChange(toType,user.getId(),EUserAssets.TRANSFER,amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,"");
        return ServerResponse.createBySuccess();
    }
@@ -504,614 +688,44 @@
    public void ForceSellTask() {
        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
            BigDecimal enable_user_amt = user.getEnableAmt();
            BigDecimal all_freez_amt = new BigDecimal("0");
            for (UserPosition position : userPositions) {
                BigDecimal actual_amt = position.getOrderTotalPrice().divide(new BigDecimal(position
                        .getOrderLever().intValue()), 2, 4);
                all_freez_amt = all_freez_amt.add(actual_amt);
            }
            BigDecimal all_profit_and_lose = new BigDecimal("0");
            PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(userId);
            all_profit_and_lose = positionVO.getAllProfitAndLose();
            SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
            BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
            BigDecimal force_stop_amt = enable_user_amt.add(all_freez_amt);
            //(沪深)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓该用户所有的持仓单");
                int[] arrs = new int[userPositions.size()];
                for (int k = 0; k < userPositions.size(); k++) {
                    UserPosition position = (UserPosition) userPositions.get(k);
                    arrs[k] = position.getId().intValue();
                    try {
                        if (!DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(), position.getBuyOrderTime())) {
                            this.iUserPositionService.sell(position.getPositionSn(), 0);
                        }
                    } catch (Exception e) {
                        log.error("[盈亏达到最大亏损]强制平仓失败...");
                    }
                }
                SiteTaskLog siteTaskLog = new SiteTaskLog();
                siteTaskLog.setTaskType("强平任务-股票持仓");
                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
                String taskcnt = accountType + "-" + user.getRealName() + "被强平[两融盈亏达到最大亏损] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 强平线:" + user_force_amt;
                siteTaskLog.setTaskCnt(taskcnt);
                String tasktarget = "此次强平" + userPositions.size() + "条股票持仓订单, 订单号为" + Arrays.toString(arrs);
                siteTaskLog.setTaskTarget(tasktarget);
                siteTaskLog.setAddTime(new Date());
                siteTaskLog.setIsSuccess(Integer.valueOf(0));
                siteTaskLog.setErrorMsg("");
                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                if (insertTaskCount > 0) {
                    log.info("[盈亏达到最大亏损]保存强制平仓task任务成功");
                } else {
                    log.info("[盈亏达到最大亏损]保存强制平仓task任务失败");
                }
            } else {
                log.info("用户未达到强制平仓线,不做强平处理...");
            }
            log.info("=====================");
        }
    }
    /*用户持仓单-单支股票盈亏-强平定时*/
    @Override
    public void ForceSellOneStockTask() {
        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
        BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
            BigDecimal enable_user_amt = user.getEnableAmt();
            BigDecimal all_freez_amt = new BigDecimal("0");
            for (UserPosition position : userPositions) {
                PositionProfitVO positionProfitVO = iUserPositionService.getPositionProfitVO(position);
                //(沪深)单支股票强制平仓线 = (下单总金额 / 杠杆 + 追加保证金) *  0.8
                BigDecimal user_force_amt = position.getOrderTotalPrice().divide(new BigDecimal(position.getOrderLever())).add(position.getMarginAdd()).multiply(force_stop_percent);
                BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
                log.info("用户强制平仓线金额 = {}", user_force_amt);
                /*if("1601344387923698".equals( position.getPositionSn())){
                    log.info("test = {}", position.getPositionSn());
                }*/
                boolean isProfit = false;
                //总盈亏<=0  并且  强制负平仓线>=总盈亏
                isProfit = (positionProfitVO.getAllProfitAndLose().compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(positionProfitVO.getAllProfitAndLose()) > -1);
                if (isProfit && !DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(), position.getBuyOrderTime())) {
                    try {
                        this.iUserPositionService.sell(position.getPositionSn(), 0);
                        SiteTaskLog siteTaskLog = new SiteTaskLog();
                        siteTaskLog.setTaskType("单股强平任务-股票持仓");
                        String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
                        String taskcnt = accountType + "-" + user.getRealName() + "被强平[两融盈亏达到最大亏损] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + positionProfitVO.getAllProfitAndLose() + ", 强平线:" + user_force_amt;
                        siteTaskLog.setTaskCnt(taskcnt);
                        String tasktarget = "此次强平订单号为:" + position.getPositionSn();
                        siteTaskLog.setTaskTarget(tasktarget);
                        siteTaskLog.setAddTime(new Date());
                        siteTaskLog.setIsSuccess(Integer.valueOf(0));
                        siteTaskLog.setErrorMsg("");
                        int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                        if (insertTaskCount > 0) {
                            log.info("[盈亏达到最大亏损]保存强制平仓task任务成功");
                        } else {
                            log.info("[盈亏达到最大亏损]保存强制平仓task任务失败");
                        }
                    } catch (Exception e) {
                        log.error("[盈亏达到最大亏损]强制平仓失败...");
                    }
                }
            }
            log.info("=====================");
        }
    }
    /*用户持仓单-单支股票/止损止盈-强平定时*/
    @Override
    public void ForceSellOneStockTaskV2() {
        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
        BigDecimal force_stop_percent = siteSetting.getForceStopPercent();
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
            BigDecimal enable_user_amt = user.getEnableAmt();
            BigDecimal all_freez_amt = new BigDecimal("0");
            for (UserPosition position : userPositions) {
                StockListVO stockListVO = new StockListVO();
                if (position.getStockGid().contains("hk")) {
                    String hk = RedisShardedPoolUtils.get(position.getStockGid(), 1);
                    stockListVO = StockApi.otherStockListVO(hk);
                } else if (position.getStockGid().contains("us")) {
                    String us = RedisShardedPoolUtils.get(position.getStockGid(), 2);
                    stockListVO = StockApi.otherStockListVO(us);
                } else {
                    Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", position.getStockCode()));
                    stockListVO = StockApi.getStockRealTime(stock);
                }
                if (stockListVO == null) {
                    continue;
                }
                if (position.getProfitTargetPrice() != null && position.getProfitTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) <= 0 || position.getStopTargetPrice() != null && position.getStopTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) >= 0) {
                    try {
                        this.iUserPositionService.sell(position.getPositionSn(), 0);
                        SiteTaskLog siteTaskLog = new SiteTaskLog();
                        siteTaskLog.setTaskType("单股止盈止损强平任务-股票持仓");
                        String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
                        String taskcnt = accountType + "-" + user.getRealName() + "被强平[达到目标盈亏] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ",现价" + stockListVO.getNowPrice() + ", 目标止盈价格:" + position.getProfitTargetPrice() + ", 目标止损价格:" + position.getStopTargetPrice();
                        siteTaskLog.setTaskCnt(taskcnt);
                        String tasktarget = "此次强平订单号为:" + position.getPositionSn();
                        siteTaskLog.setTaskTarget(tasktarget);
                        siteTaskLog.setAddTime(new Date());
                        siteTaskLog.setIsSuccess(Integer.valueOf(0));
                        siteTaskLog.setErrorMsg("");
                        int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                        if (insertTaskCount > 0) {
                            log.info("[盈利达到目标盈利]保存强制平仓task任务成功");
                        } else {
                            log.info("[盈利达到目标盈利]保存强制平仓task任务失败");
                        }
                    } catch (Exception e) {
                        log.error("[盈利达到目标盈利]强制平仓失败...");
                    }
                }
            }
            log.info("=========止盈止损定时任务============");
        }
    }
    /*用户股票持仓单-强平提醒推送消息定时*/
    @Override
    public void ForceSellMessageTask() {
        List<Integer> userIdList = this.iUserPositionService.findDistinctUserIdList();
        log.info("当前有持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserPosition> userPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPositions.size())});
            BigDecimal enable_user_amt = user.getEnableAmt();
            BigDecimal all_freez_amt = new BigDecimal("0");
            for (UserPosition position : userPositions) {
                BigDecimal actual_amt = position.getOrderTotalPrice().divide(new BigDecimal(position
                        .getOrderLever().intValue()), 2, 4);
                all_freez_amt = all_freez_amt.add(actual_amt);
            }
            BigDecimal all_profit_and_lose = new BigDecimal("0");
            PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(userId);
            all_profit_and_lose = positionVO.getAllProfitAndLose();
            SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
            BigDecimal force_stop_percent = siteSetting.getForceStopRemindRatio();
            /*BigDecimal force_stop_amt = force_stop_percent.multiply(all_freez_amt);
            BigDecimal user_force_amt = enable_user_amt.add(force_stop_amt);
            boolean isProfit = false;
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) == -1 && user_force_amt.compareTo(all_profit_and_lose.negate()) != 1);
            */
            BigDecimal force_stop_amt = enable_user_amt.add(all_freez_amt);
            //(沪深)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓该用户所有的持仓单");
                int count = iSiteMessageService.getIsDayCount(userId, "股票预警");
                if (count == 0) {
                    //给达到消息强平提醒用户推送消息
                    SiteMessage siteMessage = new SiteMessage();
                    siteMessage.setUserId(userId);
                    siteMessage.setUserName(user.getRealName());
                    siteMessage.setTypeName("股票预警");
                    siteMessage.setStatus(1);
                    siteMessage.setContent("【股票预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 提醒线:" + user_force_amt + ",请及时关注哦。");
                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
                    iSiteMessageService.insert(siteMessage);
                }
            } else {
                log.info("用户未达到强制平仓线,不做强平处理...");
            }
            log.info("=====================");
        }
    }
    @Override
    public void ForceSellIndexTask() {
        List<Integer> userIdList = this.iUserIndexPositionService.findDistinctUserIdList();
        log.info("当前有 指数持仓 的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserIndexPosition> userIndexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user
                    .getRealName(), Integer.valueOf(userIndexPositions.size())});
            IndexPositionVO indexPositionVO = this.iUserIndexPositionService.findUserIndexPositionAllProfitAndLose(userId);
            BigDecimal enable_index_amt = user.getEnableIndexAmt();
            BigDecimal all_freez_amt = indexPositionVO.getAllIndexFreezAmt();
            BigDecimal all_profit_and_lose = indexPositionVO.getAllIndexProfitAndLose();
            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[]{userId, enable_index_amt, all_freez_amt, all_profit_and_lose});
            SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
            BigDecimal force_stop_percent = siteIndexSetting.getForceSellPercent();
            BigDecimal force_stop_amt = enable_index_amt.add(all_freez_amt);
            //(指数)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓该用户所有的指数持仓单");
                int[] arrs = new int[userIndexPositions.size()];
                for (int k = 0; k < userIndexPositions.size(); k++) {
                    UserIndexPosition userIndexPosition = (UserIndexPosition) userIndexPositions.get(k);
                    arrs[k] = userIndexPosition.getId().intValue();
                    try {
                        this.iUserIndexPositionService.sellIndex(userIndexPosition.getPositionSn(), 0);
                    } catch (Exception e) {
                        log.error("[盈亏达到最大亏损]强制平仓指数失败...");
                    }
                }
                SiteTaskLog siteTaskLog = new SiteTaskLog();
                siteTaskLog.setTaskType("强平任务-指数持仓");
                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
                String taskcnt = accountType + "-" + user.getRealName() + "被强平 [指数盈亏达到最大亏损] 用户 id = " + user.getId() + ", 可用资金 = " + enable_index_amt + ", 冻结资金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏 = " + all_profit_and_lose + ", 强平线 = " + user_force_amt;
                siteTaskLog.setTaskCnt(taskcnt);
                String tasktarget = "此次强平" + userIndexPositions.size() + "条指数持仓订单, 订单号为" + Arrays.toString(arrs);
                siteTaskLog.setTaskTarget(tasktarget);
                siteTaskLog.setAddTime(new Date());
                siteTaskLog.setIsSuccess(Integer.valueOf(0));
                siteTaskLog.setErrorMsg("");
                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                if (insertTaskCount > 0) {
                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务成功");
                } else {
                    log.info("[盈亏达到最大亏损] 保存强制平仓 指数 task任务失败");
                }
            } else {
                log.info("用户指数持仓未达到强制平仓线, 不做强平处理...");
            }
            log.info("=====================");
        }
    }
    /*指数强平提醒推送消息,每分钟检测一次*/
    @Override
    public void ForceSellIndexsMessageTask() {
        List<Integer> userIdList = this.iUserIndexPositionService.findDistinctUserIdList();
        log.info("当前有 指数持仓 的用户数量 为 {}", Integer.valueOf(userIdList.size()));
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("=====================");
            Integer userId = (Integer) userIdList.get(i);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserIndexPosition> userIndexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId);
            log.info("用户id = {} 姓名 = {} 持仓中订单数: {}", new Object[]{userId, user
                    .getRealName(), Integer.valueOf(userIndexPositions.size())});
            IndexPositionVO indexPositionVO = this.iUserIndexPositionService.findUserIndexPositionAllProfitAndLose(userId);
            BigDecimal enable_index_amt = user.getEnableIndexAmt();
            BigDecimal all_freez_amt = indexPositionVO.getAllIndexFreezAmt();
            BigDecimal all_profit_and_lose = indexPositionVO.getAllIndexProfitAndLose();
            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[]{userId, enable_index_amt, all_freez_amt, all_profit_and_lose});
            SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting();
            BigDecimal force_stop_percent = siteIndexSetting.getForceStopRemindRatio();
            BigDecimal force_stop_amt = enable_index_amt.add(all_freez_amt);
            //(指数)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓该用户所有的指数持仓单");
                int count = iSiteMessageService.getIsDayCount(userId, "指数预警");
                if (count == 0) {
                    //给达到消息强平提醒用户推送消息
                    SiteMessage siteMessage = new SiteMessage();
                    siteMessage.setUserId(userId);
                    siteMessage.setUserName(user.getRealName());
                    siteMessage.setTypeName("指数预警");
                    siteMessage.setStatus(1);
                    siteMessage.setContent("【指数预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_index_amt + ", 冻结资金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏 = " + all_profit_and_lose + ", 提醒线 = " + user_force_amt + ",请及时关注哦。");
                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
                    iSiteMessageService.insert(siteMessage);
                }
            } else {
                log.info("用户指数持仓未达到强制平仓线, 不做强平处理...");
            }
            log.info("=====================");
        }
    }
//    public void qh1() {
//        this.stockPoll.qh1();
//    }
//
//    public void zs1() {
//        this.stockPoll.zs1();
//    }
    @Override
    public void ForceSellFuturesTask() {
        List<Integer> userIdList = this.iUserFuturesPositionService.findDistinctUserIdList();
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("===================== \n");
            Integer userId = (Integer) userIdList.get(i);
            System.out.println("userId" + userId);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserFuturesPosition> userFuturesPositions = this.iUserFuturesPositionService.findFuturesPositionByUserIdAndSellPriceIsNull(userId);
            System.out.println("userFuturesPositions" + userFuturesPositions);
            System.out.println("继续");
            log.info("用户id = {} 姓名 = {} 期货持仓中订单数 {}", new Object[]{userId, user
                    .getRealName(), Integer.valueOf(userFuturesPositions.size())});
            FuturesPositionVO futuresPositionVO = this.iUserFuturesPositionService.findUserFuturesPositionAllProfitAndLose(userId);
            BigDecimal enable_Futures_amt = user.getEnableFutAmt();
            BigDecimal all_deposit_amt = futuresPositionVO.getAllFuturesDepositAmt();
            BigDecimal all_profit_and_lose = futuresPositionVO.getAllFuturesProfitAndLose();
            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[]{userId, enable_Futures_amt, all_deposit_amt, all_profit_and_lose});
            SiteFuturesSetting siteFuturesSetting = this.iSiteFuturesSettingService.getSetting();
            BigDecimal force_stop_percent = siteFuturesSetting.getForceSellPercent();
            BigDecimal force_stop_amt = enable_Futures_amt.add(all_deposit_amt);
            //(期货)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.8
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓用户 {} 所有的 期货 持仓单", user.getId());
                int[] arrs = new int[userFuturesPositions.size()];
                for (int k = 0; k < userFuturesPositions.size(); k++) {
                    UserFuturesPosition userFuturesPosition = (UserFuturesPosition) userFuturesPositions.get(k);
                    arrs[k] = userFuturesPosition.getId().intValue();
                    try {
                        this.iUserFuturesPositionService.sellFutures(userFuturesPosition.getPositionSn(), 0);
                    } catch (Exception e) {
                        log.error("[盈亏达到最大亏损] 强制平仓 期货 失败...");
                    }
                }
                SiteTaskLog siteTaskLog = new SiteTaskLog();
                siteTaskLog.setTaskType("强平任务-期货持仓");
                String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户";
                String taskcnt = accountType + "-" + user.getRealName() + "被强平[期货盈亏达到最大亏损]用户id = " + user.getId() + ", 可用资金 = " + enable_Futures_amt + ", 冻结保证金 = " + all_deposit_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 强平线:" + user_force_amt;
                siteTaskLog.setTaskCnt(taskcnt);
                String tasktarget = "此次强平" + userFuturesPositions.size() + "条期货持仓订单, 订单号为" + Arrays.toString(arrs);
                siteTaskLog.setTaskTarget(tasktarget);
                siteTaskLog.setAddTime(new Date());
                siteTaskLog.setIsSuccess(Integer.valueOf(0));
                siteTaskLog.setErrorMsg("");
                int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
                if (insertTaskCount > 0) {
                    log.info("[盈亏达到最大亏损]保存强制平仓 期货 task任务成功");
                } else {
                    log.info("[盈亏达到最大亏损]保存强制平仓 期货 task任务失败");
                }
            } else {
                log.info("用户期货;持仓未达到强制平仓线,不做强平处理...");
            }
            log.info("===================== \n");
        }
    }
    @Override
    public void ForceSellFuturesMessageTask() {
        List<Integer> userIdList = this.iUserFuturesPositionService.findDistinctUserIdList();
        for (int i = 0; i < userIdList.size(); i++) {
            log.info("===================== \n");
            Integer userId = (Integer) userIdList.get(i);
            System.out.println("userId" + userId);
            User user = this.userMapper.selectByPrimaryKey(userId);
            if (user == null) {
                continue;
            }
            List<UserFuturesPosition> userFuturesPositions = this.iUserFuturesPositionService.findFuturesPositionByUserIdAndSellPriceIsNull(userId);
            System.out.println("userFuturesPositions" + userFuturesPositions);
            System.out.println("继续");
            log.info("用户id = {} 姓名 = {} 期货持仓中订单数 {}", new Object[]{userId, user
                    .getRealName(), Integer.valueOf(userFuturesPositions.size())});
            FuturesPositionVO futuresPositionVO = this.iUserFuturesPositionService.findUserFuturesPositionAllProfitAndLose(userId);
            BigDecimal enable_Futures_amt = user.getEnableFutAmt();
            BigDecimal all_deposit_amt = futuresPositionVO.getAllFuturesDepositAmt();
            BigDecimal all_profit_and_lose = futuresPositionVO.getAllFuturesProfitAndLose();
            log.info("用户 {} 可用资金 = {} 总冻结保证金 = {} 所有持仓单的总盈亏 = {}", new Object[]{userId, enable_Futures_amt, all_deposit_amt, all_profit_and_lose});
            SiteFuturesSetting siteFuturesSetting = this.iSiteFuturesSettingService.getSetting();
            BigDecimal force_stop_percent = siteFuturesSetting.getForceStopRemindRatio();
            BigDecimal force_stop_amt = enable_Futures_amt.add(all_deposit_amt);
            //(期货)强制平仓线 = (账户可用资金 + 冻结保证金) *  0.4
            BigDecimal user_force_amt = force_stop_percent.multiply(force_stop_amt);
            BigDecimal fu_user_force_amt = user_force_amt.negate(); //负平仓线
            log.info("用户消息强制平仓线金额 = {}", user_force_amt);
            boolean isProfit = false;
            //总盈亏<=0  并且  强制负平仓线>=总盈亏
            isProfit = (all_profit_and_lose.compareTo(new BigDecimal("0")) < 1 && fu_user_force_amt.compareTo(all_profit_and_lose) > -1);
            if (isProfit) {
                log.info("强制平仓用户 {} 所有的 期货 持仓单", user.getId());
                int count = iSiteMessageService.getIsDayCount(userId, "期货预警");
                if (count == 0) {
                    //给达到消息强平提醒用户推送消息
                    SiteMessage siteMessage = new SiteMessage();
                    siteMessage.setUserId(userId);
                    siteMessage.setUserName(user.getRealName());
                    siteMessage.setTypeName("期货预警");
                    siteMessage.setStatus(1);
                    siteMessage.setContent("【期货预警】提醒您,用户id = " + user.getId() + ", 可用资金 = " + enable_Futures_amt + ", 冻结保证金 = " + all_deposit_amt + ", 强平比例 = " + force_stop_percent + ", 总盈亏" + all_profit_and_lose + ", 提醒线:" + user_force_amt + ",请及时关注哦。");
                    siteMessage.setAddTime(DateTimeUtil.getCurrentDate());
                    iSiteMessageService.insert(siteMessage);
                }
            } else {
                log.info("用户期货;持仓未达到强制平仓线,不做强平处理...");
            }
            log.info("===================== \n");
        }
    }
    @Override
    public void qh1() {
@@ -1150,10 +764,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 -> "IN".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);
        }
@@ -1164,43 +792,33 @@
    }
    @Transactional
    public ServerResponse addSimulatedAccount(Integer agentId, String phone, String pwd, String amt, Integer accountType, HttpServletRequest request) {
        if (StringUtils.isBlank(phone) || StringUtils.isBlank(pwd)) {
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
        }
        User dbUser = this.userMapper.findByPhone(phone);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("phone",phone);
        User dbUser = userMapper.selectOne(queryWrapper);
        if (dbUser != null) {
            return ServerResponse.createByErrorMsg("The phone number is registered");
        }
        if ((new BigDecimal(amt)).compareTo(new BigDecimal("200000")) == 1) {
            return ServerResponse.createByErrorMsg("The phone number is registered");
        }
        amt = "0";   //代理后台添加用户时金额默认为0
        User user = new User();
        user.setAccountType(accountType);
        user.setPhone(phone);
        user.setUserPwd(SymmetricCryptoUtil.encryptPassword(pwd));
        user.setUserAmt(new BigDecimal(amt));
        user.setEnableAmt(new BigDecimal(amt));
        user.setSumChargeAmt(new BigDecimal("0"));
        user.setSumBuyAmt(new BigDecimal("0"));
        user.setIsLock(Integer.valueOf(0));
        user.setIsLogin(Integer.valueOf(0));
        user.setIsActive(Integer.valueOf(0));
        user.setRegTime(new Date());
        if (accountType.intValue() == 1) {
            user.setNickName("模拟用户");
        }
        user.setUserIndexAmt(new BigDecimal("0"));
        user.setEnableIndexAmt(new BigDecimal("0"));
        user.setUserFutAmt(new BigDecimal("0"));
        user.setEnableFutAmt(new BigDecimal("0"));
        if (agentId != null) {
            AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId);
@@ -1209,6 +827,9 @@
        }
        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),"","");
        if (insertCount > 0) {
            return ServerResponse.createBySuccessMsg("Success");
        }
@@ -1216,24 +837,54 @@
    }
    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 -> "IN".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) {
        return ServerResponse.createBySuccess(this.userMapper.selectByPrimaryKey(userId));
        return ServerResponse.createBySuccess(this.userMapper.selectById(userId));
    }
    public ServerResponse updateLock(Integer userId) {
        User user = this.userMapper.selectByPrimaryKey(userId);
        User user = this.userMapper.selectById(userId);
        if (user == null) {
            return ServerResponse.createByErrorMsg("User does not exist");
        }
@@ -1244,7 +895,7 @@
            user.setIsLock(Integer.valueOf(1));
        }
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccess("Modified successfully");
        }
@@ -1258,38 +909,11 @@
            return ServerResponse.createByErrorMsg("The parameter cannot be null");
        }
        User user = this.userMapper.selectByPrimaryKey(userId);
        User user = this.userMapper.selectById(userId);
        if (user == null) {
            return ServerResponse.createByErrorMsg("User does not exist");
        }
        BigDecimal user_amt = user.getUserAmt();
        BigDecimal user_enable = user.getEnableAmt();
        BigDecimal user_amt_back = new BigDecimal("0");
        BigDecimal user_enable_back = new BigDecimal("0");
        if (direction.intValue() == 0) {
            user_amt_back = user_amt.add(new BigDecimal(amt));
            user_enable_back = user_enable.add(new BigDecimal(amt));
        } else if (direction.intValue() == 1) {
            if (user_amt.compareTo(new BigDecimal(amt)) == -1) {
                return ServerResponse.createByErrorMsg("The deduction failed and the total funds were insufficient");
            }
            if (user_enable.compareTo(new BigDecimal(amt)) == -1) {
                return ServerResponse.createByErrorMsg("Deduction failed, insufficient available funds");
            }
            user_amt_back = user_amt.subtract(new BigDecimal(amt));
            user_enable_back = user_enable.subtract(new BigDecimal(amt));
        } else {
            return ServerResponse.createByErrorMsg("This operation does not exist");
        }
        user.setUserAmt(user_amt_back);
        user.setEnableAmt(user_enable_back);
        this.userMapper.updateByPrimaryKeySelective(user);
        this.userMapper.updateById(user);
        SiteTaskLog siteTaskLog = new SiteTaskLog();
@@ -1301,9 +925,6 @@
        siteTaskLog.setTaskCnt(cnt.toString());
        StringBuffer target = new StringBuffer();
        target.append("用户id : ").append(user.getId())
                .append("修改前 总资金 = ").append(user_amt).append(" 可用 = ").append(user_enable)
                .append("修改后 总资金 = ").append(user_amt_back).append(" 可用 = ").append(user_enable_back);
        siteTaskLog.setTaskTarget(target.toString());
        siteTaskLog.setIsSuccess(Integer.valueOf(0));
@@ -1366,7 +987,7 @@
        }
        int delUserCount = this.userMapper.deleteByPrimaryKey(userId);
        int delUserCount = this.userMapper.deleteById(userId);
        if (delUserCount > 0) {
            return ServerResponse.createBySuccessMsg("Successful operation");
        }
@@ -1394,7 +1015,7 @@
            return ServerResponse.createByErrorMsg("id and state cannot be empty");
        }
        User user = this.userMapper.selectByPrimaryKey(userId);
        User user = this.userMapper.selectById(userId);
        if (user == null) {
            return ServerResponse.createByErrorMsg("This user cannot be found");
        }
@@ -1406,9 +1027,12 @@
            user.setAuthMsg(authMsg);
        }
        if(state == 2){
            user.setIsLock(0);
        }
        user.setIsActive(state);
        int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
        int updateCount = this.userMapper.updateById(user);
        if (updateCount > 0) {
            return ServerResponse.createBySuccessMsg("Successful audit");
        }
@@ -1462,16 +1086,11 @@
        agentUserListVO.setIsLogin(user.getIsLogin());
        agentUserListVO.setRegAddress(user.getRegAddress());
        agentUserListVO.setIsActive(user.getIsActive());
        agentUserListVO.setImg1Key(user.getImg1Key());
        agentUserListVO.setImg2Key(user.getImg2Key());
        agentUserListVO.setImg3Key(user.getImg3Key());
        agentUserListVO.setUserAmt(user.getUserAmt());
        agentUserListVO.setEnableAmt(user.getEnableAmt());
        agentUserListVO.setUserIndexAmt(user.getUserIndexAmt());
        agentUserListVO.setEnableIndexAmt(user.getEnableIndexAmt());
        agentUserListVO.setUserFuturesAmt(user.getUserFutAmt());
        agentUserListVO.setEnableFuturesAmt(user.getEnableFutAmt());
        PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId());
@@ -1481,7 +1100,6 @@
        agentUserListVO.setAllFreezAmt(allFreezAmt);
        BigDecimal forceLine = forcePercent.multiply(allFreezAmt);
        forceLine = forceLine.add(user.getEnableAmt());
        agentUserListVO.setForceLine(forceLine);
@@ -1490,7 +1108,7 @@
        agentUserListVO.setAllIndexFreezAmt(indexPositionVO.getAllIndexFreezAmt());
        BigDecimal indexForceLine = indexForcePercent.multiply(indexPositionVO.getAllIndexFreezAmt());
        indexForceLine = indexForceLine.add(user.getEnableIndexAmt());
        agentUserListVO.setIndexForceLine(indexForceLine);
@@ -1499,16 +1117,8 @@
        agentUserListVO.setAllFuturesProfitAndLose(futuresPositionVO.getAllFuturesProfitAndLose());
        BigDecimal futuresForceLine = futuresForcePercent.multiply(futuresPositionVO.getAllFuturesDepositAmt());
        futuresForceLine = futuresForceLine.add(user.getEnableFutAmt());
        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;
    }
@@ -1535,61 +1145,6 @@
        userInfoVO.setIsActive(user.getIsActive());
        userInfoVO.setAuthMsg(user.getAuthMsg());
        userInfoVO.setVaildNumber(user.getVaildNumber());
        userInfoVO.setTradingAmount(user.getTradingAmount());
        userInfoVO.setEnableAmt(user.getEnableAmt());
        userInfoVO.setEnableAmtToUsdt(user.getEnableAmt().
                divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN).toString());
        PositionVO positionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId(), EStockType.IN.getCode());
        userInfoVO.setAllFreezAmt(positionVO.getAllFreezAmt());
        userInfoVO.setAllFreezAmtToUsdt(positionVO.getAllFreezAmt()
                .divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN).toString());
        BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose();
        // 卢比股票的盈利
        userInfoVO.setAllProfitAndLose(allProfitAndLose);
        userInfoVO.setAllProfitAndLoseToUsdt(allProfitAndLose.
                divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN).toString());
        BigDecimal userAllAmt = user.getUserAmt();
        userAllAmt = userAllAmt.add(allProfitAndLose);
        userInfoVO.setUserAmt(userAllAmt);
        userInfoVO.setUserAmtToUsdt(user.getUserAmt().
                divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN).toString());
        PositionVO usPositionVO = this.iUserPositionService.findUserPositionAllProfitAndLose(user.getId(), EStockType.US.getCode());
        userInfoVO.setUsAllFreezAmt(usPositionVO.getAllFreezAmt());
        BigDecimal usAllProfitAndLose = positionVO.getAllProfitAndLose();
        userInfoVO.setUsAllProfitAndLose(usAllProfitAndLose);
        userInfoVO.setAllProfitAndLoseToUsdt(usAllProfitAndLose.
                divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN).toString());
        BigDecimal userAllIndexAmt = user.getUserIndexAmt();
        userAllIndexAmt = userAllIndexAmt.add(usAllProfitAndLose);
        userInfoVO.setUserIndexAmt(userAllIndexAmt);
        userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt());
        BigDecimal totleAssets = user.getUserAmt().
                divide(siteSetting.getExchangeRate()).
                setScale(2, BigDecimal.ROUND_DOWN)
                .add(user.getUserIndexAmt());
        userInfoVO.setTotalAssets(totleAssets.setScale(2).toString());
        return userInfoVO;
    }
@@ -1617,20 +1172,21 @@
        userMapper.updateUserAmt(amt, user_id);
    }
//    @Override
//    public ServerResponse queryMyOption(String code, HttpServletRequest request) {
//        User user = getCurrentUser(request);
//
//        if (user == null) {
//            return ServerResponse.createBySuccessMsg("請先登錄");
//        }
//        String stockcode = code;
//        if(code.contains("hf")){
//            stockcode = code.split("_")[1].toString();
//        }
//        stockcode = stockcode.replace("sh","").replace("sz","").replace("bj","");
//        return this.iStockOptionService.isOption(user.getId(), stockcode);
//    }
    @Override
    public ServerResponse queryMyOption(String code, HttpServletRequest request) {
        User user = getCurrentUser(request);
        return this.iStockOptionService.isOption(user.getId(), code);
    }
    @Override
    public ServerResponse getMoenyLog(String type,HttpServletRequest request) {
        User user = getCurrentUser(request);
        QueryWrapper<MoneyLog>  queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type",type);
        queryWrapper.eq("user_id",user.getId());
        return  ServerResponse.createBySuccess(mapper.selectList(queryWrapper));
    }
}