package com.gxwebsoft.dormitory.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.dormitory.mapper.DormitoryBedMapper;
import com.gxwebsoft.dormitory.service.DormitoryBedService;
import com.gxwebsoft.dormitory.entity.DormitoryBed;
import com.gxwebsoft.dormitory.param.DormitoryBedParam;
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-10-03 10:49:27
 */
@Service
public class DormitoryBedServiceImpl extends ServiceImpl<DormitoryBedMapper, DormitoryBed> implements DormitoryBedService {

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

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

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

}
