package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.RechargePlanMapper;
import com.gxwebsoft.shop.service.RechargePlanService;
import com.gxwebsoft.shop.entity.RechargePlan;
import com.gxwebsoft.shop.param.RechargePlanParam;
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 2023-04-20 20:36:24
 */
@Service
public class RechargePlanServiceImpl extends ServiceImpl<RechargePlanMapper, RechargePlan> implements RechargePlanService {

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

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

    @Override
    public RechargePlan getByIdRel(Integer planId) {
        RechargePlanParam param = new RechargePlanParam();
        param.setPlanId(planId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
