package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaCompanyUserMapper;
import com.gxwebsoft.oa.service.OaCompanyUserService;
import com.gxwebsoft.oa.entity.OaCompanyUser;
import com.gxwebsoft.oa.param.OaCompanyUserParam;
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 2024-09-20 12:33:12
 */
@Service
public class OaCompanyUserServiceImpl extends ServiceImpl<OaCompanyUserMapper, OaCompanyUser> implements OaCompanyUserService {

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

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

    @Override
    public OaCompanyUser getByIdRel(Integer companyUserId) {
        OaCompanyUserParam param = new OaCompanyUserParam();
        param.setCompanyUserId(companyUserId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
