You've already forked FrameTour-BE
refactor(paging): 重构分页查询使用 PageHelper
-将 MyBatis-Plus 的分页插件替换为 PageHelper - 更新了相关控制器、服务接口和实现类中的分页查询方法 - 优化了分页查询的逻辑,提高了代码的可读性和维护性
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReqV2;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchQueryReq;
|
||||
@@ -42,8 +42,8 @@ public class VoucherManagementController {
|
||||
}
|
||||
|
||||
@PostMapping("/batch/list")
|
||||
public ApiResponse<Page<VoucherBatchResp>> getBatchList(@RequestBody VoucherBatchQueryReq req) {
|
||||
Page<VoucherBatchResp> page = voucherBatchService.queryBatchList(req);
|
||||
public ApiResponse<PageInfo<VoucherBatchResp>> getBatchList(@RequestBody VoucherBatchQueryReq req) {
|
||||
PageInfo<VoucherBatchResp> page = voucherBatchService.queryBatchList(req);
|
||||
return ApiResponse.success(page);
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ public class VoucherManagementController {
|
||||
}
|
||||
|
||||
@PostMapping("/codes")
|
||||
public ApiResponse<Page<VoucherCodeResp>> getCodeList(@RequestBody VoucherCodeQueryReq req) {
|
||||
Page<VoucherCodeResp> page = voucherCodeService.queryCodeList(req);
|
||||
public ApiResponse<PageInfo<VoucherCodeResp>> getCodeList(@RequestBody VoucherCodeQueryReq req) {
|
||||
PageInfo<VoucherCodeResp> page = voucherCodeService.queryCodeList(req);
|
||||
return ApiResponse.success(page);
|
||||
}
|
||||
|
||||
@@ -78,14 +78,14 @@ public class VoucherManagementController {
|
||||
}
|
||||
|
||||
@GetMapping("/scenic/{scenicId}/users")
|
||||
public ApiResponse<Page<VoucherCodeResp>> getUsersInScenic(@PathVariable Long scenicId,
|
||||
public ApiResponse<PageInfo<VoucherCodeResp>> getUsersInScenic(@PathVariable Long scenicId,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
VoucherCodeQueryReq req = new VoucherCodeQueryReq();
|
||||
req.setScenicId(scenicId);
|
||||
req.setPageNum(pageNum);
|
||||
req.setPageSize(pageSize);
|
||||
Page<VoucherCodeResp> page = voucherCodeService.queryCodeList(req);
|
||||
PageInfo<VoucherCodeResp> page = voucherCodeService.queryCodeList(req);
|
||||
return ApiResponse.success(page);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherUsageHistoryReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageRecordResp;
|
||||
@@ -24,9 +24,9 @@ public class VoucherUsageController {
|
||||
private final IVoucherUsageService voucherUsageService;
|
||||
|
||||
@PostMapping("/history")
|
||||
public ApiResponse<Page<VoucherUsageRecordResp>> getUsageHistory(@RequestBody VoucherUsageHistoryReq req) {
|
||||
public ApiResponse<PageInfo<VoucherUsageRecordResp>> getUsageHistory(@RequestBody VoucherUsageHistoryReq req) {
|
||||
try {
|
||||
Page<VoucherUsageRecordResp> result = voucherUsageService.getUsageHistory(req);
|
||||
PageInfo<VoucherUsageRecordResp> result = voucherUsageService.getUsageHistory(req);
|
||||
return ApiResponse.success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("查询券码使用记录失败", e);
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.ycwl.basic.pricing.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ycwl.basic.pricing.entity.PriceVoucherUsageRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -121,16 +120,15 @@ public interface PriceVoucherUsageRecordMapper extends BaseMapper<PriceVoucherUs
|
||||
Date getLastUseTimeByFaceIdAndBatchId(@Param("faceId") Long faceId, @Param("batchId") Long batchId);
|
||||
|
||||
/**
|
||||
* 分页查询券码使用记录
|
||||
* 查询券码使用记录(用于PageHelper分页)
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param batchId 批次ID(可选)
|
||||
* @param voucherCode 券码(可选)
|
||||
* @param faceId 用户faceId(可选)
|
||||
* @param scenicId 景区ID(可选)
|
||||
* @param startTime 开始时间(可选)
|
||||
* @param endTime 结束时间(可选)
|
||||
* @return 分页结果
|
||||
* @return 使用记录列表
|
||||
*/
|
||||
@Select("<script>" +
|
||||
"SELECT * FROM price_voucher_usage_record WHERE deleted = 0" +
|
||||
@@ -142,8 +140,7 @@ public interface PriceVoucherUsageRecordMapper extends BaseMapper<PriceVoucherUs
|
||||
"<if test=\"endTime != null\">AND use_time <= #{endTime}</if>" +
|
||||
"ORDER BY use_time DESC" +
|
||||
"</script>")
|
||||
Page<PriceVoucherUsageRecord> selectPageWithConditions(Page<PriceVoucherUsageRecord> page,
|
||||
@Param("batchId") Long batchId,
|
||||
List<PriceVoucherUsageRecord> selectListWithConditions(@Param("batchId") Long batchId,
|
||||
@Param("voucherCode") String voucherCode,
|
||||
@Param("faceId") Long faceId,
|
||||
@Param("scenicId") Long scenicId,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.ycwl.basic.pricing.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherUsageHistoryReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageRecordResp;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageStatsResp;
|
||||
@@ -18,7 +18,7 @@ public interface IVoucherUsageService {
|
||||
* @param req 查询请求
|
||||
* @return 分页结果
|
||||
*/
|
||||
Page<VoucherUsageRecordResp> getUsageHistory(VoucherUsageHistoryReq req);
|
||||
PageInfo<VoucherUsageRecordResp> getUsageHistory(VoucherUsageHistoryReq req);
|
||||
|
||||
/**
|
||||
* 获取指定券码的使用记录
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.ycwl.basic.pricing.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReqV2;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchQueryReq;
|
||||
@@ -17,7 +17,7 @@ public interface VoucherBatchService {
|
||||
*/
|
||||
Long createBatchV2(VoucherBatchCreateReqV2 req);
|
||||
|
||||
Page<VoucherBatchResp> queryBatchList(VoucherBatchQueryReq req);
|
||||
PageInfo<VoucherBatchResp> queryBatchList(VoucherBatchQueryReq req);
|
||||
|
||||
VoucherBatchResp getBatchDetail(Long id);
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.ycwl.basic.pricing.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherClaimReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherCodeQueryReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherCodeResp;
|
||||
@@ -13,7 +13,7 @@ public interface VoucherCodeService {
|
||||
|
||||
VoucherCodeResp claimVoucher(VoucherClaimReq req);
|
||||
|
||||
Page<VoucherCodeResp> queryCodeList(VoucherCodeQueryReq req);
|
||||
PageInfo<VoucherCodeResp> queryCodeList(VoucherCodeQueryReq req);
|
||||
|
||||
List<VoucherCodeResp> getMyVoucherCodes(Long faceId);
|
||||
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.ycwl.basic.pricing.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.exception.BizException;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherBatchCreateReq;
|
||||
@@ -153,8 +154,8 @@ public class VoucherBatchServiceImpl implements VoucherBatchService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<VoucherBatchResp> queryBatchList(VoucherBatchQueryReq req) {
|
||||
Page<PriceVoucherBatchConfig> page = new Page<>(req.getPageNum(), req.getPageSize());
|
||||
public PageInfo<VoucherBatchResp> queryBatchList(VoucherBatchQueryReq req) {
|
||||
PageHelper.startPage(req.getPageNum(), req.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<PriceVoucherBatchConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PriceVoucherBatchConfig::getDeleted, 0)
|
||||
@@ -164,14 +165,10 @@ public class VoucherBatchServiceImpl implements VoucherBatchService {
|
||||
.like(StringUtils.hasText(req.getBatchName()), PriceVoucherBatchConfig::getBatchName, req.getBatchName())
|
||||
.orderByDesc(PriceVoucherBatchConfig::getCreateTime);
|
||||
|
||||
Page<PriceVoucherBatchConfig> entityPage = voucherBatchMapper.selectPage(page, wrapper);
|
||||
java.util.List<PriceVoucherBatchConfig> list = voucherBatchMapper.selectList(wrapper);
|
||||
java.util.List<VoucherBatchResp> respList = list.stream().map(this::convertToResp).toList();
|
||||
|
||||
Page<VoucherBatchResp> respPage = new Page<>();
|
||||
BeanUtils.copyProperties(entityPage, respPage);
|
||||
|
||||
respPage.setRecords(entityPage.getRecords().stream().map(this::convertToResp).toList());
|
||||
|
||||
return respPage;
|
||||
return new PageInfo<>(respList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.ycwl.basic.pricing.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.exception.BizException;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherClaimReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherCodeQueryReq;
|
||||
@@ -124,8 +125,8 @@ public VoucherCodeResp claimVoucher(VoucherClaimReq req) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<VoucherCodeResp> queryCodeList(VoucherCodeQueryReq req) {
|
||||
Page<PriceVoucherCode> page = new Page<>(req.getPageNum(), req.getPageSize());
|
||||
public PageInfo<VoucherCodeResp> queryCodeList(VoucherCodeQueryReq req) {
|
||||
PageHelper.startPage(req.getPageNum(), req.getPageSize());
|
||||
|
||||
LambdaQueryWrapper<PriceVoucherCode> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PriceVoucherCode::getDeleted, 0)
|
||||
@@ -136,19 +137,15 @@ public VoucherCodeResp claimVoucher(VoucherClaimReq req) {
|
||||
.like(StringUtils.hasText(req.getCode()), PriceVoucherCode::getCode, req.getCode())
|
||||
.orderByDesc(PriceVoucherCode::getId);
|
||||
|
||||
Page<PriceVoucherCode> entityPage = voucherCodeMapper.selectPage(page, wrapper);
|
||||
|
||||
Page<VoucherCodeResp> respPage = new Page<>();
|
||||
BeanUtils.copyProperties(entityPage, respPage);
|
||||
List<PriceVoucherCode> list = voucherCodeMapper.selectList(wrapper);
|
||||
|
||||
List<VoucherCodeResp> respList = new ArrayList<>();
|
||||
for (PriceVoucherCode code : entityPage.getRecords()) {
|
||||
for (PriceVoucherCode code : list) {
|
||||
PriceVoucherBatchConfig batch = voucherBatchMapper.selectById(code.getBatchId());
|
||||
respList.add(convertToResp(code, batch));
|
||||
}
|
||||
respPage.setRecords(respList);
|
||||
|
||||
return respPage;
|
||||
return new PageInfo<>(respList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.ycwl.basic.pricing.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherUsageHistoryReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageRecordResp;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherUsageStatsResp;
|
||||
@@ -36,24 +37,20 @@ public class VoucherUsageServiceImpl implements IVoucherUsageService {
|
||||
private final PriceVoucherBatchConfigMapper batchConfigMapper;
|
||||
|
||||
@Override
|
||||
public Page<VoucherUsageRecordResp> getUsageHistory(VoucherUsageHistoryReq req) {
|
||||
Page<PriceVoucherUsageRecord> page = new Page<>(req.getPageNum(), req.getPageSize());
|
||||
public PageInfo<VoucherUsageRecordResp> getUsageHistory(VoucherUsageHistoryReq req) {
|
||||
PageHelper.startPage(req.getPageNum(), req.getPageSize());
|
||||
|
||||
Page<PriceVoucherUsageRecord> entityPage = usageRecordMapper.selectPageWithConditions(
|
||||
page, req.getBatchId(), req.getVoucherCode(), req.getFaceId(),
|
||||
List<PriceVoucherUsageRecord> list = usageRecordMapper.selectListWithConditions(
|
||||
req.getBatchId(), req.getVoucherCode(), req.getFaceId(),
|
||||
req.getScenicId(), req.getStartTime(), req.getEndTime());
|
||||
|
||||
Page<VoucherUsageRecordResp> respPage = new Page<>();
|
||||
BeanUtils.copyProperties(entityPage, respPage);
|
||||
|
||||
List<VoucherUsageRecordResp> respList = new ArrayList<>();
|
||||
for (PriceVoucherUsageRecord record : entityPage.getRecords()) {
|
||||
for (PriceVoucherUsageRecord record : list) {
|
||||
VoucherUsageRecordResp resp = convertToResp(record);
|
||||
respList.add(resp);
|
||||
}
|
||||
respPage.setRecords(respList);
|
||||
|
||||
return respPage;
|
||||
return new PageInfo<>(respList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user