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.Merchant;
import com.gxwebsoft.common.system.mapper.MerchantMapper;
import com.gxwebsoft.common.system.param.MerchantParam;
import com.gxwebsoft.common.system.service.MerchantService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户Service实现
 *
 * @author 科技小王子
 * @since 2024-04-05 00:03:54
 */
@Service
public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> implements MerchantService {

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

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

    @Override
    public Merchant getByIdRel(Long merchantId) {
        MerchantParam param = new MerchantParam();
        param.setMerchantId(merchantId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
