package com.gxwebsoft.love.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.love.entity.UserPlanEquity;
import com.gxwebsoft.love.mapper.UserPlanEquityMapper;
import com.gxwebsoft.love.param.UserPlanEquityParam;
import com.gxwebsoft.love.service.UserPlanEquityService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员套餐管理表Service实现
 *
 * @author 科技小王子
 * @since 2023-06-23 11:34:03
 */
@Service
public class UserPlanEquityServiceImpl extends ServiceImpl<UserPlanEquityMapper, UserPlanEquity> implements UserPlanEquityService {

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

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

    @Override
    public UserPlanEquity getByIdRel(Integer planEquityId) {
        UserPlanEquityParam param = new UserPlanEquityParam();
        param.setPlanEquityId(planEquityId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
