package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.CouponMapper;
import com.gxwebsoft.shop.service.CouponService;
import com.gxwebsoft.shop.entity.Coupon;
import com.gxwebsoft.shop.param.CouponParam;
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 2022-11-28 18:26:05
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService {

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

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

    @Override
    public Coupon getByIdRel(Integer couponId) {
        CouponParam param = new CouponParam();
        param.setCouponId(couponId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
