package com.gxwebsoft.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.house.mapper.ReservationMapper;
import com.gxwebsoft.house.service.ReservationService;
import com.gxwebsoft.house.entity.Reservation;
import com.gxwebsoft.house.param.ReservationParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预约记录表Service实现
 *
 * @author 科技小王子
 * @since 2023-08-03 18:23:43
 */
@Service
public class ReservationServiceImpl extends ServiceImpl<ReservationMapper, Reservation> implements ReservationService {

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

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

    @Override
    public Reservation getByIdRel(Integer logId) {
        ReservationParam param = new ReservationParam();
        param.setLogId(logId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
