package com.gxwebsoft.love.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.love.mapper.UserPlanPriceMapper;
import com.gxwebsoft.love.service.UserPlanPriceService;
import com.gxwebsoft.love.entity.UserPlanPrice;
import com.gxwebsoft.love.param.UserPlanPriceParam;
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-06-20 18:07:50
 */
@Service
public class UserPlanPriceServiceImpl extends ServiceImpl<UserPlanPriceMapper, UserPlanPrice> implements UserPlanPriceService {

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

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

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

}
