| | |
| | | package com.nq.service.impl; |
| | | |
| | | 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.*; |
| | |
| | | import com.nq.utils.stock.pinyin.GetPyByChinese; |
| | | import com.nq.utils.stock.sina.StockApi; |
| | | import com.nq.utils.timeutil.DateTimeUtil; |
| | | import com.nq.utils.timeutil.TimeUtil; |
| | | import com.nq.vo.agent.AgentIncomeVO; |
| | | import com.nq.vo.position.AdminPositionVO; |
| | | import com.nq.vo.position.AgentPositionVO; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String a = "09:00"; |
| | | System.out.println(Integer.parseInt(a.split(":")[0])>12); |
| | | } |
| | | |
| | | @Transactional |
| | | public ServerResponse sell(String positionSn, int doType){ |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | BigDecimal siitteBuyFee = iSiteSettingService.getSiteSetting().getBuyFee(); |
| | | Boolean b = tradingHourService.timeCheck(userPosition.getStockCode()); |
| | | |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内"); |
| | | } |
| | |
| | | // 手续费率 |
| | | BigDecimal siitteBuyFee = siteSetting.getSellFee(); |
| | | |
| | | |
| | | |
| | | // Calendar calendar = Calendar.getInstance(); |
| | | // int time = calendar.get(Calendar.HOUR_OF_DAY); |
| | | // if(time<12 && time>=Integer.parseInt(siteSetting.getTransAmEnd().split(":")[0])){ //上午 |
| | | // return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内",request); |
| | | // } |
| | | // if(time>12 && time>=Integer.parseInt(siteSetting.getTransPmEnd().split(":")[0])){//下午 |
| | | // return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内",request); |
| | | // } |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | if(null == stock){ |
| | | return ServerResponse.createBySuccessMsg("股票不存在!", request); |
| | | } |
| | | //判断股票是否在可交易时间段 |
| | | // Boolean b = isStockMarketOpen(stock.getStockType()); |
| | | // Boolean wb = tradingHourService.weekDayeCheck(stock.getStockCode()); |
| | | // if (!b || !wb) { |
| | | // return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request); |
| | | // } |
| | | |
| | | Boolean b = tradingHourService.timeCheck(userPosition.getStockCode()); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内"); |
| | | } |
| | | |
| | | if (userPosition == null) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,订单不存在", request); |
| | | } |
| | |
| | | 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())); |
| | | BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode()); |
| | | if (nowPrice.compareTo(new BigDecimal("0")) != 1) { |
| | | return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试", request); |
| | |
| | | userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("平仓成功!", request); |
| | | } |
| | | |
| | | public boolean isStockMarketOpen(String stockType){ |
| | | ZoneId zone = ZoneId.of("Asia/Shanghai"); |
| | | LocalTime now = LocalTime.now(zone); |
| | | if("US".equalsIgnoreCase(stockType)){ |
| | | LocalTime startTime = LocalTime.of(21, 30); |
| | | LocalTime endTime = LocalTime.of(4, 0); |
| | | if (now.isAfter(startTime) || now.isBefore(endTime)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }else if("IN".equalsIgnoreCase(stockType)){ |
| | | LocalTime instartTime = LocalTime.of(11, 15); |
| | | LocalTime inendTime = LocalTime.of(17, 30); |
| | | if (now.isAfter(instartTime) && now.isBefore(inendTime)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | List<UserPositionVO> userPositionVOS = Lists.newArrayList(); |
| | | if (userPositions.size() > 0) { |
| | | for (UserPosition position : userPositions) { |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode())); |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, priceServices.getNowPrice(position.getStockCode(),stockType)); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | userPositionVOS.add(userPositionVO); |