refactor(tenant-withdraw): 优化分页查询返回VO并填充租户名称
This commit is contained in:
@@ -84,8 +84,8 @@ public class KeyboardTenantWithdrawOrderController {
|
||||
@Operation(summary = "获得租户提现订单表(申请-审核-打款-完成/失败)分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-withdraw-order:query')")
|
||||
public CommonResult<PageResult<KeyboardTenantWithdrawOrderRespVO>> getTenantWithdrawOrderPage(@Valid KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> pageResult = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardTenantWithdrawOrderRespVO.class));
|
||||
PageResult<KeyboardTenantWithdrawOrderRespVO> pageResult = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO);
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@@ -95,10 +95,9 @@ public class KeyboardTenantWithdrawOrderController {
|
||||
public void exportTenantWithdrawOrderExcel(@Valid KeyboardTenantWithdrawOrderPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardTenantWithdrawOrderDO> list = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO).getList();
|
||||
List<KeyboardTenantWithdrawOrderRespVO> list = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "租户提现订单表(申请-审核-打款-完成/失败).xls", "数据", KeyboardTenantWithdrawOrderRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardTenantWithdrawOrderRespVO.class));
|
||||
ExcelUtils.write(response, "租户提现订单表(申请-审核-打款-完成/失败).xls", "数据", KeyboardTenantWithdrawOrderRespVO.class, list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -142,4 +142,12 @@ public class KeyboardTenantWithdrawOrderRespVO {
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "租户编号", example = "1")
|
||||
@ExcelProperty("租户编号")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "租户名称", example = "芋道源码")
|
||||
@ExcelProperty("租户名称")
|
||||
private String tenantName;
|
||||
|
||||
}
|
||||
@@ -57,6 +57,6 @@ public interface KeyboardTenantWithdrawOrderService {
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 租户提现订单表(申请-审核-打款-完成/失败)分页
|
||||
*/
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO);
|
||||
PageResult<KeyboardTenantWithdrawOrderRespVO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -1,23 +1,25 @@
|
||||
package com.yolo.keyboard.service.tenantwithdraworder;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.*;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderPageReqVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderRespVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderSaveReqVO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.yolo.keyboard.dal.mysql.tenantwithdraworder.KeyboardTenantWithdrawOrderMapper;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.dal.mysql.tenant.TenantMapper;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.TENANT_WITHDRAW_ORDER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,9 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
@Resource
|
||||
private KeyboardTenantWithdrawOrderMapper tenantWithdrawOrderMapper;
|
||||
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
|
||||
@Override
|
||||
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@@ -78,8 +83,34 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardTenantWithdrawOrderDO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
return tenantWithdrawOrderMapper.selectPage(pageReqVO);
|
||||
public PageResult<KeyboardTenantWithdrawOrderRespVO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
// 分页查询租户提现订单数据
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> pageResult = tenantWithdrawOrderMapper.selectPage(pageReqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return PageResult.empty(pageResult.getTotal());
|
||||
}
|
||||
|
||||
// 批量获取租户名称 - 提升性能,避免N+1查询
|
||||
List<Long> tenantIds = pageResult.getList().stream()
|
||||
.map(KeyboardTenantWithdrawOrderDO::getTenantId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<TenantDO> tenants = tenantMapper.selectBatchIds(tenantIds);
|
||||
Map<Long, String> tenantNameMap = CollUtil.isEmpty(tenants)
|
||||
? new HashMap<>() // 如果没有查询到租户数据,返回空map
|
||||
: tenants.stream().collect(Collectors.toMap(TenantDO::getId, TenantDO::getName, (a, b) -> a)); // 构建租户ID到名称的映射
|
||||
|
||||
// 转换为 VO 并填充租户名称
|
||||
List<KeyboardTenantWithdrawOrderRespVO> voList = pageResult.getList().stream().map(order -> {
|
||||
// 将DO转换为VO
|
||||
KeyboardTenantWithdrawOrderRespVO vo = BeanUtils.toBean(order, KeyboardTenantWithdrawOrderRespVO.class);
|
||||
// 根据租户ID获取并设置租户名称
|
||||
vo.setTenantName(tenantNameMap.get(order.getTenantId()));
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 返回包含VO列表和总数的分页结果
|
||||
return new PageResult<>(voList, pageResult.getTotal());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user