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.CreditBranch;
import com.gxwebsoft.credit.mapper.CreditBranchMapper;
import com.gxwebsoft.credit.param.CreditBranchParam;
import com.gxwebsoft.credit.service.CreditBranchService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分支机构Service实现
 *
 * @author 科技小王子
 * @since 2026-01-07 13:52:14
 */
@Service
public class CreditBranchServiceImpl extends ServiceImpl<CreditBranchMapper, CreditBranch> implements CreditBranchService {

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

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

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

}
