package com.gxwebsoft.dormitory.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.dormitory.mapper.DormitoryRecordMapper;
import com.gxwebsoft.dormitory.service.DormitoryRecordService;
import com.gxwebsoft.dormitory.entity.DormitoryRecord;
import com.gxwebsoft.dormitory.param.DormitoryRecordParam;
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 DormitoryRecordServiceImpl extends ServiceImpl<DormitoryRecordMapper, DormitoryRecord> implements DormitoryRecordService {

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

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

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

}
