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.CreditSuspectedRelationship;
import com.gxwebsoft.credit.mapper.CreditSuspectedRelationshipMapper;
import com.gxwebsoft.credit.param.CreditSuspectedRelationshipParam;
import com.gxwebsoft.credit.service.CreditSuspectedRelationshipService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 疑似关系Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditSuspectedRelationshipServiceImpl extends ServiceImpl<CreditSuspectedRelationshipMapper, CreditSuspectedRelationship> implements CreditSuspectedRelationshipService {

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

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

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

}
