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.CreditSupplier;
import com.gxwebsoft.credit.mapper.CreditSupplierMapper;
import com.gxwebsoft.credit.param.CreditSupplierParam;
import com.gxwebsoft.credit.service.CreditSupplierService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:51:47
 */
@Service
public class CreditSupplierServiceImpl extends ServiceImpl<CreditSupplierMapper, CreditSupplier> implements CreditSupplierService {

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

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

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

}
