mitao
2024-08-06 356b6e4b0a11a6e44717dc9b92beaacc9c0c4b7a
ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java
@@ -408,7 +408,7 @@
            memberAuctionSalesroomVO.setSalesroomId(auctionSalesroom.getId());
            memberAuctionSalesroomVO.setStartTime(auctionSalesroom.getStartTime());
            memberAuctionSalesroomVO.setEndTime(auctionSalesroom.getEndTime());
            memberAuctionSalesroomVO.setCoverPic(auctionSalesroom.getCoverPic());
            memberAuctionSalesroomVO.setCoverPic(auctionSalesroom.getClientCoverPic());
            memberAuctionSalesroomVO.setBond(auctionSalesroom.getBond());
            memberAuctionSalesroomVO.setAuthentication(auctionSalesroom.getAuthentication());
            memberAuctionSalesroomDTO.setAuctionSalesroomId(auctionSalesroom.getId());
@@ -669,16 +669,24 @@
    @Override
    public void SaveBid(BidDTO bidVO) {
        Member membeOne = memberClient.getMembeOne(bidVO.getMemberId(), SecurityConstants.INNER).getData();
        RLock lock = redissonClient.getLock(
                "bid-" + bidVO.getAuctionType() + "-" + bidVO.getTargetId());
        lock.lock(10, TimeUnit.SECONDS);
        try {
            Member membeOne = memberClient.getMembeOne(bidVO.getMemberId(), SecurityConstants.INNER)
                    .getData();
        if (bidVO.getAuctionType()==2){
            AuctionSalesroomGoods byId = auctionSalesroomGoodsMapper.selectById(bidVO.getTargetId());
            if (byId.getStartingPrice().doubleValue()>bidVO.getLastBidAmount().doubleValue()){
                AuctionSalesroomGoods byId = auctionSalesroomGoodsMapper.selectById(
                        bidVO.getTargetId());
                if (byId.getStartingPrice().doubleValue() > bidVO.getLastBidAmount()
                        .doubleValue()) {
                throw new ServiceException("出价不能比起拍价低");
            }
            AuctionSalesroom byId1 = this.getById(bidVO.getAuctionSalesroomId());
            if(byId1==null){
                LambdaQueryWrapper<AuctionSalesroom> wrapper= Wrappers.lambdaQuery();
                wrapper.eq(AuctionSalesroom::getAuctionSalesroomNo,bidVO.getAuctionSalesroomId());
                    wrapper.eq(AuctionSalesroom::getAuctionSalesroomNo,
                            bidVO.getAuctionSalesroomId());
                wrapper.eq(AuctionSalesroom::getDelFlag,0);
                AuctionSalesroom one = this.getOne(wrapper);
                bidVO.setAuctionSalesroomId(one.getId());
@@ -693,12 +701,14 @@
            AuctionBidRecord one3 = auctionBidRecordService.getOne(wrapper3);
            if (byId.getSalesroomStock()==1){
                if (one3!=null){
                    if (bidVO.getLastBidAmount().doubleValue()<one3.getLastBidAmount().doubleValue()){
                        if (bidVO.getLastBidAmount().doubleValue() < one3.getLastBidAmount()
                                .doubleValue()) {
                        throw new ServiceException("出价不能比当前最高价低");
                    }
                }
                if (one3!=null){
                    if (bidVO.getLastBidAmount().doubleValue()<one3.getLastBidAmount().add(byId.getMinimumMarkupAmount()).doubleValue()){
                        if (bidVO.getLastBidAmount().doubleValue() < one3.getLastBidAmount()
                                .add(byId.getMinimumMarkupAmount()).doubleValue()) {
                        throw new ServiceException("出价不能比当前最高价低加每次加价低");
                    }
                }
@@ -741,7 +751,6 @@
                auctionBidRecordService.save(one);
            }
            LambdaQueryWrapper<AuctionBidRecord> wrapper2=Wrappers.lambdaQuery();
            wrapper2.eq(AuctionBidRecord::getAuctionSalesroomId,bidVO.getAuctionSalesroomId());
            wrapper2.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId());
@@ -764,13 +773,10 @@
            String finalMsg = msg;
                    sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(finalMsg)
                            .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER);
        }else {
            AuctionGoods byId = auctionGoodsService.getById(bidVO.getTargetId());
            if (byId.getStartingPrice().doubleValue()>bidVO.getLastBidAmount().doubleValue()){
                if (byId.getStartingPrice().doubleValue() > bidVO.getLastBidAmount()
                        .doubleValue()) {
                throw new ServiceException("出价不能比起拍价低");
            }
            BigDecimal bigDecimal=byId.getStartingPrice().add(byId.getMinimumMarkupAmount());
@@ -785,7 +791,8 @@
            AuctionBidRecord one = auctionBidRecordService.getOne(wrapper1);
            if (byId.getAuctionStock()==1){
                if (one != null) {
                    BigDecimal bigDecimal1 = one.getLastBidAmount().add(byId.getMinimumMarkupAmount());
                        BigDecimal bigDecimal1 = one.getLastBidAmount()
                                .add(byId.getMinimumMarkupAmount());
                    if (bigDecimal1.doubleValue() > bidVO.getLastBidAmount().doubleValue()) {
                        throw new ServiceException("出价不能比上次出价加每次最少加价低");
                    }
@@ -839,6 +846,11 @@
            sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(finalMsg)
                            .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER);
            }
        } finally {
            if (lock.isLocked()) {
                lock.unlock();
            }
        }
    }
@@ -1047,11 +1059,12 @@
    public PageDTO<WdMemberAuctionSalesroomVO> getWdAuctionSalesroomList(
            MemberAuctionSalesroomDTO memberAuctionSalesroomDTO) {
        List<OrderAuctionBond> data = orderClient.getOrderAuctionBondList1(memberAuctionSalesroomDTO, SecurityConstants.INNER).getData();
        if (CollUtils.isEmpty(data)) {
            return PageDTO.empty(0L, 0L);
        }
        Set<Long> goodsSkuIdList = null;
        goodsSkuIdList = data.stream().map(OrderAuctionBond::getAuctionSalesroomId)
                .collect(Collectors.toSet());
        Page<AuctionSalesroom> page = new Page<>(memberAuctionSalesroomDTO.getPageCurr(),
                memberAuctionSalesroomDTO.getPageSize());
        LambdaQueryWrapper<AuctionSalesroom> wrapper1=Wrappers.lambdaQuery();
@@ -1070,13 +1083,10 @@
        if (memberAuctionSalesroomDTO.getStatus() != 4) {
            wrapper1.eq(AuctionSalesroom::getStatus, memberAuctionSalesroomDTO.getStatus());
        }
        wrapper1.last("ORDER BY\n" +
                "        CASE\n" +
                "        WHEN status = 0 THEN 2\n" +
                "        WHEN status = 1 THEN 1\n" +
                "        WHEN status = 2 THEN 3\n" +
                "        END,status asc ");
        wrapper1.last(memberAuctionSalesroomDTO.getStatus() == 4, "ORDER BY\n"
                + "    FIELD(status, 1, 0, 2),\n"
                + "    start_time DESC");
        wrapper1.last(memberAuctionSalesroomDTO.getStatus() != 4, "ORDER BY start_time DESC");
        Page<AuctionSalesroom> auctionSalesroomList=this.page(page,wrapper1);
        PageDTO<WdMemberAuctionSalesroomVO> wdMemberAuctionSalesroomVOPageDTO = PageDTO.of(auctionSalesroomList, WdMemberAuctionSalesroomVO.class);
        List<WdMemberAuctionSalesroomVO> list = wdMemberAuctionSalesroomVOPageDTO.getList();
@@ -1442,10 +1452,15 @@
     */
    @Override
    public void stopCurrentGoods(Long id) throws JsonProcessingException {
        AuctionSalesroomGoods auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectById(id);
        RLock lock = redissonClient.getLock("stopCurrentGoods" + id);
        lock.lock(10, TimeUnit.SECONDS);
        try {
            AuctionSalesroomGoods auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectById(
                    id);
        if (StringUtils.isNull(auctionSalesroomGoods)) {
            throw new ServiceException("拍卖商品不存在");
        }
            if (auctionSalesroomGoods.getStatus().equals(AuctionGoodsStatusEnum.IN_PROGRESS)) {
        AuctionSalesroom auctionSalesroom = this.getById(
                auctionSalesroomGoods.getAuctionSalesroomId());
        auctionSalesroomGoods.setStatus(AuctionGoodsStatusEnum.ENDED);
@@ -1455,8 +1470,10 @@
                        .eq(AuctionBidRecord::getAuctionSalesroomId,
                                auctionSalesroomGoods.getAuctionSalesroomId())
                        .eq(AuctionBidRecord::getTargetId, auctionSalesroomGoods.getId())
                        .eq(AuctionBidRecord::getAuctionType, AuctionOrderTypeEnum.AUCTION_ITEMS)
                        .orderByDesc(AuctionBidRecord::getLastBidAmount));
                                .eq(AuctionBidRecord::getAuctionType,
                                        AuctionOrderTypeEnum.AUCTION_ITEMS)
                                .orderByDesc(AuctionBidRecord::getLastBidAmount)
                                .orderByAsc(AuctionBidRecord::getLastBidTime));
        if (CollUtils.isNotEmpty(auctionBidRecordList)) {
            List<AuctionBidRecord> auctionBidRecords = new ArrayList<>();
            if (auctionBidRecordList.size() >= auctionSalesroomGoods.getSalesroomStock()) {
@@ -1477,7 +1494,8 @@
                GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
                goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId());
                goodsStockUpdDTO.setAuctionStock(
                        auctionSalesroomGoods.getSalesroomStock() - auctionBidRecordList.size());
                                auctionSalesroomGoods.getSalesroomStock()
                                        - auctionBidRecordList.size());
                goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO),
                        SecurityConstants.INNER);
            }
@@ -1497,13 +1515,20 @@
        }
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM_GOODS);
        map.put("auctionSalesroomId", auctionSalesroomGoods.getAuctionSalesroomId().toString());
                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);
            }
        } finally {
            if (lock.isLocked()) {
                lock.unlock();
            }
        }
    }
    public void addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount,
@@ -1530,7 +1555,7 @@
                        ConfigEnum.MEMBER_POINTS_POINTS.getKey())
                .getData();
        if (lastBidAmount.intValue() > 0) {
        if (lastBidAmount.compareTo(BigDecimal.ZERO) > 0) {
            BigDecimal divide = lastBidAmount.divide(
                    new BigDecimal(memberPointsMoney.getConfigValue()), 0,
                    RoundingMode.DOWN);