package com.liangjian.dataplatform.member.dao.secondary;

import com.liangjian.dataplatform.member.entity.po.secondary.WeixinUserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @Author: 黄子奇
 * @Date: 2019/11/14
 */
public interface WeixinUserInfoRepository extends JpaRepository<WeixinUserInfo, String>, JpaSpecificationExecutor<WeixinUserInfo> {

    Optional<WeixinUserInfo> queryBySecretPhone(String secretPhone);

    Optional<WeixinUserInfo> queryByOpenid(String openid);

    @Deprecated
    @Transactional
    @Modifying
    @Query(value = "update mem_weixin_user_info0 set point = :point where id = :id", nativeQuery = true)
    int update1(@Param("id") String id, @Param("point") Integer point);

    @Deprecated
    @Transactional
    @Modifying
    @Query(value = "update mem_weixin_user_info1 set point = :point where id = :id", nativeQuery = true)
    int update2(@Param("id") String id, @Param("point") Integer point);

    @Deprecated
    @Transactional
    @Modifying
    @Query(value = "update mem_weixin_user_info2 set point = :point where id = :id", nativeQuery = true)
    int update3(@Param("id") String id, @Param("point") Integer point);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update mem_weixin_user_info set point = :point,version =version+1 where id = :id and version=:version", nativeQuery = true)
    int updateWeiUser(@Param("point") Integer point,@Param("id") String id,@Param("version") Long version);

}
