| | |
| | | package com.ruoyi.auction.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | 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.AuctionBondJl; |
| | | import com.ruoyi.auction.domain.AuctionBrowseRecord; |
| | | import com.ruoyi.auction.domain.MemberAuctionCollection; |
| | | import com.ruoyi.auction.mapper.AuctionBondJlMapper; |
| | |
| | | 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.*; |
| | | 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; |
| | | import com.ruoyi.system.api.domain.GoodsCategory; |
| | | import com.ruoyi.system.api.domain.GoodsFlavorType; |
| | | import com.ruoyi.system.api.domain.GoodsSeries; |
| | | import com.ruoyi.system.api.domain.GoodsSku; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.MemberAddress; |
| | | import com.ruoyi.system.api.domain.Order; |
| | | import com.ruoyi.system.api.domain.OrderAuctionBond; |
| | | import com.ruoyi.system.api.domain.WebsocketMessageDTO; |
| | | import com.ruoyi.system.api.domain.dto.AuctionGoodsListDTO; |
| | | import com.ruoyi.system.api.domain.dto.AuctionGoodsListPageDTO; |
| | | import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO; |
| | |
| | | import com.ruoyi.system.api.domain.dto.MemberAuctionSalesroomDTO; |
| | | import com.ruoyi.system.api.domain.dto.OrderDTO; |
| | | import com.ruoyi.system.api.domain.dto.RefundDTO; |
| | | import com.ruoyi.system.api.domain.vo.*; |
| | | import com.ruoyi.system.api.domain.dto.SmsSendDTO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionGoodsListVO; |
| | | import com.ruoyi.system.api.domain.vo.AuctionGoodsinfoVO; |
| | | import com.ruoyi.system.api.domain.vo.GoodsInfoTitleValueVO; |
| | | import com.ruoyi.system.api.domain.vo.getHomeGoodsSkuXxiVO; |
| | | import com.ruoyi.system.api.feignClient.AuctionClient; |
| | | 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.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | |
| | | @Resource |
| | | private AuctionBondJlMapper auctionBondJlMapper; |
| | | @Resource |
| | | private AuthClient authClient; |
| | | private static final String SUCCESS_TEMPLATE = "【酒鼎老酒】恭喜!您参与的“content”竞拍已中拍!"; |
| | | private static final String FAILED_TEMPLATE = "【酒鼎老酒】很遗憾!您参与的”content“竞拍未中拍!"; |
| | | |
| | | /** |
| | | * 获取拍卖商品列表的分页数据 |
| | |
| | | SecurityConstants.INNER); |
| | | } |
| | | |
| | | auctionBidRecordService.updateBatchById(auctionBidRecordList); |
| | | |
| | | // 创建待支付订单 |
| | | CustomConfig moneyConfig = sysUserClient.getconfig( |
| | | ConfigEnum.MEMBER_POINTS_MONEY.getKey()).getData(); |
| | | CustomConfig pointsConfig = sysUserClient.getconfig( |
| | | ConfigEnum.MEMBER_POINTS_POINTS.getKey()).getData(); |
| | | Map<Long, String> orderIdMap = new HashMap<>(); |
| | | for (AuctionBidRecord auctionBidRecord : auctionBidRecordList) { |
| | | BigDecimal lastBidAmount = auctionBidRecord.getLastBidAmount(); |
| | | BigDecimal divide = lastBidAmount.divide( |
| | |
| | | orderDTO.setSkuName(goodsSku.getSkuName()); |
| | | } |
| | | orderDTO.setOrderTimeSx(auctionGoods.getEndTime()); |
| | | orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER); |
| | | orderDTO.setGoodsId(auctionGoods.getGoodsSkuId()); |
| | | Long orderId = orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER) |
| | | .getData(); |
| | | if (Objects.nonNull(orderId)) { |
| | | orderIdMap.put(auctionBidRecord.getMemberId(), orderId.toString()); |
| | | auctionBidRecord.setOrderId(orderId); |
| | | } |
| | | } |
| | | // 更新出价记录 |
| | | auctionBidRecordService.updateBatchById(auctionBidRecordList); |
| | | Map<Long, String> bidMap = auctionBidRecordList.stream().collect( |
| | | Collectors.toMap(AuctionBidRecord::getMemberId, |
| | | item -> item.getId().toString())); |
| | | List<Long> successMemberIdList = auctionBidRecords.stream() |
| | | .filter(auctionBidRecord -> auctionBidRecord.getStatus() |
| | | .equals(BidStatusEnum.SUCCESSFUL)) |
| | | .map(AuctionBidRecord::getMemberId) |
| | | .collect(Collectors.toList()); |
| | | List<Long> failedMemberIdList = auctionBidRecords.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(id, 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(id, 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 { |
| | | // 没有人出价,退回拍卖商品库存 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送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", 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")); |
| | | String msg = JSONObject.toJSONString(map); |
| | | sysUserClient.pushBatch( |
| | | WebsocketMessageDTO.builder().message(msg).userId(member.getUserId()).build(), |
| | | SecurityConstants.INNER); |
| | | log.info("===================>发送websocket通知,消息体{}", msg); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<AuctionGoodsListVO> getAuctionGoodsList(AuctionGoodsListDTO auctionGoodsListDTO) { |
| | | Set<Long> goodsSkuIdList = null; |
| | |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | if (auctionGoodsListDTO.getStartStatus() != 4) { |
| | | wrapper1.eq(AuctionGoods::getStartStatus,auctionGoodsListDTO.getStartStatus()); |
| | | } |
| | | wrapper1.last("ORDER BY\n" + |
| | | " CASE\n" + |
| | | " WHEN start_status = 0 THEN 2\n" + |
| | | " WHEN start_status = 1 THEN 1\n" + |
| | | " WHEN start_status = 2 THEN 3\n" + |
| | | " END,start_status asc "); |
| | | |
| | | 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(); |
| | |
| | | SecurityConstants.INNER); |
| | | } |
| | | |
| | | auctionBidRecordService.updateBatchById(auctionBidRecordList); |
| | | |
| | | // 创建待支付订单 |
| | | CustomConfig moneyConfig = sysUserClient.getconfig( |
| | | ConfigEnum.MEMBER_POINTS_MONEY.getKey()).getData(); |
| | | CustomConfig pointsConfig = sysUserClient.getconfig( |
| | | ConfigEnum.MEMBER_POINTS_POINTS.getKey()).getData(); |
| | | Map<Long, String> orderIdMap = new HashMap<>(); |
| | | for (AuctionBidRecord auctionBidRecord : auctionBidRecordList) { |
| | | BigDecimal lastBidAmount = auctionBidRecord.getLastBidAmount(); |
| | | BigDecimal divide = lastBidAmount.divide( |
| | |
| | | orderDTO.setSkuName(goodsSku.getSkuName()); |
| | | } |
| | | orderDTO.setOrderTimeSx(auctionGoods.getEndTime()); |
| | | orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER); |
| | | orderDTO.setGoodsId(auctionGoods.getGoodsSkuId()); |
| | | Long orderId = orderClient.saveOrderOne(orderDTO, SecurityConstants.INNER) |
| | | .getData(); |
| | | if (Objects.nonNull(orderId)) { |
| | | orderIdMap.put(auctionBidRecord.getMemberId(), orderId.toString()); |
| | | auctionBidRecord.setOrderId(orderId); |
| | | } |
| | | } |
| | | // 更新出价记录 |
| | | auctionBidRecordService.updateBatchById(auctionBidRecordList); |
| | | Map<Long, String> bidMap = auctionBidRecordList.stream().collect( |
| | | Collectors.toMap(AuctionBidRecord::getMemberId, |
| | | item -> item.getId().toString())); |
| | | List<Long> successMemberIdList = auctionBidRecords.stream() |
| | | .filter(auctionBidRecord -> auctionBidRecord.getStatus() |
| | | .equals(BidStatusEnum.SUCCESSFUL)) |
| | | .map(AuctionBidRecord::getMemberId) |
| | | .collect(Collectors.toList()); |
| | | List<Long> failedMemberIdList = auctionBidRecords.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(id, 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(id, 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 { |
| | | // 没有人出价,退回拍卖商品库存 |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) throws JsonProcessingException { |
| | | Map<String, Object> map = new ConcurrentHashMap<>(); |
| | | map.put("notification_type", NotificationTypeConstant.AUCTION_GOODS); |
| | | map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss")); |
| | | map.put("target_id", 1); |
| | | map.put("message_type", "end"); |
| | | String msg = objectMapper.writeValueAsString(map); |
| | | System.out.println(msg); |
| | | System.out.println(SUCCESS_TEMPLATE.replace("content", "剑南春")); |
| | | } |
| | | |
| | | @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(); |
| | | } |
| | | } |