<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.community.huiju.dao.TaUserMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TaUser" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="building_owner_info_id" property="buildingOwnerInfoId" jdbcType="INTEGER" />
    <result column="head_portrait" property="headPortrait" jdbcType="VARCHAR" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="login_name" property="loginName" jdbcType="VARCHAR" />
    <result column="login_password" property="loginPassword" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="gender" property="gender" jdbcType="CHAR" />
    <result column="status" property="status" jdbcType="CHAR" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />
    <result column="parent_id" property="parentId" jdbcType="INTEGER" />
    <result column="accept_agreement_status" property="acceptAgreementStatus" jdbcType="CHAR" />
    <result column="verify_status" property="verifyStatus" jdbcType="CHAR" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="INTEGER" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
    <result column="hk_person_no" property="hkPersonNo" jdbcType="BIGINT" />
    <result column="hk_user_id" property="hkUserId" jdbcType="INTEGER" />
    <result column="hk_card_no" property="hkCardNo" jdbcType="VARCHAR" />
    <result column="face_status" property="faceStatus" jdbcType="CHAR" />
    <result column="id_card" property="idCard" jdbcType="INTEGER"/>
    <result column="openid" property="openid" jdbcType="VARCHAR" />
    <result column="nickname" property="nickname" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, building_owner_info_id, head_portrait, user_name, login_name, login_password,
    email, gender, status, remark, parent_id, accept_agreement_status, verify_status,
    create_user, create_date, update_user, update_date, hk_person_no, hk_user_id, hk_card_no, face_status, id_card, openid, nickname
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from ta_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from ta_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TaUser" useGeneratedKeys="true" keyProperty="id" >
    insert into ta_user (id, community_id, building_owner_info_id,
      head_portrait, user_name, login_name,
      login_password, email, gender,
      status, remark, parent_id,
      accept_agreement_status, verify_status, create_user,
      create_date, update_user, update_date, hk_person_no,
      hk_user_id, hk_card_no, face_status, id_card, openid, nickname
      )
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{buildingOwnerInfoId,jdbcType=INTEGER},
      #{headPortrait,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{loginName,jdbcType=VARCHAR},
      #{loginPassword,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{gender,jdbcType=CHAR},
      #{status,jdbcType=CHAR}, #{remark,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER},
      #{acceptAgreementStatus,jdbcType=CHAR}, #{verifyStatus,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER},
      #{createDate,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=INTEGER}, #{updateDate,jdbcType=TIMESTAMP},
      #{hkPersonNo,jdbcType=BIGINT}, #{hkUserId,jdbcType=INTEGER}, #{hkCardNo,jdbcType=VARCHAR}, #{faceStatus,jdbcType=CHAR},
      #{idCard,jdbcType=VARCHAR}, #{openid,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
      )
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TaUser" useGeneratedKeys="true" keyProperty="id" >
    insert into ta_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="buildingOwnerInfoId != null" >
        building_owner_info_id,
      </if>
      <if test="headPortrait != null" >
        head_portrait,
      </if>
      <if test="userName != null" >
        user_name,
      </if>
      <if test="loginName != null" >
        login_name,
      </if>
      <if test="loginPassword != null" >
        login_password,
      </if>
      <if test="email != null" >
        email,
      </if>
      <if test="gender != null" >
        gender,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="remark != null" >
        remark,
      </if>
      <if test="parentId != null" >
        parent_id,
      </if>
      <if test="acceptAgreementStatus != null" >
        accept_agreement_status,
      </if>
      <if test="verifyStatus != null" >
        verify_status,
      </if>
      <if test="createUser != null" >
        create_user,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="updateUser != null" >
        update_user,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
      <if test="hkPersonNo != null" >
        hk_person_no,
      </if>
      <if test="hkUserId != null" >
        hk_user_id,
      </if>
      <if test="hkCardNo != null" >
        hk_card_no,
      </if>
      <if test="faceStatus != null" >
        face_status,
      </if>
      <if test="idCard != null">
        id_card,
      </if>
      <if test="openid != null" >
        openid,
      </if>
      <if test="nickname != null" >
        nickname,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="buildingOwnerInfoId != null" >
        #{buildingOwnerInfoId,jdbcType=INTEGER},
      </if>
      <if test="headPortrait != null" >
        #{headPortrait,jdbcType=VARCHAR},
      </if>
      <if test="userName != null" >
        #{userName,jdbcType=VARCHAR},
      </if>
      <if test="loginName != null" >
        #{loginName,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null" >
        #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="gender != null" >
        #{gender,jdbcType=CHAR},
      </if>
      <if test="status != null" >
        #{status,jdbcType=CHAR},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null" >
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="acceptAgreementStatus != null" >
        #{acceptAgreementStatus,jdbcType=CHAR},
      </if>
      <if test="verifyStatus != null" >
        #{verifyStatus,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="hkPersonNo != null" >
        #{hkPersonNo,jdbcType=BIGINT},
      </if>
      <if test="hkUserId != null" >
        #{hkUserId,jdbcType=INTEGER},
      </if>
      <if test="hkCardNo != null" >
        #{hkCardNo,jdbcType=VARCHAR},
      </if>
      <if test="faceStatus != null" >
        #{faceStatus,jdbcType=CHAR},
      </if>
      <if test="idCard != null">
        #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="openid != null" >
        #{openid,jdbcType=VARCHAR},
      </if>
      <if test="nickname != null" >
        #{nickname,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TaUser" >
    update ta_user
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="buildingOwnerInfoId != null" >
        building_owner_info_id = #{buildingOwnerInfoId,jdbcType=INTEGER},
      </if>
      <if test="headPortrait != null" >
        head_portrait = #{headPortrait,jdbcType=VARCHAR},
      </if>
      <if test="userName != null" >
        user_name = #{userName,jdbcType=VARCHAR},
      </if>
      <if test="loginName != null" >
        login_name = #{loginName,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null" >
        login_password = #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="gender != null" >
        gender = #{gender,jdbcType=CHAR},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=CHAR},
      </if>
      <if test="remark != null" >
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null" >
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="acceptAgreementStatus != null" >
        accept_agreement_status = #{acceptAgreementStatus,jdbcType=CHAR},
      </if>
      <if test="verifyStatus != null" >
        verify_status = #{verifyStatus,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        update_date = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="hkPersonNo != null" >
        hk_person_no = #{hkPersonNo,jdbcType=BIGINT},
      </if>
      <if test="hkUserId != null" >
        hk_user_id = #{hkUserId,jdbcType=INTEGER},
      </if>
      <if test="hkCardNo != null" >
        hk_card_no = #{hkCardNo,jdbcType=VARCHAR},
      </if>
      <if test="faceStatus != null" >
        face_status = #{faceStatus,jdbcType=CHAR},
      </if>
      <if test="idCard != null and idCard != ''">
        id_card = #{idCard,jdbcType=VARCHAR},
      </if>
      <if test="openid != null" >
        openid = #{openid,jdbcType=VARCHAR},
      </if>
      <if test="nickname != null" >
        nickname = #{nickname,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TaUser" >
    update ta_user
    set community_id = #{communityId,jdbcType=INTEGER},
      building_owner_info_id = #{buildingOwnerInfoId,jdbcType=INTEGER},
      head_portrait = #{headPortrait,jdbcType=VARCHAR},
      user_name = #{userName,jdbcType=VARCHAR},
      login_name = #{loginName,jdbcType=VARCHAR},
      login_password = #{loginPassword,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      gender = #{gender,jdbcType=CHAR},
      status = #{status,jdbcType=CHAR},
      remark = #{remark,jdbcType=VARCHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      accept_agreement_status = #{acceptAgreementStatus,jdbcType=CHAR},
      verify_status = #{verifyStatus,jdbcType=CHAR},
      create_user = #{createUser,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      update_date = #{updateDate,jdbcType=TIMESTAMP},
      hk_person_no = #{hkPersonNo,jdbcType=BIGINT},
      hk_user_id = #{hkUserId,jdbcType=INTEGER},
      hk_card_no = #{hkCardNo,jdbcType=VARCHAR},
      face_status = #{faceStatus,jdbcType=CHAR},
      id_card = #{idCard,jdbcType=VARCHAR},
      openid = #{openid,jdbcType=VARCHAR},
      nickname = #{nickname,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByLoginNameAndByLoginPassword" parameterType="map" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from ta_user
    where login_name=#{loginName,jdbcType=VARCHAR} and login_password = #{loginPassword,jdbcType=VARCHAR}
  </select>

  <select id="selectByLoginName" parameterType="map" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from ta_user
    where login_name=#{map.loginName,jdbcType=VARCHAR}
    <if test="map.communityId != null and map.communityId != ''">
      and community_id = #{map.communityId,jdbcType=INTEGER}
    </if>
  </select>

  <select id="updateLongName" parameterType="com.community.huiju.model.TaUser" resultMap="BaseResultMap">
    update ta_user
    set
    login_name = #{loginName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="selectHouseUserList" resultType="com.community.huiju.model.TaUser" >
    SELECT
    tu.id as id,
    tu.gender as gender,
    tu.user_name as userName,
    tu.login_name as loginName,
    tu.head_portrait as headPortrait,
    tu.face_status as faceStatus,
    tuv.verify_status as userVerifyStatus,
    tuv.id as userVerifyId,
    tsr.role_name as roleName,
    tf.face_img as faceImg
    FROM ta_user tu INNER JOIN ta_user_verify tuv ON tu.id = tuv.user_id
    INNER JOIN ta_sys_role tsr ON tuv.role_id = tsr.id
    LEFT JOIN ta_face tf ON tf.ta_user_verify_id = tuv.id
    WHERE
	tuv.community_id = #{communityId}
	AND tuv.phase_id = #{phaseId}
	AND tuv.building_id = #{buildingId}
	AND tuv.unit_id = #{unitId}
	AND tuv.`level_id` = #{levelId}
	AND tuv.room_no_id = #{roomNoId}
	AND tuv.user_id != #{userId}
	AND tuv.role_id != 1
  </select>

  <select id="selectTaFaceParentId" parameterType="java.lang.Integer" resultMap="BaseResultMap" >
    select
      <include refid="Base_Column_List" />
    from ta_user
    where 1=1
    <if test="otherUserId != null" >
     and id = #{otherUserId,jdbcType=INTEGER}
    </if>
    <if test="id != null" >
     and parent_id = #{id}
    </if>
    limit 1
  </select>

  <select id="getByLoginName" parameterType="java.lang.Integer" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from ta_user
    where community_id = #{communityId,jdbcType=INTEGER}
    <if test="phone != null" >
      and login_name = #{phone,jdbcType=INTEGER}
    </if>
  </select>
  <select id="getByLoginNameList" parameterType="string" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ta_user
    where
      and login_name = #{loginName,jdbcType=INTEGER}
  </select>

  <select id="getByOpenId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ta_user
    where openid = #{openid,jdbcType=INTEGER}
  </select>

</mapper>