| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.google.common.collect.Lists; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.config.StockPoll; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EConfigKey; |
| | | 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.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; |
| | |
| | | import com.nq.utils.redis.CookieUtils; |
| | | import com.nq.utils.redis.JsonUtil; |
| | | import com.nq.utils.redis.RedisShardedPoolUtils; |
| | | import com.nq.utils.stock.sina.StockApi; |
| | | import com.nq.vo.agent.AgentUserListVO; |
| | | import com.nq.vo.futuresposition.FuturesPositionVO; |
| | | 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.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; |
| | |
| | | @Resource |
| | | StockOptionMapper stockOptionMapper; |
| | | |
| | | @Autowired |
| | | DkMapper dkMapper; |
| | | |
| | | |
| | | @Autowired |
| | | IUserService userService; |
| | |
| | | StockMapper stockMapper; |
| | | @Autowired |
| | | IUserPositionService iUserPositionService; |
| | | @Autowired |
| | | IUserBankService iUserBankService; |
| | | @Resource |
| | | AgentUserMapper agentUserMapper; |
| | | @Resource |
| | |
| | | IUserIndexPositionService iUserIndexPositionService; |
| | | @Autowired |
| | | ISiteIndexSettingService iSiteIndexSettingService; |
| | | @Autowired |
| | | StockPoll stockPoll; |
| | | |
| | | @Autowired |
| | | StockSubscribeMapper stockSubscribeMapper; |
| | |
| | | MoneyLogMapper mapper; |
| | | |
| | | @Resource |
| | | IUserPositionService userPositionService; |
| | | @Resource |
| | | SiteAmtTransLogMapper siteAmtTransLogMapper; |
| | | @Autowired |
| | | IUserFuturesPositionService iUserFuturesPositionService; |
| | | @Autowired |
| | | ISiteFuturesSettingService iSiteFuturesSettingService; |
| | | @Autowired |
| | | IStockFuturesService iStockFuturesService; |
| | | |
| | | @Autowired |
| | | ISiteMessageService iSiteMessageService; |
| | | |
| | | @Autowired |
| | | private ApplyLeverMapper applyLeverMapper; |
| | |
| | | |
| | | @Autowired |
| | | IUserService iUserService; |
| | | |
| | | @Autowired |
| | | IStockConfigServices iStockConfigServices; |
| | | |
| | | |
| | | public ServerResponse reg(String yzmCode, String agentCode, String phone, String userPwd, HttpServletRequest request) { |
| | |
| | | user.setRegAddress(uadd); |
| | | |
| | | user.setIsLogin(Integer.valueOf(0)); |
| | | |
| | | user.setRealType(0); |
| | | int insertCount = this.userMapper.insert(user); |
| | | |
| | | if (insertCount > 0) { |
| | |
| | | if (user.getIsLogin().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("登录失败。账户锁定",request); |
| | | } |
| | | userAssetsServices.assetsByTypeAndUserId(EStockType.IN.getCode(),user.getId()); |
| | | //新增账号资产 |
| | | userAssetsServices.addUserAssetsListByUserId(user.getId()); |
| | | this.iSiteLoginLogService.saveLog(user, request); |
| | | return ServerResponse.createBySuccess(user); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public ServerResponse auth(String realName, String idCard, String vaildNumber, String img1key, String img2key, String img3key, HttpServletRequest request) { |
| | | public ServerResponse auth(String realName, String idCard, Integer realType, String vaildNumber, String img1key, String img2key, String img3key, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(realName) || |
| | | StringUtils.isBlank(idCard)) { |
| | | |
| | |
| | | user.setRealName(realName); |
| | | user.setIdCard(idCard); |
| | | user.setVaildNumber(vaildNumber); |
| | | user.setRealType(realType); |
| | | |
| | | user.setIsActive(Integer.valueOf(1)); |
| | | |
| | |
| | | RUserAssets rUserAssets = new RUserAssets(); |
| | | UserAssets userAssets = userAssetsList.get(i); |
| | | // 浮动盈亏 |
| | | String profitAndLose = getProfitAndLose(userId).toString(); |
| | | String profitAndLose = getProfitAndLose(userId, userAssets.getAccectType()).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); |
| | |
| | | |
| | | |
| | | |
| | | RUserAssets rUserAssets = new 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.setFreezeMoneyUSD(allFreeMoney.setScale(s,BigDecimal.ROUND_DOWN).toString()); |
| | | rUserAssets.setSymbol("$"); |
| | | rUserAssets.setSymbolCode("USD"); |
| | | rUserAssetsList.add(rUserAssets); |
| | | rUserAssetsList.add(rUserAssets);*/ |
| | | |
| | | return ServerResponse.createBySuccess(rUserAssetsList); |
| | | } |
| | | |
| | | public BigDecimal getProfitAndLose(Integer userId){ |
| | | public BigDecimal getProfitAndLose(Integer userId, String accectType){ |
| | | List<UserPosition> userPositions; |
| | | userPositions = userPositionMapper. |
| | | findMyPositionByCodeAndSpell(userId, |
| | | userPositions = userPositionMapper.findMyPositionByCodeAndSpell(userId, |
| | | "","", |
| | | 0, "IN"); |
| | | 0, accectType); |
| | | |
| | | |
| | | List<UserPositionVO> userPositionVOS = Lists.newArrayList(); |
| | |
| | | |
| | | @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); |
| | | try { |
| | | User user = userService.getCurrentUser(request); |
| | | UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId()); |
| | | BigDecimal amtBig = new BigDecimal(amt).abs(); |
| | | |
| | | // 转换手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.EXCHANGE_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(amtBig); |
| | | //资金校验 |
| | | BigDecimal needAmt = amtBig.add(orderFree); |
| | | if(formAssets.getAvailableBalance().compareTo(needAmt)<0){ |
| | | return ServerResponse.createByErrorMsg("余额不足", request); |
| | | } |
| | | |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.TRANSFER, amtBig.negate(),fromType+"/"+toType,""); |
| | | //转换金额 |
| | | amtBig = userAssetsServices.exchangeAmountByRate(fromType, toType, amtBig); |
| | | userAssetsServices.availablebalanceChange(toType,user.getId(), EUserAssets.TRANSFER, amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,""); |
| | | |
| | | return ServerResponse.createBySuccess("操作成功", request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | 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(); |
| | | } |
| | | |
| | | |
| | |
| | | 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 -> EStockType.getDefault().getCode().equals(stock.getAccectType())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | 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"); |
| | | } |
| | | try { |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("phone",phone); |
| | | User dbUser = userMapper.selectOne(queryWrapper); |
| | | if (dbUser != null) { |
| | | return ServerResponse.createByErrorMsg("The phone number is registered"); |
| | | } |
| | | |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("phone",phone); |
| | | User dbUser = userMapper.selectOne(queryWrapper); |
| | | if (dbUser != null) { |
| | | return ServerResponse.createByErrorMsg("The phone number is registered"); |
| | | User user = new User(); |
| | | user.setAccountType(accountType); |
| | | user.setPhone(phone); |
| | | 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("模拟用户"); |
| | | } |
| | | |
| | | |
| | | if (agentId != null) { |
| | | AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId); |
| | | user.setAgentName(agentUser.getAgentName()); |
| | | user.setAgentId(agentUser.getId()); |
| | | } |
| | | |
| | | int insertCount = this.userMapper.insert(user); |
| | | dbUser = userMapper.selectOne(queryWrapper); |
| | | userAssetsServices.getAvailableBalance(EStockType.getDefault().getCode(),dbUser.getId() ); |
| | | userAssetsServices.availablebalanceChange(EStockType.getDefault().getCode(),dbUser.getId(),EUserAssets.TOP_UP,new BigDecimal(amt),"",""); |
| | | if (insertCount > 0) { |
| | | return ServerResponse.createBySuccessMsg("Success"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("User addition failure"); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | |
| | | |
| | | User user = new User(); |
| | | user.setAccountType(accountType); |
| | | user.setPhone(phone); |
| | | 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("模拟用户"); |
| | | } |
| | | |
| | | |
| | | if (agentId != null) { |
| | | AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId); |
| | | user.setAgentName(agentUser.getAgentName()); |
| | | user.setAgentId(agentUser.getId()); |
| | | } |
| | | |
| | | 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"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("User addition failure"); |
| | | } |
| | | |
| | | |
| | |
| | | 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 -> EStockType.getDefault().getCode().equals(stock.getAccectType())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse updateAmt(Integer userId, String amt, Integer direction) { |
| | | if (userId == null || amt == null || direction == null) { |
| | | return ServerResponse.createByErrorMsg("The parameter cannot be null"); |
| | |
| | | userInfoVO.setNickName(user.getNickName()); |
| | | userInfoVO.setRealName(user.getRealName()); |
| | | userInfoVO.setIdCard(user.getIdCard()); |
| | | userInfoVO.setRealType(user.getRealType()); |
| | | userInfoVO.setAccountType(user.getAccountType()); |
| | | userInfoVO.setRecomPhone(user.getRecomPhone()); |
| | | userInfoVO.setIsLock(user.getIsLock()); |
| | |
| | | userInfoVO.setIsActive(user.getIsActive()); |
| | | userInfoVO.setAuthMsg(user.getAuthMsg()); |
| | | userInfoVO.setVaildNumber(user.getVaildNumber()); |
| | | |
| | | userInfoVO.setLoanLimit(user.getLoanLimit()); |
| | | userInfoVO.setCreditScore(user.getCreditScore()); |
| | | //查询代还款金额 |
| | | BigDecimal spMoney = dkMapper.sumSpMoneyByUserIdAndRStatus(String.valueOf(user.getId())); |
| | | userInfoVO.setRefundAmount(spMoney); |
| | | return userInfoVO; |
| | | } |
| | | |