| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.Repository.ExchangeRateRepository; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockAiMapper; |
| | |
| | | import com.nq.enums.*; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.vo.stock.ai.StockAIOrderPositionVO; |
| | | import com.nq.vo.stock.ai.StockAiOrderTypeVO; |
| | | import com.nq.vo.stock.ai.StockAiOrderVO; |
| | | import com.nq.vo.stock.ai.StockAiVO; |
| | |
| | | iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), user.getId(), EUserAssets.BUY_AI, buyNum); |
| | | StockAIOrder stockAIOrder = new StockAIOrder(); |
| | | stockAIOrder.setUserId(user.getId()); |
| | | stockAIOrder.setStockAiId(id); |
| | | stockAIOrder.setStockAiId(id.intValue()); |
| | | stockAIOrder.setBuyDate(new Date()); |
| | | stockAIOrder.setBuyAmount(buyNum); |
| | | stockAIOrder.setRemainAmount(buyNum); |
| | |
| | | BigDecimal earnings = model.getCoverPrice().subtract(model.getStockPrice()).multiply(BigDecimal.valueOf(model.getStockNum())); |
| | | model.setCreatDate(new Date()); |
| | | model.setEarnings(earnings); |
| | | model.setStatus(0); |
| | | stockAIOrder.setRealEarning(stockAIOrder.getRealEarning().add(earnings)); |
| | | |
| | | //保存 |
| | |
| | | } |
| | | //结算 TODO结算建仓 计算收益 |
| | | /*//所有建仓 |
| | | |
| | | List<StockAIOrderPosition> stockAIOrderPositionList = stockAiOrderPositionMapper |
| | | .selectList(new QueryWrapper<StockAIOrderPosition>() |
| | | .eq("stock_ai_order_id", id)); |
| | |
| | | amount = amount.add(earningsSUM); |
| | | }*/ |
| | | StockAI stockAI = stockAiMapper.selectById(stockAIOrder.getStockAiId()); |
| | | //结算修改为平仓状态 |
| | | stockAiOrderPositionMapper.updateStatusByOrderId(stockAIOrder.getId(), 1); |
| | | //归还本金 |
| | | iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.AI_SETTLEMENT, stockAIOrder.getBuyAmount()); |
| | | //收益 |
| | |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | /** |
| | | * 建仓列表 |
| | | * 建仓列表 |
| | | * @param pageNum |
| | | * @param pageSize |
| | | * @param stockAiOrderId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ServerResponse getPositionList(Integer pageNum, Integer pageSize, Integer stockAiOrderId) { |
| | | try { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockAIOrderPositionVO> positionVOList = stockAiOrderPositionMapper.getPositionListByOrderId(stockAiOrderId); |
| | | PageInfo<StockAIOrderPositionVO> pageInfo = new PageInfo<>(positionVOList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | log.error("StockAiService getPositionList error", e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | } |