package com.kym.service.miniapp.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.kym.entity.miniapp.OrderRechargeRights;
import com.kym.entity.miniapp.UserRechargeRights;
import com.kym.entity.miniapp.vo.UserOrderRechargeRightsVo;
import com.kym.mapper.miniapp.UserRechargeRightsMapper;
import com.kym.service.miniapp.UserRechargeRightsService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户充值权益详情表 服务实现类
 * </p>
 *
 * @author skyline
 * @since 2023-10-18
 */
@Service
public class UserRechargeRightsServiceImpl extends MPJBaseServiceImpl<UserRechargeRightsMapper, UserRechargeRights> implements UserRechargeRightsService {


    /**
     * 通过订单号查询订单使用的权益卡信息
     *
     * @param startChargeSeq
     * @return
     */
    @Override
    public UserOrderRechargeRightsVo getUserOrderRechargeRights(String startChargeSeq) {
        var userId = StpUtil.getLoginIdAsLong();
        MPJLambdaWrapper<UserRechargeRights> wrapper = JoinWrappers.lambda(UserRechargeRights.class)
                .selectAsClass(UserRechargeRights.class, UserOrderRechargeRightsVo.class)
                .selectAs(OrderRechargeRights::getStartChargeSeq, UserOrderRechargeRightsVo::getStartChargeSeq)
                .selectAs(OrderRechargeRights::getDiscountAmount, UserOrderRechargeRightsVo::getOrderDiscountAmount)
                .rightJoin(OrderRechargeRights.class, on ->
                        on.eq(OrderRechargeRights::getRightsId, UserRechargeRights::getRightsId).eq(OrderRechargeRights::getUserId, UserRechargeRights::getUserId))
                .eq(OrderRechargeRights::getStartChargeSeq, startChargeSeq)
                .eq(UserRechargeRights::getUserId, userId);
        return  selectJoinOne(UserOrderRechargeRightsVo.class,wrapper);
    }

    @Override
    public List<UserRechargeRights> listStationAvailableRights(Map<String, ?> params) {
        return baseMapper.listStationAvailableRights(params);
    }


}
