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.CreditCourtAnnouncement;
import com.gxwebsoft.credit.mapper.CreditCourtAnnouncementMapper;
import com.gxwebsoft.credit.param.CreditCourtAnnouncementParam;
import com.gxwebsoft.credit.service.CreditCourtAnnouncementService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 法院公告司法大数据Service实现
 *
 * @author 科技小王子
 * @since 2025-12-19 19:49:13
 */
@Service
public class CreditCourtAnnouncementServiceImpl extends ServiceImpl<CreditCourtAnnouncementMapper, CreditCourtAnnouncement> implements CreditCourtAnnouncementService {

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

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

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

}
