package com.gxwebsoft.common.system.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.common.system.entity.MerchantType;
import com.gxwebsoft.common.system.mapper.MerchantTypeMapper;
import com.gxwebsoft.common.system.param.MerchantTypeParam;
import com.gxwebsoft.common.system.service.MerchantTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户类型Service实现
 *
 * @author 科技小王子
 * @since 2024-04-05 00:08:51
 */
@Service
public class MerchantTypeServiceImpl extends ServiceImpl<MerchantTypeMapper, MerchantType> implements MerchantTypeService {

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

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

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

}
