package org.jeecg.modules.xcx.coupon.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hotelcouponlog.entity.HotelCouponLog;
import org.jeecg.modules.hotelcouponlog.service.IHotelCouponLogService;
import org.jeecg.modules.xcx.coupon.req.CouponPageReq;
import org.jeecg.modules.xcx.coupon.service.ICouponService;
import org.jeecgframework.codegenerate.a.a;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CouponServiceImpl implements ICouponService {

    @Resource
    private IHotelCouponLogService hotelCouponLogService;
    @Resource
    private ShiroRealm shiroRealm;

    @Override
    public Result<?> couponPage(CouponPageReq couponPageReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(couponPageReq.getToken());
        Page<HotelCouponLog> page = new Page<>(couponPageReq.getPageNo(), couponPageReq.getPageSize());
        Page<HotelCouponLog> hotelCouponLogPage = hotelCouponLogService.lambdaQuery()
                .eq(HotelCouponLog::getDelFlag, 0)
                .eq(HotelCouponLog::getStatus, 0)
                .eq(HotelCouponLog::getUserId, hanHaiMember.getId())
                .orderByDesc(HotelCouponLog::getCreateTime)
                .page(page);

        return Result.OK(hotelCouponLogPage);
    }
}
