| | |
| | | package com.nq.service.impl; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.nq.dao.*; |
| | |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.locks.Lock; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | IStockConfigServices iStockConfigServices; |
| | | |
| | | @Autowired |
| | | UserPositionCheckDzService userPositionCheckDzService; |
| | | |
| | | |
| | | |
| | | @Transactional |
| | |
| | | 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()); |
| | |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("无该申购记录"); |
| | | } |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("code", userStockSubscribe.getNewCode()).eq("type",userStockSubscribe.getType())); |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("newlist_id", userStockSubscribe.getNewStockId())); |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("该新股不存在"); |
| | | } |
| | |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setStockName(userStockSubscribe.getNewName()); |
| | | userPosition.setStockGid(stockSubscribe.getStockType() + userStockSubscribe.getNewCode()); |
| | | |
| | | 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.setIsLock(Integer.valueOf(0)); |
| | | |
| | | |
| | | userPosition.setOrderLever(10); |
| | | userPosition.setOrderLever(1); |
| | | |
| | | |
| | | //递延费特殊处理 |
| | |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | 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); |
| | |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public ServerResponse buyDz(String stockCode, String password, Integer num, HttpServletRequest request) throws Exception { |
| | | public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request) throws Exception { |
| | | /*实名认证开关开启*/ |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) { |
| | | return ServerResponse.createByErrorMsg("Order failed, please first real name authentication"); |
| | | } |
| | |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("stock_code", stockCode)); |
| | | if (!Objects.equals(stockDz.getPassword(), password)) { |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", dzId)); |
| | | if (StringUtils.isNotEmpty(stockDz.getPassword()) && !Objects.equals(stockDz.getPassword(), password)) { |
| | | return ServerResponse.createByErrorMsg("密码错误", request); |
| | | } |
| | | if (stockDz.getIsLock() != 0) { |
| | |
| | | if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){ |
| | | return ServerResponse.createByErrorMsg("不在内幕交易时间之内", request); |
| | | } |
| | | BigDecimal nowPrice = priceServices.getNowPrice(stockCode).multiply(stockDz.getDiscount()); |
| | | // BigDecimal nowPrice = priceServices.getNowPrice(stockDz.getStockCode()).multiply(stockDz.getDiscount()); |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("股票价格0,请重试", request); |
| | |
| | | return ServerResponse.createByErrorMsg("最小购买数据" + stockDz.getStockNum(), request); |
| | | } |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num.intValue())); |
| | | BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100)); |
| | | BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance()); |
| | | BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100)); |
| | | BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance()); |
| | | if (buyAmt.compareTo(availableBalance) > 0) { |
| | | return ServerResponse.createByErrorMsg("订单失败,配资不足", request); |
| | | } |
| | | |
| | | //判断审核开关 |
| | | if(stockDz.getSwitchType() == 1){ |
| | | UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt); |
| | | UserPositionCheckDz userPositionCheckDz = Convert.convert(UserPositionCheckDz.class, userPosition); |
| | | userPositionCheckDz.setDzId(dzId); |
| | | userPositionCheckDzService.save(userPositionCheckDz); |
| | | return ServerResponse.createBySuccess("购买成功,等待审核", request); |
| | | } |
| | | |
| | | // 创建UserPosition对象 |
| | | UserPosition userPosition = getUserPosition(num, user, stockDz, nowPrice, stock, buyAmt); |
| | | userPositionMapper.insert(userPosition); |
| | | userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | } |
| | | |
| | | private UserPosition getUserPosition(Integer num, User user, StockDz stockDz, BigDecimal nowPrice, Stock stock, BigDecimal buyAmt) { |
| | | UserPosition userPosition = new UserPosition(); |
| | | userPosition.setPositionType(3); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | |
| | | userPosition.setAllProfitAndLose(all_profit_and_lose); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | return userPosition; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional |
| | | public void stockConstraint(List<UserPosition> list) { |
| | | SiteSetting siteSetting = iSiteSettingService.getSiteSetting(); |
| | | try { |
| | | SiteSetting siteSetting = iSiteSettingService.getSiteSetting(); |
| | | |
| | | for (UserPosition position : list) { |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, position.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | continue; |
| | | } |
| | | //平仓检查 |
| | | Result result = getResult(position); |
| | | if (result == null) continue; |
| | | for (UserPosition position : list) { |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, position.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | continue; |
| | | } |
| | | //平仓检查 |
| | | Result result = getResult(position); |
| | | if (result == null) continue; |
| | | |
| | | Integer liquidation = 0; |
| | | liquidation = isLiquidation(position, result.signum, result.profit, liquidation); |
| | | if(liquidation != 0){ |
| | | extracted(position, result.nowPrice, result.stock,liquidation); |
| | | Integer liquidation = 0; |
| | | liquidation = isLiquidation(position, result.signum, result.profit, liquidation); |
| | | if(liquidation != 0){ |
| | | extracted(position, result.nowPrice, result.stock,liquidation); |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | log.error("强制平仓--->错误",e); |
| | | } |
| | | } |
| | | |