From 392b42c4891cf2e6beda57ab32c51598f290f4b7 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 14 三月 2025 20:56:27 +0800 Subject: [PATCH] bug修改 --- ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java | 739 +++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 465 insertions(+), 274 deletions(-) diff --git a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java index 7ec091d..7503e82 100644 --- a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java +++ b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/service/impl/AuctionSalesroomServiceImpl.java @@ -25,7 +25,6 @@ import com.ruoyi.auction.controller.management.vo.MgtAuctionSalesroomScreenVO; import com.ruoyi.auction.controller.management.vo.MgtAuctionSalesroomVO; import com.ruoyi.auction.domain.AuctionBidRecord; -import com.ruoyi.auction.domain.AuctionBondJl; import com.ruoyi.auction.domain.AuctionBrowseRecord; import com.ruoyi.auction.domain.AuctionVideo; import com.ruoyi.auction.mapper.AuctionBidRecordMapper; @@ -37,7 +36,6 @@ import com.ruoyi.auction.service.IAuctionGoodsService; import com.ruoyi.auction.service.IAuctionSalesroomService; import com.ruoyi.auction.service.IAuctionVideoService; -import com.ruoyi.auction.util.CreateQrCode; import com.ruoyi.auction.util.HttpUtils; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.SecurityConstants; @@ -50,6 +48,7 @@ import com.ruoyi.common.core.enums.ClientTypeEnum; import com.ruoyi.common.core.enums.OrderFromEnum; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.IDhelper; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.page.BeanUtils; @@ -61,6 +60,7 @@ import com.ruoyi.system.api.constants.ConfigEnum; import com.ruoyi.system.api.constants.NotificationTypeConstant; import com.ruoyi.system.api.domain.AppMiniLoginVO; +import com.ruoyi.system.api.domain.AuctionBondJl; import com.ruoyi.system.api.domain.AuctionGoods; import com.ruoyi.system.api.domain.AuctionSalesroom; import com.ruoyi.system.api.domain.AuctionSalesroomGoods; @@ -82,17 +82,20 @@ import com.ruoyi.system.api.domain.dto.OrderAuctionBondDTO; import com.ruoyi.system.api.domain.dto.OrderDTO; import com.ruoyi.system.api.domain.dto.RefundDTO; +import com.ruoyi.system.api.domain.dto.SmsSendDTO; import com.ruoyi.system.api.domain.vo.ForepartAuctionSalesroomGoodsVO; import com.ruoyi.system.api.domain.vo.ForepartAuctionSalesroomVO; import com.ruoyi.system.api.domain.vo.MemberAuctionSalesroomInfoVO; import com.ruoyi.system.api.domain.vo.MemberAuctionSalesroomVO; import com.ruoyi.system.api.domain.vo.PayInfoVO; import com.ruoyi.system.api.domain.vo.WdMemberAuctionSalesroomVO; +import com.ruoyi.system.api.feignClient.AuthClient; 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.feignClient.PromotionClient; import com.ruoyi.system.api.feignClient.SysUserClient; +import com.ruoyi.system.api.model.LoginUser; import io.seata.spring.annotation.GlobalTransactional; import java.io.IOException; import java.math.BigDecimal; @@ -105,6 +108,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -113,6 +117,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.util.EntityUtils; @@ -129,6 +134,7 @@ * @author mitao * @since 2024-05-16 */ +@Slf4j @Service public class AuctionSalesroomServiceImpl extends ServiceImpl<AuctionSalesroomMapper, AuctionSalesroom> implements IAuctionSalesroomService { @@ -180,6 +186,11 @@ @Resource private RedissonClient redissonClient; + @Resource + private AuthClient authClient; + + private static final String SUCCESS_TEMPLATE = "【酒鼎老酒】恭喜!您参与的“content”竞拍已中拍!"; + private static final String FAILED_TEMPLATE = "【酒鼎老酒】很遗憾!您参与的”content“竞拍未中拍!"; public static RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).build(); // 配置您申请的KEY,在个人中心->我的数据,接口名称上方查看 public static final String APPKEY = ""; @@ -385,7 +396,9 @@ @Override public AppMiniLoginVO isMiniLogin(AppMiniLoginDTO appMiniLoginDto) { AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); - R<SysUser> sysUserR = sysUserClient.queryUserByPhone(appMiniLoginDto.getPhone()); + LoginUser loginUser = SecurityUtils.getLoginUser(); + Long userid = loginUser.getUserid(); + R<SysUser> sysUserR = sysUserClient.getSysUser(userid); SysUser data = sysUserR.getData(); appMiniLoginVo.setSysUser(data); appMiniLoginVo.setPhone(appMiniLoginDto.getCode()); @@ -408,7 +421,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()); @@ -465,8 +478,18 @@ memberAuctionSalesroomInfoVO.setEndTime(byId.getEndTime()); memberAuctionSalesroomInfoVO.setType(byId.getType()); memberAuctionSalesroomInfoVO.setDescription(byId.getDescription()); - memberAuctionSalesroomInfoVO.setSharePic(byId.getSharePic()); memberAuctionSalesroomInfoVO.setShareTitle(byId.getShareTitle()); + memberAuctionSalesroomInfoVO.setAuctionAgreement(byId.getAuctionAgreement()); + if (StringUtils.isNotBlank(byId.getShareTitle())) { + memberAuctionSalesroomInfoVO.setShareTitle(byId.getShareTitle()); + } else { + memberAuctionSalesroomInfoVO.setShareTitle(byId.getSalesroomName()); + } + if (StringUtils.isNotBlank(byId.getSharePic())) { + memberAuctionSalesroomInfoVO.setSharePic(byId.getSharePic()); + } else { + memberAuctionSalesroomInfoVO.setSharePic(byId.getCoverPic()); + } memberAuctionSalesroomInfoVO.setStartTime(byId.getStartTime()); memberAuctionSalesroomInfoVO.setStatus(byId.getStatus()); memberAuctionSalesroomInfoVO.setCoverPic(byId.getCoverPic()); @@ -496,7 +519,7 @@ forepartAuctionSalesroomGoodsVO.setGoodsSkuId(salesroomGoods.getId()); forepartAuctionSalesroomGoodsVO.setCoverPic(goodsSku.getCoverPic()); forepartAuctionSalesroomGoodsVO.setStartingPrice(salesroomGoods.getStartingPrice()); - forepartAuctionSalesroomGoodsVO.setSalesroomStock(salesroomGoods.getSalesroomStock()); + // forepartAuctionSalesroomGoodsVO.setSalesroomStock(salesroomGoods.getSalesroomStock()); forepartAuctionSalesroomGoodsVO.setGoodsSkustatus(salesroomGoods.getStatus().getCode()); forepartAuctionSalesroomGoodsVO.setMinimumMarkupAmount(salesroomGoods.getMinimumMarkupAmount()); forepartAuctionSalesroomGoodsVO.setStartTime(salesroomGoods.getStartTime()); @@ -504,6 +527,10 @@ forepartAuctionSalesroomGoodsVO.setListingDuration(salesroomGoods.getListingDuration()); forepartAuctionSalesroomGoodsVO.setSpec(goodsSku.getSpec()); forepartAuctionSalesroomGoodsVO.setSpecUnit(goodsSku.getSpecUnit()); + forepartAuctionSalesroomGoodsVO.setDealQuantity(salesroomGoods.getDealQuantity()); + forepartAuctionSalesroomGoodsVO.setMaxAmount(salesroomGoods.getMaxAmount()); + forepartAuctionSalesroomGoodsVO.setBidNum(salesroomGoods.getBidNum()); + forepartAuctionSalesroomGoodsVO.setUnit(goodsSku.getUnit()); LambdaQueryWrapper<AuctionBidRecord> wrapper1=Wrappers.lambdaQuery(); wrapper1.eq(AuctionBidRecord::getMemberId,memberAuctionSalesroomDTO.getMemberId()); wrapper1.eq(AuctionBidRecord::getAuctionSalesroomId,byId.getId()); @@ -669,149 +696,186 @@ @Override public void SaveBid(BidDTO bidVO) { - 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()){ - 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::getDelFlag,0); - AuctionSalesroom one = this.getOne(wrapper); - bidVO.setAuctionSalesroomId(one.getId()); - } + 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()); + R<GoodsSku> goodsSkuOneR = goodsSkuClient.getGoodsSkuOne(byId.getGoodsSkuId(), + SecurityConstants.INNER); + GoodsSku goodsSku = goodsSkuOneR.getData(); + // 判断否大于最高价 + if (Objects.nonNull(byId.getMaxAmount()) + && byId.getMaxAmount().compareTo(bidVO.getLastBidAmount()) < 0) { + throw new ServiceException("出价不能高出最高价"); + } + // 查询用户出价记录判断是否第一次出价 首次出价,可以只出起拍价,而不是需要比起拍价高。 + Long count = auctionBidRecordService.lambdaQuery() + .eq(AuctionBidRecord::getAuctionSalesroomId, bidVO.getAuctionSalesroomId()) + .eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()) + .eq(AuctionBidRecord::getAuctionType, bidVO.getAuctionType()) + .eq(AuctionBidRecord::getMemberId, bidVO.getMemberId()).count(); - LambdaQueryWrapper<AuctionBidRecord> wrapper3=Wrappers.lambdaQuery(); - wrapper3.eq(AuctionBidRecord::getAuctionSalesroomId,bidVO.getAuctionSalesroomId()); - wrapper3.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId()); - wrapper3.eq(AuctionBidRecord::getDelFlag,0); - wrapper3.orderByDesc(AuctionBidRecord::getLastBidAmount); - wrapper3.last("limit 1"); - AuctionBidRecord one3 = auctionBidRecordService.getOne(wrapper3); - if (byId.getSalesroomStock()==1){ - if (one3!=null){ - if (bidVO.getLastBidAmount().doubleValue()<one3.getLastBidAmount().doubleValue()){ - throw new ServiceException("出价不能比当前最高价低"); + if (byId.getStartingPrice().doubleValue() > bidVO.getLastBidAmount() + .doubleValue() && count > 0) { + 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::getDelFlag, 0); + AuctionSalesroom one = this.getOne(wrapper); + bidVO.setAuctionSalesroomId(one.getId()); + } + + LambdaQueryWrapper<AuctionBidRecord> wrapper3 = Wrappers.lambdaQuery(); + wrapper3.eq(AuctionBidRecord::getAuctionSalesroomId, bidVO.getAuctionSalesroomId()); + wrapper3.eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()); + wrapper3.eq(AuctionBidRecord::getDelFlag, 0); + wrapper3.orderByDesc(AuctionBidRecord::getLastBidAmount); + wrapper3.last("limit 1"); + AuctionBidRecord one3 = auctionBidRecordService.getOne(wrapper3); + if (byId.getBidNum() == 1) { + if (one3 != null) { + if (bidVO.getLastBidAmount().doubleValue() < one3.getLastBidAmount() + .doubleValue()) { + throw new ServiceException("出价不能比当前最高价低"); + } + } + if (one3 != null) { + if (bidVO.getLastBidAmount().doubleValue() < one3.getLastBidAmount() + .add(byId.getMinimumMarkupAmount()).doubleValue()) { + throw new ServiceException("出价不能比当前最高价低加每次加价低"); + } } } - if (one3!=null){ - if (bidVO.getLastBidAmount().doubleValue()<one3.getLastBidAmount().add(byId.getMinimumMarkupAmount()).doubleValue()){ - throw new ServiceException("出价不能比当前最高价低加每次加价低"); - } - } - } - BigDecimal bigDecimal=byId.getStartingPrice().add(byId.getMinimumMarkupAmount()); - if (bigDecimal.doubleValue()>bidVO.getLastBidAmount().doubleValue()){ - throw new ServiceException("出价不能比每次最少加价低"); - } - - LambdaQueryWrapper<AuctionBidRecord> wrapper1=Wrappers.lambdaQuery(); - wrapper1.eq(AuctionBidRecord::getMemberId,bidVO.getMemberId()); - wrapper1.eq(AuctionBidRecord::getAuctionSalesroomId,bidVO.getAuctionSalesroomId()); - wrapper1.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId()); - wrapper1.eq(AuctionBidRecord::getDelFlag,0); - - AuctionBidRecord one = auctionBidRecordService.getOne(wrapper1); - if (one!=null){ - one.setLastBidAmount(bidVO.getLastBidAmount()); - one.setLastBidTime(LocalDateTime.now()); - one.setBidCount(one.getBidCount()+1); - auctionBidRecordService.updateById(one); - }else{ - one=new AuctionBidRecord(); - one.setAuctionSalesroomId(bidVO.getAuctionSalesroomId()); - one.setTargetId(bidVO.getTargetId()); - one.setMemberId(bidVO.getMemberId()); - one.setLastBidTime(LocalDateTime.now()); - if(membeOne.getRealName()!=null&&membeOne.getRealName()!=""){ - one.setNickname(membeOne.getRealName()); - }else{ - one.setNickname(membeOne.getNickname()); + BigDecimal bigDecimal = byId.getStartingPrice().add(byId.getMinimumMarkupAmount()); + if (bigDecimal.doubleValue() > bidVO.getLastBidAmount().doubleValue() + && count > 0) { + throw new ServiceException("出价不能比每次最少加价低"); } - one.setPhone(membeOne.getPhone()); - one.setAuctionType(AuctionOrderTypeEnum.AUCTION_ITEMS); - one.setStatus(BidStatusEnum.ELIMINATE); - one.setBidCount(1); - one.setLastBidAmount(bidVO.getLastBidAmount()); - auctionBidRecordService.save(one); - } + LambdaQueryWrapper<AuctionBidRecord> wrapper1 = Wrappers.lambdaQuery(); + wrapper1.eq(AuctionBidRecord::getMemberId, bidVO.getMemberId()); + wrapper1.eq(AuctionBidRecord::getAuctionSalesroomId, bidVO.getAuctionSalesroomId()); + wrapper1.eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()); + wrapper1.eq(AuctionBidRecord::getDelFlag, 0); - - LambdaQueryWrapper<AuctionBidRecord> wrapper2=Wrappers.lambdaQuery(); - wrapper2.eq(AuctionBidRecord::getAuctionSalesroomId,bidVO.getAuctionSalesroomId()); - wrapper2.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId()); - wrapper2.eq(AuctionBidRecord::getDelFlag,0); - wrapper2.orderByDesc(AuctionBidRecord::getLastBidAmount); - AuctionBidRecord one2 = auctionBidRecordService.getOne(wrapper1); - - Map<String, Object> map = new ConcurrentHashMap<>(); - map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM); - map.put("auctionSalesroomId", bidVO.getAuctionSalesroomId()); - map.put("byId", byId.getStatus()); - map.put("lastBidAmount",one2.getLastBidAmount()); - map.put("message_type", "BidRecor"); - map.put("type",3); - String msg = null; - try { - msg = objectMapper.writeValueAsString(map); - } catch (JsonProcessingException e) { - } - 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()){ - throw new ServiceException("出价不能比起拍价低"); - } - BigDecimal bigDecimal=byId.getStartingPrice().add(byId.getMinimumMarkupAmount()); - if (bigDecimal.doubleValue()>bidVO.getLastBidAmount().doubleValue()){ - throw new ServiceException("出价不能比每次最少加价低"); - } - LambdaQueryWrapper<AuctionBidRecord> wrapper1=Wrappers.lambdaQuery(); - wrapper1.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId()); - wrapper1.eq(AuctionBidRecord::getDelFlag,0); - wrapper1.orderByDesc(AuctionBidRecord::getLastBidAmount); - wrapper1.last("limit 1"); - AuctionBidRecord one = auctionBidRecordService.getOne(wrapper1); - if (byId.getAuctionStock()==1){ + AuctionBidRecord one = auctionBidRecordService.getOne(wrapper1); if (one != null) { - BigDecimal bigDecimal1 = one.getLastBidAmount().add(byId.getMinimumMarkupAmount()); - if (bigDecimal1.doubleValue() > bidVO.getLastBidAmount().doubleValue()) { - throw new ServiceException("出价不能比上次出价加每次最少加价低"); + one.setLastBidAmount(bidVO.getLastBidAmount()); + one.setLastBidTime(LocalDateTime.now()); + one.setBidCount(one.getBidCount() + 1); + auctionBidRecordService.updateById(one); + } else { + one = new AuctionBidRecord(); + one.setAuctionSalesroomId(bidVO.getAuctionSalesroomId()); + one.setTargetId(bidVO.getTargetId()); + one.setMemberId(bidVO.getMemberId()); + one.setLastBidTime(LocalDateTime.now()); + if (membeOne.getRealName() != null && membeOne.getRealName() != "") { + one.setNickname(membeOne.getRealName()); + } else { + one.setNickname(membeOne.getNickname()); } + one.setPhone(membeOne.getPhone()); + one.setAuctionType(AuctionOrderTypeEnum.AUCTION_ITEMS); + one.setStatus(BidStatusEnum.ELIMINATE); + one.setBidCount(1); + one.setLastBidAmount(bidVO.getLastBidAmount()); + one.setGoodsName(Objects.nonNull(goodsSku) ? goodsSku.getSkuName() : ""); + auctionBidRecordService.save(one); } - } - LambdaQueryWrapper<AuctionBidRecord> wrapper3=Wrappers.lambdaQuery(); - wrapper3.eq(AuctionBidRecord::getTargetId,bidVO.getTargetId()); - wrapper3.eq(AuctionBidRecord::getDelFlag,0); - wrapper3.eq(AuctionBidRecord::getMemberId,bidVO.getMemberId()); - wrapper3.orderByDesc(AuctionBidRecord::getLastBidAmount); - wrapper3.last("limit 1"); - AuctionBidRecord one3 = auctionBidRecordService.getOne(wrapper3); - if (one3!=null){ + + LambdaQueryWrapper<AuctionBidRecord> wrapper2 = Wrappers.lambdaQuery(); + wrapper2.eq(AuctionBidRecord::getAuctionSalesroomId, bidVO.getAuctionSalesroomId()); + wrapper2.eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()); + wrapper2.eq(AuctionBidRecord::getDelFlag, 0); + wrapper2.orderByDesc(AuctionBidRecord::getLastBidAmount); + AuctionBidRecord one2 = auctionBidRecordService.getOne(wrapper1); + + Map<String, Object> map = new ConcurrentHashMap<>(); + map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM); + map.put("auctionSalesroomId", bidVO.getAuctionSalesroomId()); + map.put("byId", byId.getStatus()); + map.put("lastBidAmount", one2.getLastBidAmount()); + map.put("message_type", "BidRecor"); + map.put("type", 3); + String msg = null; + try { + msg = objectMapper.writeValueAsString(map); + } catch (JsonProcessingException e) { + } + String finalMsg = msg; + sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(finalMsg) + .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER); + // 发送短信 + authClient.sendSms( + SmsSendDTO.builder().mobileList(Lists.newArrayList(membeOne.getPhone())) + .content("【酒鼎老酒】出价成功").build(), SecurityConstants.INNER); + } else { + AuctionGoods byId = auctionGoodsService.getById(bidVO.getTargetId()); + R<GoodsSku> goodsSkuOneR = goodsSkuClient.getGoodsSkuOne(byId.getGoodsSkuId(), + SecurityConstants.INNER); + GoodsSku goodsSku = goodsSkuOneR.getData(); + // 查询用户出价记录判断是否第一次出价 首次出价,可以只出起拍价,而不是需要比起拍价高。 + Long count = auctionBidRecordService.lambdaQuery() + .eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()) + .eq(AuctionBidRecord::getAuctionType, bidVO.getAuctionType()) + .eq(AuctionBidRecord::getMemberId, bidVO.getMemberId()).count(); + if (byId.getStartingPrice().doubleValue() > bidVO.getLastBidAmount() + .doubleValue() && count > 0) { + throw new ServiceException("出价不能比起拍价低"); + } + BigDecimal bigDecimal = byId.getStartingPrice().add(byId.getMinimumMarkupAmount()); + if (bigDecimal.doubleValue() > bidVO.getLastBidAmount().doubleValue() + && count > 0) { + throw new ServiceException("出价不能比每次最少加价低"); + } + LambdaQueryWrapper<AuctionBidRecord> wrapper1 = Wrappers.lambdaQuery(); + wrapper1.eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()); + wrapper1.eq(AuctionBidRecord::getDelFlag, 0); + wrapper1.orderByDesc(AuctionBidRecord::getLastBidAmount); + wrapper1.last("limit 1"); + AuctionBidRecord one = auctionBidRecordService.getOne(wrapper1); + if (byId.getAuctionStock() == 1) { + if (one != null) { + BigDecimal bigDecimal1 = one.getLastBidAmount() + .add(byId.getMinimumMarkupAmount()); + if (bigDecimal1.doubleValue() > bidVO.getLastBidAmount().doubleValue()) { + throw new ServiceException("出价不能比上次出价加每次最少加价低"); + } + + } + } + LambdaQueryWrapper<AuctionBidRecord> wrapper3 = Wrappers.lambdaQuery(); + wrapper3.eq(AuctionBidRecord::getTargetId, bidVO.getTargetId()); + wrapper3.eq(AuctionBidRecord::getDelFlag, 0); + wrapper3.eq(AuctionBidRecord::getMemberId, bidVO.getMemberId()); + wrapper3.orderByDesc(AuctionBidRecord::getLastBidAmount); + wrapper3.last("limit 1"); + AuctionBidRecord one3 = auctionBidRecordService.getOne(wrapper3); + if (one3 != null) { one3.setLastBidAmount(bidVO.getLastBidAmount()); one3.setLastBidTime(LocalDateTime.now()); - one3.setBidCount(one.getBidCount()+1); + one3.setBidCount(one.getBidCount() + 1); auctionBidRecordService.updateById(one3); - }else{ - one3=new AuctionBidRecord(); + } else { + one3 = new AuctionBidRecord(); one3.setAuctionSalesroomId(bidVO.getAuctionSalesroomId()); one3.setTargetId(bidVO.getTargetId()); one3.setMemberId(bidVO.getMemberId()); - if(membeOne.getRealName()!=null&&membeOne.getRealName()!=""){ + if (membeOne.getRealName() != null && membeOne.getRealName() != "") { one3.setNickname(membeOne.getRealName()); - }else{ + } else { one3.setNickname(membeOne.getNickname()); } one3.setPhone(membeOne.getPhone()); @@ -820,25 +884,35 @@ one3.setStatus(BidStatusEnum.ELIMINATE); one3.setBidCount(1); one3.setLastBidAmount(bidVO.getLastBidAmount()); + one3.setGoodsName(Objects.nonNull(goodsSku) ? goodsSku.getSkuName() : ""); auctionBidRecordService.save(one3); } - Map<String, Object> map = new ConcurrentHashMap<>(); - map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM); - map.put("auctionSalesroomId", byId.getId()); - map.put("byId", byId.getStartStatus()); - map.put("lastBidAmount",one3.getLastBidAmount()); - map.put("message_type", "BidRecor"); - map.put("type",4); - String msg = null; - try { - msg = objectMapper.writeValueAsString(map); - } catch (JsonProcessingException e) { - } - String finalMsg = msg; - sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(finalMsg) - .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER); + Map<String, Object> map = new ConcurrentHashMap<>(); + map.put("notification_type", NotificationTypeConstant.AUCTION_SALESROOM); + map.put("auctionSalesroomId", byId.getId()); + map.put("byId", byId.getStartStatus()); + map.put("lastBidAmount", one3.getLastBidAmount()); + map.put("message_type", "BidRecor"); + map.put("type", 4); + String msg = null; + try { + msg = objectMapper.writeValueAsString(map); + } catch (JsonProcessingException e) { + } + String finalMsg = msg; + sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(finalMsg) + .clientType(ClientTypeEnum.MEMBER).build(), SecurityConstants.INNER); + // 发送短信 + authClient.sendSms( + SmsSendDTO.builder().mobileList(Lists.newArrayList(membeOne.getPhone())) + .content("【酒鼎老酒】出价成功").build(), SecurityConstants.INNER); + } + } finally { + if (lock.isLocked()) { + lock.unlock(); + } } } @@ -879,6 +953,7 @@ AuctionSalesroom::getEndTime, AuctionSalesroom::getType, AuctionSalesroom::getAuthentication, AuctionSalesroom::getStatus, AuctionSalesroom::getQrCode) + .in(CollUtils.isNotEmpty(query.getIds()), AuctionSalesroom::getId, query.getIds()) .like(StringUtils.isNotEmpty(query.getSalesroomName()), AuctionSalesroom::getSalesroomName, query.getSalesroomName()) .eq(StringUtils.isNotNull(query.getAuthentication()), @@ -910,7 +985,7 @@ // 计算每个拍卖场所有拍品数量 Map<Long, Integer> map = auctionSalesroomGoods.stream() .collect(Collectors.groupingBy(AuctionSalesroomGoods::getAuctionSalesroomId, - Collectors.summingInt(AuctionSalesroomGoods::getSalesroomStock))); + Collectors.summingInt(AuctionSalesroomGoods::getBidNum))); for (MgtAuctionSalesroomVO mgtAuctionSalesroomVO : list) { Integer i = map.get(mgtAuctionSalesroomVO.getId()); if (StringUtils.isNotNull(i)) { @@ -921,25 +996,51 @@ return auctionSalesroomVOPageDTO; } - /** - * 查看二维码 - * - * @param id 拍卖场id - * @return 二维码 - */ @Override - public String getQrCode(Long id) throws Exception { - AuctionSalesroom auctionSalesroom = this.getById(id); - if (StringUtils.isBlank(auctionSalesroom.getQrCode())) { - AuctionSalesroomQrCodeVO vo = new AuctionSalesroomQrCodeVO(); - vo.setAuctionSalesroomNo(auctionSalesroom.getAuctionSalesroomNo()); - vo.setType(auctionSalesroom.getType().getCode()); - String url = remoteFileService.obsUpload( - CreateQrCode.createQRCodeStream(objectMapper.writeValueAsString(vo))).getData(); - auctionSalesroom.setQrCode(url); - this.updateById(auctionSalesroom); + public List<MgtAuctionSalesroomVO> getAuctionSalesroomList(MgtAuctionSalesroomQuery query) { + // 分页查询 + List<AuctionSalesroom> auctionSalesroomList = this.lambdaQuery() + .select(AuctionSalesroom::getId, AuctionSalesroom::getSalesroomName, + AuctionSalesroom::getCreateTime, AuctionSalesroom::getStartTime, + AuctionSalesroom::getEndTime, AuctionSalesroom::getType, + AuctionSalesroom::getAuthentication, AuctionSalesroom::getStatus, + AuctionSalesroom::getQrCode) + .in(CollUtils.isNotEmpty(query.getIds()), AuctionSalesroom::getId, query.getIds()) + .like(StringUtils.isNotEmpty(query.getSalesroomName()), + AuctionSalesroom::getSalesroomName, query.getSalesroomName()) + .eq(StringUtils.isNotNull(query.getAuthentication()), + AuctionSalesroom::getAuthentication, query.getAuthentication()) + .eq(StringUtils.isNotNull(query.getStatus()), AuctionSalesroom::getStatus, + query.getStatus()).between( + StringUtils.isNotNull(query.getStartTime()) && StringUtils.isNotNull( + query.getEndTime()), AuctionSalesroom::getStartTime, + query.getStartTime(), + query.getEndTime()) + .orderByDesc(AuctionSalesroom::getCreateTime) + .list(); + + List<MgtAuctionSalesroomVO> list = BeanUtils.copyList(auctionSalesroomList, + MgtAuctionSalesroomVO.class); + List<Long> auctionSalesroomIdList = list.stream().map(MgtAuctionSalesroomVO::getId) + .collect(Collectors.toList()); + if (StringUtils.isNotEmpty(auctionSalesroomIdList)) { + // 所有拍卖场的拍卖商品 + List<AuctionSalesroomGoods> auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectList( + Wrappers.<AuctionSalesroomGoods>lambdaQuery() + .in(AuctionSalesroomGoods::getAuctionSalesroomId, + auctionSalesroomIdList)); + // 计算每个拍卖场所有拍品数量 + Map<Long, Integer> map = auctionSalesroomGoods.stream() + .collect(Collectors.groupingBy(AuctionSalesroomGoods::getAuctionSalesroomId, + Collectors.summingInt(AuctionSalesroomGoods::getBidNum))); + for (MgtAuctionSalesroomVO mgtAuctionSalesroomVO : list) { + Integer i = map.get(mgtAuctionSalesroomVO.getId()); + if (StringUtils.isNotNull(i)) { + mgtAuctionSalesroomVO.setAuctionGoodsNum(i); + } + } } - return auctionSalesroom.getQrCode(); + return list; } @Override @@ -959,11 +1060,14 @@ if (StringUtils.isNull(data.getMinimumMarkupAmount())) { throw new ServiceException("拍卖商品最低加价金额不能为空"); } - if (StringUtils.isNull(data.getSalesroomStock())) { - throw new ServiceException("拍卖商品拍品数量不能为空"); + if (StringUtils.isNull(data.getBidNum())) { + throw new ServiceException("可中拍人数不能为空"); } if (StringUtils.isNull(data.getListingDuration())) { throw new ServiceException("拍卖商品拍卖时间不能为空"); + } + if (StringUtils.isBlank(data.getDescription())) { + throw new ServiceException("拍卖商品介绍不能为空"); } } }); @@ -977,15 +1081,12 @@ AuctionSalesroomQrCodeVO vo = new AuctionSalesroomQrCodeVO(); vo.setAuctionSalesroomNo(nextId.toString()); vo.setType(auctionSalesroom.getType().getCode()); - String url = remoteFileService.obsUpload( - CreateQrCode.createQRCodeStream(objectMapper.writeValueAsString(vo))).getData(); - auctionSalesroom.setQrCode(url); // 添加 this.save(auctionSalesroom); List<GoodsStockUpdDTO> goodsStockUpdDTOS = auctionSalesroomGoods.stream().map(item -> { GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(item.getGoodsSkuId()); - goodsStockUpdDTO.setAuctionStock(item.getSalesroomStock() * -1); + goodsStockUpdDTO.setAuctionStock(item.getBidNum() * -1 * item.getDealQuantity()); return goodsStockUpdDTO; }).collect(Collectors.toList()); goodsSkuClient.updGoodsStock(goodsStockUpdDTOS, SecurityConstants.INNER); @@ -1006,10 +1107,6 @@ AuctionSalesroomQrCodeVO vo = new AuctionSalesroomQrCodeVO(); vo.setAuctionSalesroomNo(auctionSalesroomOrg.getAuctionSalesroomNo()); vo.setType(auctionSalesroom.getType().getCode()); - String url = remoteFileService.obsUpload( - CreateQrCode.createQRCodeStream(objectMapper.writeValueAsString(vo))) - .getData(); - auctionSalesroom.setQrCode(url); } this.updateById(auctionSalesroom); List<AuctionSalesroomGoods> list = auctionSalesroomGoodsMapper.selectList( @@ -1023,8 +1120,8 @@ .map(auctionSalesroomGood -> { GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(salesroomGoods.getGoodsSkuId()); - goodsStockUpdDTO.setAuctionStock(salesroomGoods.getSalesroomStock() - - auctionSalesroomGood.getSalesroomStock()); + goodsStockUpdDTO.setAuctionStock(salesroomGoods.getBidNum() * salesroomGoods.getDealQuantity() + - auctionSalesroomGood.getBidNum() * auctionSalesroomGood.getDealQuantity()); return goodsStockUpdDTO; })) .collect(Collectors.toList()); @@ -1047,32 +1144,14 @@ 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()); - - /* MemberAuctionSalesroomWdDTO memberAuctionSalesroomWdDTO=new MemberAuctionSalesroomWdDTO(); - if (goodsSkuIdList.size()>0){ - memberAuctionSalesroomWdDTO.setGoodsSkuIdList(goodsSkuIdList); - }else{ - Set<Long> goodsSkuIdList1 = new HashSet<>(); - goodsSkuIdList1.add(0L); - memberAuctionSalesroomWdDTO.setGoodsSkuIdList(goodsSkuIdList1); - } - - if(MemberAuctionSalesroomDTO.getStatus()!=4){ - if (MemberAuctionSalesroomDTO.getStatus()==0){ - memberAuctionSalesroomWdDTO.setStatus(5); - }else{ - memberAuctionSalesroomWdDTO.setStatus(MemberAuctionSalesroomDTO.getStatus()); - } - - }*/ - + .collect(Collectors.toSet()); 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); @@ -1089,13 +1168,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(); @@ -1256,51 +1332,53 @@ MgtAuctionSalesroomVO mgtAuctionSalesroomVO = this.getAuctionSalesroom(id, Boolean.TRUE); MgtAuctionSalesroomScreenVO vo = BeanUtils.copyBean( mgtAuctionSalesroomVO, MgtAuctionSalesroomScreenVO.class); - 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)); + 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<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; @@ -1373,7 +1451,7 @@ // 扣减库存 GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(data.getId()); - goodsStockUpdDTO.setAuctionStock(dto.getSalesroomStock() * -1); + goodsStockUpdDTO.setAuctionStock(dto.getBidNum() * dto.getDealQuantity() * -1); R<?> result = goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), SecurityConstants.INNER); if (result.getCode() != Constants.SUCCESS) { @@ -1479,43 +1557,107 @@ .eq(AuctionBidRecord::getTargetId, auctionSalesroomGoods.getId()) .eq(AuctionBidRecord::getAuctionType, AuctionOrderTypeEnum.AUCTION_ITEMS) - .orderByDesc(AuctionBidRecord::getLastBidAmount)); + .orderByDesc(AuctionBidRecord::getLastBidAmount) + .orderByAsc(AuctionBidRecord::getLastBidTime)); if (CollUtils.isNotEmpty(auctionBidRecordList)) { List<AuctionBidRecord> auctionBidRecords = new ArrayList<>(); - if (auctionBidRecordList.size() >= auctionSalesroomGoods.getSalesroomStock()) { - for (int i = 0; i < auctionSalesroomGoods.getSalesroomStock(); i++) { + Map<Long, String> orderIdMap = new HashMap<>(); + if (auctionBidRecordList.size() >= auctionSalesroomGoods.getBidNum()) { + for (int i = 0; i < auctionSalesroomGoods.getBidNum(); i++) { AuctionBidRecord auctionBidRecord = auctionBidRecordList.get(i); auctionBidRecord.setStatus(BidStatusEnum.SUCCESSFUL); - auctionBidRecordMapper.updateById(auctionBidRecord); auctionBidRecords.add(auctionBidRecord); + Long orderId = addOrder(auctionBidRecord.getTargetId(), + auctionBidRecord.getMemberId(), + auctionBidRecord.getLastBidAmount(), + auctionSalesroom.getBond(), + auctionSalesroomGoods.getDealQuantity()); + orderIdMap.put(auctionBidRecord.getMemberId(), orderId.toString()); + auctionBidRecord.setOrderId(orderId); + auctionBidRecordMapper.updateById(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); + Long orderId = addOrder(auctionBidRecord.getTargetId(), + auctionBidRecord.getMemberId(), + auctionBidRecord.getLastBidAmount(), + auctionSalesroom.getBond(), + auctionSalesroomGoods.getDealQuantity()); + orderIdMap.put(auctionBidRecord.getMemberId(), orderId.toString()); + auctionBidRecord.setOrderId(orderId); + auctionBidRecordMapper.updateById(auctionBidRecord); } // 没有出价记录,回退库存 GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); goodsStockUpdDTO.setAuctionStock( - auctionSalesroomGoods.getSalesroomStock() - - auctionBidRecordList.size()); + auctionSalesroomGoods.getBidNum() + * auctionSalesroomGoods.getDealQuantity() + - auctionBidRecordList.size() + * auctionSalesroomGoods.getDealQuantity()); goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), SecurityConstants.INNER); } - for (AuctionBidRecord auctionBidRecord : auctionBidRecords) { - addOrder(auctionBidRecord.getTargetId(), auctionBidRecord.getMemberId(), - auctionBidRecord.getLastBidAmount(), - auctionSalesroom.getBond()); + GoodsSku goodsSku = goodsSkuClient.getGoodsSkuOne( + auctionSalesroomGoods.getGoodsSkuId(), + SecurityConstants.INNER).getData(); + List<Long> successMemberIdList = auctionBidRecordList.stream() + .filter(auctionBidRecord -> auctionBidRecord.getStatus() + .equals(BidStatusEnum.SUCCESSFUL)) + .map(AuctionBidRecord::getMemberId) + .collect(Collectors.toList()); + List<Long> failedMemberIdList = auctionBidRecordList.stream() + .filter(auctionBidRecord -> !auctionBidRecord.getStatus() + .equals(BidStatusEnum.SUCCESSFUL)) + .map(AuctionBidRecord::getMemberId) + .collect(Collectors.toList()); + Map<Long, String> bidMap = auctionBidRecordList.stream().collect( + Collectors.toMap(AuctionBidRecord::getMemberId, + item -> item.getId().toString())); + if (CollUtils.isNotEmpty(successMemberIdList)) { + List<Member> successMemberList = memberClient.getMemberListByIds( + successMemberIdList, SecurityConstants.INNER).getData(); + if (CollUtils.isNotEmpty(successMemberList)) { + // 推送websocket消息 + sendWebsocketMsg(auctionSalesroomGoods.getId(), successMemberList, + goodsSku, 1, orderIdMap, bidMap); + // 发送短信通知 + List<String> mobileList = successMemberList.stream() + .map(Member::getPhone) + .collect(Collectors.toList()); + authClient.sendSms(SmsSendDTO.builder().mobileList(mobileList) + .content(SUCCESS_TEMPLATE.replace("content", + goodsSku.getSkuName())) + .build(), SecurityConstants.INNER); + } + } + if (CollUtils.isNotEmpty(failedMemberIdList)) { + List<Member> failedMemberList = memberClient.getMemberListByIds( + failedMemberIdList, SecurityConstants.INNER).getData(); + if (CollUtils.isNotEmpty(failedMemberList)) { + // 推送websocket消息 + sendWebsocketMsg(auctionSalesroomGoods.getId(), failedMemberList, + goodsSku, 0, orderIdMap, bidMap); + // 发送短信通知 + List<String> mobileList = failedMemberList.stream() + .map(Member::getPhone) + .collect(Collectors.toList()); + authClient.sendSms(SmsSendDTO.builder().mobileList(mobileList) + .content(FAILED_TEMPLATE.replace("content", + goodsSku.getSkuName())) + .build(), SecurityConstants.INNER); + } } } else { // 没有出价记录,回退库存 GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(auctionSalesroomGoods.getGoodsSkuId()); goodsStockUpdDTO.setAuctionStock( - auctionSalesroomGoods.getSalesroomStock()); + auctionSalesroomGoods.getBidNum() + * auctionSalesroomGoods.getDealQuantity()); goodsSkuClient.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO), SecurityConstants.INNER); } @@ -1531,14 +1673,41 @@ sysUserClient.pushAll(msg, SecurityConstants.INNER); } } finally { - if (lock.isLocked() && lock.isHeldByCurrentThread()) { + if (lock.isLocked()) { lock.unlock(); } } } - public void addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount, - BigDecimal bound) { + /** + * 发送websocket通知 + * @param id + * @param memberList + * @param goodsSku + * @param successFlag // 中标状态 1:中标 0:未中标 + */ + private void sendWebsocketMsg(Long id, List<Member> memberList, GoodsSku goodsSku, + Integer successFlag, Map<Long, String> userIdMap, Map<Long, String> bidMap) { + for (Member member : memberList) { + Map<String, Object> map = new ConcurrentHashMap<>(); + map.put("notification_type", NotificationTypeConstant.AUCTION_POPUP); + map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss")); + map.put("target_id", id); + map.put("goods_name", Objects.nonNull(goodsSku) ? goodsSku.getSkuName() : ""); + map.put("success_flag", successFlag); + map.put("order_id", successFlag == 1 ? userIdMap.getOrDefault(member.getId(), "") : ""); + map.put("auction_bid_record_id", bidMap.getOrDefault(member.getId(), "0")); + map.put("member_id", member.getId().toString()); + String msg = com.alibaba.fastjson2.JSONObject.toJSONString(map); + sysUserClient.pushByClientType( + WebsocketMessageDTO.builder().message(msg).clientType(ClientTypeEnum.MEMBER) + .build(), SecurityConstants.INNER); + log.info("===================>发送websocket通知,消息体{}", msg); + } + } + + public Long addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount, + BigDecimal bound, Integer dealQuantity) { OrderDTO order = new OrderDTO(); order.setGoodsSkuId(goodsSkuId); order.setOrderTime(LocalDateTime.now()); @@ -1547,8 +1716,8 @@ AuctionSalesroomGoods auctionSalesroomGoods = auctionSalesroomGoodsMapper.selectById( goodsSkuId); - order.setGoodsQuantity(1); - order.setTotalAmount(lastBidAmount); + order.setGoodsQuantity(dealQuantity); + order.setTotalAmount(lastBidAmount.multiply(new BigDecimal(dealQuantity))); order.setAuctionSalesroomId(auctionSalesroomGoods.getAuctionSalesroomId()); R<MemberAddress> memberAddressR = memberClient.getMemberAddressOne(memberId, @@ -1561,7 +1730,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); @@ -1587,7 +1756,8 @@ order.setSkuName(goodsSku.getSkuName()); order.setCoverPic(goodsSku.getCoverPic()); order.setPrice(lastBidAmount); - orderClient.saveOrderOne(order, SecurityConstants.INNER); + order.setGoodsId(auctionSalesroomGoods.getGoodsSkuId()); + return orderClient.saveOrderOne(order, SecurityConstants.INNER).getData(); } /** * 开始下一拍卖商品 @@ -1678,8 +1848,7 @@ map.put("message_type", "start"); map.put("type", "1"); String msg = objectMapper.writeValueAsString(map); - sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg) - .clientType(ClientTypeEnum.AUCTIONEER).build(), SecurityConstants.INNER); + sysUserClient.pushAll(msg, SecurityConstants.INNER); } @Override @@ -1713,7 +1882,8 @@ // 等待中的商品退库存 GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); goodsStockUpdDTO.setGoodsSkuId(salesroomGoods.getGoodsSkuId()); - goodsStockUpdDTO.setAuctionStock(salesroomGoods.getSalesroomStock()); + goodsStockUpdDTO.setAuctionStock( + salesroomGoods.getBidNum() * salesroomGoods.getDealQuantity()); dtoList.add(goodsStockUpdDTO); } // 批量更新商品库存 @@ -1725,6 +1895,7 @@ Wrappers.<AuctionBidRecord>lambdaQuery() .eq(AuctionBidRecord::getAuctionSalesroomId, auctionSalesroomId) .eq(AuctionBidRecord::getStatus, BidStatusEnum.SUCCESSFUL)); + log.info("拍卖场{},已中标的用户:{}", auctionSalesroomId, auctionBidRecordList); Set<Long> memberIdList = new HashSet<>(); if (CollUtils.isNotEmpty(auctionBidRecordList)) { memberIdList = auctionBidRecordList.stream().map(AuctionBidRecord::getMemberId) @@ -1741,8 +1912,7 @@ map.put("message_type", "end"); map.put("type", "1"); String msg = objectMapper.writeValueAsString(map); - sysUserClient.pushByClientType(WebsocketMessageDTO.builder().message(msg) - .clientType(ClientTypeEnum.AUCTIONEER).build(), SecurityConstants.INNER); + sysUserClient.pushAll(msg, SecurityConstants.INNER); } @Override @@ -1784,4 +1954,25 @@ public AuctionSalesroomGoods getAuctionSalesroomGoodsById(Long goodsSkuId) { return auctionSalesroomGoodsMapper.selectById(goodsSkuId); } + + @Override + public AuctionBondJl getAuctionBondJLBySalesroomId(Long targetId, Long memberId, + Integer bondType) { + return auctionBondJlMapper.selectOne( + Wrappers.lambdaQuery(AuctionBondJl.class).eq(AuctionBondJl::getMemberId, memberId) + .eq(AuctionBondJl::getAuctionSalesroomId, targetId) + .eq(AuctionBondJl::getBondType, bondType) + .last("limit 1")); + } + + @Override + public List<GoodsSku> getGoodsSkuByAuctionSalesroomGoodsSet( + Set<Long> auctionSalesroomGoodsSet) { + List<AuctionSalesroomGoods> auctionSalesroomGoodsList = auctionSalesroomGoodsMapper.selectBatchIds( + auctionSalesroomGoodsSet); + Set<Long> goodsSkuIdSet = auctionSalesroomGoodsList.stream() + .map(AuctionSalesroomGoods::getGoodsSkuId).collect( + Collectors.toSet()); + return goodsSkuClient.getGoodsListByIds(goodsSkuIdSet, SecurityConstants.INNER).getData(); + } } -- Gitblit v1.7.1