mitao
2024-09-21 f44e4d609e7efaed9eac545137970b1e334f8106
ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java
@@ -14,6 +14,7 @@
import com.ruoyi.auction.domain.AuctionBidRecord;
import com.ruoyi.auction.domain.AuctionBrowseRecord;
import com.ruoyi.auction.domain.MemberAuctionCollection;
import com.ruoyi.auction.mapper.AuctionBondJlMapper;
import com.ruoyi.auction.mapper.AuctionGoodsMapper;
import com.ruoyi.auction.service.IAuctionBidRecordService;
import com.ruoyi.auction.service.IAuctionBrowseRecordService;
@@ -32,9 +33,11 @@
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.common.core.utils.page.CollUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.system.api.constants.ConfigEnum;
import com.ruoyi.system.api.constants.NotificationTypeConstant;
import com.ruoyi.system.api.domain.AuctionBondJl;
import com.ruoyi.system.api.domain.AuctionGoods;
import com.ruoyi.system.api.domain.CustomConfig;
import com.ruoyi.system.api.domain.GoodsBrand;
@@ -114,6 +117,9 @@
    @Resource
    private IAuctionBrowseRecordService iAuctionBrowseRecordService;
    @Resource
    private AuctionBondJlMapper auctionBondJlMapper;
    /**
     * 获取拍卖商品列表的分页数据
@@ -242,7 +248,19 @@
            auctionGoodsOrg.setSharePic(dto.getSharePic());
            this.updateById(auctionGoodsOrg);
        }
        auctionAsyncMethodService.auctionGoodsScheduleTask(Lists.newArrayList(auctionGoods));
        if (auctionGoods.getEndTime().isBefore(LocalDateTime.now())) {
            // 退回剩余库存
            GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO();
            goodsStockUpdDTO.setAuctionStock(auctionGoods.getAuctionStock());
            goodsStockUpdDTO.setGoodsSkuId(auctionGoods.getGoodsSkuId());
            goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO),
                    SecurityConstants.INNER);
            auctionGoods.setStartStatus(AuctionStartStatusEnum.ENDED);
            this.updateById(auctionGoods);
        } else {
            auctionAsyncMethodService.auctionGoodsScheduleTask(Lists.newArrayList(auctionGoods));
        }
    }
    /**
@@ -378,6 +396,7 @@
                        orderDTO.setSkuName(goodsSku.getSkuName());
                    }
                    orderDTO.setOrderTimeSx(auctionGoods.getEndTime());
                    orderDTO.setGoodsId(auctionGoods.getGoodsSkuId());
                    orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER);
                }
            } else {
@@ -404,7 +423,8 @@
                for (OrderAuctionBond orderAuctionBond : auctionBondList) {
                    // 已中标需在订单完成后退保证金
                    if (unRefundMemberIdList.contains(orderAuctionBond.getMemberId())) {
                    if (unRefundMemberIdList.contains(orderAuctionBond.getMemberId())
                            || Objects.isNull(orderAuctionBond.getBond())) {
                        continue;
                    }
                    RefundDTO refundDTO = new RefundDTO();
@@ -415,10 +435,10 @@
                // 远程调用订单服务进行退款
                Map<String, Object> data = orderClient.refund(refundDTOList,
                        SecurityConstants.INNER).getData();
                if (CollUtils.isNotEmpty(data)) {
                // 处理退款返回结果
                List<String> successfulOrders = new ArrayList<>();
                List<String> failedOrders = new ArrayList<>();
                data.forEach((key, value) -> {
                    if ((boolean) value) {
                        successfulOrders.add(key);
@@ -434,9 +454,11 @@
                    }
                    return null;
                }).filter(Objects::nonNull).collect(Collectors.toList());
                // 远程调用订单服务修改订单状态
                orderClient.updateOrderAuctionBondStatus(ids, BondStatusEnum.REFUNDED,
                        SecurityConstants.INNER);
                }
            }
        }
    }
@@ -448,6 +470,9 @@
            List<GoodsSku> goodsSku = goodsSkuClient.getGoodsByName(auctionGoodsListDTO.getGoodsSkuName(),
                            SecurityConstants.INNER)
                    .getData();
            if (CollUtils.isEmpty(goodsSku)) {
                return PageDTO.empty(0L, 1L);
            }
            if (goodsSku!=null){
                goodsSkuIdList = goodsSku.stream().map(GoodsSku::getId)
                        .collect(Collectors.toSet());
@@ -533,12 +558,19 @@
        auctionGoodsinfoVO.setMinimumMarkupAmount(byId.getMinimumMarkupAmount());
        auctionGoodsinfoVO.setSpec(goodsSkuOne.getSpec());
        auctionGoodsinfoVO.setSpecUnit(goodsSkuOne.getSpecUnit());
        auctionGoodsinfoVO.setShareTitle(goodsSkuOne.getShareTitle());
        auctionGoodsinfoVO.setDetail(goodsSkuOne.getDetail());
        auctionGoodsinfoVO.setBond(byId.getBond());
        auctionGoodsinfoVO.setYears(goodsSkuOne.getYears());
        auctionGoodsinfoVO.setSharePic(byId.getSharePic());
        auctionGoodsinfoVO.setShareTitle(byId.getShareTitle());
        if (StringUtils.isNotBlank(byId.getShareTitle())) {
            auctionGoodsinfoVO.setShareTitle(byId.getShareTitle());
        } else {
            auctionGoodsinfoVO.setShareTitle(goodsSkuOne.getSkuName());
        }
        if (StringUtils.isNotBlank(byId.getSharePic())) {
            auctionGoodsinfoVO.setSharePic(byId.getSharePic());
        } else {
            auctionGoodsinfoVO.setSharePic(goodsSkuOne.getCoverPic());
        }
        LambdaQueryWrapper<AuctionBidRecord> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(AuctionBidRecord::getAuctionType,1);
        wrapper1.eq(AuctionBidRecord::getTargetId,byId.getId());
@@ -576,15 +608,18 @@
        }else {
            auctionGoodsinfoVO.setIsCollection(1);
        }
        List<OrderAuctionBond> datas = orderClient.getAuctionGoodsOrderAuctionBondList(auctionGoodsListDTO, SecurityConstants.INNER).getData();
       if(datas!=null){
           if (datas.size()>0){
        LambdaQueryWrapper<AuctionBondJl> wrapper8=Wrappers.lambdaQuery();
        wrapper8.eq(AuctionBondJl::getAuctionGoodsId,byId.getId());
        wrapper8.eq(AuctionBondJl::getMemberId,auctionGoodsListDTO.getMemberId());
        wrapper8.eq(AuctionBondJl::getIsState,0);
        AuctionBondJl auctionBondJl = auctionBondJlMapper.selectOne(wrapper8);
       if(auctionBondJl!=null){
               auctionGoodsinfoVO.setIsApply(2);
           }else{
               auctionGoodsinfoVO.setIsApply(1);
           }
       }
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime newTime7 = now.minusDays(7);
@@ -601,6 +636,7 @@
            AuctionBrowseRecord auctionBrowseRecord=new AuctionBrowseRecord();
            auctionBrowseRecord.setBrowseType(AuctionOrderTypeEnum.REGULAR_ITEMS);
            auctionBrowseRecord.setMemberId(auctionGoodsListDTO.getMemberId());
            auctionBrowseRecord.setSkuName(goodsSkuOne.getSkuName());
            auctionBrowseRecord.setTargetId(auctionGoodsListDTO.getGoodsSkuId());
            iAuctionBrowseRecordService.save(auctionBrowseRecord);
        }
@@ -636,59 +672,72 @@
    @Override
    public PageDTO<AuctionGoodsListVO> getWdAuctionSalesList(AuctionGoodsListDTO auctionGoodsListDTO) {
        MemberAuctionSalesroomDTO memberAuctionSalesroomDTO =new MemberAuctionSalesroomDTO();
        memberAuctionSalesroomDTO.setMemberId(auctionGoodsListDTO.getMemberId());
        List<OrderAuctionBond> data = orderClient.getAuctionGoodsOrderAuctionBondList(auctionGoodsListDTO, SecurityConstants.INNER).getData();
        Set<Long> goodsSkuIdList = null;
        List<Long> goodsSkuIdList = null;
        if (data.size()>0){
            goodsSkuIdList = data.stream().map(OrderAuctionBond::getAuctionGoodsId)
                    .collect(Collectors.toSet());
                    .collect(Collectors.toList());
        }else {
            Set<Long> goodsSkuIdList1 =new HashSet<>();
            List<Long> goodsSkuIdList1 =new ArrayList<>();
            goodsSkuIdList1.add(0L);
            goodsSkuIdList=goodsSkuIdList1;
        }
        AuctionGoodsListPageDTO auctionGoodsListPageDTO=new AuctionGoodsListPageDTO();
        if (goodsSkuIdList!=null){
            auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList);
        List<Long> goodsSkuIdList1 =null;
        if (StringUtils.isNotEmpty(auctionGoodsListDTO.getGoodsSkuName())) {
            List<GoodsSku> goodsSku = goodsSkuClient.getGoodsByName(auctionGoodsListDTO.getGoodsSkuName(),
                            SecurityConstants.INNER)
                    .getData();
            goodsSkuIdList1= goodsSku.stream().map(GoodsSku::getId)
                    .collect(Collectors.toList());
        }
        if (auctionGoodsListDTO.getStartStatus()!=4){
            if (auctionGoodsListDTO.getStartStatus()==0){
                auctionGoodsListPageDTO.setStartStatus(5);
            }else{
                auctionGoodsListPageDTO.setStartStatus(auctionGoodsListDTO.getStartStatus());
            }
        Page<AuctionGoods> page = new Page<>(auctionGoodsListDTO.getPageCurr(),
                auctionGoodsListDTO.getPageSize());
        LambdaQueryWrapper<AuctionGoods> wrapper1=Wrappers.lambdaQuery();
        if (goodsSkuIdList.size()>0){
            wrapper1.in(AuctionGoods::getId,goodsSkuIdList);
        }
        if (StringUtils.isNotEmpty(auctionGoodsListDTO.getGoodsSkuName())) {
        if (goodsSkuIdList1.size()>0){
            wrapper1.in(AuctionGoods::getGoodsSkuId,goodsSkuIdList1);
        }else{
            goodsSkuIdList1=new ArrayList<>();
            goodsSkuIdList1.add(0L);
            wrapper1.in(AuctionGoods::getGoodsSkuId,goodsSkuIdList1);
        }
        }
        if (auctionGoodsListDTO.getStartStatus() != 4) {
            wrapper1.eq(AuctionGoods::getStartStatus,auctionGoodsListDTO.getStartStatus());
        }
        wrapper1.last(auctionGoodsListDTO.getStartStatus() == 4, "ORDER BY\n"
                + "    FIELD(start_status, 1, 0, 2),\n"
                + "    start_time DESC");
        wrapper1.last(auctionGoodsListDTO.getStartStatus() != 4, "ORDER BY start_time DESC");
        Page<AuctionGoods> auctionSalesroomList=this.page(page,wrapper1);
        PageDTO<AuctionGoodsListVO> wdMemberAuctionSalesroomVOPageDTO = PageDTO.of(auctionSalesroomList, AuctionGoodsListVO.class);
        List<AuctionGoodsListVO> list = wdMemberAuctionSalesroomVOPageDTO.getList();
        for (AuctionGoodsListVO auctionGoodsVO:list){
        Page<AuctionGoodsListVO> page = new Page<>();
        page.setSize(auctionGoodsListDTO.getPageSize());
        page.setCurrent(auctionGoodsListDTO.getPageCurr());
        List<AuctionGoods> auctionGoodsPgeList = auctionGoodsMapper.getAuctionGoodsPgeList1(page, auctionGoodsListPageDTO);
        List<AuctionGoodsListVO> auctionGoodsVOS=new ArrayList<>();
        for (AuctionGoods auctionGoods:auctionGoodsPgeList){
            AuctionGoodsListVO auctionGoodsVO=new AuctionGoodsListVO();
            auctionGoodsVO.setAuctionStock(auctionGoods.getAuctionStock());
            auctionGoodsVO.setGoodsSkuId(auctionGoods.getId());
            auctionGoodsVO.setEndTime(auctionGoods.getEndTime());
            auctionGoodsVO.setStartTime(auctionGoods.getStartTime());
            auctionGoodsVO.setStartingPrice(auctionGoods.getStartingPrice());
            auctionGoodsVO.setStartStatus(auctionGoods.getStartStatus());
            GoodsSku goodsSkuOne = goodsSkuClient.getGoodsSkuOne(auctionGoods.getGoodsSkuId(), SecurityConstants.INNER).getData();
            GoodsSku goodsSkuOne = goodsSkuClient.getGoodsSkuOne(auctionGoodsVO.getGoodsSkuId(), SecurityConstants.INNER).getData();
            auctionGoodsVO.setUnit(goodsSkuOne.getUnit());
            auctionGoodsVO.setSpec(goodsSkuOne.getSpec());
            auctionGoodsVO.setSpecUnit(goodsSkuOne.getSpecUnit());
            auctionGoodsVO.setGoodsSkuName(goodsSkuOne.getSkuName());
            auctionGoodsVO.setCoverPic(goodsSkuOne.getCoverPic());
            LambdaQueryWrapper<AuctionBidRecord> wrapper1= Wrappers.lambdaQuery();
            wrapper1.eq(AuctionBidRecord::getMemberId,auctionGoodsListDTO.getMemberId());
            wrapper1.eq(AuctionBidRecord::getAuctionType,1);
            wrapper1.eq(AuctionBidRecord::getTargetId,auctionGoods.getId());
            wrapper1.eq(AuctionBidRecord::getDelFlag,0);
            AuctionBidRecord list1 = auctionBidRecordService.getOne(wrapper1);
            LambdaQueryWrapper<AuctionBidRecord> wrapper2= Wrappers.lambdaQuery();
            wrapper2.eq(AuctionBidRecord::getMemberId,auctionGoodsListDTO.getMemberId());
            wrapper2.eq(AuctionBidRecord::getAuctionType,1);
            wrapper2.eq(AuctionBidRecord::getTargetId,auctionGoodsVO.getId());
            wrapper2.eq(AuctionBidRecord::getDelFlag,0);
            AuctionBidRecord list1 = auctionBidRecordService.getOne(wrapper2);
            if (list1!=null){
                if (list1.getStatus().getCode()==2){
                    auctionGoodsVO.setIsStatus(2);
@@ -698,12 +747,10 @@
            }else{
                auctionGoodsVO.setIsStatus(1);
            }
            auctionGoodsVOS.add(auctionGoodsVO);
            auctionGoodsVO.setGoodsSkuId(auctionGoodsVO.getId());
        }
        page.setRecords(auctionGoodsVOS);
        return PageDTO.of(page);
        return wdMemberAuctionSalesroomVOPageDTO;
    }
    @Override
@@ -784,6 +831,7 @@
                            orderDTO.setSkuName(goodsSku.getSkuName());
                        }
                        orderDTO.setOrderTimeSx(auctionGoods.getEndTime());
                        orderDTO.setGoodsId(auctionGoods.getGoodsSkuId());
                        orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER);
                    }
                } else {
@@ -892,6 +940,19 @@
        this.updateById(auctionGoods);
    }
    /**
     * 根据商品id获取正在进行的拍卖商品
     *
     * @param id 商品id
     * @return
     */
    @Override
    public List<AuctionGoods> getAuctionGoodsBySkuId(Long id) {
        return this.list(new LambdaQueryWrapper<AuctionGoods>().eq(AuctionGoods::getGoodsSkuId,
                        id).eq(AuctionGoods::getListingStatus, ListingStatusEnum.ON_SHELVES)
                .eq(AuctionGoods::getStartStatus, AuctionStartStatusEnum.IN_AUCTION));
    }
    public static void main(String[] args) throws JsonProcessingException {
        Map<String, Object> map = new ConcurrentHashMap<>();
        map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS);
@@ -901,4 +962,12 @@
        String msg = objectMapper.writeValueAsString(map);
        System.out.println(msg);
    }
    @Override
    public List<GoodsSku> getGoodsSkuByAuctionGoodsIdSet(Set<Long> auctionGoodsIdSet) {
        List<AuctionGoods> auctionGoodsList = this.listByIds(auctionGoodsIdSet);
        List<Long> goodsSkuIdList = auctionGoodsList.stream().map(AuctionGoods::getGoodsSkuId)
                .collect(Collectors.toList());
        return goodsSkuClient.getGoodsListByIds(goodsSkuIdList, SecurityConstants.INNER).getData();
    }
}