package com.fs.company.mapper;

import com.fs.company.domain.CompanyUser;
import com.fs.company.vo.CompanyUserVO;
import com.fs.company.vo.DocCompanyUserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 物业公司管理员信息Mapper接口
 *
 * @author fs
 * @date 2021-05-25
 */
public interface CompanyUserMapper
{
    /**
     * 查询物业公司管理员信息
     *
     * @param userId 物业公司管理员信息ID
     * @return 物业公司管理员信息
     */
    public CompanyUser selectCompanyUserById(Long userId);

    /**
     * 查询物业公司管理员信息列表
     *
     * @param companyUser 物业公司管理员信息
     * @return 物业公司管理员信息集合
     */
    public List<CompanyUser> selectCompanyUserList(CompanyUser companyUser);

    /**
     * 新增物业公司管理员信息
     *
     * @param companyUser 物业公司管理员信息
     * @return 结果
     */
    public int insertCompanyUser(CompanyUser companyUser);

    /**
     * 修改物业公司管理员信息
     *
     * @param companyUser 物业公司管理员信息
     * @return 结果
     */
    public int updateCompanyUser(CompanyUser companyUser);

    public int updateAllCompanyUser(CompanyUser companyUser);

    /**
     * 删除物业公司管理员信息
     *
     * @param userId 物业公司管理员信息ID
     * @return 结果
     */
    public int deleteCompanyUserById(Long userId);

    /**
     * 批量删除物业公司管理员信息
     *
     * @param userIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyUserByIds(Long[] userIds);

    int updateUserAvatar(@Param("userName")String username, @Param("avatar") String avatar);

    int resetUserPwd(@Param("userName")String userName,  @Param("password")String encryptPassword);


    CompanyUser selectUserByUserName(@Param("userName")String userName);
    @Select("select count(1) from company_user where user_name=#{userName}")
    int checkUserName(String userName);
    @Update("update company_user set password=#{password} where user_id=#{userId}")
    int resetUserPwdByUserId( @Param("userId")Long userId, @Param("password") String encryptPassword);

    List<CompanyUser> selectAllUsersList(CompanyUser user);

    List<CompanyUserVO> selectMyUserList(CompanyUser user);
    @Select("select u.* from company_user u where u.dept_id in ( SELECT dept_id FROM company_dept WHERE dept_id = #{maps.deptId} or find_in_set( #{maps.deptId} , ancestors ) ) ${maps.params.dataScope}")
    List<CompanyUser> getUserListByDeptId(@Param("maps") CompanyUser user);
    @Select("select count(1) from company_user  where company_id=#{companyId} and del_flag=0  ")
    Integer selectCompanyUserCountByCompanyId(Long companyId);
    @Select("select count(1) from company_user  where user_name=#{userName} and del_flag=0  ")
    Integer checkUserNameUnique(String userName);
    @Select("select u.*,d.dept_name from company_user u left join company_dept d on d.dept_id=u.dept_id  where u.user_id in (select )  ")
    List<DocCompanyUserVO> selectDocCompanyUserList(Long docId);
    @Select("select u.*,d.dept_name from company_user u left join company_dept d on d.dept_id=u.dept_id  where find_in_set(u.user_id,#{companyUserIds})  ")
    List<DocCompanyUserVO> selectDocCompanyUserListByIds(String companyUserIds);
    @Select("select u.* from company_user u   where u.company_id=#{companyId} and u.nick_name=#{nickName} limit 1 ")
    CompanyUser selectCompanyUserByCompanyIdAndNickName(@Param("companyId")long companyId,@Param("nickName") String nickName);

    List<CompanyUserVO> selecCompanyAllUsersList(CompanyUser map);

    @Select("select user_id from company_user where company_id=#{companyId} and user_type = '00'")
    Long selectCompanyAdminByCompanyId(Long companyId);

    @Select("select * from company_user where company_id=#{companyId} and user_type = '00'")
    CompanyUser selectCompanyUserAdminByCompanyId(Long companyId);
}
