package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaCompanyMapper;
import com.gxwebsoft.oa.service.OaCompanyService;
import com.gxwebsoft.oa.entity.OaCompany;
import com.gxwebsoft.oa.param.OaCompanyParam;
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 OaCompanyServiceImpl extends ServiceImpl<OaCompanyMapper, OaCompany> implements OaCompanyService {

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

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

    @Override
    public OaCompany getByIdRel(Integer companyId) {
        OaCompanyParam param = new OaCompanyParam();
        param.setCompanyId(companyId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
