| | |
| | | package com.ruoyi.auction.controller.management; |
| | | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.util.DateUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.google.zxing.WriterException; |
| | | import com.ruoyi.auction.controller.management.dto.MgtAuctionSaleroomBidRecordQuery; |
| | | import com.ruoyi.auction.controller.management.dto.MgtAuctionSalesroomDTO; |
| | | import com.ruoyi.auction.controller.management.dto.MgtAuctionSalesroomQuery; |
| | | import com.ruoyi.auction.controller.management.vo.AuctionBidRecordVO; |
| | | import com.ruoyi.auction.controller.management.vo.MgtAuctionBidRecordVO; |
| | | import com.ruoyi.auction.controller.management.vo.MgtAuctionSalesroomVO; |
| | | import com.ruoyi.auction.domain.AuctionBidRecord; |
| | | import com.ruoyi.auction.mapper.AuctionBidRecordMapper; |
| | | import com.ruoyi.auction.service.IAuctionSalesroomGoodsService; |
| | | import com.ruoyi.auction.service.IAuctionSalesroomService; |
| | | import com.ruoyi.auction.util.weChat.EnvVersion; |
| | | import com.ruoyi.auction.util.weChat.WeChatUtil; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.enums.AuctionOrderTypeEnum; |
| | | 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.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | 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.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; |
| | | |
| | |
| | | @RestController |
| | | @RequestMapping("/mgt/auction-salesroom") |
| | | @RequiredArgsConstructor |
| | | @Api(value = "拍卖场管理相关接口", tags = {"管理后台接口"}) |
| | | @Api(value = "拍卖场管理相关接口", tags = {"管理后台-拍卖场管理相关接口"}) |
| | | public class MgtAuctionSalesroomController { |
| | | |
| | | private final IAuctionSalesroomService auctionSalesroomService; |
| | | private final AuctionBidRecordMapper auctionBidRecordMapper; |
| | | private final IAuctionSalesroomGoodsService auctionSalesroomGoodsService; |
| | | private final GoodsSkuClient goodsSkuClient; |
| | | private final WeChatUtil weChatUtil; |
| | | |
| | | /** |
| | | * 分页查询拍卖场 |
| | |
| | | @PostMapping("/page") |
| | | @ApiOperation(value = "获取拍卖场列表的分页数据", notes = "获取拍卖场列表的分页数据") |
| | | public R<PageDTO<MgtAuctionSalesroomVO>> getAuctionSalesroomPage( |
| | | MgtAuctionSalesroomQuery query) { |
| | | @Validated @RequestBody MgtAuctionSalesroomQuery query) { |
| | | return R.ok(auctionSalesroomService.getAuctionSalesroomPage(query)); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping("/qr-code/{id}") |
| | | @ApiOperation(value = "查看二维码", notes = "查看二维码") |
| | | public R<String> getQrCode(@PathVariable("id") Long id) { |
| | | public R<String> getQrCode( |
| | | @ApiParam(name = "id", value = "拍卖场id", required = true) @PathVariable("id") Long id) { |
| | | |
| | | AuctionSalesroom auctionSalesroom = auctionSalesroomService.getById(id); |
| | | if (StringUtils.isNotEmpty(auctionSalesroom.getQrCode())){ |
| | | return R.ok(auctionSalesroom.getQrCode()); |
| | | } |
| | | try { |
| | | return R.ok(auctionSalesroomService.getQrCode(id)); |
| | | |
| | | String qrCode = weChatUtil.getwxacodeunlimit("pages/mall/mall", |
| | | "id=" + auctionSalesroom.getAuctionSalesroomNo() + "&t=" |
| | | + auctionSalesroom.getType().getCode(), |
| | | EnvVersion.TRIAL, null); // TODO 上线需要修改为正式环境 |
| | | auctionSalesroom.setQrCode(qrCode); |
| | | auctionSalesroomService.updateById(auctionSalesroom); |
| | | return R.ok(qrCode); |
| | | } catch (Exception e) { |
| | | log.info("查看二维码异常", e); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加/编辑 拍卖场 |
| | | * |
| | | * @param dto 拍卖场数据传输对象 |
| | | */ |
| | | @PostMapping("/save") |
| | | @ApiOperation(value = "添加/编辑 拍卖场", notes = "添加/编辑 拍卖场") |
| | | public R<?> saveAuctionSalesroom( |
| | | @Validated @RequestBody MgtAuctionSalesroomDTO dto) { |
| | | try { |
| | | auctionSalesroomService.saveAuctionSalesroom(dto); |
| | | } catch (IOException | WriterException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 查看详情 |
| | | * |
| | | * @param id 拍卖会id |
| | | * @return 拍卖场视图对象 |
| | | */ |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "查看详情", notes = "查看详情") |
| | | public R<MgtAuctionSalesroomVO> getAuctionSalesroom( |
| | | @ApiParam(name = "id", value = "拍卖会id", required = true) @PathVariable("id") Long id) { |
| | | return R.ok(auctionSalesroomService.getAuctionSalesroom(id, Boolean.FALSE)); |
| | | } |
| | | |
| | | /** |
| | | * 查看详情-出价记录 |
| | | * |
| | | * @param query 拍卖场出价记录查询对象 |
| | | * @return PageDTO<MgtAuctionBidRecordVO> |
| | | */ |
| | | @PostMapping("/bid-record") |
| | | @ApiOperation(value = "查看详情-出价记录", notes = "查看详情-出价记录") |
| | | public R<PageDTO<MgtAuctionBidRecordVO>> getAuctionSalesroomBidRecordList( |
| | | @Validated @RequestBody MgtAuctionSaleroomBidRecordQuery query) { |
| | | return R.ok(auctionSalesroomService.getAuctionSalesroomBidRecordList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 删除拍卖场 |
| | | */ |
| | | @DeleteMapping("/{id}") |
| | | @ApiOperation(value = "删除拍卖场", notes = "删除拍卖场") |
| | | public R<?> deleteAuctionSalesroom(@PathVariable("id") Long id){ |
| | | auctionSalesroomService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导出列表 |
| | | */ |
| | | @ApiOperation("导出列表") |
| | | @PostMapping("/export") |
| | | public void export(@RequestBody MgtAuctionSalesroomQuery query, HttpServletResponse response) { |
| | | List<AuctionBidRecordVO> result = Collections.emptyList(); |
| | | List<MgtAuctionSalesroomVO> list = auctionSalesroomService.getAuctionSalesroomList(query); |
| | | List<Long> ids = list.stream().map(MgtAuctionSalesroomVO::getId).collect(Collectors.toList()); |
| | | |
| | | |
| | | List<AuctionBidRecord> auctionBidRecordList = auctionBidRecordMapper.selectList( |
| | | new LambdaQueryWrapper<AuctionBidRecord>() |
| | | .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()); |
| | | |
| | | 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()); |
| | | } |
| | | |
| | | 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(result); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |