| | |
| | | import com.google.common.collect.Lists; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.utils.*; |
| | | import com.nq.utils.redis.RedisKeyUtil; |
| | | import com.nq.utils.stock.BuyAndSellUtils; |
| | | import com.nq.utils.stock.GeneratePosition; |
| | | import com.nq.utils.stock.GetStayDays; |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | | import com.nq.utils.stock.sina.StockApi; |
| | | import com.nq.utils.timeutil.DateTimeUtil; |
| | | import com.nq.vo.agent.AgentIncomeVO; |
| | |
| | | import com.nq.vo.position.PositionVO; |
| | | import com.nq.vo.position.UserPositionVO; |
| | | import com.nq.vo.stock.StockListVO; |
| | | import com.nq.vo.stock.ai.StockAiOrderTypeVO; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | 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 java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | try { |
| | | synchronized (user.getId()){ |
| | | if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) { |
| | | return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request); |
| | |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | } |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse sell(String positionSn, int doType) { |
| | | try { |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在"); |
| | |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("平仓成功!"); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse sell(String positionSn, int doType, Integer number,HttpServletRequest request) { |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (userPosition == null) { |
| | |
| | | } |
| | | |
| | | private ServerResponse<Object> getObjectServerResponse(HttpServletRequest request, UserPosition userPosition, BigDecimal nowPrice, BigDecimal siitteBuyFee, Stock stock) { |
| | | try { |
| | | userPosition.setSellOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setSellOrderPrice(nowPrice); |
| | | userPosition.setSellOrderTime(new Date()); |
| | |
| | | userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("平仓成功!", request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ServerResponse allSell(HttpServletRequest request, String stockType) throws Exception { |
| | | //判断股票是否在可交易时间段 |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse closingStayTask(UserPosition position, Integer stayDays) throws Exception { |
| | | log.info("=================closingStayTask===================="); |
| | | log.info("修改留仓费,持仓id={},持仓天数={}", position.getId(), stayDays); |
| | |
| | | * @Date: 2022/10/26 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse newStockToPosition(Integer id,BigDecimal amountToBeCovered) { |
| | | try { |
| | | UserStockSubscribe userStockSubscribe = userStockSubscribeMapper.load(id); |
| | | if (userStockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("无该申购记录"); |
| | |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse buyVipQc(String stockCode, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) throws Exception { |
| | | |
| | | /*实名认证开关开启*/ |
| | |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request) throws Exception { |
| | | /*实名认证开关开启*/ |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void stockConstraint(List<UserPosition> list) { |
| | | try { |
| | | //SiteSetting siteSetting = iSiteSettingService.getSiteSetting(); |
| | |
| | | |
| | | //平仓 |
| | | private void extracted(UserPosition position, BigDecimal nowPrice, Stock stock,Integer liquidation) { |
| | | try { |
| | | //-1强平 0未触发 1止损强平 2止盈强平 |
| | | BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.SELL_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(position.getOrderNum())); |
| | |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), position.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | } |
| | | |
| | | |
| | | |
| | | log.info("强制平仓成功,订单id: {}", position.getId()); |
| | | } catch (Exception e) { |
| | | log.info("extracted Exception {}", e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | userPositionVO.setProfitAndLose(BigDecimal.ZERO); |
| | | userPositionVO.setProfitAndLoseParent("0%"); |
| | | userPositionVO.setProfitAndLoseParent2(BigDecimal.ZERO); |
| | | userPositionVO.setIsListed(false); |
| | | }else{ |
| | | userPositionVO.setIsListed(true); |
| | |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse checkDz(Integer id, Integer checkType, Integer orderNum, HttpServletRequest request) { |
| | | try { |
| | | UserPositionCheckDz userPositionCheckDz = userPositionCheckDzService.getById(id); |
| | | if (userPositionCheckDz == null) { |
| | | return ServerResponse.createByErrorMsg("订单不存在", request); |
| | | } |
| | | if (userPositionCheckDz.getCheckType() != 0) { |
| | | return ServerResponse.createByErrorMsg("订单已审核", request); |
| | | } |
| | | if (checkType == 2) { |
| | | userPositionCheckDz.setCheckType(checkType); |
| | | userPositionCheckDzService.updateById(userPositionCheckDz); |
| | | return ServerResponse.createBySuccess("审核成功", request); |
| | | } |
| | | User user = userMapper.selectById(userPositionCheckDz.getUserId()); |
| | | |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId())); |
| | | |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stockDz.getStockType(), user.getId()); |
| | | if (userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0) { |
| | | return ServerResponse.createByErrorMsg("用户账户有待补资金未补齐,审核失败", request); |
| | | } |
| | | |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("股票价格0,请重试", request); |
| | | } |
| | | userPositionCheckDz.setOrderNum(orderNum); |
| | | userPositionCheckDz.setOrderTotalPrice(nowPrice.multiply(new BigDecimal(orderNum.intValue()))); |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(userPositionCheckDz.getOrderNum())); |
| | | 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); |
| | | } |
| | | userPositionCheckDz.setCheckType(checkType); |
| | | userPositionCheckDzService.updateById(userPositionCheckDz); |
| | | UserPosition userPosition = Convert.convert(UserPosition.class, userPositionCheckDz); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | userPosition.setId(null); |
| | | userPosition.setDzId(stockDz.getId()); |
| | | userPositionMapper.insert(userPosition); |
| | | userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓", request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |