package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.MerchantGoodsPackageMapper;
import com.gxwebsoft.shop.service.MerchantGoodsPackageService;
import com.gxwebsoft.shop.entity.MerchantGoodsPackage;
import com.gxwebsoft.shop.param.MerchantGoodsPackageParam;
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 MerchantGoodsPackageServiceImpl extends ServiceImpl<MerchantGoodsPackageMapper, MerchantGoodsPackage> implements MerchantGoodsPackageService {

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

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

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

}
