<?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.steerinfo.ftp.securitytype.mapper.SecurityTypeMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ftp.securitytype.model.SecurityType">
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="SECURITY_TYPE" jdbcType="VARCHAR" property="securityType" />
    <result column="SECURITY_NAME" jdbcType="VARCHAR" property="securityName" />
    <result column="SECURITY_INFO" jdbcType="VARCHAR" property="securityInfo" />
    <result column="SEQNO" jdbcType="DECIMAL" property="seqno" />
    <result column="SECURITY_PARENTID" jdbcType="VARCHAR" property="securityParentid" />
    <result column="SECURITY_NODE" jdbcType="VARCHAR" property="securityNode" />
    <result column="SECURITY_UPLOAD_URL" jdbcType="VARCHAR" property="securityUploadUrl" />
    <result column="CREATE_MAN" jdbcType="VARCHAR" property="createMan" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_MAN" jdbcType="VARCHAR" property="updateMan" />
    <result column="UPDATE_TIME" jdbcType="VARCHAR" property="updateTime" />
  </resultMap>
  <sql id="columns">
    ID, SECURITY_TYPE, SECURITY_NAME, SECURITY_INFO, SEQNO, SECURITY_PARENTID, SECURITY_NODE, 
    SECURITY_UPLOAD_URL, CREATE_MAN, CREATE_TIME, UPDATE_MAN, UPDATE_TIME
  </sql>
  <sql id="columns_alias">
    t.ID, t.SECURITY_TYPE, t.SECURITY_NAME, t.SECURITY_INFO, t.SEQNO, t.SECURITY_PARENTID, 
    t.SECURITY_NODE, t.SECURITY_UPLOAD_URL, t.CREATE_MAN, t.CREATE_TIME, t.UPDATE_MAN, 
    t.UPDATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM SECURITY_TYPE
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM SECURITY_TYPE t
  </sql>
  <sql id="where">
    <where> 
      <if test="id != null and id != ''">
        and ID = #{id}
      </if>
      <if test="securityType != null and securityType != ''">
        and SECURITY_TYPE = #{securityType}
      </if>
      <if test="securityName != null and securityName != ''">
        and SECURITY_NAME = #{securityName}
      </if>
      <if test="securityInfo != null and securityInfo != ''">
        and SECURITY_INFO = #{securityInfo}
      </if>
      <if test="seqno != null">
        and SEQNO = #{seqno}
      </if>
      <if test="securityParentid != null and securityParentid != ''">
        and SECURITY_PARENTID = #{securityParentid}
      </if>
      <if test="securityNode != null and securityNode != ''">
        and SECURITY_NODE = #{securityNode}
      </if>
      <if test="securityUploadUrl != null and securityUploadUrl != ''">
        and SECURITY_UPLOAD_URL = #{securityUploadUrl}
      </if>
      <if test="createMan != null and createMan != ''">
        and CREATE_MAN = #{createMan}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateMan != null and updateMan != ''">
        and UPDATE_MAN = #{updateMan}
      </if>
      <if test="updateTime != null and updateTime != ''">
        and UPDATE_TIME = #{updateTime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="id != null and id != ''">
        and ID LIKE '%${id}%'
      </if>
      <if test="securityType != null and securityType != ''">
        and SECURITY_TYPE LIKE '%${securityType}%'
      </if>
      <if test="securityName != null and securityName != ''">
        and SECURITY_NAME LIKE '%${securityName}%'
      </if>
      <if test="securityInfo != null and securityInfo != ''">
        and (SECURITY_INFO is null
        OR SECURITY_INFO = ''
        OR REGEXP_LIKE(SECURITY_INFO,'(${securityInfo})'))
      </if>
      <if test="seqno != null">
        and SEQNO = #{seqno}
      </if>
      <if test="securityParentid != null and securityParentid != ''">
        and SECURITY_PARENTID LIKE '%${securityParentid}%'
      </if>
      <if test="securityNode != null and securityNode != ''">
        and SECURITY_NODE LIKE '%${securityNode}%'
      </if>
      <if test="securityUploadUrl != null and securityUploadUrl != ''">
        and SECURITY_UPLOAD_URL LIKE '%${securityUploadUrl}%'
      </if>
      <if test="createMan != null and createMan != ''">
        and CREATE_MAN LIKE '%${createMan}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="updateMan != null and updateMan != ''">
        and UPDATE_MAN LIKE '%${updateMan}%'
      </if>
      <if test="updateTime != null and updateTime != ''">
        and UPDATE_TIME LIKE '%${updateTime}%'
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from SECURITY_TYPE
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from SECURITY_TYPE
    where 1!=1 
      <if test="securityType != null and securityType != ''">
        or SECURITY_TYPE = #{securityType}
      </if>
      <if test="securityName != null and securityName != ''">
        or SECURITY_NAME = #{securityName}
      </if>
      <if test="securityInfo != null and securityInfo != ''">
        or SECURITY_INFO = #{securityInfo}
      </if>
      <if test="seqno != null">
        or SEQNO = #{seqno}
      </if>
      <if test="securityParentid != null and securityParentid != ''">
        or SECURITY_PARENTID = #{securityParentid}
      </if>
      <if test="securityNode != null and securityNode != ''">
        or SECURITY_NODE = #{securityNode}
      </if>
      <if test="securityUploadUrl != null and securityUploadUrl != ''">
        or SECURITY_UPLOAD_URL = #{securityUploadUrl}
      </if>
      <if test="createMan != null and createMan != ''">
        or CREATE_MAN = #{createMan}
      </if>
      <if test="createTime != null">
        or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
      </if>
      <if test="updateMan != null and updateMan != ''">
        or UPDATE_MAN = #{updateMan}
      </if>
      <if test="updateTime != null and updateTime != ''">
        or UPDATE_TIME = #{updateTime}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ftp.securitytype.model.SecurityType">
    insert into SECURITY_TYPE (ID, SECURITY_TYPE, SECURITY_NAME, 
      SECURITY_INFO, SEQNO, SECURITY_PARENTID, 
      SECURITY_NODE, SECURITY_UPLOAD_URL, CREATE_MAN, 
      CREATE_TIME, UPDATE_MAN, UPDATE_TIME
      )
    values (#{id,jdbcType=VARCHAR}, #{securityType,jdbcType=VARCHAR}, #{securityName,jdbcType=VARCHAR}, 
      #{securityInfo,jdbcType=VARCHAR}, #{seqno,jdbcType=DECIMAL}, #{securityParentid,jdbcType=VARCHAR}, 
      #{securityNode,jdbcType=VARCHAR}, #{securityUploadUrl,jdbcType=VARCHAR}, #{createMan,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateMan,jdbcType=VARCHAR}, #{updateTime,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ftp.securitytype.model.SecurityType">
    insert into SECURITY_TYPE
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="securityType != null">
        SECURITY_TYPE,
      </if>
      <if test="securityName != null">
        SECURITY_NAME,
      </if>
      <if test="securityInfo != null">
        SECURITY_INFO,
      </if>
      <if test="seqno != null">
        SEQNO,
      </if>
      <if test="securityParentid != null">
        SECURITY_PARENTID,
      </if>
      <if test="securityNode != null">
        SECURITY_NODE,
      </if>
      <if test="securityUploadUrl != null">
        SECURITY_UPLOAD_URL,
      </if>
      <if test="createMan != null">
        CREATE_MAN,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateMan != null">
        UPDATE_MAN,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="securityType != null">
        #{securityType,jdbcType=VARCHAR},
      </if>
      <if test="securityName != null">
        #{securityName,jdbcType=VARCHAR},
      </if>
      <if test="securityInfo != null">
        #{securityInfo,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        #{seqno,jdbcType=DECIMAL},
      </if>
      <if test="securityParentid != null">
        #{securityParentid,jdbcType=VARCHAR},
      </if>
      <if test="securityNode != null">
        #{securityNode,jdbcType=VARCHAR},
      </if>
      <if test="securityUploadUrl != null">
        #{securityUploadUrl,jdbcType=VARCHAR},
      </if>
      <if test="createMan != null">
        #{createMan,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateMan != null">
        #{updateMan,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ftp.securitytype.model.SecurityType">
    update SECURITY_TYPE
    set SECURITY_TYPE = #{securityType,jdbcType=VARCHAR},
      SECURITY_NAME = #{securityName,jdbcType=VARCHAR},
      SECURITY_INFO = #{securityInfo,jdbcType=VARCHAR},
      SEQNO = #{seqno,jdbcType=DECIMAL},
      SECURITY_PARENTID = #{securityParentid,jdbcType=VARCHAR},
      SECURITY_NODE = #{securityNode,jdbcType=VARCHAR},
      SECURITY_UPLOAD_URL = #{securityUploadUrl,jdbcType=VARCHAR},
      CREATE_MAN = #{createMan,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      UPDATE_MAN = #{updateMan,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=VARCHAR}
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ftp.securitytype.model.SecurityType">
    update SECURITY_TYPE
    <set>
      <if test="securityType != null">
        SECURITY_TYPE = #{securityType,jdbcType=VARCHAR},
      </if>
      <if test="securityName != null">
        SECURITY_NAME = #{securityName,jdbcType=VARCHAR},
      </if>
      <if test="securityInfo != null">
        SECURITY_INFO = #{securityInfo,jdbcType=VARCHAR},
      </if>
      <if test="seqno != null">
        SEQNO = #{seqno,jdbcType=DECIMAL},
      </if>
      <if test="securityParentid != null">
        SECURITY_PARENTID = #{securityParentid,jdbcType=VARCHAR},
      </if>
      <if test="securityNode != null">
        SECURITY_NODE = #{securityNode,jdbcType=VARCHAR},
      </if>
      <if test="securityUploadUrl != null">
        SECURITY_UPLOAD_URL = #{securityUploadUrl,jdbcType=VARCHAR},
      </if>
      <if test="createMan != null">
        CREATE_MAN = #{createMan,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateMan != null">
        UPDATE_MAN = #{updateMan,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=VARCHAR},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
    ORDER BY SEQNO
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into SECURITY_TYPE 
      (ID, 
      SECURITY_TYPE, SECURITY_NAME, SECURITY_INFO, 
      SEQNO, SECURITY_PARENTID, SECURITY_NODE, 
      SECURITY_UPLOAD_URL, CREATE_MAN, 
      CREATE_TIME, UPDATE_MAN, UPDATE_TIME
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.id,jdbcType=VARCHAR}, 
      #{item.securityType,jdbcType=VARCHAR}, #{item.securityName,jdbcType=VARCHAR}, #{item.securityInfo,jdbcType=VARCHAR}, 
      #{item.seqno,jdbcType=DECIMAL}, #{item.securityParentid,jdbcType=VARCHAR}, #{item.securityNode,jdbcType=VARCHAR}, 
      #{item.securityUploadUrl,jdbcType=VARCHAR}, #{item.createMan,jdbcType=VARCHAR}, 
      #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateMan,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=VARCHAR}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update SECURITY_TYPE
     set
       ID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.id,jdbcType=VARCHAR}
       </foreach>
       ,SECURITY_TYPE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityType,jdbcType=VARCHAR}
       </foreach>
       ,SECURITY_NAME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityName,jdbcType=VARCHAR}
       </foreach>
       ,SECURITY_INFO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityInfo,jdbcType=VARCHAR}
       </foreach>
       ,SEQNO=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.seqno,jdbcType=DECIMAL}
       </foreach>
       ,SECURITY_PARENTID=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityParentid,jdbcType=VARCHAR}
       </foreach>
       ,SECURITY_NODE=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityNode,jdbcType=VARCHAR}
       </foreach>
       ,SECURITY_UPLOAD_URL=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.securityUploadUrl,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_MAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.createMan,jdbcType=VARCHAR}
       </foreach>
       ,CREATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
       </foreach>
       ,UPDATE_MAN=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.updateMan,jdbcType=VARCHAR}
       </foreach>
       ,UPDATE_TIME=
       <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
          when #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=VARCHAR}
       </foreach>
     where ID in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.id,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from SECURITY_TYPE
    where ID in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="getTree" resultMap="BaseResultMap">
    select ID, SECURITY_NAME, SECURITY_PARENTID, SECURITY_NODE from SECURITY_TYPE
    WHERE 1=1 and SECURITY_INFO is null OR SECURITY_INFO = '' OR REGEXP_LIKE(SECURITY_TYPE,'(2|师傅|NULL|)')
    order by SEQNO
  </select>

  <select id="getTreeByInfo" parameterType="java.lang.String" resultMap="BaseResultMap">
    select ID, SECURITY_NAME, SECURITY_PARENTID, SECURITY_NODE from SECURITY_TYPE
    WHERE 1=1
    <if test="_parameter != null and _parameter != ''">
      and SECURITY_INFO is null
      OR SECURITY_INFO = ''
      OR REGEXP_LIKE(SECURITY_INFO,#{securityInfo})
    </if>
    order by SEQNO
  </select>

  <select id="getParent" resultMap="BaseResultMap">
    select ID, SECURITY_NAME, SECURITY_NODE from SECURITY_TYPE
    where ID in (select distinct PARENTID from T_RM_WORKPROC)
    order by SEQNO
  </select>

  <!--查询下拉框的值-->
  <select id="getIdAndName" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT ID, SECURITY_NAME, SECURITY_NODE FROM SECURITY_TYPE
    where 1=1 and SECURITY_INFO is null
    OR SECURITY_INFO = ''
    OR REGEXP_LIKE(SECURITY_INFO,#{securityInfo})
    ORDER BY SECURITY_NAME
  </select>

  <select id="getMaxSeqNo" resultType="java.lang.Integer">
    SELECT nvl(MAX(SEQNO),'0') FROM SECURITY_TYPE
  </select>
  <!--组装路径-->
  <select id="getURL" resultType="java.lang.String" parameterType="java.lang.String">
    SELECT SECURITY_UPLOAD_URL FROM SECURITY_TYPE where ID=#{parentId}
  </select>

  <!--查找子级-->
  <select id="getParentNum" resultType="java.lang.Integer" parameterType="java.lang.String">
    SELECT COUNT(SECURITY_PARENTID) FROM SECURITY_TYPE WHERE SECURITY_PARENTID=#{Id}
  </select>
</mapper>