<?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.gaowj.business.uploadfile.uploadfileDAO">
	<insert id="insert_uploadfile" parameterType="map">
		insert into C_T_SYS_FILE(
		<trim prefix="" suffixOverrides=",">
			<foreach collection="infoListKey" item="key">
				${key},
			</foreach>
		</trim>
	      <![CDATA[ ) values( ]]>
		<trim prefix="" suffixOverrides=",">
			<foreach collection="infoList" item="value">
				#{value},
			</foreach>
		</trim>
	      <![CDATA[ ) ]]>
	</insert>

	<update id="update_uploadfile" parameterType="map">
	       <![CDATA[
            update C_T_SYS_FILE set 
         ]]>
		<trim prefix="" suffixOverrides=",">
			<foreach collection="info" item="info">
				${info.key} = #{info.value} ,
			</foreach>
		</trim>
		<where>
			<if test="UUID != null and UUID != ''">
				and UUID = #{UUID}
           </if>
		</where>
	</update>
	
	<update id="setnull_binary_data" parameterType="list">
        <![CDATA[
            update  C_T_SYS_FILE set BINARY_DATA = null where UUID IN
         ]]>
		<foreach collection="list" item="UUID" open="(" separator="," close=")">
			#{UUID} 
         </foreach>
	</update>

	<delete id="delete_uploadfile" parameterType="list">
        <![CDATA[
            update  C_T_SYS_FILE set DELETE_FLAG = '1' where UUID IN
         ]]>
		<foreach collection="list" item="UUID" open="(" separator="," close=")">
			#{UUID} 
         </foreach>
	</delete>
	
	<delete id="resume_uploadfile" parameterType="list">
        <![CDATA[
            update  C_T_SYS_FILE set DELETE_FLAG = '0' where UUID IN
         ]]>
		<foreach collection="list" item="UUID" open="(" separator="," close=")">
			#{UUID} 
         </foreach>
	</delete>
	
	<delete id="delete_true_uploadfile" parameterType="list">
        <![CDATA[
            delete from  C_T_SYS_FILE where DELETE_FLAG = '1' and UUID IN
         ]]>
		<foreach collection="list" item="UUID" open="(" separator="," close=")">
			#{UUID} 
         </foreach>
	</delete>
	
	<select id="list_uploadnofile" parameterType="map" resultType="upperCaseKeyMap">
	 <![CDATA[
	  select f.UUID,f.FILE_NAME,f.FILE_SVAE_NAME,f.MAINDATA_ID,f.CREATOR_ID,f.CREATE_TIME,f.MODULE_ID,f.DELETE_FLAG,f.FILE_SAVE_PATH,f.UPDATE_ID,f.UPDATE_TIME,
	  (select EMNAME from C_T_SYS_LOGINUSER u where u.CODE = f.CREATOR_ID) CREATE_NAME,
	  (select EMNAME from C_T_SYS_LOGINUSER u where u.CODE = f.UPDATE_ID) UPDATE_NAME,
	  (case when f.BINARY_DATA is null then '0' else '1' end) exist_file 
	  from C_T_SYS_FILE f where 1=1 
     ]]>
		<if test="UUID != null and UUID != ''">
			and f.UUID = #{UUID}
        </if>
		<if test="START_TIME != null and START_TIME != ''">
			and f.CREATE_TIME &gt;= #{START_TIME} 
        </if>
		<if test="END_TIME != null and END_TIME != ''">
			and f.CREATE_TIME &lt;= #{END_TIME}
        </if>
        <if test="DELETE_FLAG != null and DELETE_FLAG != ''">
			and f.DELETE_FLAG = #{DELETE_FLAG}
        </if>
        <if test="FILE_NAME != null and FILE_NAME != ''">
			and f.FILE_NAME like '%${FILE_NAME}%'
        </if>
        <if test="FILE_SVAE_NAME != null and FILE_SVAE_NAME != ''">
			and f.FILE_SVAE_NAME like '%${FILE_SVAE_NAME}%'
        </if>
        <if test="MAINDATA_ID != null and MAINDATA_ID != ''">
			and f.MAINDATA_ID like '%${MAINDATA_ID}%'
        </if>
        <if test="MODULE_ID != null and MODULE_ID != ''">
			and f.MODULE_ID like '%${MODULE_ID}%'
        </if>
        <if test="FILE_SAVE_PATH != null and FILE_SAVE_PATH != ''">
			and f.FILE_SAVE_PATH like '%${FILE_SAVE_PATH}%'
        </if>
        <if test="USTART_TIME != null and USTART_TIME != ''">
			and f.UPDATE_TIME &gt;= #{USTART_TIME} 
        </if>
		<if test="UEND_TIME != null and UEND_TIME != ''">
			and f.UPDATE_TIME &lt;= #{UEND_TIME}
        </if>
        <if test="CREATOR_ID != null and CREATOR_ID != ''">
			and f.CREATOR_ID = #{CREATOR_ID}
        </if>
        <if test="UPDATE_ID != null and UPDATE_ID != ''">
			and f.UPDATE_ID = #{UPDATE_ID}
        </if>
        <if test="UUIDLIST != null and UUIDLIST != ''">
            and UUID IN
           <foreach collection="UUIDLIST" item="UUID"  open="("  separator=","  close=")">  
             #{UUID} 
           </foreach>
         </if>
         <if test="MAINDATA_IDLIST != null and MAINDATA_IDLIST != ''">
            and MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach>
         </if>
         <if test="MODULE_IDLIST != null and MODULE_IDLIST != ''">
            and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
         </if>
		order by f.CREATE_TIME DESC
	</select>

	<select id="list_uploadfile" parameterType="map" resultType="upperCaseKeyMap">
	 <![CDATA[
	  select f.*,
	  (select EMNAME from C_T_SYS_LOGINUSER u where u.CODE = f.CREATOR_ID) CREATE_NAME,
	  (select EMNAME from C_T_SYS_LOGINUSER u where u.CODE = f.UPDATE_ID) UPDATE_NAME,
	  (case when f.BINARY_DATA is null then '0' else '1' end) exist_file  
	  from C_T_SYS_FILE f where 1=1 
     ]]>
		<if test="UUID != null and UUID != ''">
			and f.UUID = #{UUID}
        </if>
		<if test="START_TIME != null and START_TIME != ''">
			and f.CREATE_TIME &gt;= #{START_TIME} 
        </if>
		<if test="END_TIME != null and END_TIME != ''">
			and f.CREATE_TIME &lt;= #{END_TIME}
        </if>
        <if test="DELETE_FLAG != null and DELETE_FLAG != ''">
			and f.DELETE_FLAG = #{DELETE_FLAG}
        </if>
        <if test="FILE_NAME != null and FILE_NAME != ''">
			and f.FILE_NAME like '%${FILE_NAME}%'
        </if>
        <if test="FILE_SVAE_NAME != null and FILE_SVAE_NAME != ''">
			and f.FILE_SVAE_NAME like '%${FILE_SVAE_NAME}%'
        </if>
        <if test="MAINDATA_ID != null and MAINDATA_ID != ''">
			and f.MAINDATA_ID like '%${MAINDATA_ID}%'
        </if>
        <if test="MODULE_ID != null and MODULE_ID != ''">
			and f.MODULE_ID like '%${MODULE_ID}%'
        </if>
        <if test="FILE_SAVE_PATH != null and FILE_SAVE_PATH != ''">
			and f.FILE_SAVE_PATH like '%${FILE_SAVE_PATH}%'
        </if>
        <if test="USTART_TIME != null and USTART_TIME != ''">
			and f.UPDATE_TIME &gt;= #{USTART_TIME} 
        </if>
		<if test="UEND_TIME != null and UEND_TIME != ''">
			and f.UPDATE_TIME &lt;= #{UEND_TIME}
        </if>
        <if test="CREATOR_ID != null and CREATOR_ID != ''">
			and f.CREATOR_ID = #{CREATOR_ID}
        </if>
        <if test="UPDATE_ID != null and UPDATE_ID != ''">
			and f.UPDATE_ID = #{UPDATE_ID}
        </if>
        <if test="UUIDLIST != null and UUIDLIST != ''">
            and UUID IN
           <foreach collection="UUIDLIST" item="UUID"  open="("  separator=","  close=")">  
             #{UUID} 
           </foreach>
         </if>
         <if test="MAINDATA_IDLIST != null and MAINDATA_IDLIST != ''">
            and MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach>
         </if>
         <if test="MODULE_IDLIST != null and MODULE_IDLIST != ''">
            and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
         </if>
		order by f.CREATE_TIME DESC
	</select>

	<select id="listCount_uploadfile" parameterType="map" resultType="int">
	 <![CDATA[
	   select count(*) c from C_T_SYS_FILE f where 1=1 
     ]]>
		<if test="UUID != null and UUID != ''">
			and f.UUID = #{UUID}
        </if>
		<if test="START_TIME != null and START_TIME != ''">
			and f.CREATE_TIME &gt;= #{START_TIME} 
        </if>
		<if test="END_TIME != null and END_TIME != ''">
			and f.CREATE_TIME &lt;= #{END_TIME}
        </if>
        <if test="DELETE_FLAG != null and DELETE_FLAG != ''">
			and f.DELETE_FLAG = #{DELETE_FLAG}
        </if>
        <if test="FILE_NAME != null and FILE_NAME != ''">
			and f.FILE_NAME like '%${FILE_NAME}%'
        </if>
        <if test="FILE_SVAE_NAME != null and FILE_SVAE_NAME != ''">
			and f.FILE_SVAE_NAME like '%${FILE_SVAE_NAME}%'
        </if>
        <if test="MAINDATA_ID != null and MAINDATA_ID != ''">
			and f.MAINDATA_ID like '%${MAINDATA_ID}%'
        </if>
        <if test="MODULE_ID != null and MODULE_ID != ''">
			and f.MODULE_ID like '%${MODULE_ID}%'
        </if>
        <if test="FILE_SAVE_PATH != null and FILE_SAVE_PATH != ''">
			and f.FILE_SAVE_PATH like '%${FILE_SAVE_PATH}%'
        </if>
        <if test="USTART_TIME != null and USTART_TIME != ''">
			and f.UPDATE_TIME &gt;= #{USTART_TIME} 
        </if>
		<if test="UEND_TIME != null and UEND_TIME != ''">
			and f.UPDATE_TIME &lt;= #{UEND_TIME}
        </if>
        <if test="CREATOR_ID != null and CREATOR_ID != ''">
			and f.CREATOR_ID = #{CREATOR_ID}
        </if>
        <if test="UPDATE_ID != null and UPDATE_ID != ''">
			and f.UPDATE_ID = #{UPDATE_ID}
        </if>
        <if test="UUIDLIST != null and UUIDLIST != ''">
            and UUID IN
           <foreach collection="UUIDLIST" item="UUID"  open="("  separator=","  close=")">  
             #{UUID} 
           </foreach>
         </if>
         <if test="MAINDATA_IDLIST != null and MAINDATA_IDLIST != ''">
            and MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach>
         </if>
         <if test="MODULE_IDLIST != null and MODULE_IDLIST != ''">
            and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
         </if>
	</select>
	<!--供其它模块接口使用-->
	<select id="list_uploadnofile_webservices" parameterType="map" resultType="upperCaseKeyMap">
	 <![CDATA[
	  select f.FILE_NAME,f.FILE_SVAE_NAME,f.MAINDATA_ID,f.FILE_SAVE_PATH,
	  (case when f.BINARY_DATA is null then '0' else '1' end) exist_file 
	  from C_T_SYS_FILE f where 1=1 
     ]]>
		<if test="UUID != null and UUID != ''">
			and f.UUID = #{UUID}
        </if>
		<if test="START_TIME != null and START_TIME != ''">
			and f.CREATE_TIME &gt;= #{START_TIME} 
        </if>
		<if test="END_TIME != null and END_TIME != ''">
			and f.CREATE_TIME &lt;= #{END_TIME}
        </if>
        <if test="DELETE_FLAG != null and DELETE_FLAG != ''">
			and f.DELETE_FLAG = #{DELETE_FLAG}
        </if>
        <if test="FILE_NAME != null and FILE_NAME != ''">
			and f.FILE_NAME like '%${FILE_NAME}%'
        </if>
        <if test="FILE_SVAE_NAME != null and FILE_SVAE_NAME != ''">
			and f.FILE_SVAE_NAME like '%${FILE_SVAE_NAME}%'
        </if>
        <if test="MAINDATA_ID != null and MAINDATA_ID != ''">
			and f.MAINDATA_ID like '%${MAINDATA_ID}%'
        </if>
        <if test="MODULE_ID != null and MODULE_ID != ''">
			and f.MODULE_ID like '%${MODULE_ID}%'
        </if>
        <if test="FILE_SAVE_PATH != null and FILE_SAVE_PATH != ''">
			and f.FILE_SAVE_PATH like '%${FILE_SAVE_PATH}%'
        </if>
        <if test="USTART_TIME != null and USTART_TIME != ''">
			and f.UPDATE_TIME &gt;= #{USTART_TIME} 
        </if>
		<if test="UEND_TIME != null and UEND_TIME != ''">
			and f.UPDATE_TIME &lt;= #{UEND_TIME}
        </if>
        <if test="CREATOR_ID != null and CREATOR_ID != ''">
			and f.CREATOR_ID = #{CREATOR_ID}
        </if>
        <if test="UPDATE_ID != null and UPDATE_ID != ''">
			and f.UPDATE_ID = #{UPDATE_ID}
        </if>
        <if test="UUIDLIST != null and UUIDLIST != ''">
            and UUID IN
           <foreach collection="UUIDLIST" item="UUID"  open="("  separator=","  close=")">  
             #{UUID} 
           </foreach>
         </if>
         <if test="MAINDATA_IDLIST != null and MAINDATA_IDLIST != ''">
            and MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach>
         </if>
         <if test="MODULE_IDLIST != null and MODULE_IDLIST != ''">
            and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
         </if>
		order by f.CREATE_TIME DESC
	</select>
    <delete id="delete_uploadfile_common" parameterType="map">
        <![CDATA[
            update  C_T_SYS_FILE set DELETE_FLAG = '1' 
         ]]>
         <where>
		      MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach> 
             and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
        </where>
	</delete>
	
	<delete id="resume_uploadfile_common" parameterType="map">
        <![CDATA[
            update  C_T_SYS_FILE set DELETE_FLAG = '0' 
         ]]>
		<where>
		      MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach> 
             and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
        </where>
	</delete>
	
	<delete id="delete_true_uploadfile_common" parameterType="map">
        <![CDATA[
            delete from  C_T_SYS_FILE where DELETE_FLAG = '1' 
         ]]>
            and MAINDATA_ID IN
           <foreach collection="MAINDATA_IDLIST" item="MAINDATA_ID"  open="("  separator=","  close=")">  
             #{MAINDATA_ID} 
           </foreach> 
            and MODULE_ID IN
           <foreach collection="MODULE_IDLIST" item="MODULE_ID"  open="("  separator=","  close=")">  
             #{MODULE_ID} 
           </foreach>
	</delete>
</mapper>