package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.AuthorizeCodeMapper;
import com.gxwebsoft.common.system.service.AuthorizeCodeService;
import com.gxwebsoft.common.system.entity.AuthorizeCode;
import com.gxwebsoft.common.system.param.AuthorizeCodeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 授权码Service实现
 *
 * @author 科技小王子
 * @since 2025-08-05 01:17:27
 */
@Service
public class AuthorizeCodeServiceImpl extends ServiceImpl<AuthorizeCodeMapper, AuthorizeCode> implements AuthorizeCodeService {

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

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

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

}
