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.CreditCompetitor;
import com.gxwebsoft.credit.mapper.CreditCompetitorMapper;
import com.gxwebsoft.credit.param.CreditCompetitorParam;
import com.gxwebsoft.credit.service.CreditCompetitorService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 竞争对手Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:49:05
 */
@Service
public class CreditCompetitorServiceImpl extends ServiceImpl<CreditCompetitorMapper, CreditCompetitor> implements CreditCompetitorService {

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

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

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

}
