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.CreditCustomer;
import com.gxwebsoft.credit.mapper.CreditCustomerMapper;
import com.gxwebsoft.credit.param.CreditCustomerParam;
import com.gxwebsoft.credit.service.CreditCustomerService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户Service实现
 *
 * @author 科技小王子
 * @since 2025-12-21 21:20:58
 */
@Service
public class CreditCustomerServiceImpl extends ServiceImpl<CreditCustomerMapper, CreditCustomer> implements CreditCustomerService {

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

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

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

}
