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.CreditPatent;
import com.gxwebsoft.credit.mapper.CreditPatentMapper;
import com.gxwebsoft.credit.param.CreditPatentParam;
import com.gxwebsoft.credit.service.CreditPatentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 专利Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditPatentServiceImpl extends ServiceImpl<CreditPatentMapper, CreditPatent> implements CreditPatentService {

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

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

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

}
