| | |
| | | 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; |
| | |
| | | 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 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; |
| | |
| | | |
| | | @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 = ""; |
| | |
| | | .orderByAsc(AuctionBidRecord::getLastBidTime)); |
| | | if (CollUtils.isNotEmpty(auctionBidRecordList)) { |
| | | List<AuctionBidRecord> auctionBidRecords = new ArrayList<>(); |
| | | Map<Long, String> orderIdMap = new HashMap<>(); |
| | | 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); |
| | | Long orderId = addOrder(auctionBidRecord.getTargetId(), |
| | | auctionBidRecord.getMemberId(), |
| | | auctionBidRecord.getLastBidAmount(), |
| | | auctionSalesroom.getBond()); |
| | | 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()); |
| | | orderIdMap.put(auctionBidRecord.getMemberId(), orderId.toString()); |
| | | auctionBidRecord.setOrderId(orderId); |
| | | auctionBidRecordMapper.updateById(auctionBidRecord); |
| | | } |
| | | // 没有出价记录,回退库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | |
| | | 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()); |
| | | 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); |
| | | // 发送短信通知 |
| | | 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); |
| | | // 发送短信通知 |
| | | 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 { |
| | | // 没有出价记录,回退库存 |
| | |
| | | } |
| | | } |
| | | |
| | | public void addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount, |
| | | /** |
| | | * 发送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) { |
| | | 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(), "") : ""); |
| | | String msg = com.alibaba.fastjson2.JSONObject.toJSONString(map); |
| | | sysUserClient.pushBatch( |
| | | WebsocketMessageDTO.builder().message(msg).userId(member.getUserId()).build(), |
| | | SecurityConstants.INNER); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | | |
| | | public Long addOrder(Long goodsSkuId, Long memberId, BigDecimal lastBidAmount, |
| | | BigDecimal bound) { |
| | | OrderDTO order = new OrderDTO(); |
| | | order.setGoodsSkuId(goodsSkuId); |
| | |
| | | order.setCoverPic(goodsSku.getCoverPic()); |
| | | order.setPrice(lastBidAmount); |
| | | order.setGoodsId(auctionSalesroomGoods.getGoodsSkuId()); |
| | | orderClient.saveOrderOne(order, SecurityConstants.INNER); |
| | | return orderClient.saveOrderOne(order, SecurityConstants.INNER).getData(); |
| | | } |
| | | /** |
| | | * 开始下一拍卖商品 |