package com.hfkj.dao;

import com.hfkj.entity.SecUser;
import com.hfkj.model.SecUserModel;
import com.hfkj.sysenum.SecUserTypeEnum;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * mapper扩展类
 */
public interface SecUserMapperExt {


    @Select({
            "<script>",
            "select su.*,bo.name as organization_name from sec_user su left join bs_organization bo on su.organization_id = bo.id",
            "where su.company_id = #{companyId} and su.status = 1",
            "<if test=\"organizationId != null and organizationId != ''\">",
            "and su.organization_id = #{organizationId}",
            "</if>",
            "<if test=\"userName != null and userName != ''\">",
            "and su.user_name like '%${userName}%'",
            "</if>",
            "<if test=\"phone != null and phone != ''\">,",
            "and su.telephone like '%${phone}%'",
            "</if>",
            "order by su.create_time desc",
            "</script>"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
            @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
            @Result(column="admin_flag", property="adminFlag", jdbcType=JdbcType.INTEGER),
            @Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT),
            @Result(column="organization_id", property="organizationId", jdbcType=JdbcType.BIGINT),
            @Result(column="object_type", property="objectType", jdbcType=JdbcType.INTEGER),
            @Result(column="object_id", property="objectId", jdbcType=JdbcType.BIGINT),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="organization_name", property="organizationName", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<SecUserModel> findPage(@Param("companyId") Long companyId, @Param("organizationId") Long organizationId, @Param("userName") String userName, @Param("phone") String phone);

    @Select({
            "<script>" +
            " SELECT * FROM sec_user WHERE login_name = #{loginName} AND `password` = #{password} AND status = 1 " +
            "</script>"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
            @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR),
            @Result(column="admin_flag", property="adminFlag", jdbcType=JdbcType.INTEGER),
            @Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT),
            @Result(column="organization_id", property="organizationId", jdbcType=JdbcType.BIGINT),
            @Result(column="object_type", property="objectType", jdbcType=JdbcType.INTEGER),
            @Result(column="object_id", property="objectId", jdbcType=JdbcType.BIGINT),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="organization_name", property="organizationName", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    SecUser login(@Param("loginName") String loginName,@Param("password") String password);
}
