package com.crm.ucard.dao.repository;

import com.crm.rely.backend.core.pojo.table.UserInfoTable;
import com.crm.rely.backend.dao.repository.BaseRepository;
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 UserInfoRepository extends BaseRepository<UserInfoTable> {

    /**
     * 用户名密码查询用户
     *
     * @param username
     * @param password
     * @return
     */
    UserInfoTable findFirstByUsernameAndPassword(String username, String password);
    UserInfoTable getFirstByUsername(String username);

    UserInfoTable getFirstByEmailNotNullAndEmail(String email);

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

    /**
     * 查询用户名是否已存在
     *
     * @param username
     * @return
     */
    boolean existsByUsername(String username);

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

    UserInfoTable getFirstByCId(Long cId);

    UserInfoTable getFirstById(Long id);

    List<UserInfoTable> findAllByPid(Long pid);

    Integer countByPid(Long pid);
}
