@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("platform_bill")
public class PlatformBill implements Serializable {
/** 账单详情编号 */
private Long id;
/** 交易时间 */
private Timestamp transactionTime;
/** 商户号,用商户号跟商户表 store 连接*/
private String mchtNo;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PlatformBillDto implements Serializable {
/** 账单详情编号 */
private Long id;
/** 交易时间,用List集合装,前端传入开始时间和结束时间*/
private List<Timestamp> transactionTime;
/** 商户号,用商户号跟商户表 stroe 连接*/
private String mchtNo;
/** 商户名称,这个 name 是从商户表 stroe 查过来的*/
private String name;
}
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@Repository
public interface PlatformBillMapper extends CoreMapper<PlatformBill> {
/**
* 账单表连商户表,查账单信息和商户名称
* @param
* @return
*/
// 自定义 sql 语句
@Select("SELECT p.id,p.transaction_time,p.mcht_no,s.name FROM platform_bill AS p LEFT JOIN store AS s ON p.mcht_no = s.id ${ew.customSqlSegment}")
IPage<PlatformBillDto> getList(Page<PlatformBillDto> pageParam, @Param(Constants.WRAPPER) QueryWrapper<PlatformBillDto> queryWrapper);
}
import com.baomidou.mybatisplus.core.metadata.IPage;
public interface PlatformBillService extends BaseService<PlatformBill>{
IPage<PlatformBillDto> getList(Page<PlatformBillDto> pageParam, PlatformBillDto platformBillDto);
}
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.StringUtils;
@Service
@AllArgsConstructor
//@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PlatformBillServiceImpl extends BaseServiceImpl<PlatformBillMapper, PlatformBill> implements PlatformBillService {
@Override
public IPage<PlatformBillDto> getList(Page<PlatformBillDto> pageParam, PlatformBillDto platformBillDto) {
// 条件构造器
QueryWrapper<PlatformBillDto> queryWrapper = new QueryWrapper<>();
// 有分页查询 无条件查询,如果没有传条件过来,那么全部查询且分页
if (PlatformBillDto == null) {
return baseMapper.getList(pageParam,null);
}
// 查询订单号
String orderId = PlatformBillDto.getOrderId();
// 传过来的时间,开始时间 与 结束时间,用 List 集合装
List<Timestamp> transactionTime = PlatformBillDto.getTransactionTime();
// 还需要什么条件查询的,根据自己需要加
// 如果有传过来的订单号,那么会加入条件构造器中
if (!StringUtils.isEmpty(orderId)) {
queryWrapper.eq("order_id", orderId);
}
// 传过来的时间,开始时间在第 0 位,结束时间在第 1 位,
// 前端传参要写transactionTime=2022-xx-xx&transactionTime=2022-xx-xx, 看自己时间格式是什么。
if (!StringUtils.isEmpty(transactionTime)) {
queryWrapper.between("transaction_Time", transactionTime.get(0),transactionTime.get(1));
}
// queryWrapper 把所有条件传进去
return baseMapper.getList(pageParam, queryWrapper);
}
}
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataVo<T> implements Serializable{
private Integer count;
private List<T> data;
public DataVo(Integer count, List<T> data) {
this.count = count;
this.data = data;
}
}
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
@RestController
@RequestMapping("/platformBill")
public class PlatformBillController {
@GetMapping("/getList")
public DataVo getList(Integer page,Integer size,PlatformBillDto platformBillDto) {
DataVo result = new DataVo();
// 分页参数
Page<PlatformBillDto> pageParam = new Page<>(page, size);
IPage<PlatformBillDto> pageModel = PlatformBillDto.getList(pageParam, platformBillDto);
// 查出数据
List<PlatformBillDto> data = pageModel.getRecords();
// 统计条数
long conunt = pageModel.getTotal();
result.setCount(conunt);
result.setData(data);
return result;
}
}