package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.MerchantChargePackageMapper;
import com.gxwebsoft.shop.service.MerchantChargePackageService;
import com.gxwebsoft.shop.entity.MerchantChargePackage;
import com.gxwebsoft.shop.param.MerchantChargePackageParam;
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 2024-11-20 01:55:04
 */
@Service
public class MerchantChargePackageServiceImpl extends ServiceImpl<MerchantChargePackageMapper, MerchantChargePackage> implements MerchantChargePackageService {

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

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

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

}
