package com.ssj.dao.weixin.user.dao;

import com.ssj.bean.weixin.user.domain.UserAccount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/** 
 * @author  ZhangCaibao 
 * @version 2018年2月2日 下午4:12:29 
 * 类说明 
 */
@Repository
public interface UserAccountDao extends JpaRepository<UserAccount, String> {

	@Query(nativeQuery = true, value = "select *  from tb_user_account  where openid =?1 LIMIT 1 ")
	UserAccount findUserAccountByOpenid(String openid);
	
	@Query(nativeQuery = true, value = "select *  from tb_user_account  where user_id =?1  ")
	List<UserAccount> findUserAccountByUserId(String userId);
	
	 @Query(nativeQuery = true, value = "update tb_user_account set unionid = ?2   where openid = ?1 ")
	 @Modifying
	public void updateByOpenId(String openid,String unionid);
	 
	@Query(nativeQuery = true, value = "update tb_user_account set user_id = ?2 where user_id = ?1 ")
	@Modifying
	public void updateByUserId(String wxUserId,String mobileUserId);
	
	public UserAccount findByUserIdAndType(String userId,int type);
	
	 @Query(nativeQuery = true, value = "update tb_user_account set user_id = ?2   where unionid = ?1 ")
	 @Modifying
	 public void updateUserIdByUnionId(String unionid,String userId);

	 @Query(nativeQuery = true,value = "update tb_user_account set appid=null,openid=null where user_id=?1")
	 @Modifying
	 public void updateOpenIdAndAppIdByUserId(String userId);

	 @Query(nativeQuery = true,value = "select * tb_user_account where user_id=?1")
	 public List<UserAccount> findByUserId(String userId);

	 @Modifying
	 @Query(nativeQuery = true,value = "delete from tb_user_account where user_id=?1")
	 public void deleteByUserId(String userId);
}
