<?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.datasource.bus.VidoManagerMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.CORPINFO_ID,
		f.VIDONAME,
		f.VIDOURL,
		f.OPDATE,
		f.OPUSER,
		f.ISDELETE,
		f.ISSHOW,
		f.FILEPATH,
		f.VIDOMANAGER_ID,
		f.LONGITUDE,
		f.LATITUDE,
		f.BIURL
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		CORPINFO_ID,
		VIDONAME,
		VIDOURL,
		OPDATE,
		OPUSER,
		ISDELETE,
		ISSHOW,
		FILEPATH,
		VIDOMANAGER_ID,
		LONGITUDE,
		LATITUDE,
		BIURL
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{CORPINFO_ID},
		#{VIDONAME},
		#{VIDOURL},
		#{OPDATE},
		#{OPUSER},
		#{ISDELETE},
		#{ISSHOW},
		#{FILEPATH},
		#{VIDOMANAGER_ID},
		#{LONGITUDE},
		#{LATITUDE},
		#{BIURL}
	</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
			VIDOMANAGER_ID = #{VIDOMANAGER_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
				CORPINFO_ID = #{CORPINFO_ID},
			</if>
			<if test="VIDONAME != null and VIDONAME != ''"><!-- 关键词检索 -->
				VIDONAME = #{VIDONAME},
			</if>
			<if test="VIDOURL != null and VIDOURL != ''"><!-- 关键词检索 -->
				VIDOURL = #{VIDOURL},
			</if>
			<if test="ISSHOW != null and ISSHOW != ''"><!-- 关键词检索 -->
				ISSHOW = #{ISSHOW},
			</if>
			<if test="FILEPATH != null and FILEPATH != ''"><!-- 关键词检索 -->
				FILEPATH = #{FILEPATH},
			</if>
			<if test="BIURL != null and BIURL != ''"><!-- 关键词检索 -->
				BIURL = #{BIURL},
			</if>
			<if test="LONGITUDE != null and LONGITUDE != ''"><!-- 关键词检索 -->
				LONGITUDE = #{LONGITUDE},
			</if>
			<if test="LATITUDE != null and LATITUDE != ''"><!-- 关键词检索 -->
				LATITUDE = #{LATITUDE},
			</if>
			VIDOMANAGER_ID = VIDOMANAGER_ID
		where
			VIDOMANAGER_ID = #{VIDOMANAGER_ID}
	</update>
	<update id="editIsShowBycorpinfoid" parameterType="pd">
		update
		<include refid="tableName"></include>
		set ISSHOW= #{ISSHOW}
		where
			CORPINFO_ID = #{CORPINFO_ID}
	</update>
	<update id="editIsShow" parameterType="pd">
		update
		<include refid="tableName"></include>
		set ISSHOW= #{ISSHOW}
		where
			VIDOMANAGER_ID = #{VIDOMANAGER_ID}
	</update>
	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
			f.CORPINFO_ID,
			f.VIDONAME,
			f.OPDATE,
			f.OPUSER,
			f.ISDELETE,
			f.ISSHOW,
			f.FILEPATH,
			f.VIDOMANAGER_ID,
			f.BIURL,
			f.LONGITUDE,
			f.LATITUDE,
			CONCAT(f.VIDOURL,(SELECT TOKEN FROM BUS_VIDO_TOKEN WHERE TOKEN_ID = '4befc4288a9449d283b6ae42804a27ad')) YSYVIDEOURL,
			f.VIDOURL GBSVIDEOURL,
			f.VIDOURL
		from
		<include refid="tableName"></include> f
		where
			f.VIDOMANAGER_ID = #{VIDOMANAGER_ID} and
			 f.ISDELETE = '0'
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID=#{CORPINFO_ID}
		</if>
		<if test="ISSHOW != null and ISSHOW != ''"><!-- 关键词检索 -->
			and f.ISSHOW=#{ISSHOW}
		</if>
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			f.CORPINFO_ID,
			f.VIDONAME,
			f.OPDATE,
			f.OPUSER,
			f.ISDELETE,
			f.ISSHOW,
			f.FILEPATH,
			f.VIDOMANAGER_ID,
			f.BIURL,
			c.CORP_NAME,
			CONCAT(f.VIDOURL,(SELECT TOKEN FROM BUS_VIDO_TOKEN WHERE TOKEN_ID = '4befc4288a9449d283b6ae42804a27ad')) YSYVIDEOURL,
			f.VIDOURL GBSVIDEOURL
		from
		<include refid="tableName"></include> f
			left join bus_CORP_INFO c on f.CORPINFO_ID=c.CORPINFO_ID
		where
			f.ISDELETE = '0'
			<if test="pd.CORPINFO_ID != null and pd.CORPINFO_ID != ''"><!-- 关键词检索 -->
				and f.CORPINFO_ID=#{pd.CORPINFO_ID}
			</if>
			<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
				and
					(
					<!--	根据需求自己加检索条件
						字段1 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
						 or
						字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					-->
					)
			</if>

	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
			f.CORPINFO_ID,
			f.VIDONAME,
			f.OPDATE,
			f.OPUSER,
			f.ISDELETE,
			f.ISSHOW,
			f.FILEPATH,
			f.VIDOMANAGER_ID,
			f.BIURL,
			CONCAT(f.VIDOURL,(SELECT TOKEN FROM BUS_VIDO_TOKEN WHERE TOKEN_ID = '4befc4288a9449d283b6ae42804a27ad')) YSYVIDEOURL,
			f.VIDOURL GBSVIDEOURL
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0'
			<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
				and f.CORPINFO_ID=#{CORPINFO_ID}
			</if>
			<if test="ISSHOW != null and ISSHOW != ''"><!-- 关键词检索 -->
				and f.ISSHOW=#{ISSHOW}
			</if>
			<if test="ArrayDATA_IDS != null and ArrayDATA_IDS != ''"><!-- 关键词检索 -->
				and VIDOMANAGER_ID in
				<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
		                 #{item}
				</foreach>
			</if>

	</select>

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

	<!-- 修改视频token -->
	<update id="editVideoToken" parameterType="pd">
		UPDATE
			BUS_VIDO_TOKEN
		SET
			TOKEN= #{TOKEN}
		WHERE
			TOKEN_ID = #{TOKEN_ID}
	</update>
</mapper>
