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.CreditRiskRelation;
import com.gxwebsoft.credit.mapper.CreditRiskRelationMapper;
import com.gxwebsoft.credit.param.CreditRiskRelationParam;
import com.gxwebsoft.credit.service.CreditRiskRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 风险关系表Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:51:40
 */
@Service
public class CreditRiskRelationServiceImpl extends ServiceImpl<CreditRiskRelationMapper, CreditRiskRelation> implements CreditRiskRelationService {

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

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

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

}
