package com.diagbot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.diagbot.entity.ServiceToken;
import com.diagbot.entity.ServiceTokenWithUser;
import com.diagbot.entity.wrapper.ServiceTokenWrapper;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.mapper.ServiceTokenMapper;
import com.diagbot.service.ServiceTokenService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 服务令牌表 服务实现类
 * </p>
 *
 * @author zhaops
 * @since 2018-09-17
 */
@Service
public class ServiceTokenServiceImpl extends ServiceImpl<ServiceTokenMapper, ServiceToken> implements ServiceTokenService {
    /**
     * 更新令牌
     *
     * @param entity
     * @param updateWrapper
     * @return
     */
    public Integer updateRecord(ServiceToken entity, UpdateWrapper<ServiceToken> updateWrapper) {
        updateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        return this.baseMapper.update(entity, updateWrapper);
    }

    /**
     * 查找令牌（单记录）
     *
     * @param queryWrapper
     * @return
     */
    public ServiceToken selectOneRecord(QueryWrapper<ServiceToken> queryWrapper) {
        queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<ServiceTokenWithUser> getByAppkeyAndSecret(Map map) {
        return baseMapper.getByAppkeyAndSecret(map);
    }

    @Override
    public List<ServiceTokenWrapper> getByAppkeyAndSecretAndProductId(Map map) {
        return baseMapper.getByAppkeyAndSecretAndProduct(map);
    }


    /**
     * 根据userId和productId获取试用商品的数量
     * @param map
     * @return
     */
    @Override
    public Integer getTryTokenCount(Map map){
        return baseMapper.getTryTokenCount(map);
    }

    /**
     * 根据userId和productId获取试用商品token
     */
	@Override
	public ServiceToken getTryTokenByUserIdAndProductId(Map map) {
		// TODO Auto-generated method stub
		return baseMapper.getTryTokenByUserIdAndProductId(map);
	}
    
    

}
