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.CreditExternal;
import com.gxwebsoft.credit.mapper.CreditExternalMapper;
import com.gxwebsoft.credit.param.CreditExternalParam;
import com.gxwebsoft.credit.service.CreditExternalService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 对外投资Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:50:11
 */
@Service
public class CreditExternalServiceImpl extends ServiceImpl<CreditExternalMapper, CreditExternal> implements CreditExternalService {

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

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

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

}
