package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.Order;
import com.gxwebsoft.shop.entity.OrderInfo;
import com.gxwebsoft.shop.mapper.OrderInfoMapper;
import com.gxwebsoft.shop.param.OrderInfoParam;
import com.gxwebsoft.shop.service.OrderInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 场地Service实现
 *
 * @author 科技小王子
 * @since 2024-05-14 13:20:04
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Override
    public PageResult<OrderInfo> pageRel(OrderInfoParam param) {
        PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        List<OrderInfo> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<OrderInfo> listRel(OrderInfoParam param) {
        List<OrderInfo> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>();
        page.setDefaultOrder("sort_number asc, create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public OrderInfo getByIdRel(Integer id) {
        OrderInfoParam param = new OrderInfoParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public void updateByOutTradeNo(Order order) {
        baseMapper.updateByOutTradeNo(order);
    }

//    @Override
//    public List<OrderInfo> getTodayOrder(PeriodParam param) {
//      // 多表查询
//      MPJLambdaWrapper<OrderInfo> mpjLambdaWrapper = new MPJLambdaWrapper<>();
//      mpjLambdaWrapper.selectAll(OrderInfo.class)
//        .select(Order::getOrderNo)
//        .select(Order::getOrderStatus)
//        .leftJoin(Order.class,Order::getOrderId,OrderInfo::getOrderId)
//        .eq(OrderInfo::getDateTime,param.getDateTime())
//        .eq(Order::getPayStatus,1)
//        .eq(OrderInfo::getMerchantId,param.getMerchantId());
//      return baseMapper.selectJoinList(OrderInfo.class, mpjLambdaWrapper);
//    }

}
