| | |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.config.RequestConfig; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private RemoteFileService remoteFileService; |
| | | |
| | | @Resource |
| | | private RedissonClient redissonClient; |
| | | public static RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build(); |
| | | // 配置您申请的KEY,在个人中心->我的数据,接口名称上方查看 |
| | | public static final String APPKEY = ""; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<WdMemberAuctionSalesroomVO> getWdAuctionSalesroomList(MemberAuctionSalesroomDTO MemberAuctionSalesroomDTO) { |
| | | MemberAuctionSalesroomDTO memberAuctionSalesroomDTO =new MemberAuctionSalesroomDTO(); |
| | | memberAuctionSalesroomDTO.setMemberId(MemberAuctionSalesroomDTO.getMemberId()); |
| | | public PageDTO<WdMemberAuctionSalesroomVO> getWdAuctionSalesroomList( |
| | | MemberAuctionSalesroomDTO memberAuctionSalesroomDTO) { |
| | | List<OrderAuctionBond> data = orderClient.getOrderAuctionBondList1(memberAuctionSalesroomDTO, SecurityConstants.INNER).getData(); |
| | | Set<Long> goodsSkuIdList = null; |
| | | goodsSkuIdList = data.stream().map(OrderAuctionBond::getAuctionSalesroomId) |
| | |
| | | |
| | | }*/ |
| | | |
| | | Page<AuctionSalesroom> page = new Page<>(); |
| | | page.setSize(memberAuctionSalesroomDTO.getPageSize()); |
| | | page.setCurrent(memberAuctionSalesroomDTO.getPageCurr()); |
| | | Page<AuctionSalesroom> page = new Page<>(memberAuctionSalesroomDTO.getPageCurr(), |
| | | memberAuctionSalesroomDTO.getPageSize()); |
| | | // page.setSize(memberAuctionSalesroomDTO.getPageSize()); |
| | | // page.setCurrent(memberAuctionSalesroomDTO.getPageCurr()); |
| | | LambdaQueryWrapper<AuctionSalesroom> wrapper1=Wrappers.lambdaQuery(); |
| | | if (goodsSkuIdList.size()>0){ |
| | | wrapper1.in(AuctionSalesroom::getId,goodsSkuIdList); |
| | |
| | | goodsSkuIdList1.add(0L); |
| | | wrapper1.in(AuctionSalesroom::getId,goodsSkuIdList); |
| | | } |
| | | if (MemberAuctionSalesroomDTO.getSalesroomName()!=null){ |
| | | wrapper1.like(AuctionSalesroom::getSalesroomName,MemberAuctionSalesroomDTO.getSalesroomName()); |
| | | if (memberAuctionSalesroomDTO.getSalesroomName() != null) { |
| | | wrapper1.like(AuctionSalesroom::getSalesroomName, |
| | | memberAuctionSalesroomDTO.getSalesroomName()); |
| | | } |
| | | wrapper1.eq(AuctionSalesroom::getDelFlag,0); |
| | | if(MemberAuctionSalesroomDTO.getStatus()!=4){ |
| | | wrapper1.eq(AuctionSalesroom::getStatus,MemberAuctionSalesroomDTO.getStatus()); |
| | | if (memberAuctionSalesroomDTO.getStatus() != 4) { |
| | | wrapper1.eq(AuctionSalesroom::getStatus, memberAuctionSalesroomDTO.getStatus()); |
| | | } |
| | | wrapper1.last("ORDER BY\n" + |
| | | " CASE\n" + |
| | |
| | | auctionSalesroom.setSalesroomId(auctionSalesroom.getId()); |
| | | MemberAuctionSalesroomDTO memberAuctionSalesroomDTO1=new MemberAuctionSalesroomDTO(); |
| | | memberAuctionSalesroomDTO1.setAuctionSalesroomId(auctionSalesroom.getId()); |
| | | memberAuctionSalesroomDTO1.setMemberId(MemberAuctionSalesroomDTO.getMemberId()); |
| | | memberAuctionSalesroomDTO1.setMemberId(memberAuctionSalesroomDTO.getMemberId()); |
| | | auctionSalesroom.setIsBond(2); |
| | | List<OrderAuctionBond> data1 = orderClient.getOrderAuctionBondList1(memberAuctionSalesroomDTO1, SecurityConstants.INNER).getData(); |
| | | if (data1.size()>0){ |
| | |
| | | MgtAuctionSalesroomVO mgtAuctionSalesroomVO = this.getAuctionSalesroom(id, Boolean.TRUE); |
| | | MgtAuctionSalesroomScreenVO vo = BeanUtils.copyBean( |
| | | mgtAuctionSalesroomVO, MgtAuctionSalesroomScreenVO.class); |
| | | if (vo.getStatus().equals(AuctionStartStatusEnum.IN_AUCTION)) { |
| | | List<MgtAuctionSalesroomGoodsVO> auctionSalesroomGoodsVOS = vo.getAuctionSalesroomGoodsVOS(); |
| | | if (StringUtils.isNotEmpty(auctionSalesroomGoodsVOS)) { |
| | | List<MgtAuctionSalesroomGoodsVO> collect = auctionSalesroomGoodsVOS.stream() |
| | | .peek(goods -> { |
| | | List<AuctionBidRecord> list = auctionBidRecordService.lambdaQuery() |
| | | .eq(AuctionBidRecord::getTargetId, goods.getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, |
| | | AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .list(); |
| | | if (StringUtils.isNotEmpty(list)) { |
| | | long bidCount = list.stream() |
| | | .filter(item -> BidStatusEnum.SUCCESSFUL.equals( |
| | | item.getStatus())) |
| | | .count(); |
| | | goods.setBidCount((int) bidCount); |
| | | goods.setBidQuantity((int) bidCount); |
| | | goods.setBidPersonCount(list.size()); |
| | | } |
| | | if (goods.getStatus().equals(AuctionGoodsStatusEnum.IN_PROGRESS)) { |
| | | vo.setCurrentAuctionSalesroomGoods(goods); |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | vo.setAuctionSalesroomGoodsVOS(collect); |
| | | if (StringUtils.isNotNull(vo.getCurrentAuctionSalesroomGoods())) { |
| | | int index = collect.indexOf(vo.getCurrentAuctionSalesroomGoods()); |
| | | if (collect.size() > 1 && index < collect.size() - 1) { |
| | | vo.setNextAuctionSalesroomGoods(collect.get(index + 1)); |
| | | } |
| | | // 分页查询当前拍品出价信息 |
| | | List<AuctionBidRecord> list = auctionBidRecordService.lambdaQuery() |
| | | .eq(AuctionBidRecord::getTargetId, |
| | | vo.getCurrentAuctionSalesroomGoods().getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, |
| | | AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .list(); |
| | | if (StringUtils.isNotEmpty(list)) { |
| | | vo.setMgtAuctionBidRecordVOList(CollUtils.emptyList()); |
| | | } |
| | | vo.setMgtAuctionBidRecordVOList( |
| | | BeanUtils.copyList(list, MgtAuctionBidRecordVO.class)); |
| | | } else { |
| | | Optional<MgtAuctionSalesroomGoodsVO> first = collect.stream() |
| | | .filter(c -> c.getStatus().equals(AuctionGoodsStatusEnum.WAITING)) |
| | | .findFirst(); |
| | | vo.setNextAuctionSalesroomGoods(first.orElse(null)); |
| | | List<MgtAuctionSalesroomGoodsVO> auctionSalesroomGoodsVOS = vo.getAuctionSalesroomGoodsVOS(); |
| | | if (StringUtils.isNotEmpty(auctionSalesroomGoodsVOS)) { |
| | | List<MgtAuctionSalesroomGoodsVO> collect = auctionSalesroomGoodsVOS.stream() |
| | | .peek(goods -> { |
| | | List<AuctionBidRecord> list = auctionBidRecordService.lambdaQuery() |
| | | .eq(AuctionBidRecord::getTargetId, goods.getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, |
| | | AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .list(); |
| | | if (StringUtils.isNotEmpty(list)) { |
| | | long bidCount = list.stream() |
| | | .filter(item -> BidStatusEnum.SUCCESSFUL.equals( |
| | | item.getStatus())) |
| | | .count(); |
| | | goods.setBidCount((int) bidCount); |
| | | goods.setBidQuantity((int) bidCount); |
| | | goods.setBidPersonCount(list.size()); |
| | | } |
| | | if (goods.getStatus().equals(AuctionGoodsStatusEnum.IN_PROGRESS)) { |
| | | vo.setCurrentAuctionSalesroomGoods(goods); |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | vo.setAuctionSalesroomGoodsVOS(collect); |
| | | if (StringUtils.isNotNull(vo.getCurrentAuctionSalesroomGoods())) { |
| | | int index = collect.indexOf(vo.getCurrentAuctionSalesroomGoods()); |
| | | if (collect.size() > 1 && index < collect.size() - 1) { |
| | | vo.setNextAuctionSalesroomGoods(collect.get(index + 1)); |
| | | } |
| | | // 分页查询当前拍品出价信息 |
| | | List<AuctionBidRecord> list = auctionBidRecordService.lambdaQuery() |
| | | .eq(AuctionBidRecord::getTargetId, |
| | | vo.getCurrentAuctionSalesroomGoods().getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, |
| | | AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .list(); |
| | | if (StringUtils.isNotEmpty(list)) { |
| | | vo.setMgtAuctionBidRecordVOList(CollUtils.emptyList()); |
| | | } |
| | | vo.setMgtAuctionBidRecordVOList( |
| | | BeanUtils.copyList(list, MgtAuctionBidRecordVO.class)); |
| | | } else { |
| | | Optional<MgtAuctionSalesroomGoodsVO> first = collect.stream() |
| | | .filter(c -> c.getStatus().equals(AuctionGoodsStatusEnum.WAITING)) |
| | | .findFirst(); |
| | | vo.setNextAuctionSalesroomGoods(first.orElse(null)); |
| | | } |
| | | } |
| | | return vo; |
| | |
| | | */ |
| | | @Override |
| | | public void stopCurrentGoods(Long id) throws JsonProcessingException { |
| | | AuctionSalesroomGoods auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectById(id); |
| | | if (StringUtils.isNull(auctionSalesroomGoods)) { |
| | | throw new ServiceException("拍卖商品不存在"); |
| | | } |
| | | AuctionSalesroom auctionSalesroom = this.getById( |
| | | auctionSalesroomGoods.getAuctionSalesroomId()); |
| | | auctionSalesroomGoods.setStatus(AuctionGoodsStatusEnum.ENDED); |
| | | auctionSalesroomGoodsMapper.updateById(auctionSalesroomGoods); |
| | | List<AuctionBidRecord> auctionBidRecordList = auctionBidRecordMapper.selectList( |
| | | Wrappers.lambdaQuery(AuctionBidRecord.class) |
| | | .eq(AuctionBidRecord::getAuctionSalesroomId, |
| | | auctionSalesroomGoods.getAuctionSalesroomId()) |
| | | .eq(AuctionBidRecord::getTargetId, auctionSalesroomGoods.getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .orderByDesc(AuctionBidRecord::getLastBidAmount)); |
| | | if (CollUtils.isNotEmpty(auctionBidRecordList)) { |
| | | List<AuctionBidRecord> auctionBidRecords = new ArrayList<>(); |
| | | if (auctionBidRecordList.size() >= auctionSalesroomGoods.getSalesroomStock()) { |
| | | for (int i = 0; i < auctionSalesroomGoods.getSalesroomStock(); i++) { |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | auctionBidRecordMapper.updateById(auctionBidRecord); |
| | | auctionBidRecords.add(auctionBidRecord); |
| | | } |
| | | } else { |
| | | for (int i = 0; i < auctionBidRecordList.size(); i++) { |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | auctionBidRecordMapper.updateById(auctionBidRecord); |
| | | auctionBidRecords.add(auctionBidRecord); |
| | | } |
| | | // 没有出价记录,回退库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); |
| | | goodsStockUpdDTO.setAuctionStock( |
| | | auctionSalesroomGoods.getSalesroomStock() - auctionBidRecordList.size()); |
| | | goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), |
| | | SecurityConstants.INNER); |
| | | RLock lock = redissonClient.getLock("stopCurrentGoods" + id); |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | try { |
| | | AuctionSalesroomGoods auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectById( |
| | | id); |
| | | if (StringUtils.isNull(auctionSalesroomGoods)) { |
| | | throw new ServiceException("拍卖商品不存在"); |
| | | } |
| | | for (AuctionBidRecord auctionBidRecord : auctionBidRecords) { |
| | | addOrder(auctionBidRecord.getTargetId(), auctionBidRecord.getMemberId(), |
| | | auctionBidRecord.getLastBidAmount(), |
| | | auctionSalesroom.getBond()); |
| | | if (auctionSalesroomGoods.getStatus().equals(AuctionGoodsStatusEnum.IN_PROGRESS)) { |
| | | AuctionSalesroom auctionSalesroom = this.getById( |
| | | auctionSalesroomGoods.getAuctionSalesroomId()); |
| | | auctionSalesroomGoods.setStatus(AuctionGoodsStatusEnum.ENDED); |
| | | auctionSalesroomGoodsMapper.updateById(auctionSalesroomGoods); |
| | | List<AuctionBidRecord> auctionBidRecordList = auctionBidRecordMapper.selectList( |
| | | Wrappers.lambdaQuery(AuctionBidRecord.class) |
| | | .eq(AuctionBidRecord::getAuctionSalesroomId, |
| | | auctionSalesroomGoods.getAuctionSalesroomId()) |
| | | .eq(AuctionBidRecord::getTargetId, auctionSalesroomGoods.getId()) |
| | | .eq(AuctionBidRecord::getAuctionType, |
| | | AuctionOrderTypeEnum.AUCTION_ITEMS) |
| | | .orderByDesc(AuctionBidRecord::getLastBidAmount)); |
| | | if (CollUtils.isNotEmpty(auctionBidRecordList)) { |
| | | List<AuctionBidRecord> auctionBidRecords = new ArrayList<>(); |
| | | if (auctionBidRecordList.size() >= auctionSalesroomGoods.getSalesroomStock()) { |
| | | for (int i = 0; i < auctionSalesroomGoods.getSalesroomStock(); i++) { |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | auctionBidRecordMapper.updateById(auctionBidRecord); |
| | | auctionBidRecords.add(auctionBidRecord); |
| | | } |
| | | } else { |
| | | for (int i = 0; i < auctionBidRecordList.size(); i++) { |
| | | AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); |
| | | auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); |
| | | auctionBidRecordMapper.updateById(auctionBidRecord); |
| | | auctionBidRecords.add(auctionBidRecord); |
| | | } |
| | | // 没有出价记录,回退库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); |
| | | goodsStockUpdDTO.setAuctionStock( |
| | | auctionSalesroomGoods.getSalesroomStock() |
| | | - auctionBidRecordList.size()); |
| | | goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), |
| | | SecurityConstants.INNER); |
| | | } |
| | | for (AuctionBidRecord auctionBidRecord : auctionBidRecords) { |
| | | addOrder(auctionBidRecord.getTargetId(), auctionBidRecord.getMemberId(), |
| | | auctionBidRecord.getLastBidAmount(), |
| | | auctionSalesroom.getBond()); |
| | | } |
| | | } else { |
| | | // 没有出价记录,回退库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); |
| | | goodsStockUpdDTO.setAuctionStock( |
| | | auctionSalesroomGoods.getSalesroomStock()); |
| | | goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), |
| | | SecurityConstants.INNER); |
| | | } |
| | | Map<String, Object> map = new ConcurrentHashMap<>(); |
| | | map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM_GOODS); |
| | | map.put("auctionSalesroomId", |
| | | auctionSalesroomGoods.getAuctionSalesroomId().toString()); |
| | | map.put("auctionSalesroomGoodsId", auctionSalesroomGoods.getId().toString()); |
| | | map.put("AuctionTypeEnum", auctionSalesroomGoods.getStatus()); |
| | | map.put("message_type", "stop"); |
| | | map.put("type", "2"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | sysUserClient.pushAll(msg, SecurityConstants.INNER); |
| | | } |
| | | } else { |
| | | // 没有出价记录,回退库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); |
| | | goodsStockUpdDTO.setAuctionStock( |
| | | auctionSalesroomGoods.getSalesroomStock()); |
| | | goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), |
| | | SecurityConstants.INNER); |
| | | } finally { |
| | | if (lock.isLocked() && lock.isHeldByCurrentThread()) { |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | Map<String, Object> map = new ConcurrentHashMap<>(); |
| | | map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM_GOODS); |
| | | map.put("auctionSalesroomId", auctionSalesroomGoods.getAuctionSalesroomId().toString()); |
| | | map.put("auctionSalesroomGoodsId", auctionSalesroomGoods.getId().toString()); |
| | | map.put("AuctionTypeEnum", auctionSalesroomGoods.getStatus()); |
| | | map.put("message_type", "stop"); |
| | | map.put("type", "2"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | sysUserClient.pushAll(msg, SecurityConstants.INNER); |
| | | } |
| | | |
| | | public void addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount, |
| | |
| | | List<AuctionBidRecord> auctionBidRecordList = auctionBidRecordMapper.selectList( |
| | | Wrappers.<AuctionBidRecord>lambdaQuery() |
| | | .eq(AuctionBidRecord::getAuctionSalesroomId, auctionSalesroomId) |
| | | .ne(AuctionBidRecord::getStatus, BidStatusEnum.SUCCESSFUL)); |
| | | .eq(AuctionBidRecord::getStatus, BidStatusEnum.SUCCESSFUL)); |
| | | Set<Long> memberIdList = new HashSet<>(); |
| | | if (CollUtils.isNotEmpty(auctionBidRecordList)) { |
| | | memberIdList = auctionBidRecordList.stream().map(AuctionBidRecord::getMemberId) |