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.CreditXgxf;
import com.gxwebsoft.credit.mapper.CreditXgxfMapper;
import com.gxwebsoft.credit.param.CreditXgxfParam;
import com.gxwebsoft.credit.service.CreditXgxfService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 限制高消费Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:51:55
 */
@Service
public class CreditXgxfServiceImpl extends ServiceImpl<CreditXgxfMapper, CreditXgxf> implements CreditXgxfService {

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

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

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

}
