<?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.th.demo.mapping.system.SysUserMapper">
  <resultMap id="BaseResultMap" type="com.th.demo.model.system.SysUser">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="USER_NAME" jdbcType="VARCHAR" property="userName" />
    <result column="PASSWORD" jdbcType="VARCHAR" property="password" />
    <result column="USER_DESC" jdbcType="VARCHAR" property="userDesc" />
    <result column="IS_USED" jdbcType="DECIMAL" property="isUsed" />
    <result column="REMARK" jdbcType="VARCHAR" property="remark" />
    <result column="ADD_ID" jdbcType="VARCHAR" property="addId" />
    <result column="ADD_TIME" jdbcType="TIMESTAMP" property="addTime" />
    <result column="MODIFY_ID" jdbcType="VARCHAR" property="modifyId" />
    <result column="MODIFY_TIME" jdbcType="TIMESTAMP" property="modifyTime" />
    <result column="CANCEL_ID" jdbcType="VARCHAR" property="cancelId" />
    <result column="CANCEL_TIME" jdbcType="TIMESTAMP" property="cancelTime" />
    <result column="CANCEL_FLAG" jdbcType="VARCHAR" property="cancelFlag" />
    <result column="ATTR1" jdbcType="VARCHAR" property="attr1" />
    <result column="ATTR2" jdbcType="VARCHAR" property="attr2" />
    <result column="ATTR3" jdbcType="VARCHAR" property="attr3" />
    <result column="ATTR4" jdbcType="VARCHAR" property="attr4" />
    <result column="ATTR5" jdbcType="DECIMAL" property="attr5" />
    <result column="ATTR6" jdbcType="DECIMAL" property="attr6" />
    <result column="ID_CARD" jdbcType="VARCHAR" property="idCard" />
    <result column="PHONE" jdbcType="VARCHAR" property="phone" />
    <result column="MOBILE" jdbcType="VARCHAR" property="mobile" />
    <result column="USER_CODE" jdbcType="VARCHAR" property="userCode" />
    <result column="BELONG_ID" jdbcType="VARCHAR" property="belongId" />
  </resultMap>
  <sql id="Base_Column_List">
    ID, USER_NAME, PASSWORD, USER_DESC, IS_USED, REMARK, ADD_ID, ADD_TIME, MODIFY_ID, 
    MODIFY_TIME, CANCEL_ID, CANCEL_TIME, CANCEL_FLAG, ATTR1, ATTR2, ATTR3, ATTR4, ATTR5, 
    ATTR6,ID_CARD,PHONE,MOBILE,USER_CODE,BELONG_ID
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from sys_user
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from sys_user
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.system.SysUser">

    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.String">
      SELECT  REPLACE(UUID(),'-','') as id from dual
    </selectKey>
    insert into sys_user (ID, USER_NAME, PASSWORD,
      USER_DESC, IS_USED, REMARK, 
      ADD_ID, ADD_TIME, MODIFY_ID, 
      MODIFY_TIME, CANCEL_ID, CANCEL_TIME, 
      CANCEL_FLAG, ATTR1, ATTR2, 
      ATTR3, ATTR4, ATTR5, 
      ATTR6,ID_CARD,PHONE,MOBILE,USER_CODE,BELONG_ID)
    values (#{id,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
      #{userDesc,jdbcType=VARCHAR}, #{isUsed,jdbcType=DECIMAL}, #{remark,jdbcType=VARCHAR}, 
      #{addId,jdbcType=VARCHAR}, #{addTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=VARCHAR},
      #{modifyTime,jdbcType=TIMESTAMP}, #{cancelId,jdbcType=VARCHAR}, #{cancelTime,jdbcType=TIMESTAMP},
      #{cancelFlag,jdbcType=VARCHAR}, #{attr1,jdbcType=VARCHAR}, #{attr2,jdbcType=VARCHAR}, 
      #{attr3,jdbcType=VARCHAR}, #{attr4,jdbcType=VARCHAR}, #{attr5,jdbcType=DECIMAL},
      #{attr6,jdbcType=DECIMAL}, #{idCard,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{userCode,jdbcType=VARCHAR},
    #{belongId,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.system.SysUser">
    insert into sys_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="userName != null">
        USER_NAME,
      </if>
      <if test="password != null">
        PASSWORD,
      </if>
      <if test="userDesc != null">
        USER_DESC,
      </if>
      <if test="isUsed != null">
        IS_USED,
      </if>
      <if test="remark != null">
        REMARK,
      </if>
      <if test="addId != null">
        ADD_ID,
      </if>
      <if test="addTime != null">
        ADD_TIME,
      </if>
      <if test="modifyId != null">
        MODIFY_ID,
      </if>
      <if test="modifyTime != null">
        MODIFY_TIME,
      </if>
      <if test="cancelId != null">
        CANCEL_ID,
      </if>
      <if test="cancelTime != null">
        CANCEL_TIME,
      </if>
      <if test="cancelFlag != null">
        CANCEL_FLAG,
      </if>
      <if test="attr1 != null">
        ATTR1,
      </if>
      <if test="attr2 != null">
        ATTR2,
      </if>
      <if test="attr3 != null">
        ATTR3,
      </if>
      <if test="attr4 != null">
        ATTR4,
      </if>
      <if test="attr5 != null">
        ATTR5,
      </if>
      <if test="attr6 != null">
        ATTR6,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="userName != null">
        #{userName,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="userDesc != null">
        #{userDesc,jdbcType=VARCHAR},
      </if>
      <if test="isUsed != null">
        #{isUsed,jdbcType=DECIMAL},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="addId != null">
        #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null">
        #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null">
        #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null">
        #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null">
        #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null">
        #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="attr1 != null">
        #{attr1,jdbcType=VARCHAR},
      </if>
      <if test="attr2 != null">
        #{attr2,jdbcType=VARCHAR},
      </if>
      <if test="attr3 != null">
        #{attr3,jdbcType=VARCHAR},
      </if>
      <if test="attr4 != null">
        #{attr4,jdbcType=VARCHAR},
      </if>
      <if test="attr5 != null">
        #{attr5,jdbcType=DECIMAL},
      </if>
      <if test="attr6 != null">
        #{attr6,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.th.demo.model.system.SysUser">
    update SYS_USER
    <set>
      <if test="userName != null">
        USER_NAME = #{userName,jdbcType=VARCHAR},
      </if>
      <if test="password != null">
        PASSWORD = #{password,jdbcType=VARCHAR},
      </if>
      <if test="userDesc != null">
        USER_DESC = #{userDesc,jdbcType=VARCHAR},
      </if>
      <if test="isUsed != null">
        IS_USED = #{isUsed,jdbcType=DECIMAL},
      </if>
      <if test="remark != null">
        REMARK = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="addId != null">
        ADD_ID = #{addId,jdbcType=VARCHAR},
      </if>
      <if test="addTime != null">
        ADD_TIME = #{addTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyId != null">
        MODIFY_ID = #{modifyId,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelId != null">
        CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      </if>
      <if test="cancelTime != null">
        CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      </if>
      <if test="cancelFlag != null">
        CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR},
      </if>
      <if test="attr1 != null">
        ATTR1 = #{attr1,jdbcType=VARCHAR},
      </if>
      <if test="attr2 != null">
        ATTR2 = #{attr2,jdbcType=VARCHAR},
      </if>
      <if test="attr3 != null">
        ATTR3 = #{attr3,jdbcType=VARCHAR},
      </if>
      <if test="attr4 != null">
        ATTR4 = #{attr4,jdbcType=VARCHAR},
      </if>
      <if test="attr5 != null">
        ATTR5 = #{attr5,jdbcType=DECIMAL},
      </if>
      <if test="attr6 != null">
        ATTR6 = #{attr6,jdbcType=DECIMAL},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.th.demo.model.system.SysUser">
    update sys_user
    set USER_NAME = #{userName,jdbcType=VARCHAR},
      PASSWORD = #{password,jdbcType=VARCHAR},
      USER_DESC = #{userDesc,jdbcType=VARCHAR},
      IS_USED = #{isUsed,jdbcType=DECIMAL},
      REMARK = #{remark,jdbcType=VARCHAR},
      ADD_ID = #{addId,jdbcType=VARCHAR},
      ADD_TIME = #{addTime,jdbcType=TIMESTAMP},
      MODIFY_ID = #{modifyId,jdbcType=VARCHAR},
      MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP},
      CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR},
      ATTR1 = #{attr1,jdbcType=VARCHAR},
      ATTR2 = #{attr2,jdbcType=VARCHAR},
      ATTR3 = #{attr3,jdbcType=VARCHAR},
      ATTR4 = #{attr4,jdbcType=VARCHAR},
      ATTR5 = #{attr5,jdbcType=DECIMAL},
      ATTR6 = #{attr6,jdbcType=DECIMAL},
      ID_CARD = #{idCard,jdbcType=VARCHAR},
      PHONE = #{phone,jdbcType=VARCHAR},
      MOBILE = #{mobile,jdbcType=VARCHAR},
      USER_CODE = #{userCode,jdbcType=VARCHAR},
      BELONG_ID =  #{belongId,jdbcType=VARCHAR}
        where ID = #{id,jdbcType=VARCHAR}
  </update>


  <select id="selectAll" resultMap="BaseResultMap" parameterType="java.lang.Integer">
    select *
    from sys_user where CANCEL_FLAG != '9'

  </select>

  <select id="selectUser" resultMap="BaseResultMap">
    select *
    from sys_user where CANCEL_FLAG != '9'
    and user_name like  '%'||#{param1,jdbcType=VARCHAR}||'%'
    and user_desc like  '%'||#{param2,jdbcType=VARCHAR}||'%'
  </select>



  <select id="selectUserByLogin" resultMap="BaseResultMap">
    select * from sys_user where  user_name = #{param1,jdbcType=VARCHAR} and cancel_flag = '0'
  </select>

  <select id="select" resultMap="BaseResultMap">
        select a.*,b.name as attr3
    from sys_user a left join t_maint_customer  b on a.attr3 = b.id where ifnull(a.CANCEL_FLAG,'0') != '9'
    and a.user_desc like  concat ('%',#{param1,jdbcType=VARCHAR},'%')
    and a.belong_id = #{param2,jdbcType=VARCHAR}
  </select>


  <select id="selectByAdmin" resultMap="BaseResultMap">
        select *
    from sys_user where ifnull(CANCEL_FLAG,'0') != '9'
    and belong_id = id    and user_desc like  concat ('%',#{param1,jdbcType=VARCHAR},'%')
  </select>

  <select id="selectByDeptPost" resultMap="BaseResultMap">
    select *
    from sys_user where CANCEL_FLAG != '9'
    and id in (select user_id from sys_userdeptpost where
    dept_id in
    <foreach item="item" index="index" collection="deptId"
             open="(" separator="," close=")">
      #{item}
    </foreach>and post_id in
    <foreach item="item" index="index" collection="postId"
             open="(" separator="," close=")">
      #{item}
    </foreach>
    )
  </select>
  <select id="selectPassWord" resultMap="BaseResultMap">
    select
    *
    from sys_user
    where ID = #{id,jdbcType=VARCHAR}
  </select>


  <select id="selectByDept" resultMap="BaseResultMap">
   select * from sys_user t,sys_user_deptpost d where t.id = d.user_id  and  d.dept_id = #{param1,jdbcType=VARCHAR}
  </select>


  <select id="selectByUserName" resultMap="BaseResultMap">
   select * from sys_user t where t.USER_NAME = #{param1,jdbcType=VARCHAR} and cancel_flag = '0'
  </select>

  <select id="selectListByUserName" resultMap="BaseResultMap">
    select * from sys_user t where t.USER_NAME = #{param1,jdbcType=VARCHAR} and cancel_flag = '0'
  </select>

</mapper>