<?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.ssm.mapper.system.SysPositionMapper" >
  <resultMap id="BaseResultMap" type="com.ssm.model.system.SysPosition" >
    <id column="PositionID" property="positionid" jdbcType="INTEGER" />
    <result column="PositionCode" property="positioncode" jdbcType="VARCHAR" />
    <result column="CreatedUserID" property="createduserid" jdbcType="INTEGER" />
    <result column="CreatedDatetime" property="createddatetime" jdbcType="TIMESTAMP" />
    <result column="LastUpdateUserID" property="lastupdateuserid" jdbcType="INTEGER" />
    <result column="LastUpdateDatetime" property="lastupdatedatetime" jdbcType="TIMESTAMP" />
    <result column="PositionName" property="positionname" jdbcType="VARCHAR" />
    <result column="LanguageType" property="languagetype" jdbcType="INTEGER" />
    <result column="DepID" property="depid" jdbcType="INTEGER" />
    <result column="IsDeleted" property="isdeleted" jdbcType="BIT" />
    <result property="depname" column="DepName" jdbcType="VARCHAR"></result>
    <result property="employeeno" column="EmployeeNo" jdbcType="VARCHAR"></result>
  </resultMap>
  
  
  
 <resultMap id="BaseResultMap1" type="com.ssm.model.system.SysPosition" extends="BaseResultMap">
<!--  	 <collection property="sysUserslist" javaType="List"  ofType="com.ssm.model.system.SysUser">
  	   <result property="employeeno" column="EmployeeNo"></result>
  	 </collection> -->
  </resultMap>
  <select id="getPostionFind" resultMap="BaseResultMap1" parameterType="com.ssm.model.system.SysPosition">
		SELECT
			p.PositionName as PositionName,
			p.PositionCode as PositionCode,
			d.DepName as DepName,
			s.EmployeeNo as EmployeeNo,
			p.PositionID as PositionID,
			p.DepID as DepID
		FROM
			SysPosition p
		LEFT JOIN  SysDepartment d ON p.DepID=d.DepID
		LEFT JOIN SysUser s ON s.UserID =p.CreatedUserID
		WHERE p.IsDeleted=0 and s.UserID=#{userid}
     	<if test="positionname != null and positionname != ''">
             AND p.PositionName = #{positionname}
     	</if>
     	 	<if test="positioncode != null and positioncode != ''">
             AND p.PositionCode = #{positioncode}
     	</if>
     	 	<if test="depid != null and depid != '' and depid!='-1'">
             AND p.DepID = #{depid}
     	</if>
     order by d.DepID
  </select>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    PositionID, PositionCode, CreatedUserID, CreatedDatetime, LastUpdateUserID, LastUpdateDatetime, 
    PositionName, LanguageType, DepID, IsDeleted
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.ssm.model.system.SysPositionExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from SysPosition
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from SysPosition
    where PositionID = #{positionid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from SysPosition
    where PositionID = #{positionid,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.ssm.model.system.SysPositionExample" >
    delete from SysPosition
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.ssm.model.system.SysPosition" >
    insert into SysPosition (PositionID, PositionCode, CreatedUserID, 
      CreatedDatetime, LastUpdateUserID, LastUpdateDatetime, 
      PositionName, LanguageType, DepID, 
      IsDeleted)
    values (#{positionid,jdbcType=INTEGER}, #{positioncode,jdbcType=VARCHAR}, #{createduserid,jdbcType=INTEGER}, 
      #{createddatetime,jdbcType=TIMESTAMP}, #{lastupdateuserid,jdbcType=INTEGER}, #{lastupdatedatetime,jdbcType=TIMESTAMP}, 
      #{positionname,jdbcType=VARCHAR}, #{languagetype,jdbcType=INTEGER}, #{depid,jdbcType=INTEGER}, 
      #{isdeleted,jdbcType=BIT})
  </insert>
  <insert id="insertSelective" parameterType="com.ssm.model.system.SysPosition" >
    insert into SysPosition
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="positionid != null" >
        PositionID,
      </if>
      <if test="positioncode != null" >
        PositionCode,
      </if>
      <if test="createduserid != null" >
        CreatedUserID,
      </if>
      <if test="createddatetime != null" >
        CreatedDatetime,
      </if>
      <if test="lastupdateuserid != null" >
        LastUpdateUserID,
      </if>
      <if test="lastupdatedatetime != null" >
        LastUpdateDatetime,
      </if>
      <if test="positionname != null" >
        PositionName,
      </if>
      <if test="languagetype != null" >
        LanguageType,
      </if>
      <if test="depid != null" >
        DepID,
      </if>
      <if test="isdeleted != null" >
        IsDeleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="positionid != null" >
        #{positionid,jdbcType=INTEGER},
      </if>
      <if test="positioncode != null" >
        #{positioncode,jdbcType=VARCHAR},
      </if>
      <if test="createduserid != null" >
        #{createduserid,jdbcType=INTEGER},
      </if>
      <if test="createddatetime != null" >
        #{createddatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastupdateuserid != null" >
        #{lastupdateuserid,jdbcType=INTEGER},
      </if>
      <if test="lastupdatedatetime != null" >
        #{lastupdatedatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="positionname != null" >
        #{positionname,jdbcType=VARCHAR},
      </if>
      <if test="languagetype != null" >
        #{languagetype,jdbcType=INTEGER},
      </if>
      <if test="depid != null" >
        #{depid,jdbcType=INTEGER},
      </if>
      <if test="isdeleted != null" >
        #{isdeleted,jdbcType=BIT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.ssm.model.system.SysPositionExample" resultType="java.lang.Integer" >
    select count(*) from SysPosition
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update SysPosition
    <set >
      <if test="record.positionid != null" >
        PositionID = #{record.positionid,jdbcType=INTEGER},
      </if>
      <if test="record.positioncode != null" >
        PositionCode = #{record.positioncode,jdbcType=VARCHAR},
      </if>
      <if test="record.createduserid != null" >
        CreatedUserID = #{record.createduserid,jdbcType=INTEGER},
      </if>
      <if test="record.createddatetime != null" >
        CreatedDatetime = #{record.createddatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.lastupdateuserid != null" >
        LastUpdateUserID = #{record.lastupdateuserid,jdbcType=INTEGER},
      </if>
      <if test="record.lastupdatedatetime != null" >
        LastUpdateDatetime = #{record.lastupdatedatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.positionname != null" >
        PositionName = #{record.positionname,jdbcType=VARCHAR},
      </if>
      <if test="record.languagetype != null" >
        LanguageType = #{record.languagetype,jdbcType=INTEGER},
      </if>
      <if test="record.depid != null" >
        DepID = #{record.depid,jdbcType=INTEGER},
      </if>
      <if test="record.isdeleted != null" >
        IsDeleted = #{record.isdeleted,jdbcType=BIT},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update SysPosition
    set PositionID = #{record.positionid,jdbcType=INTEGER},
      PositionCode = #{record.positioncode,jdbcType=VARCHAR},
      CreatedUserID = #{record.createduserid,jdbcType=INTEGER},
      CreatedDatetime = #{record.createddatetime,jdbcType=TIMESTAMP},
      LastUpdateUserID = #{record.lastupdateuserid,jdbcType=INTEGER},
      LastUpdateDatetime = #{record.lastupdatedatetime,jdbcType=TIMESTAMP},
      PositionName = #{record.positionname,jdbcType=VARCHAR},
      LanguageType = #{record.languagetype,jdbcType=INTEGER},
      DepID = #{record.depid,jdbcType=INTEGER},
      IsDeleted = #{record.isdeleted,jdbcType=BIT}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.ssm.model.system.SysPosition" >
    update SysPosition
    <set >
      <if test="positioncode != null" >
        PositionCode = #{positioncode,jdbcType=VARCHAR},
      </if>
      <if test="createduserid != null" >
        CreatedUserID = #{createduserid,jdbcType=INTEGER},
      </if>
      <if test="createddatetime != null" >
        CreatedDatetime = #{createddatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="lastupdateuserid != null" >
        LastUpdateUserID = #{lastupdateuserid,jdbcType=INTEGER},
      </if>
      <if test="lastupdatedatetime != null" >
        LastUpdateDatetime = #{lastupdatedatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="positionname != null" >
        PositionName = #{positionname,jdbcType=VARCHAR},
      </if>
      <if test="languagetype != null" >
        LanguageType = #{languagetype,jdbcType=INTEGER},
      </if>
      <if test="depid != null" >
        DepID = #{depid,jdbcType=INTEGER},
      </if>
      <if test="isdeleted != null" >
        IsDeleted = #{isdeleted,jdbcType=BIT},
      </if>
    </set>
    where PositionID = #{positionid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ssm.model.system.SysPosition" >
    update SysPosition
    set PositionCode = #{positioncode,jdbcType=VARCHAR},
      CreatedUserID = #{createduserid,jdbcType=INTEGER},
      CreatedDatetime = #{createddatetime,jdbcType=TIMESTAMP},
      LastUpdateUserID = #{lastupdateuserid,jdbcType=INTEGER},
      LastUpdateDatetime = #{lastupdatedatetime,jdbcType=TIMESTAMP},
      PositionName = #{positionname,jdbcType=VARCHAR},
      LanguageType = #{languagetype,jdbcType=INTEGER},
      DepID = #{depid,jdbcType=INTEGER},
      IsDeleted = #{isdeleted,jdbcType=BIT}
    where PositionID = #{positionid,jdbcType=INTEGER}
  </update>
  <!-- 删除职位 -->
  <update id="deleteSysPostion" parameterType="INTEGER">
      update SysPosition
    set  IsDeleted =1 where PositionID=#{positionid,jdbcType=INTEGER}
  </update>
  <select id="QuerySysPostionId" parameterType="INTEGER" resultType="java.lang.Integer" >
  	select count(*) from SysPosition s where s.DepID=#{depid}
  </select>
  <select id="selectAllPostion" resultMap="BaseResultMap">
  	SELECT * from SysPosition s where s.IsDeleted= 0
  </select>
</mapper>