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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.AccessKeyMapper;
import com.gxwebsoft.common.system.service.AccessKeyService;
import com.gxwebsoft.common.system.entity.AccessKey;
import com.gxwebsoft.common.system.param.AccessKeyParam;
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 2023-05-16 19:19:55
 */
@Service
public class AccessKeyServiceImpl extends ServiceImpl<AccessKeyMapper, AccessKey> implements AccessKeyService {

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

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

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

}
