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.CreditNearbyCompany;
import com.gxwebsoft.credit.mapper.CreditNearbyCompanyMapper;
import com.gxwebsoft.credit.param.CreditNearbyCompanyParam;
import com.gxwebsoft.credit.service.CreditNearbyCompanyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 附近企业Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditNearbyCompanyServiceImpl extends ServiceImpl<CreditNearbyCompanyMapper, CreditNearbyCompany> implements CreditNearbyCompanyService {

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

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

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

}
