package com.gxwebsoft.docs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.docs.mapper.DocsUserMapper;
import com.gxwebsoft.docs.service.DocsUserService;
import com.gxwebsoft.docs.entity.DocsUser;
import com.gxwebsoft.docs.param.DocsUserParam;
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-03-26 09:29:15
 */
@Service
public class DocsUserServiceImpl extends ServiceImpl<DocsUserMapper, DocsUser> implements DocsUserService {

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

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

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

}
