package com.nq.service.impl; import com.nq.dao.*; import com.nq.pojo.*; import com.nq.service.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.collect.Lists; import com.nq.common.ServerResponse; import com.nq.utils.CurrencyUtils; import com.nq.utils.timeutil.DateTimeUtil; import com.nq.utils.KeyUtils; import com.nq.utils.redis.JsonUtil; import com.nq.utils.stock.BuyAndSellUtils; import com.nq.vo.agent.AgentIncomeVO; import com.nq.vo.indexposition.AdminIndexPositionVO; import com.nq.vo.indexposition.AgentIndexPositionVO; import com.nq.vo.indexposition.IndexPositionProfitVO; import com.nq.vo.indexposition.IndexPositionVO; import com.nq.vo.indexposition.UserIndexPositionVO; import com.nq.vo.stock.MarketVO; import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Date; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service("iUserIndexPositionService") public class UserIndexPositionServiceImpl implements IUserIndexPositionService { private static final Logger log = LoggerFactory.getLogger(UserIndexPositionServiceImpl.class); @Resource UserIndexPositionMapper userIndexPositionMapper; @Autowired IUserService iUserService; @Autowired IStockIndexService iStockIndexService; @Autowired ISiteIndexSettingService iSiteIndexSettingService; @Resource UserMapper userMapper; @Resource UserCashDetailMapper userCashDetailMapper; @Autowired IAgentUserService iAgentUserService; @Resource AgentUserMapper agentUserMapper; @Autowired ISiteProductService iSiteProductService; @Autowired IUserIndexPositionService iUserIndexPositionService; @Resource SiteTaskLogMapper siteTaskLogMapper; @Autowired CurrencyUtils currencyUtils; @Transactional public ServerResponse buyIndex(Integer indexId, Integer buyNum, Integer buyType, Integer lever,BigDecimal profitTarget,BigDecimal stopTarget, HttpServletRequest request) throws Exception { return ServerResponse.createBySuccess("Order successful"); } /** * 挂单指数 * @param indexId * @param buyNum * @param buyType * @param lever * @param userId * @return * @throws Exception */ @Transactional public ServerResponse buyIndexOrder(Integer indexId, Integer buyNum, Integer buyType, Integer lever,BigDecimal profitTarget,BigDecimal stopTarget,Integer userId) throws Exception { if (indexId == null || buyNum == null || buyType == null) { return ServerResponse.createByErrorMsg("参数不能为空"); } User user = this.userMapper.selectById(userId); /*实名认证开关开启*/ SiteProduct siteProduct = iSiteProductService.getProductSetting(); if (siteProduct.getRealNameDisplay() && (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCard()))) { return ServerResponse.createByErrorMsg("下单失败,请先实名认证"); } if(siteProduct.getHolidayDisplay()){ return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); } log.info("用户 {} 下单, 指数id = {} ,数量 = {} 手 , 方向 = {} , 杠杆 = {}", new Object[]{user .getId(), indexId, buyNum, buyType, lever}); if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { log.error("用户 {} 已被锁定", user.getId()); return ServerResponse.createByErrorMsg("下单失败,账户已被锁定"); } SiteIndexSetting siteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting(); if (siteIndexSetting == null) { log.error("下单出错,指数设置表不存在"); return ServerResponse.createByErrorMsg("下单失败,系统设置错误"); } StockIndex stockIndex = this.iStockIndexService.selectIndexById(indexId); if (stockIndex.getIndexGid().contains("us")){ String am_begin = siteIndexSetting.getTransAmBeginUs(); String am_end = siteIndexSetting.getTransAmEndUs(); String pm_begin = siteIndexSetting.getTransPmBeginUs(); String pm_end = siteIndexSetting.getTransPmEndUs(); boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); if (!am_flag && !pm_flag) { return ServerResponse.createByErrorMsg("下单失败,不在交易时段内"); } }else { String am_begin = siteIndexSetting.getTransAmBegin(); String am_end = siteIndexSetting.getTransAmEnd(); String pm_begin = siteIndexSetting.getTransPmBegin(); String pm_end = siteIndexSetting.getTransPmEnd(); boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); if (!am_flag && !pm_flag) { return ServerResponse.createByErrorMsg("下单失败,不在交易时段内"); } } if (stockIndex == null) { log.error("下单出错,指数不存在"); return ServerResponse.createByErrorMsg("指数不存在"); } if (1 != stockIndex.getTransState().intValue()) { log.error("下单出错,指数未开启交易"); return ServerResponse.createByErrorMsg("该指数不能交易"); } //保证金= 指数保证金*数量/杠杆倍数 BigDecimal all_deposit_amt = (new BigDecimal(stockIndex.getDepositAmt().intValue())).multiply(new BigDecimal(buyNum.intValue())).divide(new BigDecimal(lever)).setScale(4,2); return ServerResponse.createBySuccess("Order successful"); } /** * 指数交易止盈止损平仓 * * * @return */ @Override public ServerResponse indexPositiontask(){ List userIdList = this.userIndexPositionMapper.findDistinctUserIdList(); log.info("当前有指数持仓单的用户数量 为 {}", Integer.valueOf(userIdList.size())); SiteIndexSetting SiteIndexSetting = this.iSiteIndexSettingService.getSiteIndexSetting(); BigDecimal buyMaxPercent = SiteIndexSetting.getBuyMaxPercent(); BigDecimal forceSellPercent = SiteIndexSetting.getForceSellPercent(); // BigDecimal force_stop_percent = SiteIndexSetting.ge(); for (int i = 0; i < userIdList.size(); i++) { log.info("====================="); Integer userId = (Integer)userIdList.get(i); User user = this.userMapper.selectById(userId); if(user == null){ continue; } List userindexPositions = this.iUserIndexPositionService.findIndexPositionByUserIdAndSellPriceIsNull(userId); log.info("用户id = {} 姓名 = {} 指数持仓中订单数: {}", new Object[] { userId, user.getRealName(), Integer.valueOf(userindexPositions.size()) }); BigDecimal all_freez_amt = new BigDecimal("0"); for (UserIndexPosition userIndexPosition : userindexPositions) { // BigDecimal profitAndLose = positionProfitVO.getProfitAndLose(); MarketVO marketVO = this.iStockIndexService.querySingleIndex(userIndexPosition.getIndexGid()); String nowPrice = marketVO.getNowPrice(); if (nowPrice == null){ nowPrice = String.valueOf(0); } if(userIndexPosition.getProfitTargetPrice()!=null && userIndexPosition.getProfitTargetPrice().compareTo(new BigDecimal(nowPrice)) <= 0 ||userIndexPosition.getStopTargetPrice() != null && userIndexPosition.getStopTargetPrice().compareTo(new BigDecimal(nowPrice)) >= 0) { try { this.iUserIndexPositionService.sellIndex(userIndexPosition.getPositionSn(), 0); User user1 = this.userMapper.selectById(userId); SiteTaskLog siteTaskLog = new SiteTaskLog(); siteTaskLog.setTaskType("指数止盈止损强平任务-指数持仓"); String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户"; String tasktarget = "此次强平订单号为:" + userIndexPosition.getPositionSn(); siteTaskLog.setTaskTarget(tasktarget); siteTaskLog.setAddTime(new Date()); siteTaskLog.setIsSuccess(Integer.valueOf(0)); siteTaskLog.setErrorMsg(""); int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog); if (insertTaskCount > 0) { log.info("指数止盈止损强平任务-指数持仓 task任务成功"); } else { log.info("指数止盈止损强平任务-指数持仓 task任务保存失败"); } } catch (Exception e) { log.error("【指数止盈止损强平任务】强制平仓失败..."); } } } log.info("=========止盈止损定时任务============"); } return null; } @Override public ServerResponse del(Integer positionId) { if (positionId == null) { return ServerResponse.createByErrorMsg("id不能为空"); } UserIndexPosition position = this.userIndexPositionMapper.selectByPrimaryKey(positionId); if (position == null) { ServerResponse.createByErrorMsg("该持仓不存在"); } int updateCount = this.userIndexPositionMapper.deleteByPrimaryKey(positionId); if (updateCount > 0) { return ServerResponse.createBySuccessMsg("删除成功"); } return ServerResponse.createByErrorMsg("删除失败"); } @Transactional public ServerResponse sellIndex(String positionSn, int doType) throws Exception { log.info("【用户交易平仓指数】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType)); return ServerResponse.createBySuccessMsg("Closed position successfully!"); } public ServerResponse lock(Integer positionId, Integer state, String lockMsg) { if (positionId == null || state == null) { return ServerResponse.createByErrorMsg("参数不能为空"); } UserIndexPosition userIndexPosition = this.userIndexPositionMapper.selectByPrimaryKey(positionId); if (userIndexPosition == null) { return ServerResponse.createByErrorMsg("持仓不存在"); } if (userIndexPosition.getSellOrderPrice() != null) { return ServerResponse.createByErrorMsg("平仓单不能锁仓"); } if (state.intValue() == 1 && StringUtils.isBlank(lockMsg)) { return ServerResponse.createByErrorMsg("锁仓提示信息必填"); } if (state.intValue() == 1) { userIndexPosition.setIsLock(Integer.valueOf(1)); userIndexPosition.setLockMsg(lockMsg); } else { userIndexPosition.setIsLock(Integer.valueOf(0)); } int updateCount = this.userIndexPositionMapper.updateByPrimaryKeySelective(userIndexPosition); if (updateCount > 0) { return ServerResponse.createBySuccessMsg("操作成功"); } return ServerResponse.createByErrorMsg("操作失败"); } public ServerResponse listByAgent(Integer positionType, Integer state, Integer userId, Integer agentId, String positionSn, String beginTime, String endTime, HttpServletRequest request, int pageNum, int pageSize) { AgentUser currentAgent = this.iAgentUserService.getCurrentAgent(request); if (agentId != null) { AgentUser agentUser = this.agentUserMapper.selectByPrimaryKey(agentId); if (agentUser.getParentId() != currentAgent.getId()) { return ServerResponse.createByErrorMsg("不能查询非下级代理用户持仓"); } } Integer searchId = null; if (agentId == null) { searchId = currentAgent.getId(); } else { searchId = agentId; } Timestamp begin_time = null; if (StringUtils.isNotBlank(beginTime)) { begin_time = DateTimeUtil.searchStrToTimestamp(beginTime); } Timestamp end_time = null; if (StringUtils.isNotBlank(endTime)) { end_time = DateTimeUtil.searchStrToTimestamp(endTime); } PageHelper.startPage(pageNum, pageSize); List userIndexPositions = this.userIndexPositionMapper.listByAgent(positionType, state, userId, searchId, positionSn, begin_time, end_time); List agentIndexPositionVOS = Lists.newArrayList(); for (UserIndexPosition userIndexPosition : userIndexPositions) { AgentIndexPositionVO agentIndexPositionVO = assembleAgentIndexPositionVO(userIndexPosition); agentIndexPositionVOS.add(agentIndexPositionVO); } PageInfo pageInfo = new PageInfo(userIndexPositions); pageInfo.setList(agentIndexPositionVOS); return ServerResponse.createBySuccess(pageInfo); } private AgentIndexPositionVO assembleAgentIndexPositionVO(UserIndexPosition userIndexPosition) { AgentIndexPositionVO agentIndexPositionVO = new AgentIndexPositionVO(); agentIndexPositionVO.setId(userIndexPosition.getId()); agentIndexPositionVO.setPositionSn(userIndexPosition.getPositionSn()); agentIndexPositionVO.setPositionType(userIndexPosition.getPositionType()); agentIndexPositionVO.setUserId(userIndexPosition.getUserId()); agentIndexPositionVO.setRealName(userIndexPosition.getRealName()); agentIndexPositionVO.setAgentId(userIndexPosition.getAgentId()); agentIndexPositionVO.setIndexName(userIndexPosition.getIndexName()); agentIndexPositionVO.setIndexCode(userIndexPosition.getIndexCode()); agentIndexPositionVO.setIndexGid(userIndexPosition.getIndexGid()); agentIndexPositionVO.setBuyOrderTime(userIndexPosition.getBuyOrderTime()); agentIndexPositionVO.setBuyOrderPrice(userIndexPosition.getBuyOrderPrice()); agentIndexPositionVO.setSellOrderTime(userIndexPosition.getSellOrderTime()); agentIndexPositionVO.setSellOrderPrice(userIndexPosition.getSellOrderPrice()); agentIndexPositionVO.setOrderDirection(userIndexPosition.getOrderDirection()); agentIndexPositionVO.setOrderNum(userIndexPosition.getOrderNum()); agentIndexPositionVO.setAllDepositAmt(userIndexPosition.getAllDepositAmt()); agentIndexPositionVO.setOrderFee(userIndexPosition.getOrderFee()); agentIndexPositionVO.setOrderStayDays(userIndexPosition.getOrderNum()); agentIndexPositionVO.setEachPoint(userIndexPosition.getEachPoint()); agentIndexPositionVO.setIsLock(userIndexPosition.getIsLock()); agentIndexPositionVO.setLockMsg(userIndexPosition.getLockMsg()); IndexPositionProfitVO indexPositionProfitVO = getIndexPositionProfitVO(userIndexPosition); agentIndexPositionVO.setProfitAndLose(indexPositionProfitVO.getProfitAndLose()); agentIndexPositionVO.setAllProfitAndLose(indexPositionProfitVO.getAllProfitAndLose()); agentIndexPositionVO.setNow_price(indexPositionProfitVO.getNowPrice()); return agentIndexPositionVO; } public ServerResponse listByAdmin(Integer agentId, Integer positionType, Integer state, Integer userId, String positionSn, String beginTime, String endTime, int pageNum, int pageSize) { PageHelper.startPage(pageNum, pageSize); Timestamp begin_time = null; if (StringUtils.isNotBlank(beginTime)) { begin_time = DateTimeUtil.searchStrToTimestamp(beginTime); } Timestamp end_time = null; if (StringUtils.isNotBlank(endTime)) { end_time = DateTimeUtil.searchStrToTimestamp(endTime); } List userIndexPositions = this.userIndexPositionMapper.listByAdmin(positionType, state, userId, agentId, positionSn, begin_time, end_time); List adminIndexPositionVOS = Lists.newArrayList(); for (UserIndexPosition userIndexPosition : userIndexPositions) { AdminIndexPositionVO adminIndexPositionVO = assembleAdminIndexPositionVO(userIndexPosition); adminIndexPositionVOS.add(adminIndexPositionVO); } PageInfo pageInfo = new PageInfo(userIndexPositions); pageInfo.setList(adminIndexPositionVOS); return ServerResponse.createBySuccess(pageInfo); } public ServerResponse findMyIndexPositionByNameAndCode(String indexName, String indexCode, Integer state, HttpServletRequest request, int pageNum, int pageSize) { User user = this.iUserService.getCurrentUser(request); PageHelper.startPage(pageNum, pageSize); List userIndexPositions = this.userIndexPositionMapper.findMyIndexPositionByNameAndCode(user.getId(), indexName, indexCode, state); List userIndexPositionVOS = Lists.newArrayList(); if (userIndexPositions.size() > 0) { for (UserIndexPosition userIndexPosition : userIndexPositions) { UserIndexPositionVO userIndexPositionVO = assembleUserIndexPositionVO(userIndexPosition); userIndexPositionVOS.add(userIndexPositionVO); } } PageInfo pageInfo = new PageInfo(userIndexPositions); pageInfo.setList(userIndexPositionVOS); return ServerResponse.createBySuccess(pageInfo); } /*根据指数代码查询用户最早入仓股票*/ public ServerResponse findUserIndexPositionByCode(HttpServletRequest request, String indexGid) { User user = this.iUserService.getCurrentRefreshUser(request); UserIndexPosition position = this.userIndexPositionMapper.findUserIndexPositionByCode(user.getId(), indexGid); List userPositionVOS = Lists.newArrayList(); UserIndexPositionVO userPositionVO = null; if(position != null){ userPositionVO = assembleUserIndexPositionVO(position); } userPositionVOS.add(userPositionVO); PageInfo pageInfo = new PageInfo(); pageInfo.setList(userPositionVOS); return ServerResponse.createBySuccess(pageInfo); } private UserIndexPositionVO assembleUserIndexPositionVO(UserIndexPosition userIndexPosition) { UserIndexPositionVO userIndexPositionVO = new UserIndexPositionVO(); userIndexPositionVO.setId(userIndexPosition.getId()); userIndexPositionVO.setPositionSn(userIndexPosition.getPositionSn()); userIndexPositionVO.setPositionType(userIndexPosition.getPositionType()); userIndexPositionVO.setUserId(userIndexPosition.getUserId()); userIndexPositionVO.setRealName(userIndexPosition.getRealName()); userIndexPositionVO.setAgentId(userIndexPosition.getAgentId()); userIndexPositionVO.setIndexName(userIndexPosition.getIndexName()); userIndexPositionVO.setIndexCode(userIndexPosition.getIndexCode()); userIndexPositionVO.setIndexGid(userIndexPosition.getIndexGid()); userIndexPositionVO.setBuyOrderTime(userIndexPosition.getBuyOrderTime()); userIndexPositionVO.setBuyOrderPrice(userIndexPosition.getBuyOrderPrice()); userIndexPositionVO.setSellOrderTime(userIndexPosition.getSellOrderTime()); userIndexPositionVO.setSellOrderPrice(userIndexPosition.getSellOrderPrice()); userIndexPositionVO.setOrderDirection(userIndexPosition.getOrderDirection()); userIndexPositionVO.setOrderNum(userIndexPosition.getOrderNum()); userIndexPositionVO.setAllDepositAmt(userIndexPosition.getAllDepositAmt()); userIndexPositionVO.setOrderFee(userIndexPosition.getOrderFee()); userIndexPositionVO.setOrderStayDays(userIndexPosition.getOrderNum()); userIndexPositionVO.setEachPoint(userIndexPosition.getEachPoint()); userIndexPositionVO.setIsLock(userIndexPosition.getIsLock()); userIndexPositionVO.setLockMsg(userIndexPosition.getLockMsg()); IndexPositionProfitVO indexPositionProfitVO = getIndexPositionProfitVO(userIndexPosition); userIndexPositionVO.setProfitAndLose(indexPositionProfitVO.getProfitAndLose()); userIndexPositionVO.setAllProfitAndLose(indexPositionProfitVO.getAllProfitAndLose()); userIndexPositionVO.setNow_price(indexPositionProfitVO.getNowPrice()); return userIndexPositionVO; } public IndexPositionVO findUserIndexPositionAllProfitAndLose(Integer userId) { List userIndexPositions = this.userIndexPositionMapper.findPositionByUserIdAndSellPriceIsNull(userId); BigDecimal allProfitAndLose = new BigDecimal("0"); BigDecimal allFreezAmt = new BigDecimal("0"); for (UserIndexPosition userIndexPosition : userIndexPositions) { MarketVO marketVO = this.iStockIndexService.querySingleIndex(userIndexPosition.getIndexGid()); log.info("IndexPositionVO 当前指数行情 = {}", JsonUtil.obj2StringPretty(marketVO)); BigDecimal nowPrice = new BigDecimal("0"); if (userIndexPosition.getIndexGid().contains("hk")){ nowPrice = currencyUtils.getNowIndexPrice(userIndexPosition.getIndexGid(),"HKD"); }else if (userIndexPosition.getIndexGid().contains("us")){ nowPrice = currencyUtils.getNowIndexPrice(userIndexPosition.getIndexGid(),"USD"); }else { nowPrice = new BigDecimal(marketVO.getNowPrice()); } if (nowPrice.compareTo(new BigDecimal("0")) != 0) { BigDecimal buyPrice = userIndexPosition.getBuyOrderPrice(); BigDecimal subPrice = nowPrice.subtract(buyPrice); BigDecimal profit_and_lose = subPrice.multiply(userIndexPosition.getEachPoint()).multiply(new BigDecimal(userIndexPosition.getOrderNum().intValue())); if ("买跌".equals(userIndexPosition.getOrderDirection())) { profit_and_lose = profit_and_lose.negate(); } log.info("持仓指数 {} ,现价点数 = {} ,买入点数 = {} 差价 = {} 盈亏 = {}", new Object[]{userIndexPosition .getIndexName(), nowPrice, buyPrice, subPrice, profit_and_lose}); BigDecimal position_profit = profit_and_lose.subtract(userIndexPosition.getOrderFee()); allProfitAndLose = allProfitAndLose.add(position_profit); BigDecimal position_freez = userIndexPosition.getAllDepositAmt(); allFreezAmt = allFreezAmt.add(position_freez); continue; } log.info("查询所有持仓单的总盈亏,现价返回0,当前为集合竞价"); } IndexPositionVO indexPositionVO = new IndexPositionVO(); indexPositionVO.setAllIndexProfitAndLose(allProfitAndLose); indexPositionVO.setAllIndexFreezAmt(allFreezAmt); return indexPositionVO; } public List findDistinctUserIdList() { return this.userIndexPositionMapper.findDistinctUserIdList(); } public List findIndexPositionByUserIdAndSellPriceIsNull(Integer userId) { return this.userIndexPositionMapper.findPositionByUserIdAndSellPriceIsNull(userId); } public ServerResponse getIndexIncome(Integer agentId, Integer positionType, String beginTime, String endTime) { if (StringUtils.isBlank(beginTime) || StringUtils.isBlank(endTime)) { return ServerResponse.createByErrorMsg("时间不能为空"); } Timestamp begin_time = null; if (StringUtils.isNotBlank(beginTime)) { begin_time = DateTimeUtil.searchStrToTimestamp(beginTime); } Timestamp end_time = null; if (StringUtils.isNotBlank(endTime)) { end_time = DateTimeUtil.searchStrToTimestamp(endTime); } List userIndexPositions = this.userIndexPositionMapper.listByAdmin(positionType, Integer.valueOf(1), null, agentId, null, begin_time, end_time); BigDecimal order_fee_amt = new BigDecimal("0"); BigDecimal order_profit_and_lose = new BigDecimal("0"); BigDecimal order_profit_and_lose_all = new BigDecimal("0"); for (UserIndexPosition userIndexPosition : userIndexPositions) { order_fee_amt = order_fee_amt.add(userIndexPosition.getOrderFee()); order_profit_and_lose = order_profit_and_lose.add(userIndexPosition.getProfitAndLose()); order_profit_and_lose_all = order_profit_and_lose_all.add(userIndexPosition.getAllProfitAndLose()); } AgentIncomeVO agentIncomeVO = new AgentIncomeVO(); agentIncomeVO.setOrderSize(Integer.valueOf(userIndexPositions.size())); agentIncomeVO.setOrderFeeAmt(order_fee_amt); agentIncomeVO.setOrderProfitAndLose(order_profit_and_lose); agentIncomeVO.setOrderAllAmt(order_profit_and_lose_all); return ServerResponse.createBySuccess(agentIncomeVO); } private AdminIndexPositionVO assembleAdminIndexPositionVO(UserIndexPosition userIndexPosition) { AdminIndexPositionVO adminIndexPositionVO = new AdminIndexPositionVO(); adminIndexPositionVO.setId(userIndexPosition.getId()); adminIndexPositionVO.setPositionSn(userIndexPosition.getPositionSn()); adminIndexPositionVO.setPositionType(userIndexPosition.getPositionType()); adminIndexPositionVO.setUserId(userIndexPosition.getUserId()); adminIndexPositionVO.setRealName(userIndexPosition.getRealName()); adminIndexPositionVO.setAgentId(userIndexPosition.getAgentId()); adminIndexPositionVO.setIndexName(userIndexPosition.getIndexName()); adminIndexPositionVO.setIndexCode(userIndexPosition.getIndexCode()); adminIndexPositionVO.setIndexGid(userIndexPosition.getIndexGid()); adminIndexPositionVO.setBuyOrderTime(userIndexPosition.getBuyOrderTime()); adminIndexPositionVO.setBuyOrderPrice(userIndexPosition.getBuyOrderPrice()); adminIndexPositionVO.setSellOrderTime(userIndexPosition.getSellOrderTime()); adminIndexPositionVO.setSellOrderPrice(userIndexPosition.getSellOrderPrice()); adminIndexPositionVO.setOrderDirection(userIndexPosition.getOrderDirection()); adminIndexPositionVO.setOrderNum(userIndexPosition.getOrderNum()); adminIndexPositionVO.setAllDepositAmt(userIndexPosition.getAllDepositAmt()); adminIndexPositionVO.setOrderFee(userIndexPosition.getOrderFee()); adminIndexPositionVO.setOrderStayDays(userIndexPosition.getOrderNum()); adminIndexPositionVO.setEachPoint(userIndexPosition.getEachPoint()); adminIndexPositionVO.setIsLock(userIndexPosition.getIsLock()); adminIndexPositionVO.setLockMsg(userIndexPosition.getLockMsg()); IndexPositionProfitVO indexPositionProfitVO = getIndexPositionProfitVO(userIndexPosition); adminIndexPositionVO.setProfitAndLose(indexPositionProfitVO.getProfitAndLose()); adminIndexPositionVO.setAllProfitAndLose(indexPositionProfitVO.getAllProfitAndLose()); adminIndexPositionVO.setNow_price(indexPositionProfitVO.getNowPrice()); return adminIndexPositionVO; } private IndexPositionProfitVO getIndexPositionProfitVO(UserIndexPosition userIndexPosition) { BigDecimal profitAndLose = new BigDecimal("0"); BigDecimal allProfitAndLose = new BigDecimal("0"); String nowPrice = ""; if (userIndexPosition.getSellOrderPrice() != null) { BigDecimal subPrice = userIndexPosition.getSellOrderPrice().subtract(userIndexPosition.getBuyOrderPrice()); profitAndLose = subPrice.multiply(userIndexPosition.getEachPoint()).multiply(new BigDecimal(userIndexPosition.getOrderNum().intValue())); if ("买跌".equals(userIndexPosition.getOrderDirection())) { profitAndLose = profitAndLose.negate(); } allProfitAndLose = profitAndLose.subtract(userIndexPosition.getOrderFee()); } else { MarketVO marketVO = this.iStockIndexService.querySingleIndex(userIndexPosition.getIndexGid()); nowPrice = marketVO.getNowPrice(); BigDecimal subPrice = (new BigDecimal(nowPrice)).subtract(userIndexPosition.getBuyOrderPrice()); profitAndLose = subPrice.multiply(userIndexPosition.getEachPoint()).multiply(new BigDecimal(userIndexPosition.getOrderNum().intValue())); if ("买跌".equals(userIndexPosition.getOrderDirection())) { profitAndLose = profitAndLose.negate(); } allProfitAndLose = profitAndLose.subtract(userIndexPosition.getOrderFee()); } IndexPositionProfitVO indexPositionProfitVO = new IndexPositionProfitVO(); indexPositionProfitVO.setProfitAndLose(profitAndLose); indexPositionProfitVO.setAllProfitAndLose(allProfitAndLose); indexPositionProfitVO.setNowPrice(nowPrice); return indexPositionProfitVO; } }