package com.gxwebsoft.dormitory.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.dormitory.mapper.DormitoryBuildingMapper;
import com.gxwebsoft.dormitory.service.DormitoryBuildingService;
import com.gxwebsoft.dormitory.entity.DormitoryBuilding;
import com.gxwebsoft.dormitory.param.DormitoryBuildingParam;
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 DormitoryBuildingServiceImpl extends ServiceImpl<DormitoryBuildingMapper, DormitoryBuilding> implements DormitoryBuildingService {

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

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

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

}
