package com.gxwebsoft.common.system.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.common.system.entity.SysFileType;
import com.gxwebsoft.common.system.mapper.SysFileTypeMapper;
import com.gxwebsoft.common.system.param.SysFileTypeParam;
import com.gxwebsoft.common.system.service.SysFileTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 存储类型Service实现
 *
 * @author 科技小王子
 * @since 2025-05-16 14:24:28
 */
@Service
public class SysFileTypeServiceImpl extends ServiceImpl<SysFileTypeMapper, SysFileType> implements SysFileTypeService {

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

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

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

}
