package com.gxwebsoft.house.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.house.mapper.HouseReservationMapper;
import com.gxwebsoft.house.service.HouseReservationService;
import com.gxwebsoft.house.entity.HouseReservation;
import com.gxwebsoft.house.param.HouseReservationParam;
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 2025-03-05 13:47:15
 */
@Service
public class HouseReservationServiceImpl extends ServiceImpl<HouseReservationMapper, HouseReservation> implements HouseReservationService {

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

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

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

}
