feat():增加列表查询

master
86191 2024-08-04 10:22:36 +08:00
parent b4181778ae
commit fa4c27713d
5 changed files with 75 additions and 18 deletions

View File

@ -3,6 +3,8 @@ package com.muyu.cloud.pay.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.cloud.pay.domain.resp.CustomerOrderPaySimpleResp;
import com.muyu.common.core.enums.SysPayType;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -59,4 +61,13 @@ public class OrderPayInfo extends BaseEntity {
*
*/
private String status;
public CustomerOrderPaySimpleResp buildCustomerOrderPaySimpleResp() {
return CustomerOrderPaySimpleResp.builder()
.cusOrderNumber(this.cusOrderNumber)
.price(this.price)
.channelTypeName(SysPayType.getInfoByCode(this.channelType))
.build();
}
}

View File

@ -11,6 +11,8 @@ import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
/**
*
@ -59,7 +61,7 @@ public class CustomerResp {
* @param orderPayCustomer
* @return
*/
public static CustomerResp customerBuild(OrderPayCustomer orderPayCustomer){
public static CustomerResp customerBuild(OrderPayCustomer orderPayCustomer, Supplier<List<CustomerOrderPaySimpleResp>> function){
return CustomerResp.builder()
.id(orderPayCustomer.getId())
.appCode(orderPayCustomer.getAppCode())
@ -67,6 +69,7 @@ public class CustomerResp {
.createBy(orderPayCustomer.getCreateBy())
.createTime(orderPayCustomer.getCreateTime())
.status(orderPayCustomer.getStatus())
.orderPaySimpleRespList(function.get())
.build();
}
}

View File

@ -3,8 +3,17 @@ package com.muyu.cloud.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.cloud.pay.domain.OrderPayInfo;
import java.util.List;
/**
*
*/
public interface OrderPayService extends IService<OrderPayInfo> {
/**
* code,
* @param appCode code
* @param limit
* @return
*/
List<OrderPayInfo> selectOrderPayByAppCodeAndLimit(String appCode, int limit);
}

View File

@ -10,6 +10,7 @@ import com.muyu.cloud.pay.domain.resp.CustomerResp;
import com.muyu.cloud.pay.mapper.OrderPayCustomerMapper;
import com.muyu.cloud.pay.service.OrderPayCustomerService;
import com.muyu.cloud.pay.service.OrderPayService;
import com.muyu.common.core.enums.SysPayType;
import com.muyu.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -17,6 +18,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
@Slf4j
@Service
@ -41,24 +43,45 @@ public class OrderPayCustomerServiceImpl extends ServiceImpl<OrderPayCustomerMap
OrderPayCustomer::getStatus, customerListReq.getStatus() //是否开启
);
List<OrderPayCustomer> orderPayCustomerList = this.list(queryWrapper);
List<CustomerResp> customerRespList = orderPayCustomerList.stream()
.map(CustomerResp::customerBuild)
return orderPayCustomerList.stream()
.map(orderPayCustomer -> CustomerResp.customerBuild(
orderPayCustomer,
() -> orderPayService.selectOrderPayByAppCodeAndLimit(orderPayCustomer.getAppCode(), 5)
.stream()
.map(OrderPayInfo::buildCustomerOrderPaySimpleResp)
.toList()
)
)
.toList();
// for (CustomerResp customerResp : customerRespList) {
//注释的这一部分在OrderPayServiceImpl中实现
// orderPayService.selectOrderPayByAppCodeAndLimit(customerResp.getAppCode(), 5);
//
// LambdaQueryWrapper<OrderPayInfo> orderPayInfoQueryWrapper = new LambdaQueryWrapper<>();
// orderPayInfoQueryWrapper.eq(OrderPayInfo::getAppCode, customerResp.getAppCode());
// orderPayInfoQueryWrapper.orderBy(true, false, OrderPayInfo::getCreateTime);
// orderPayInfoQueryWrapper.last("limit 5");
// List<OrderPayInfo> orderPayInfoList = orderPayService.selectOrderPayByAppCodeAndLimit(customerResp.getAppCode(),5);
// ArrayList<CustomerOrderPaySimpleResp> customerOrderPaySimpleList = new ArrayList<>();
// for (OrderPayInfo orderPayInfo : orderPayInfoList) {
// CustomerOrderPaySimpleResp customerOrderPaySimpleResp = new CustomerOrderPaySimpleResp();
// customerOrderPaySimpleResp.setCusOrderNumber(orderPayInfo.getCusOrderNumber());
// customerOrderPaySimpleResp.setPrice(orderPayInfo.getPrice());
// customerOrderPaySimpleResp.setChannelTypeName(SysPayType.getInfoByCode(orderPayInfo.getChannelType()));
// customerOrderPaySimpleList.add(customerOrderPaySimpleResp);
// }
// customerResp.setOrderPaySimpleRespList(customerOrderPaySimpleList);
// customerResp.setOrderPaySimpleRespList(
// orderPayService.selectOrderPayByAppCodeAndLimit(customerResp.getAppCode(),5)
// .stream()
// .map(OrderPayInfo::buildCustomerOrderPaySimpleResp)
// .toList()
// );
for (CustomerResp customerResp : customerRespList) {
LambdaQueryWrapper<OrderPayInfo> orderPayInfoQueryWrapper = new LambdaQueryWrapper<>();
orderPayInfoQueryWrapper.eq(OrderPayInfo::getAppCode, customerResp.getAppCode());
orderPayInfoQueryWrapper.orderBy(true, false, OrderPayInfo::getCreateTime);
orderPayInfoQueryWrapper.last("limit 5");
List<OrderPayInfo> orderPayInfoList = orderPayService.list(orderPayInfoQueryWrapper);
ArrayList<CustomerOrderPaySimpleResp> customerOrderPaySimpleList = new ArrayList<>();
for (OrderPayInfo orderPayInfo : orderPayInfoList) {
CustomerOrderPaySimpleResp customerOrderPaySimpleResp = new CustomerOrderPaySimpleResp();
customerOrderPaySimpleResp.setCusOrderNumber(orderPayInfo.getCusOrderNumber());
customerOrderPaySimpleResp.setPrice(orderPayInfo.getPrice());
customerOrderPaySimpleResp.setChannelTypeName(orderPayInfo.getChannelType());
}
}
return customerRespList;
}
}

View File

@ -1,15 +1,26 @@
package com.muyu.cloud.pay.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.cloud.pay.domain.OrderPayInfo;
import com.muyu.cloud.pay.mapper.OrderPayMapper;
import com.muyu.cloud.pay.service.OrderPayService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*/
@Service
public class OrderPayServiceImpl extends ServiceImpl<OrderPayMapper, OrderPayInfo> implements OrderPayService {
@Override
public List<OrderPayInfo> selectOrderPayByAppCodeAndLimit(String appCode, int limit) {
LambdaQueryWrapper<OrderPayInfo> orderPayInfoQueryWrapper = new LambdaQueryWrapper<>();
orderPayInfoQueryWrapper.eq(OrderPayInfo::getAppCode,appCode);
orderPayInfoQueryWrapper.orderBy(true, false, OrderPayInfo::getCreateTime);
orderPayInfoQueryWrapper.last("limit" + limit);
return this.list(orderPayInfoQueryWrapper);
}
}