| | |
| | | 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.nq.dao.*; |
| | |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>() |
| | | .eq(StockSubscribe::getCode, userPosition.getStockCode())); |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | return ServerResponse.createByErrorMsg("股票未上市,不能平仓", request); |
| | | } |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("股票不存在,平仓失败", request); |
| | | } |
| | | Boolean b = tradingHourService.timeCheck(userPosition.getStockCode()); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request); |
| | | } |
| | | if(userPosition.getPositionType() == 3){ |
| | | StockDz stockDz = stockDzMapper.selectOne(new LambdaQueryWrapper<StockDz>().eq(StockDz::getStockCode, userPosition.getStockCode())); |
| | | StockDz stockDz = stockDzMapper.selectOne(new LambdaQueryWrapper<StockDz>().eq(StockDz::getId, userPosition.getDzId())); |
| | | LocalDateTime buyOrderLocalDateTime = LocalDateTime.ofInstant(userPosition.getBuyOrderTime().toInstant(), ZoneId.systemDefault()); |
| | | // 计算天数差 |
| | | long daysBetween = ChronoUnit.DAYS.between(buyOrderLocalDateTime, LocalDateTime.now()); |
| | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | return ServerResponse.createByErrorMsg("this order is closed " + userPosition.getLockMsg()); |
| | | } |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | if (!priceServices.isLimitDownSell(stock.getStockCode())) { |
| | | return ServerResponse.createByErrorMsg("股票跌停,无法平仓", request); |
| | | } |
| | |
| | | Integer state, HttpServletRequest request, |
| | | int pageNum, int pageSize, String stockType) { |
| | | User user = this.iUserService.getCurrentUser(request); |
| | | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPosition> userPositions; |
| | | |
| | |
| | | for (UserPosition position : userPositions) { |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode())); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | |
| | | 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); |
| | | userPositionVO.setProfitAndLoseParent("0%"); |
| | | userPositionVO.setIsListed(false); |
| | | }else{ |
| | | userPositionVO.setIsListed(true); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | userPositionVOS.add(userPositionVO); |
| | | } |
| | | } |
| | |
| | | end_time = DateTimeUtil.searchStrToTimestamp(endTime); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | List<Integer> ids = new ArrayList<>(); |
| | | if(null != searchId){ |
| | | ids = getSubordinates(searchId); |
| | | ids.add(searchId); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, |
| | | userId, searchId, positionSn, begin_time, end_time,null); |
| | | userId, ids, positionSn, begin_time, end_time,null); |
| | | |
| | | List<AgentPositionVO> agentPositionVOS = Lists.newArrayList(); |
| | | for (UserPosition position : userPositions) { |
| | |
| | | } |
| | | |
| | | |
| | | List<Integer> ids = new ArrayList<>(); |
| | | if(null != agentId){ |
| | | ids = getSubordinates(agentId); |
| | | ids.add(agentId); |
| | | } |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, Integer.valueOf(1), |
| | | null, agentId, null, begin_time, end_time,null); |
| | | null, ids, null, begin_time, end_time,null); |
| | | |
| | | |
| | | BigDecimal order_fee_amt = new BigDecimal("0"); |
| | |
| | | if (StringUtils.isNotBlank(endTime)) { |
| | | end_time = DateTimeUtil.searchStrToTimestamp(endTime); |
| | | } |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, agentId, positionSn, begin_time, end_time,phone); |
| | | List<Integer> ids = new ArrayList<>(); |
| | | if(null != agentId){ |
| | | ids = getSubordinates(agentId); |
| | | ids.add(agentId); |
| | | } |
| | | |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, ids, positionSn, begin_time, end_time,phone); |
| | | List<AdminPositionVO> adminPositionVOS = Lists.newArrayList(); |
| | | for (UserPosition position : userPositions) { |
| | | AdminPositionVO adminPositionVO = assembleAdminPositionVO(position); |
| | | AgentUser agentUser = agentUserMapper.selectById(adminPositionVO.getAgentId()); |
| | | adminPositionVO.setAgentName(agentUser.getAgentName()); |
| | | User user = userMapper.selectById(adminPositionVO.getUserId()); |
| | | adminPositionVO.setPhone(user.getPhone()); |
| | | adminPositionVOS.add(adminPositionVO); |
| | | } |
| | | PageInfo pageInfo = new PageInfo(userPositions); |
| | | pageInfo.setList(adminPositionVOS); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | public List<Integer> getSubordinates(Integer id) { |
| | | List<AgentUser> agentUsers = agentUserMapper.selectList(new LambdaQueryWrapper<AgentUser>()); |
| | | List<Integer> subordinates = new ArrayList<>(); |
| | | for (AgentUser user : agentUsers) { |
| | | if (id.equals(user.getParentId())) { |
| | | subordinates.add(user.getId()); |
| | | subordinates.addAll(getSubordinates(user.getId())); |
| | | } |
| | | } |
| | | return subordinates; |
| | | } |
| | | |
| | | public int CountPositionNum(Integer state, Integer accountType) { |
| | |
| | | |
| | | private AgentPositionVO assembleAgentPositionVO(UserPosition position) { |
| | | AgentPositionVO agentPositionVO = new AgentPositionVO(); |
| | | |
| | | User user = userMapper.selectById(position.getUserId()); |
| | | if(null != user){ |
| | | AgentUser agentUser = agentUserMapper.selectById(user.getAgentId()); |
| | | agentPositionVO.setPhone(user.getPhone()); |
| | | if(null != agentUser){ |
| | | agentPositionVO.setAgentName(agentUser.getAgentName()); |
| | | } |
| | | } |
| | | agentPositionVO.setId(position.getId()); |
| | | agentPositionVO.setPositionSn(position.getPositionSn()); |
| | | agentPositionVO.setPositionType(position.getPositionType()); |
| | |
| | | * @Date: 2022/10/26 |
| | | */ |
| | | @Override |
| | | public ServerResponse newStockToPosition(Integer id) { |
| | | public ServerResponse newStockToPosition(Integer id,BigDecimal amountToBeCovered) { |
| | | UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id); |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("无该申购记录"); |
| | |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("该新股不存在"); |
| | | } |
| | | if (userStockSubscribe.getStatus() == 4 || userStockSubscribe.getStatus() == 3 && stockSubscribe.getType() == 2) { |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, userStockSubscribe.getNewCode())); |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("该新股不存在"); |
| | | } |
| | | UserPosition userPosition = new UserPosition(); |
| | | userPosition.setPositionType(1); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(userStockSubscribe.getUserId()); |
| | | userPosition.setNickName(userStockSubscribe.getRealName()); |
| | | userPosition.setAgentId(userStockSubscribe.getAgentId()); |
| | | |
| | | Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockCode, userStockSubscribe.getNewCode())); |
| | | |
| | | UserPosition userPosition = new UserPosition(); |
| | | |
| | | if(null == stock){ |
| | | userPosition.setStockCode(stockSubscribe.getCode()); |
| | | userPosition.setStockSpell(stockSubscribe.getName()); |
| | | }else{ |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setStockName(userStockSubscribe.getNewName()); |
| | | StringBuffer gid = new StringBuffer(); |
| | | gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():""); |
| | | gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild"); |
| | | userPosition.setStockGid(gid.toString()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice()); |
| | | userPosition.setOrderDirection("买涨"); |
| | | } |
| | | |
| | | userPosition.setOrderNum(userStockSubscribe.getApplyNumber()); |
| | | userPosition.setPositionType(1); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(userStockSubscribe.getUserId()); |
| | | userPosition.setNickName(userStockSubscribe.getRealName()); |
| | | userPosition.setAgentId(userStockSubscribe.getAgentId()); |
| | | |
| | | userPosition.setStockName(userStockSubscribe.getNewName()); |
| | | StringBuffer gid = new StringBuffer(); |
| | | gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():""); |
| | | gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild"); |
| | | userPosition.setStockGid(gid.toString()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice()); |
| | | userPosition.setOrderDirection("买涨"); |
| | | |
| | | userPosition.setOrderNum(userStockSubscribe.getApplyNumber()); |
| | | |
| | | |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | |
| | | |
| | | userPosition.setOrderLever(1); |
| | | userPosition.setOrderLever(1); |
| | | |
| | | |
| | | //递延费特殊处理 |
| | | // BigDecimal stayFee = userPosition.getOrderTotalPrice().multiply(siteSetting.getStayFee()); |
| | | BigDecimal stayFee = new BigDecimal(0); |
| | | BigDecimal allStayFee = stayFee.multiply(new BigDecimal(1)); |
| | | userPosition.setOrderStayFee(allStayFee); |
| | | userPosition.setOrderStayDays(1); |
| | | userPosition.setOrderTotalPrice(userStockSubscribe.getBond()); |
| | | //递延费特殊处理 |
| | | // BigDecimal stayFee = userPosition.getOrderTotalPrice().multiply(siteSetting.getStayFee()); |
| | | BigDecimal stayFee = new BigDecimal(0); |
| | | BigDecimal allStayFee = stayFee.multiply(new BigDecimal(1)); |
| | | userPosition.setOrderStayFee(allStayFee); |
| | | userPosition.setOrderStayDays(1); |
| | | userPosition.setOrderTotalPrice(userStockSubscribe.getBond()); |
| | | |
| | | // BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4); |
| | | BigDecimal buy_fee_amt = new BigDecimal(0); |
| | | log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt); |
| | | userPosition.setOrderFee(buy_fee_amt); |
| | | // BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4); |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(userStockSubscribe.getBond()); |
| | | log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt); |
| | | userPosition.setOrderFee(buy_fee_amt); |
| | | |
| | | |
| | | // BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4); |
| | | BigDecimal buy_yhs_amt = new BigDecimal(0); |
| | | log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt); |
| | | userPosition.setOrderSpread(buy_yhs_amt); |
| | | // BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4); |
| | | BigDecimal buy_yhs_amt = new BigDecimal(0); |
| | | log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt); |
| | | userPosition.setOrderSpread(buy_yhs_amt); |
| | | |
| | | BigDecimal spread_rate_amt = new BigDecimal(0); |
| | | userPosition.setSpreadRatePrice(spread_rate_amt); |
| | | BigDecimal spread_rate_amt = new BigDecimal(0); |
| | | userPosition.setSpreadRatePrice(spread_rate_amt); |
| | | |
| | | |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | |
| | | |
| | | BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt); |
| | | userPosition.setAllProfitAndLose(all_profit_and_lose); |
| | | BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt); |
| | | userPosition.setAllProfitAndLose(all_profit_and_lose); |
| | | |
| | | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | |
| | | int ret = 0; |
| | | ret = this.userPositionMapper.insert(userPosition); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), userPosition.getUserId()); |
| | | if(null == userAssets){ |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setAmountToBeCovered(amountToBeCovered); |
| | | userPosition.setNewId(stockSubscribe.getNewlistId()); |
| | | int ret = 0; |
| | | ret = this.userPositionMapper.insert(userPosition); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", userPosition.getUserId()); |
| | | if(null == userAssets){ |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | userAssetsMapper.updateById(userAssets); |
| | | iUserAssetsServices.availablebalanceChange("IN", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | if (ret > 0) { |
| | | userStockSubscribe.setStatus(5); |
| | | userStockSubscribeMapper.update1(userStockSubscribe); |
| | | if (userStockSubscribe.getType() == 1 || userStockSubscribe.getType() == 2) { |
| | | User user = userMapper.selectById(userStockSubscribe.getUserId()); |
| | | ret = userMapper.updateById(user); |
| | | } |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(userPosition.getOrderTotalPrice())); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney()!=null?userAssets.getFreezeMoney().setScale(2,BigDecimal.ROUND_UP):null); |
| | | userAssetsMapper.updateById(userAssets); |
| | | if (ret > 0) { |
| | | userStockSubscribe.setStatus(5); |
| | | userStockSubscribeMapper.update1(userStockSubscribe); |
| | | if (userStockSubscribe.getType() == 1 || userStockSubscribe.getType() == 2) { |
| | | User user = userMapper.selectById(userStockSubscribe.getUserId()); |
| | | ret = userMapper.updateById(user); |
| | | } |
| | | if (ret > 0) { |
| | | return ServerResponse.createBySuccessMsg("新股转持仓成功"); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | return ServerResponse.createBySuccessMsg("新股转持仓成功"); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | //判断审核开关 |
| | | if(stockDz.getSwitchType() == 1){ |
| | | UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt); |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | | UserPositionCheckDz userPositionCheckDz = Convert.convert(UserPositionCheckDz.class, userPosition); |
| | | userPositionCheckDz.setDzId(dzId); |
| | | userPositionCheckDzService.save(userPositionCheckDz); |
| | |
| | | } |
| | | |
| | | // 创建UserPosition对象 |
| | | UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt); |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | | userPositionMapper.insert(userPosition); |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(buyAmt); |
| | | userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange("IN", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | } |
| | | |
| | | private UserPosition getUserPosition(Integer num, User user, StockDz stockDz, BigDecimal nowPrice, Stock stock, BigDecimal buyAmt) { |
| | | private UserPosition getUserPosition(Integer dzId,Integer num, User user, StockDz stockDz, BigDecimal nowPrice, Stock stock, BigDecimal buyAmt) { |
| | | UserPosition userPosition = new UserPosition(); |
| | | userPosition.setPositionType(3); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setDzId(dzId); |
| | | return userPosition; |
| | | } |
| | | |