package com.gxwebsoft.dormitory.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.dormitory.mapper.DormitoryFloorMapper;
import com.gxwebsoft.dormitory.service.DormitoryFloorService;
import com.gxwebsoft.dormitory.entity.DormitoryFloor;
import com.gxwebsoft.dormitory.param.DormitoryFloorParam;
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 DormitoryFloorServiceImpl extends ServiceImpl<DormitoryFloorMapper, DormitoryFloor> implements DormitoryFloorService {

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

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

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

}
