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.CreditHistoricalLegalPerson;
import com.gxwebsoft.credit.mapper.CreditHistoricalLegalPersonMapper;
import com.gxwebsoft.credit.param.CreditHistoricalLegalPersonParam;
import com.gxwebsoft.credit.service.CreditHistoricalLegalPersonService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 历史法定代表人Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditHistoricalLegalPersonServiceImpl extends ServiceImpl<CreditHistoricalLegalPersonMapper, CreditHistoricalLegalPerson> implements CreditHistoricalLegalPersonService {

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

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

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

}
