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.CreditAdministrativeLicense;
import com.gxwebsoft.credit.mapper.CreditAdministrativeLicenseMapper;
import com.gxwebsoft.credit.param.CreditAdministrativeLicenseParam;
import com.gxwebsoft.credit.service.CreditAdministrativeLicenseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行政许可Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:13
 */
@Service
public class CreditAdministrativeLicenseServiceImpl extends ServiceImpl<CreditAdministrativeLicenseMapper, CreditAdministrativeLicense> implements CreditAdministrativeLicenseService {

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

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

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

}
