package com.gxwebsoft.dormitory.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.dormitory.entity.DormitoryApply;
import com.gxwebsoft.dormitory.mapper.DormitoryApplyMapper;
import com.gxwebsoft.dormitory.param.DormitoryApplyParam;
import com.gxwebsoft.dormitory.service.DormitoryApplyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批管理Service实现
 *
 * @author 科技小王子
 * @since 2025-10-03 15:54:30
 */
@Service
public class DormitoryApplyServiceImpl extends ServiceImpl<DormitoryApplyMapper, DormitoryApply> implements DormitoryApplyService {

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

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

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

}
