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.CreditJudiciary;
import com.gxwebsoft.credit.mapper.CreditJudiciaryMapper;
import com.gxwebsoft.credit.param.CreditJudiciaryParam;
import com.gxwebsoft.credit.service.CreditJudiciaryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 司法案件Service实现
 *
 * @author 科技小王子
 * @since 2025-12-16 15:23:58
 */
@Service
public class CreditJudiciaryServiceImpl extends ServiceImpl<CreditJudiciaryMapper, CreditJudiciary> implements CreditJudiciaryService {

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

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

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

    @Override
    public CreditJudiciary getByName(String name) {
        CreditJudiciaryParam param = new CreditJudiciaryParam();
        param.setName(name);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
