| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.*; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | |
| | | 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) { |
| | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | |
| | | 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(); |
| | |
| | | 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); |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | | |
| | | |
| | | |
| | | |
| | |
| | | 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){ |
| | |
| | | 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); |
| | | |
| | |
| | | |
| | | 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"); |
| | | } |
| | |
| | | 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); |
| | | |
| | |
| | | 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) |
| | | // ) |
| | | // ); |
| | | // 获取当前日期 |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // 获取当前周的周一和周日 |
| | | LocalDate startOfWeek = today.with(DayOfWeek.MONDAY); // 本周周一 |
| | | LocalDate endOfWeek = today.with(DayOfWeek.SUNDAY); // 本周周日 |
| | | |
| | | // 获取当前周周一和周日的开始时间和结束时间 |
| | | LocalDateTime startOfWeekTime = startOfWeek.atStartOfDay(); // 周一 00:00:00 |
| | | LocalDateTime endOfWeekTime = endOfWeek.atTime(LocalTime.MAX); // 周日 23:59:59.999999999 |
| | | |
| | | // 转换为Date类型 |
| | | Date startOfWeekDate = Date.from(startOfWeekTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | Date endOfWeekDate = Date.from(endOfWeekTime.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", startOfWeekDate) // 过滤sell_order_time >= 本周周一 |
| | | .le("sell_order_time", endOfWeekDate) // 过滤sell_order_time <= 本周周日 |
| | | .or() |
| | | .isNull("sell_order_id") |
| | | .ge("buy_order_time", startOfWeekDate) // 过滤buy_order_time >= 本周周一 |
| | | .le("buy_order_time", endOfWeekDate) // 过滤buy_order_time <= 本周周日 |
| | | ) |
| | | ); |
| | | 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); |
| | | } |
| | | } |
| | | |