rentaiming
2024-06-03 87c4df897d0c1344df54fb7afc261e7d6490a988
ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionGoodsServiceImpl.java
@@ -4,27 +4,34 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.ruoyi.auction.controller.management.dto.MgtAuctionGoodsDTO;
import com.ruoyi.auction.controller.management.dto.MgtAuctionGoodsQuery;
import com.ruoyi.auction.controller.management.vo.MgtAuctionBidRecordVO;
import com.ruoyi.auction.controller.management.vo.MgtAuctionGoodsVO;
import com.ruoyi.auction.domain.AuctionBidRecord;
import com.ruoyi.auction.domain.AuctionBrowseRecord;
import com.ruoyi.auction.domain.MemberAuctionCollection;
import com.ruoyi.auction.mapper.AuctionGoodsMapper;
import com.ruoyi.auction.service.IAuctionBidRecordService;
import com.ruoyi.auction.service.IAuctionBrowseRecordService;
import com.ruoyi.auction.service.IAuctionGoodsService;
import com.ruoyi.auction.service.IMemberAuctionCollectionService;
import com.ruoyi.auction.service.async.AuctionAsyncMethodService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.enums.AuctionOrderTypeEnum;
import com.ruoyi.common.core.enums.AuctionStartStatusEnum;
import com.ruoyi.common.core.enums.BidStatusEnum;
import com.ruoyi.common.core.enums.BondStatusEnum;
import com.ruoyi.common.core.enums.ListingStatusEnum;
import com.ruoyi.common.core.enums.OrderFromEnum;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.page.BeanUtils;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.system.api.constants.NotificationTypeConstant;
import com.ruoyi.system.api.domain.AuctionGoods;
import com.ruoyi.system.api.domain.GoodsBrand;
import com.ruoyi.system.api.domain.GoodsCategory;
@@ -45,13 +52,16 @@
import com.ruoyi.system.api.feignClient.GoodsSkuClient;
import com.ruoyi.system.api.feignClient.MemberClient;
import com.ruoyi.system.api.feignClient.OrderClient;
import com.ruoyi.system.api.util.WebSocketUsers;
import io.seata.spring.annotation.GlobalTransactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import lombok.RequiredArgsConstructor;
@@ -76,12 +86,17 @@
    private final MemberClient memberClient;
    private final OrderClient orderClient;
    private final IAuctionBidRecordService auctionBidRecordService;
    private final AuctionAsyncMethodService auctionAsyncMethodService;
    // 创建一个静态共享的ObjectMapper实例以重用
    private static final ObjectMapper objectMapper = new ObjectMapper();
    @Resource
    private IMemberAuctionCollectionService memberAuctionCollectionService;
    @Resource
    private AuctionGoodsMapper auctionGoodsMapper;
    @Resource
    private IAuctionBrowseRecordService iAuctionBrowseRecordService;
    /**
     * 获取拍卖商品列表的分页数据
@@ -180,6 +195,7 @@
                    auctionGoodsOrg.getAuctionStock() - dto.getAuctionStock());
            goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO),
                    SecurityConstants.INNER);
            auctionAsyncMethodService.auctionGoodsScheduleTask(Lists.newArrayList(auctionGoods));
        }
    }
@@ -352,6 +368,7 @@
            auctionGoodsVO.setSpecUnit(goodsSkuOne.getSpecUnit());
            auctionGoodsVO.setGoodsSkuName(goodsSkuOne.getSkuName());
            auctionGoodsVO.setCoverPic(goodsSkuOne.getCoverPic());
            auctionGoodsVO.setYears(String.valueOf(goodsSkuOne.getYears()));
            auctionGoodsVOS.add(auctionGoodsVO);
        }
@@ -373,7 +390,7 @@
        auctionGoodsinfoVO.setEndTime(byId.getEndTime());
        auctionGoodsinfoVO.setUnit(goodsSkuOne.getUnit());
        auctionGoodsinfoVO.setDescription(goodsSkuOne.getDescription());
        auctionGoodsinfoVO.setYears(goodsSkuOne.getYears());
        auctionGoodsinfoVO.setYears(String.valueOf(goodsSkuOne.getYears()));
        GoodsBrand data = goodsSkuClient.getBrandOne(goodsSkuOne.getBrandId(), SecurityConstants.INNER).getData();
        GoodsCategory data1 = goodsSkuClient.getCategoryOne(goodsSkuOne.getCategoryId(), SecurityConstants.INNER).getData();
        GoodsSeries data2 = goodsSkuClient.getSeriesOne(goodsSkuOne.getSeriesId(), SecurityConstants.INNER).getData();
@@ -390,6 +407,8 @@
        auctionGoodsinfoVO.setSpecUnit(goodsSkuOne.getSpecUnit());
        auctionGoodsinfoVO.setShareTitle(goodsSkuOne.getShareTitle());
        auctionGoodsinfoVO.setSpecUnit(goodsSkuOne.getSpecUnit());
        auctionGoodsinfoVO.setDetail(goodsSkuOne.getDetail());
        auctionGoodsinfoVO.setYears(String.valueOf(goodsSkuOne.getYears()));
        LambdaQueryWrapper<AuctionBidRecord> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(AuctionBidRecord::getMemberId,auctionGoodsListDTO.getMemberId());
        wrapper1.eq(AuctionBidRecord::getAuctionType,1);
@@ -424,6 +443,32 @@
        }else{
            auctionGoodsinfoVO.setIsApply(1);
        }
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = now.format(formatter);
        LocalDateTime parseTime = LocalDateTime.parse(formattedDate, formatter);
        LocalDateTime newTime7 = now.minusDays(7);
        String formattedDate7 = newTime7.format(formatter);
        LocalDateTime parseTime7 = LocalDateTime.parse(formattedDate7, formatter);
        LambdaQueryWrapper<AuctionBrowseRecord> wrapper3=Wrappers.lambdaQuery();
        wrapper3.eq(AuctionBrowseRecord::getDelFlag,0);
        wrapper3.eq(AuctionBrowseRecord::getTargetId,auctionGoodsListDTO.getGoodsSkuId());
        wrapper3.eq(AuctionBrowseRecord::getMemberId,auctionGoodsListDTO.getMemberId());
        wrapper3.ge(AuctionBrowseRecord::getCreateTime, parseTime7)
                .le(AuctionBrowseRecord::getCreateTime, parseTime);
        List<AuctionBrowseRecord> list = iAuctionBrowseRecordService.list(wrapper3);
        if (list.size()==0){
            AuctionBrowseRecord auctionBrowseRecord=new AuctionBrowseRecord();
            auctionBrowseRecord.setBrowseType(AuctionOrderTypeEnum.REGULAR_ITEMS);
            auctionBrowseRecord.setMemberId(auctionGoodsListDTO.getMemberId());
            auctionBrowseRecord.setTargetId(auctionGoodsListDTO.getGoodsSkuId());
            iAuctionBrowseRecordService.save(auctionBrowseRecord);
        }
        return auctionGoodsinfoVO;
    }
@@ -438,6 +483,9 @@
        AuctionGoodsListPageDTO auctionGoodsListPageDTO=new AuctionGoodsListPageDTO();
        auctionGoodsListPageDTO.setGoodsSkuIdList(goodsSkuIdList);
        if (auctionGoodsListDTO.getStartStatus()!=4){
            auctionGoodsListPageDTO.setStartStatus(auctionGoodsListDTO.getStartStatus());
        }
        Page<AuctionGoodsListVO> page = new Page<>();
        page.setSize(auctionGoodsListDTO.getPageSize());
@@ -481,4 +529,42 @@
        page.setRecords(auctionGoodsVOS);
        return PageDTO.of(page);
    }
    @Override
    public void endAuctionGoods(Long id) throws JsonProcessingException {
        AuctionGoods auctionGoods = this.getById(id);
        if (StringUtils.isNotNull(auctionGoods) && auctionGoods.getListingStatus().equals(
                ListingStatusEnum.ON_SHELVES) && auctionGoods.getStartStatus()
                .equals(AuctionStartStatusEnum.IN_PREVIEW)) {
            this.lambdaUpdate().set(AuctionGoods::getStartStatus, AuctionStartStatusEnum.IN_AUCTION)
                    .eq(AuctionGoods::getId, id);
            Map<String, Object> map = new ConcurrentHashMap<>();
            map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS);
            map.put("notification_time", LocalDateTime.now());
            map.put("target_id", id);
            map.put("message_type", "start");
            String msg = objectMapper.writeValueAsString(map);
            WebSocketUsers.sendMessageToUsersByText(msg);
            log.info("===================>发送websocket通知,消息体{}", msg);
        }
    }
    @Override
    public void startAuctionGoods(Long id) throws JsonProcessingException {
        AuctionGoods auctionGoods = this.getById(id);
        if (StringUtils.isNotNull(auctionGoods) && auctionGoods.getListingStatus().equals(
                ListingStatusEnum.ON_SHELVES) && auctionGoods.getStartStatus()
                .equals(AuctionStartStatusEnum.IN_AUCTION)) {
            this.lambdaUpdate().set(AuctionGoods::getStartStatus, AuctionStartStatusEnum.ENDED)
                    .eq(AuctionGoods::getId, id);
            Map<String, Object> map = new ConcurrentHashMap<>();
            map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS);
            map.put("notification_time", LocalDateTime.now());
            map.put("target_id", id);
            map.put("message_type", "end");
            String msg = objectMapper.writeValueAsString(map);
            WebSocketUsers.sendMessageToUsersByText(msg);
            log.info("===================>发送websocket通知,消息体{}", msg);
        }
    }
}