@Test public void testPay() throws Exception { Long accountId = 10000L; Orders orders = new Orders(); orders.setUserAccountId(accountId); orders.setPayModeId(1); orders.setRedPacketId(0l); orders.setPrice(60); orders.setSubmitDate(new Date().getTime()); List<CommodityAmount> list = new ArrayList<>(); CommodityAmount commodityAmount = new CommodityAmount(); commodityAmount.setCommodityId(2L); commodityAmount.setAmount(50); list.add(commodityAmount); service.pay(accountId, orders, list); }
@Override @Transactional(isolation = Isolation.READ_COMMITTED) public Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts) { Long date = new Date().getTime(); orders.setUserAccountId(accountId); orders.setSubmitDate(date); mapper.insertUseGenerated(orders); for (CommodityAmount ca : commodityAmounts) { Commoditys currentCommodity = comMapper.selectByKey(ca.getCommodityId()); if(currentCommodity.getStateId() != Commodity.ON_SELL){ currentCommodity = commodityService.selectOnSellCommodities(ca.getCommodityId()); if(null == currentCommodity) throw new NullPointerException("未获取到商品"); } int remainingNum = currentCommodity.getBuyTotalNumber() - currentCommodity.getBuyCurrentNumber(); int buyNum = ca.getAmount(); if (buyNum > remainingNum) { Commodity nextCommodity = commodityService.getNextCommodity(currentCommodity.getId()); updateLuckCodes(accountId, nextCommodity.getId(), buyNum - remainingNum, orders); buyNum = remainingNum; } updateLuckCodes(accountId, currentCommodity.getId(), buyNum, orders); } ordersServiceImplAsync.payAsync(accountId, orders, commodityAmounts); return orders.getId(); }
OrdersServiceImpl implements IOrdersService { @Override @Transactional(isolation = Isolation.READ_COMMITTED) public Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts) { Long date = new Date().getTime(); orders.setUserAccountId(accountId); orders.setSubmitDate(date); mapper.insertUseGenerated(orders); for (CommodityAmount ca : commodityAmounts) { Commoditys currentCommodity = comMapper.selectByKey(ca.getCommodityId()); if(currentCommodity.getStateId() != Commodity.ON_SELL){ currentCommodity = commodityService.selectOnSellCommodities(ca.getCommodityId()); if(null == currentCommodity) throw new NullPointerException("未获取到商品"); } int remainingNum = currentCommodity.getBuyTotalNumber() - currentCommodity.getBuyCurrentNumber(); int buyNum = ca.getAmount(); if (buyNum > remainingNum) { Commodity nextCommodity = commodityService.getNextCommodity(currentCommodity.getId()); updateLuckCodes(accountId, nextCommodity.getId(), buyNum - remainingNum, orders); buyNum = remainingNum; } updateLuckCodes(accountId, currentCommodity.getId(), buyNum, orders); } ordersServiceImplAsync.payAsync(accountId, orders, commodityAmounts); return orders.getId(); } }
OrdersServiceImpl implements IOrdersService { @Override @Transactional(isolation = Isolation.READ_COMMITTED) public Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts) { Long date = new Date().getTime(); orders.setUserAccountId(accountId); orders.setSubmitDate(date); mapper.insertUseGenerated(orders); for (CommodityAmount ca : commodityAmounts) { Commoditys currentCommodity = comMapper.selectByKey(ca.getCommodityId()); if(currentCommodity.getStateId() != Commodity.ON_SELL){ currentCommodity = commodityService.selectOnSellCommodities(ca.getCommodityId()); if(null == currentCommodity) throw new NullPointerException("未获取到商品"); } int remainingNum = currentCommodity.getBuyTotalNumber() - currentCommodity.getBuyCurrentNumber(); int buyNum = ca.getAmount(); if (buyNum > remainingNum) { Commodity nextCommodity = commodityService.getNextCommodity(currentCommodity.getId()); updateLuckCodes(accountId, nextCommodity.getId(), buyNum - remainingNum, orders); buyNum = remainingNum; } updateLuckCodes(accountId, currentCommodity.getId(), buyNum, orders); } ordersServiceImplAsync.payAsync(accountId, orders, commodityAmounts); return orders.getId(); }  }
OrdersServiceImpl implements IOrdersService { @Override @Transactional(isolation = Isolation.READ_COMMITTED) public Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts) { Long date = new Date().getTime(); orders.setUserAccountId(accountId); orders.setSubmitDate(date); mapper.insertUseGenerated(orders); for (CommodityAmount ca : commodityAmounts) { Commoditys currentCommodity = comMapper.selectByKey(ca.getCommodityId()); if(currentCommodity.getStateId() != Commodity.ON_SELL){ currentCommodity = commodityService.selectOnSellCommodities(ca.getCommodityId()); if(null == currentCommodity) throw new NullPointerException("未获取到商品"); } int remainingNum = currentCommodity.getBuyTotalNumber() - currentCommodity.getBuyCurrentNumber(); int buyNum = ca.getAmount(); if (buyNum > remainingNum) { Commodity nextCommodity = commodityService.getNextCommodity(currentCommodity.getId()); updateLuckCodes(accountId, nextCommodity.getId(), buyNum - remainingNum, orders); buyNum = remainingNum; } updateLuckCodes(accountId, currentCommodity.getId(), buyNum, orders); } ordersServiceImplAsync.payAsync(accountId, orders, commodityAmounts); return orders.getId(); }  @Override @Transactional(isolation = Isolation.READ_COMMITTED) Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts); @Transactional(isolation = Isolation.READ_COMMITTED) boolean updateLuckCodes(Long accountid, long commodityId, int buyNum, Orders orders); @Override List<Orders> selectByUserAccount(Long userAccount); @Override boolean deleteOder(Long id); @Override boolean update(Orders oders); @Override Map<String, Object> selectUsableRedPackets(Long accountId, Integer sum); @Override Map<String, Object> selectPaySuccess(Long accountId, Long orderId); List<String> luckCodes(Long accountId, Long commodityId, Long ordersId); }
OrdersServiceImpl implements IOrdersService { @Override @Transactional(isolation = Isolation.READ_COMMITTED) public Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts) { Long date = new Date().getTime(); orders.setUserAccountId(accountId); orders.setSubmitDate(date); mapper.insertUseGenerated(orders); for (CommodityAmount ca : commodityAmounts) { Commoditys currentCommodity = comMapper.selectByKey(ca.getCommodityId()); if(currentCommodity.getStateId() != Commodity.ON_SELL){ currentCommodity = commodityService.selectOnSellCommodities(ca.getCommodityId()); if(null == currentCommodity) throw new NullPointerException("未获取到商品"); } int remainingNum = currentCommodity.getBuyTotalNumber() - currentCommodity.getBuyCurrentNumber(); int buyNum = ca.getAmount(); if (buyNum > remainingNum) { Commodity nextCommodity = commodityService.getNextCommodity(currentCommodity.getId()); updateLuckCodes(accountId, nextCommodity.getId(), buyNum - remainingNum, orders); buyNum = remainingNum; } updateLuckCodes(accountId, currentCommodity.getId(), buyNum, orders); } ordersServiceImplAsync.payAsync(accountId, orders, commodityAmounts); return orders.getId(); }  @Override @Transactional(isolation = Isolation.READ_COMMITTED) Long pay(Long accountId, Orders orders, List<CommodityAmount> commodityAmounts); @Transactional(isolation = Isolation.READ_COMMITTED) boolean updateLuckCodes(Long accountid, long commodityId, int buyNum, Orders orders); @Override List<Orders> selectByUserAccount(Long userAccount); @Override boolean deleteOder(Long id); @Override boolean update(Orders oders); @Override Map<String, Object> selectUsableRedPackets(Long accountId, Integer sum); @Override Map<String, Object> selectPaySuccess(Long accountId, Long orderId); List<String> luckCodes(Long accountId, Long commodityId, Long ordersId);  }