package com.seer.teach.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seer.teach.mall.service.IOrderLogService;
import com.seer.teach.mall.entity.OrderLogEntity;
import com.seer.teach.mall.mapper.OrderLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seer.teach.mall.request.OrderLogPageReq;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 订单日志 服务实现类
 * </p>
 *
 * @author Wang
 * @since 2025-07-10 15:31:18
 */
@Service
public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OrderLogEntity> implements IOrderLogService {

    @Override
    public IPage<OrderLogEntity> pageList(OrderLogPageReq reqVO) {
        IPage<OrderLogEntity> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        
        LambdaQueryWrapper<OrderLogEntity> queryWrapper = new LambdaQueryWrapper<>(OrderLogEntity.class)
                .eq(OrderLogEntity::getOrderId, reqVO.getOrderId());
        
        // 如果有商家ID，则添加商家ID过滤条件
        if (Objects.nonNull(reqVO.getMerchantId())) {
            queryWrapper.eq(OrderLogEntity::getMerchantId, reqVO.getMerchantId());
        }
        
        return super.page(page, queryWrapper);
    }
}