package com.crm.custom.dao.repository;

import com.crm.rely.backend.dao.repository.BaseRepository;
import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.List;

/**
 * @program: crm-backend
 * @description:
 * @author: houn
 * @create: 2019-07-25 16:25
 */
@Repository
public interface CustomInfoRepository extends BaseRepository<CustomInfoTable> {

    /**
     * 邮箱密码查询用户
     *
     * @param email
     * @param password
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstByEmailAndPassword(String email, String password);

    /**
     * id密码查询用户
     *
     * @param id
     * @param password
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstByIdAndPassword(Long id, String password);

    /**
     * 根据id查询用户信息
     *
     * @param id
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstById(Long id);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstByCId(Long cId);

    /**
     * 根据手机号码获取账户
     *
     * @param phone
     * @return
     */
    CustomInfoTable getFirstByPhoneNotNullAndPhone(String phone);

    /**
     * 根据手机号码获取账户
     *
     * @param phone
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstByPhoneNotNullAndPhone(String phone);

    /**
     * 根据邮箱获取账号
     *
     * @param email
     * @return
     */
    CustomInfoTable getFirstByEmailNotNullAndEmail(String email);

    /**
     * 根据邮箱获取账号
     *
     * @param email
     * @return
     */
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomInfoTable findFirstByEmailNotNullAndEmail(String email);

    List<CustomInfoTable> findAllByAgentId(Long agentId);

    CustomInfoTable getFirstById(Long id);

    /**
     * 查询邮箱是否已存在
     *
     * @param email
     * @return
     */
    boolean existsByEmail(String email);

    /**
     * 查询手机号码是否已存在
     *
     * @param phone
     * @return
     */
    boolean existsByPhone(String phone);

    boolean existsByIdentity(String identity);
    CustomInfoTable getFirstBySno(String sno);
}
