From ab34ef62429262bcde69186f1e5edecc5f66c001 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期二, 11 三月 2025 15:53:18 +0800 Subject: [PATCH] 拍卖结果弹窗消息 --- ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/controller/management/MgtAuctionSalesroomController.java | 182 +++++++++++++++++++++------------------------ 1 files changed, 86 insertions(+), 96 deletions(-) diff --git a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/controller/management/MgtAuctionSalesroomController.java b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/controller/management/MgtAuctionSalesroomController.java index 19ebca6..2eecad8 100644 --- a/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/controller/management/MgtAuctionSalesroomController.java +++ b/ruoyi-modules/ruoyi-auction/src/main/java/com/ruoyi/auction/controller/management/MgtAuctionSalesroomController.java @@ -3,9 +3,7 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.util.DateUtils; -import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.google.zxing.WriterException; import com.ruoyi.auction.controller.management.dto.MgtAuctionSaleroomBidRecordQuery; import com.ruoyi.auction.controller.management.dto.MgtAuctionSalesroomDTO; @@ -25,29 +23,36 @@ 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.CollUtils; import com.ruoyi.common.core.utils.page.PageDTO; import com.ruoyi.system.api.domain.AuctionSalesroom; import com.ruoyi.system.api.domain.AuctionSalesroomGoods; import com.ruoyi.system.api.domain.GoodsSku; import com.ruoyi.system.api.feignClient.GoodsSkuClient; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import java.io.IOException; import java.math.BigDecimal; import java.net.URLEncoder; -import java.util.*; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; - +import javax.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * <p> @@ -171,27 +176,8 @@ @ApiOperation("导出列表") @PostMapping("/export") public void export(@RequestBody MgtAuctionSalesroomQuery query, HttpServletResponse response) { - PageDTO<MgtAuctionSalesroomVO> page = auctionSalesroomService.getAuctionSalesroomPage(query); - if (page.isEmpty()){ - response.setContentType( - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - response.setCharacterEncoding("utf-8"); - // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 - try { - String fileName = URLEncoder.encode( - "优惠券领取明细" + DateUtils.format(new Date(), "yyyyMMddHHmmss"), "UTF-8") - .replaceAll("\\+", "%20"); - response.setHeader("Content-disposition", - "attachment;filename*=utf-8''" + fileName + ".xlsx"); - EasyExcel.write(response.getOutputStream(), AuctionBidRecordVO.class) - .sheet("优惠券领取明细") - .doWrite(new ArrayDeque<>()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - List<MgtAuctionSalesroomVO> list = page.getList(); + List<AuctionBidRecordVO> result = Collections.emptyList(); + List<MgtAuctionSalesroomVO> list = auctionSalesroomService.getAuctionSalesroomList(query); List<Long> ids = list.stream().map(MgtAuctionSalesroomVO::getId).collect(Collectors.toList()); @@ -200,72 +186,76 @@ .in(!CollectionUtils.isEmpty(ids),AuctionBidRecord::getAuctionSalesroomId, ids) .eq(AuctionBidRecord::getAuctionType, AuctionOrderTypeEnum.AUCTION_ITEMS) ); + if (CollUtils.isNotEmpty(auctionBidRecordList)) { + // 提取 goodsIds 和 auctionSalesroomIds + Set<Long> goodsIds = auctionBidRecordList.stream() + .map(AuctionBidRecord::getTargetId) + .collect(Collectors.toSet()); - if (CollectionUtils.isEmpty(auctionBidRecordList)) { - return; + Set<Long> auctionSalesroomIds = auctionBidRecordList.stream() + .map(AuctionBidRecord::getAuctionSalesroomId) + .collect(Collectors.toSet()); + + // 查询拍卖场商品信息 + List<AuctionSalesroomGoods> salesroomGoodss = auctionSalesroomGoodsService.list( + new LambdaQueryWrapper<AuctionSalesroomGoods>() + .in(AuctionSalesroomGoods::getAuctionSalesroomId, auctionSalesroomIds) + .in(AuctionSalesroomGoods::getGoodsSkuId, goodsIds) + ); + + Map<String, AuctionSalesroomGoods> roomMap = salesroomGoodss.stream() + .collect(Collectors.toMap( + i -> String.format("%s-%s", i.getAuctionSalesroomId(), + i.getGoodsSkuId()), + i -> i + )); + + // 查询拍卖场信息 + List<AuctionSalesroom> auctionSalesroomList = auctionSalesroomService.listByIds( + auctionSalesroomIds); + Map<Long, AuctionSalesroom> auctionSalesroomMap = auctionSalesroomList.stream() + .collect(Collectors.toMap(AuctionSalesroom::getId, e -> e)); + + // 查询商品信息 + R<List<GoodsSku>> goodsListByIdsR = goodsSkuClient.getGoodsListByIds(goodsIds, + SecurityConstants.INNER); + if (R.isError(goodsListByIdsR)) { + throw new ServiceException("查询商品信息失败"); + } + List<GoodsSku> goodsSkuList = goodsListByIdsR.getData(); + Map<Long, GoodsSku> goodsSkuMap = goodsSkuList.stream() + .collect(Collectors.toMap(GoodsSku::getId, e -> e)); + + // 构建结果列表 + result = auctionBidRecordList.stream().map(auctionBidRecord -> { + AuctionBidRecordVO auctionBidRecordVO = BeanUtils.copyBean(auctionBidRecord, + AuctionBidRecordVO.class); + auctionBidRecordVO.setNum(auctionBidRecordList.indexOf(auctionBidRecord) + 1); + + AuctionSalesroomGoods salesroomGoods = roomMap.get( + String.format("%s-%s", auctionBidRecord + .getAuctionSalesroomId(), auctionBidRecord.getTargetId())); + if (salesroomGoods != null) { + BigDecimal totalAmount = auctionBidRecord.getLastBidAmount() + .multiply(new BigDecimal(salesroomGoods + .getDealQuantity())); + auctionBidRecordVO.setTotalAmount(totalAmount); + } + + AuctionSalesroom auctionSalesroom = auctionSalesroomMap.get( + auctionBidRecord.getAuctionSalesroomId()); + if (auctionSalesroom != null) { + auctionBidRecordVO.setAuctionSalesroomName(auctionSalesroom.getSalesroomName()); + } + + GoodsSku goodsSku = goodsSkuMap.get(auctionBidRecord.getTargetId()); + if (goodsSku != null) { + auctionBidRecordVO.setGoodsSkuName(goodsSku.getSkuName()); + } + + return auctionBidRecordVO; + }).collect(Collectors.toList()); } - - // 提取 goodsIds 和 auctionSalesroomIds - Set<Long> goodsIds = auctionBidRecordList.stream() - .map(AuctionBidRecord::getTargetId) - .collect(Collectors.toSet()); - - Set<Long> auctionSalesroomIds = auctionBidRecordList.stream() - .map(AuctionBidRecord::getAuctionSalesroomId) - .collect(Collectors.toSet()); - - // 查询拍卖场商品信息 - List<AuctionSalesroomGoods> salesroomGoodss = auctionSalesroomGoodsService.list( - new LambdaQueryWrapper<AuctionSalesroomGoods>() - .in(AuctionSalesroomGoods::getAuctionSalesroomId, auctionSalesroomIds) - .in(AuctionSalesroomGoods::getGoodsSkuId, goodsIds) - ); - - Map<String, AuctionSalesroomGoods> roomMap = salesroomGoodss.stream() - .collect(Collectors.toMap( - i -> String.format("%s-%s", i.getAuctionSalesroomId(), i.getGoodsSkuId()), - i -> i - )); - - // 查询拍卖场信息 - List<AuctionSalesroom> auctionSalesroomList = auctionSalesroomService.listByIds(auctionSalesroomIds); - Map<Long, AuctionSalesroom> auctionSalesroomMap = auctionSalesroomList.stream() - .collect(Collectors.toMap(AuctionSalesroom::getId, e -> e)); - - // 查询商品信息 - R<List<GoodsSku>> goodsListByIdsR = goodsSkuClient.getGoodsListByIds(goodsIds, SecurityConstants.INNER); - if (R.isError(goodsListByIdsR)) { - throw new ServiceException("查询商品信息失败"); - } - List<GoodsSku> goodsSkuList = goodsListByIdsR.getData(); - Map<Long, GoodsSku> goodsSkuMap = goodsSkuList.stream().collect(Collectors.toMap(GoodsSku::getId, e -> e)); - - // 构建结果列表 - List<AuctionBidRecordVO> result = auctionBidRecordList.stream().map(auctionBidRecord -> { - AuctionBidRecordVO auctionBidRecordVO = BeanUtils.copyBean(auctionBidRecord, AuctionBidRecordVO.class); - auctionBidRecordVO.setNum(auctionBidRecordList.indexOf(auctionBidRecord) + 1); - - AuctionSalesroomGoods salesroomGoods = roomMap.get(String.format("%s-%s", auctionBidRecord - .getAuctionSalesroomId(), auctionBidRecord.getTargetId())); - if (salesroomGoods != null) { - BigDecimal totalAmount = auctionBidRecord.getLastBidAmount().multiply(new BigDecimal(salesroomGoods - .getDealQuantity())); - auctionBidRecordVO.setTotalAmount(totalAmount); - } - - AuctionSalesroom auctionSalesroom = auctionSalesroomMap.get(auctionBidRecord.getAuctionSalesroomId()); - if (auctionSalesroom != null) { - auctionBidRecordVO.setAuctionSalesroomName(auctionSalesroom.getSalesroomName()); - } - - GoodsSku goodsSku = goodsSkuMap.get(auctionBidRecord.getTargetId()); - if (goodsSku != null) { - auctionBidRecordVO.setGoodsSkuName(goodsSku.getSkuName()); - } - - return auctionBidRecordVO; - }).collect(Collectors.toList()); - response.setContentType( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); @@ -273,12 +263,12 @@ // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 try { String fileName = URLEncoder.encode( - "优惠券领取明细" + DateUtils.format(new Date(), "yyyyMMddHHmmss"), "UTF-8") + "拍卖场出价记录" + DateUtils.format(new Date(), "yyyyMMddHHmmss"), "UTF-8") .replaceAll("\\+", "%20"); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); EasyExcel.write(response.getOutputStream(), AuctionBidRecordVO.class) - .sheet("优惠券领取明细") + .sheet("拍卖场出价记录") .doWrite(result); } catch (IOException e) { throw new RuntimeException(e); -- Gitblit v1.7.1