<?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.xintong.visualinspection.dao.cluster.UserInfoDao" >
    <resultMap id="BaseResultMap" type="com.xintong.visualinspection.bean.User" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="username" property="username" jdbcType="VARCHAR" />
        <result column="password" property="password" jdbcType="VARCHAR" />
    </resultMap>
    <resultMap id="userMap" type="com.xintong.visualinspection.bean.User">
        <id property="id" column="ID"/>
        <result property="username" column="username"/>
        <result property="password" column="PASSWORD"/>
        <collection property="roles" ofType="com.xintong.visualinspection.bean.Role">
            <result column="name" property="name"/>
        </collection>
    </resultMap>

    <select id="getAll" resultMap="BaseResultMap"  >
        SELECT
        id,username,password
        FROM t_sys_users
    </select>

    <select id="getOne" parameterType="java.lang.Integer" resultMap="BaseResultMap" >
        SELECT
        id,username,age,password
        FROM t_sys_users
        WHERE id = #{id}
    </select>

    <insert id="insert" parameterType="com.xintong.visualinspection.bean.User" >
        INSERT INTO
        t_sys_users
        (username,password,TRUENAME,ORGANID,BIRTH,AGE,MOBILE,POSITIONID,SEX,WORKNO,IDNO)
        VALUES
        (#{username},#{password},#{truename},#{organid},#{birth},#{age},#{mobile},#{positionid},#{sex},#{workno},#{idno})
    </insert>

    <update id="update" parameterType="com.xintong.visualinspection.bean.User" >
        UPDATE
        t_sys_users
        SET
        <if test="username != null">username = #{username},</if>
        <if test="age != null">age = #{age},</if>
        <if test="password != null">password = #{password},</if>
        id = #{id}
        WHERE
        id = #{id}
    </update>

	<update id="delete" parameterType="com.xintong.visualinspection.bean.User" >
        UPDATE
        	t_sys_users
        SET
        	status = -1
        WHERE
        	id = #{id}
    </update>


    <select id="findByUserName" parameterType="String" resultMap="userMap">
        select u.*
        from t_sys_users u
        where username= #{username}
    </select>
    
    
    <select id="getUsers" parameterType="com.xintong.visualinspection.bean.User" resultMap="BaseResultMap"  >
        SELECT
        id,username,password
        FROM t_sys_users
        where 1=1
        <if test="organid != null and organid != 0">and organid = #{organid} </if>
        <if test="positionid != null and positionid != 0">and positionid = #{positionid} </if>
        <if test="classid != null and classid != 0">and classid = #{classid} </if>
        <if test="teamid != null and teamid != 0">and teamid = #{teamid} </if>
        
    </select>
</mapper>