package com.gxwebsoft.credit.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.credit.entity.CreditCompany;
import com.gxwebsoft.credit.mapper.CreditCompanyMapper;
import com.gxwebsoft.credit.param.CreditCompanyParam;
import com.gxwebsoft.credit.service.CreditCompanyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业Service实现
 *
 * @author 科技小王子
 * @since 2025-12-17 08:28:03
 */
@Service
public class CreditCompanyServiceImpl extends ServiceImpl<CreditCompanyMapper, CreditCompany> implements CreditCompanyService {

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

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

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

    @Override
    public CreditCompany getByName(String name) {
      CreditCompanyParam param = new CreditCompanyParam();
      param.setName(name);
      return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public CreditCompany getByMatchName(String name) {
      CreditCompanyParam param = new CreditCompanyParam();
      param.setMatchName(name);
      return param.getOne(baseMapper.selectListRel(param));
    }

}
