package com.gxwebsoft.bszx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.bszx.mapper.BszxBranchMapper;
import com.gxwebsoft.bszx.service.BszxBranchService;
import com.gxwebsoft.bszx.entity.BszxBranch;
import com.gxwebsoft.bszx.param.BszxBranchParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 百色中学-分部Service实现
 *
 * @author 科技小王子
 * @since 2025-03-17 17:18:22
 */
@Service
public class BszxBranchServiceImpl extends ServiceImpl<BszxBranchMapper, BszxBranch> implements BszxBranchService {

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

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

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

}
