/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.usky.meeting.repository;

import com.usky.meeting.domain.SysUser;
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 java.util.List;
import java.util.Map;
import java.util.Set;

/**
* @website https://el-admin.vip
* @author shiguangji
* @date 2021-03-09
**/
public interface DmUserRepository extends JpaRepository<SysUser, String>, JpaSpecificationExecutor<SysUser> {

//    /**
//     * 查询未绑定账户的用户
//     * @param userId
//     * @return
//     */
//    @Query(value = "SELECT u.* FROM dm_user u WHERE " +
//            "u.id not in (select dm_user_id from sys_user where dm_user_id is not null and if(:userId != '',user_id != :userId,1=1))",nativeQuery = true)
//    List<SysUser> findNotBindUser(@Param("userId") String userId);
//
//    /**
//     * 根据邮箱查询
//     * @param email 邮箱
//     * @return /
//     */
//    SysUser findByEmail(String email);
//
//    @Modifying
//    @Query(value = "update dm_user set email = ?2 where id = ?1",nativeQuery = true)
//    void updateEmail(String id, String email);
//
//    /**
//     * 根据联系方式查询
//     * @param contracts 联系方式
//     * @return /
//     */
//    SysUser findByContacts(String contracts);
//
//    /**
//     * 查询所有是审批者的用户id
//     * @param isApprover
//     * @return
//     */
//    @Query(value = "select id from DmUser where is_approver = :isApprover and if(:deptId != '',dept_id = :deptId,1=1)",nativeQuery = true)
//    List<Long> findIdsByIsApprover(@Param("isApprover")Boolean isApprover,@Param("deptId") String deptId);
//
//    /**
//     * 根据部门查询
//     * @param deptIds /
//     * @return /
//     */
//    @Query(value = "SELECT count(1) FROM dm_user u WHERE u.dept_id IN ?1", nativeQuery = true)
//    int countByDepts(Set<String> deptIds);
//
//    /**
//     * 根据角色查询
//     * @param ids /
//     * @return /
//     */
//    @Query(value = "SELECT count(1) FROM dm_user u, dm_users_roles r WHERE " +
//            "u.id = r.user_id AND r.role_id in ?1", nativeQuery = true)
//    int countByRoles(Set<Long> ids);
//
//    /**
//     * 根据岗位查询
//     * @param ids /
//     * @return /
//     */
//    @Query(value = "SELECT count(1) FROM dm_user u, dm_users_jobs j WHERE u.id = j.user_id AND j.job_id IN ?1", nativeQuery = true)
//    int countByJobs(Set<Long> ids);
//
//    /**
//     * 根据部门获取用户
//     * @param deptId
//     * @return
//     */
//    @Query(value = "SELECT id,name from dm_user where dept_id=:deptId",nativeQuery = true)
//    List<Map<String, Object>> getUserByDept(@Param("deptId") String deptId);
//
//    /**
//     * 查询所有用户
//     * @return /
//     */
//    @Query(value = "select du.id,du.name,du.dept_id as deptId,du.email,su.username,su.phone from dm_user as du left join sys_user as su on du.id = su.user_id where su.enabled=1",nativeQuery = true)
//    List<Map<String,String>> getAllDmUser();
//
//    /**
//     * 查询所有用户
//     * @return /
//     */
//    @Query(value = "select du.id,du.name,du.dept_id as deptId,du.email,su.username,su.phone from dm_user as du left join sys_user as su on du.id = su.user_id where su.enabled=1 and du.name like CONCAT('%',:userName,'%')",nativeQuery = true)
//    List<Map<String,String>> getAllDmUser(@Param("userName")String userName);
}