<?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.zcloud.mapper.dsno1.video.VideoMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_VIDEO
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.NAME,
		f.FILEPATH,
		f.CREATOR,
		f.CREATTIME,
		f.ISDELETE,
		f.CORPINFO_ID,
		f.TYPE,
		f.CORPINFO_TYPE,
		f.DESCR,
		f.VIDEO_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		NAME,
		FILEPATH,
		CREATOR,
		CREATTIME,
		ISDELETE,
		CORPINFO_ID,
		TYPE,
		CORPINFO_TYPE,
		DESCR,
		VIDEO_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{NAME},
		#{FILEPATH},
		#{CREATOR},
		#{CREATTIME},
		#{ISDELETE},
		#{CORPINFO_ID},
		#{TYPE},
		#{CORPINFO_TYPE},
		#{DESCR},
		#{VIDEO_ID}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<!-- 删除-->
	<delete id="delete" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			VIDEO_ID = #{VIDEO_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			NAME = #{NAME},
			FILEPATH = #{FILEPATH},
			CREATOR = #{CREATOR},
			CREATTIME = #{CREATTIME},
			CORPINFO_ID = #{CORPINFO_ID},
			DESCR = #{DESCR},
			VIDEO_ID = VIDEO_ID
		where
			VIDEO_ID = #{VIDEO_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where
			f.VIDEO_ID = #{VIDEO_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0'
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and(
				name  LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
		<if test="pd.CORPINFO_TYPE != null and pd.CORPINFO_TYPE != ''">
			and f.CORPINFO_TYPE = #{pd.CORPINFO_TYPE}
		</if>
			<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{pd.CORPINFO_ID}
		</if>
		order by f.TYPE desc , f.CREATTIME

	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where 1=1
		<if test="TYPE !=null and TYPE !=''">
		 and TYPE =#{TYPE}
		</if>
		<if test="CORPINFO_TYPE !=null and CORPINFO_TYPE !=''">
		 and CORPINFO_TYPE =#{CORPINFO_TYPE}
		</if>
		<if test="CORPINFO_ID !=null and CORPINFO_ID !=''">
		 and CORPINFO_ID =#{CORPINFO_ID}
		</if>
	</select>

	<!-- 批量删除 -->
	<delete id="deleteAll" parameterType="String">
		update
		<include refid="tableName"></include>
		set
			ISDELETE = '1'
		where
			VIDEO_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>


	<!-- 修改 -->
	<update id="editZhiding" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			TYPE = #{TYPE}
		where
		 1=1
		 	<if test="VIDEO_ID != null and VIDEO_ID != ''">
		 		and VIDEO_ID = #{VIDEO_ID}
		 	</if>
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''">
		 		and CORPINFO_ID = #{CORPINFO_ID}
		 	</if>
		 	<if test="CORPINFO_TYPE != null and CORPINFO_TYPE != ''">
				and CORPINFO_TYPE = #{CORPINFO_TYPE}
			</if>
	</update>
</mapper>
