/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lightinit.hsdatagateway.modules.gateway.service;

import java.util.List;

import com.lightinit.hsdatagateway.common.config.Global;
import com.lightinit.hsdatagateway.common.utils.CacheUtils;
import com.google.common.base.Strings;
import com.lightinit.hsdatagateway.common.persistence.Page;
import com.lightinit.hsdatagateway.common.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lightinit.hsdatagateway.common.persistence.Page;
import com.lightinit.hsdatagateway.common.service.CrudService;
import com.lightinit.hsdatagateway.modules.gateway.entity.Auth;
import com.lightinit.hsdatagateway.modules.gateway.dao.AuthDao;

import javax.annotation.PostConstruct;

/**
 * 鉴权管理Service
 * @Author: yangrui
 * @version 2019-03-05
 */
@Service
@Transactional(readOnly = true)
public class AuthService extends CrudService<AuthDao, Auth> {

	public Auth getByUserAndAppId(String appId, String userId, String routeId){
		Auth auth = new Auth();
		auth.setAppId(appId);
		auth.setUserId(userId);
		auth.setRouteId(routeId);
		return dao.getByUserIdAndAppId(auth);
	}

	public Auth get(Long id) {
		return super.get(id);
	}
	
	public List<Auth> findList(Auth auth) {
		return super.findList(auth);
	}
	
	public Page<Auth> findPage(Page<Auth> page, Auth auth) {
		page.setOrderBy("created_at desc");
		return super.findPage(page, auth);
	}
	
	@Transactional(readOnly = false)
	public void save(Auth auth) {
		super.save(auth);
	}
	
	@Transactional(readOnly = false)
	public void delete(Auth auth) {
		super.delete(auth);
	}

	/**
	 * 判断是否可以添加修改
	 * @param auth
	 * @return
	 */
	public boolean isRepetition(Auth auth) {
		return super.isRepetition(auth);
	}

	/**
	 * api调用查询
	 * @param auth
	 * @return
	 */
	public List<Auth> findListByApi(Auth auth) {
		return dao.findListByApi(auth);
	}

	/**
	 * 根据用户、路由、应用Id修改
	 * @param auth
	 */
	@Transactional(readOnly = false)
	public int updateByApi(Auth auth) {
		return dao.updateByApi(auth);
	}
}