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.CreditBankruptcy;
import com.gxwebsoft.credit.mapper.CreditBankruptcyMapper;
import com.gxwebsoft.credit.param.CreditBankruptcyParam;
import com.gxwebsoft.credit.service.CreditBankruptcyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 破产重整Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditBankruptcyServiceImpl extends ServiceImpl<CreditBankruptcyMapper, CreditBankruptcy> implements CreditBankruptcyService {

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

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

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

}
