<?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.SysUserDeptPostMapper" >
  <resultMap id="BaseResultMap" type="com.th.demo.model.system.SysUserDeptPost" >
    <id column="ID" property="id" jdbcType="VARCHAR" />
    <result column="DEPT_ID" property="deptId" jdbcType="VARCHAR" />
    <result column="POST_ID" property="postId" jdbcType="VARCHAR" />
    <result column="USER_ID" property="userId" jdbcType="VARCHAR" />
    <result column="ADD_ID" property="addId" jdbcType="VARCHAR" />
    <result column="ADD_TIME" property="addTime" jdbcType="TIMESTAMP" />
    <result column="MODIFY_ID" property="modifyId" jdbcType="VARCHAR" />
    <result column="MODIFY_TIME" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_ID" property="cancelId" jdbcType="VARCHAR" />
    <result column="CANCEL_TIME" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_FLAG" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="ATTR1" property="attr1" jdbcType="VARCHAR" />
    <result column="ATTR2" property="attr2" jdbcType="VARCHAR" />
    <result column="ATTR3" property="attr3" jdbcType="VARCHAR" />
    <result column="ATTR4" property="attr4" jdbcType="DECIMAL" />
    <result column="ATTR5" property="attr5" jdbcType="DECIMAL" />
    <result column="ATTR6" property="attr6" jdbcType="DECIMAL" />
  </resultMap>

   <resultMap id="udpShowMap" type="com.th.demo.model.system.SysUserDeptPostShow">
    <id column="ID" property="id" jdbcType="VARCHAR" />
    <result column="DEPT_ID" property="deptId" jdbcType="VARCHAR" />
	<result column="dept_name" property="deptName" jdbcType="VARCHAR"/>
    <result column="POST_ID" property="postId" jdbcType="VARCHAR" />
	<result column="post_name" property="postName" jdbcType="VARCHAR"/>
    <result column="USER_ID" property="userId" jdbcType="VARCHAR" />
	<result column="user_name" property="userName" jdbcType="VARCHAR"/>
    <result column="ADD_ID" property="addId" jdbcType="VARCHAR" />
    <result column="ADD_TIME" property="addTime" jdbcType="TIMESTAMP" />
    <result column="MODIFY_ID" property="modifyId" jdbcType="VARCHAR" />
    <result column="MODIFY_TIME" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_ID" property="cancelId" jdbcType="VARCHAR" />
    <result column="CANCEL_TIME" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="CANCEL_FLAG" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="ATTR1" property="attr1" jdbcType="VARCHAR" />
    <result column="ATTR2" property="attr2" jdbcType="VARCHAR" />
    <result column="ATTR3" property="attr3" jdbcType="VARCHAR" />
    <result column="ATTR4" property="attr4" jdbcType="DECIMAL" />
    <result column="ATTR5" property="attr5" jdbcType="DECIMAL" />
    <result column="ATTR6" property="attr6" jdbcType="DECIMAL" />
  </resultMap>
  <sql id="Base_Column_List" >
    ID, DEPT_ID, POST_ID, USER_ID, ADD_ID, ADD_TIME, MODIFY_ID, MODIFY_TIME, CANCEL_ID,
    CANCEL_TIME, CANCEL_FLAG, ATTR1, ATTR2, ATTR3, ATTR4, ATTR5, ATTR6
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from SYS_USER_DEPTPOST
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from SYS_USER_DEPTPOST
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.th.demo.model.system.SysUserDeptPost" >
    insert into SYS_USER_DEPTPOST (ID, DEPT_ID, POST_ID, 
      USER_ID, ADD_ID, ADD_TIME, 
      MODIFY_ID, MODIFY_TIME, CANCEL_ID,
      CANCEL_TIME, CANCEL_FLAG, ATTR1, 
      ATTR2, ATTR3, ATTR4, 
      ATTR5, ATTR6)
    values (REPLACE(UUID(),'-',''), #{deptId,jdbcType=VARCHAR}, #{postId,jdbcType=VARCHAR},
      #{userId,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=DECIMAL}, 
      #{attr5,jdbcType=DECIMAL}, #{attr6,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.th.demo.model.system.SysUserDeptPost" >
    insert into SYS_USER_DEPTPOST
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        ID,
      </if>
      <if test="deptId != null" >
        DEPT_ID,
      </if>
      <if test="postId != null" >
        POST_ID,
      </if>
      <if test="userId != null" >
        USER_ID,
      </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="deptId != null" >
        #{deptId,jdbcType=VARCHAR},
      </if>
      <if test="postId != null" >
        #{postId,jdbcType=VARCHAR},
      </if>
      <if test="userId != null" >
        #{userId,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=DECIMAL},
      </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.SysUserDeptPost" >
    update SYS_USER_DEPTPOST
    <set >
      <if test="deptId != null" >
        DEPT_ID = #{deptId,jdbcType=VARCHAR},
      </if>
      <if test="postId != null" >
        POST_ID = #{postId,jdbcType=VARCHAR},
      </if>
      <if test="userId != null" >
        USER_ID = #{userId,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=DECIMAL},
      </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.SysUserDeptPost" >
    update SYS_USER_DEPTPOST
    set DEPT_ID = #{deptId,jdbcType=VARCHAR},
      POST_ID = #{postId,jdbcType=VARCHAR},
      USER_ID = #{userId,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=DECIMAL},
      ATTR5 = #{attr5,jdbcType=DECIMAL},
      ATTR6 = #{attr6,jdbcType=DECIMAL}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
   <select id="select" resultMap="udpShowMap">
    select
    t.*,d.dept_name,a.post_name,b.user_desc as user_name
    from SYS_USER_DEPTPOST t LEFT JOIN sys_department d on t.dept_id = d.id
    LEFT JOIN sys_post a on t.post_id = a.id
    LEFT JOIN sys_user b on t.user_id = b.id
    where t.user_id = #{param1,jdbcType=VARCHAR}
    and t.cancel_flag!='9'
  </select>


  <select id="selectPageTotal" resultMap="udpShowMap">
    select
    count(*)
    from SYS_USER_DEPTPOST t LEFT JOIN sys_department d on t.dept_id = d.id
    LEFT JOIN sys_post a on t.post_id = a.id
    LEFT JOIN sys_user b on t.user_id = b.id
    where t.user_id = #{param1,jdbcType=VARCHAR}
  </select>



  <select id="selectByUserId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from SYS_USER_DEPTPOST
    where user_id = #{param1,jdbcType=VARCHAR}
  </select>

  <update id="deleteByUpdate9">
    update SYS_USER_DEPTPOST
    set  CANCEL_ID = #{cancelId,jdbcType=VARCHAR},
      CANCEL_TIME = #{cancelTime,jdbcType=TIMESTAMP},
      CANCEL_FLAG = #{cancelFlag,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
</mapper>