package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.CompanyMapper;
import com.gxwebsoft.oa.service.CompanyService;
import com.gxwebsoft.oa.entity.Company;
import com.gxwebsoft.oa.param.CompanyParam;
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 2023-10-23 19:18:58
 */
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements CompanyService {

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

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

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

}
