| | |
| | | import com.yami.trading.bean.exchange.ExchangeApplyOrder; |
| | | import com.yami.trading.bean.ipo.ApplyNewSharesOrder; |
| | | import com.yami.trading.bean.ipo.NewSharesConfig; |
| | | import com.yami.trading.bean.ipo.UserPromiseRecord; |
| | | import com.yami.trading.bean.ipo.dto.SumSpotStockDto; |
| | | import com.yami.trading.bean.model.MoneyLog; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.bean.model.Wallet; |
| | | import com.yami.trading.bean.syspara.domain.Syspara; |
| | | import com.yami.trading.common.constants.Constants; |
| | | import com.yami.trading.common.exception.BusinessException; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.util.DateUtil; |
| | | import com.yami.trading.common.util.RandomUtil; |
| | | import com.yami.trading.dao.ipo.ApplyNewSharesOrderSharesMapper; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.data.DataService; |
| | | import com.yami.trading.service.data.RealtimeService; |
| | | import com.yami.trading.service.exchange.ExchangeApplyOrderService; |
| | | import com.yami.trading.service.ipo.ApplyNewSharesOrderService; |
| | | import com.yami.trading.service.ipo.NewSharesConfigService; |
| | | import com.yami.trading.service.ipo.UserPromiseRecordService; |
| | | import com.yami.trading.service.syspara.SysparaService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | @Autowired |
| | | WalletService walletService; |
| | | |
| | | @Autowired |
| | | MoneyLogService moneyLogService; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | UserPromiseRecordService userPromiseRecordService; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | throw new BusinessException("股票数申购数不足!"); |
| | | } |
| | | |
| | | if (amount.doubleValue()>newSharesConfig.getDefaultLimit().doubleValue()){ |
| | | throw new BusinessException("股票数抽签数大于限购数!"); |
| | | if (newSharesConfig.getUserApplyNums() != null && newSharesConfig.getUserApplyNums()>0){ |
| | | if (amount.doubleValue() < newSharesConfig.getUserApplyNums()){ |
| | | throw new BusinessException("请大于最低申购数量"); |
| | | } |
| | | } |
| | | |
| | | /*if (amount.doubleValue()>newSharesConfig.getDefaultLimit().doubleValue()){ |
| | | throw new BusinessException("股票数抽签数大于限购数!"); |
| | | }*/ |
| | | if (newSharesConfig.getAppliedSubscribeNumber()>newSharesConfig.getSubscribeTotalNumber()){ |
| | | throw new BusinessException("抽签数量大于总抽签股数"); |
| | | } |
| | | List<ApplyNewSharesOrder> applyNewSharesOrders= findByProductCodeAndUserId(newSharesConfig.getProductCode(),userId); |
| | | /*List<ApplyNewSharesOrder> applyNewSharesOrders= findByProductCodeAndUserId(newSharesConfig.getProductCode(),userId); |
| | | if (CollectionUtil.isNotEmpty(applyNewSharesOrders)){ |
| | | throw new BusinessException("已经有申购订单在申购中,请勿重复申请"); |
| | | } |
| | | }*/} |
| | | |
| | | newSharesConfigService.updateById(newSharesConfig); |
| | | ApplyNewSharesOrder applyNewSharesOrder=new ApplyNewSharesOrder(); |
| | | applyNewSharesOrder.setSubNumber(amount); |
| | |
| | | return sumWinningNumber; |
| | | } |
| | | |
| | | //中签认缴 |
| | | @Override |
| | | public Boolean subscribe(ApplyNewSharesOrder order) { |
| | | try { |
| | | NewSharesConfig newSharesConfig = newSharesConfigService.getByProductCode(order.getSymbolCode()); |
| | | if (newSharesConfig == null) { |
| | | throw new BusinessException("新股不存在!"); |
| | | } |
| | | Boolean isDb = false; |
| | | Wallet wallet = walletService.saveWalletByPartyId(order.getUserId()); |
| | | BigDecimal amountBefore = wallet.getMoney(); |
| | | BigDecimal amt = order.getRequiredNumber(); |
| | | if (wallet.getMoney().compareTo(amt) >= 0) { |
| | | wallet.setMoney(wallet.getMoney().subtract(amt)); |
| | | } else { |
| | | //资金不足 进入待补 |
| | | isDb = true; |
| | | BigDecimal amountToBeCovered = amt.subtract(wallet.getMoney()); |
| | | wallet.setMoney(BigDecimal.ZERO); |
| | | wallet.setAmountToBeCovered(amountToBeCovered); |
| | | } |
| | | walletService.updateById(wallet); |
| | | |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_IPO); |
| | | log.setAmountBefore(amountBefore); |
| | | log.setAmount(amt.negate()); |
| | | log.setAmountAfter(amountBefore.subtract(amt).compareTo(BigDecimal.ZERO) <= 0 ? |
| | | BigDecimal.ZERO : amountBefore.subtract(amt)); |
| | | log.setLog(order.getSymbolCode() + "新股认缴"); |
| | | log.setUserId(order.getUserId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | log.setContentType(Constants.MONEYLOG_CATEGORY_IPO); |
| | | moneyLogService.save(log); |
| | | |
| | | UserPromiseRecord userPromiseRecord = new UserPromiseRecord(); |
| | | userPromiseRecord.setUserId(order.getUserId()); |
| | | userPromiseRecord.setDeductNumber(order.getWinningNumber()); |
| | | userPromiseRecord.setDeductUsdt(order.getRequiredNumber()); |
| | | userPromiseRecord.setStatus(isDb ? 1 : 2); |
| | | Calendar calendar=Calendar.getInstance(); |
| | | if (newSharesConfig.getLockDay() > 0) { |
| | | calendar.add(Calendar.DAY_OF_YEAR,newSharesConfig.getLockDay()); |
| | | userPromiseRecord.setLockEndTime(calendar.getTime()); |
| | | } else { |
| | | userPromiseRecord.setLockEndTime(calendar.getTime()); |
| | | } |
| | | userPromiseRecord.setNewSharesConfigId(newSharesConfig.getUuid()); |
| | | userPromiseRecord.setProductCode(newSharesConfig.getProductCode()); |
| | | userPromiseRecord.setProductName(newSharesConfig.getProductName()); |
| | | userPromiseRecord.setName(newSharesConfig.getName()); |
| | | userPromiseRecord.setOrderNo(order.getOrderNo()); |
| | | userPromiseRecordService.save(userPromiseRecord); |
| | | |
| | | return true; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Transactional |
| | | public void sell(String orderNo, String userId) { |
| | | ApplyNewSharesOrder applyNewSharesOrder= findByOrderNo(orderNo); |