<?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.eightwork.EightWorkVideoManagerMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.EIGHTWORKVIDEOMANAGER_ID,
		f.CORPINFO_ID,
		f.VIDEOMANAGER_ID,
		f.CREATTIME,
		f.CREATOR,
		f.ISDELETE,
		f.OPERATTIME,
		f.OPERATOR,
		f.LONGITUDE,
		f.LATITUDE,
		f.CHECK_NO
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		EIGHTWORKVIDEOMANAGER_ID,
		CORPINFO_ID,
		VIDEOMANAGER_ID,
		CREATTIME,
		CREATOR,
		ISDELETE,
		OPERATTIME,
		OPERATOR,
		LONGITUDE,
		LATITUDE,
		CHECK_NO
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{EIGHTWORKVIDEOMANAGER_ID},
		#{CORPINFO_ID},
		#{VIDEOMANAGER_ID},
		#{CREATTIME},
		#{CREATOR},
		#{ISDELETE},
		#{OPERATTIME},
		#{OPERATOR},
		#{LONGITUDE},
		#{LATITUDE},
		#{CHECK_NO}
	</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
			EIGHTWORKVIDEOMANAGER_ID = #{EIGHTWORKVIDEOMANAGER_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			EIGHTWORKVIDEOMANAGER_ID = #{EIGHTWORKVIDEOMANAGER_ID},
			CORPINFO_ID = #{CORPINFO_ID},
			VIDEOMANAGER_ID = #{VIDEOMANAGER_ID},
			ISDELETE = #{ISDELETE},
			CREATTIME = #{CREATTIME},
			CREATOR = #{CREATOR},
			OPERATTIME = #{OPERATTIME},
			OPERATOR = #{OPERATOR},
			LONGITUDE = #{LONGITUDE},
			LATITUDE = #{LATITUDE},
			CHECK_NO = #{CHECK_NO}

		where
			EIGHTWORKVIDEOMANAGER_ID = #{EIGHTWORKVIDEOMANAGER_ID}
	</update>

	<!-- 修改 -->
	<update id="editStatus" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		ISDELETE = '1'
		where
		CHECK_NO = #{CHECK_NO}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		f.EIGHTWORKVIDEOMANAGER_ID,
		f.CORPINFO_ID,
		f.VIDEOMANAGER_ID,
		f.CREATTIME,
		f.CREATOR,
		f.ISDELETE,
		f.OPERATTIME,
		f.OPERATOR,
		f.LONGITUDE,
		f.LATITUDE,
		bc.VIDEONAME,
		bc.CODE,
		bc.GBS_NUM,
		bc.VIDEOURL,
		f.CHECK_NO
		from
		<include refid="tableName"></include> f
		left join BUS_VIDEOMANAGER bc on bc.VIDEOMANAGER_ID = f.VIDEOMANAGER_ID and bc.ISDELETE = '0'
		where
		f.VIDEOMANAGER_ID = #{VIDEOMANAGER_ID} and
		f.ISDELETE = '0'
		<if test="CORPINFO_ID != null and CORPINFO_ID != ''"><!-- 关键词检索 -->
			and f.CORPINFO_ID=#{CORPINFO_ID}
		</if>
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		f.EIGHTWORKVIDEOMANAGER_ID,
		f.CORPINFO_ID,
		f.VIDEOMANAGER_ID,
		f.CREATTIME,
		f.CREATOR,
		f.ISDELETE,
		f.OPERATTIME,
		f.OPERATOR,
		f.LONGITUDE,
		f.LATITUDE,
		bc.VIDEONAME,
		bc.CODE,
		bc.GBS_NUM,
		bc.VIDEOURL,
		f.CHECK_NO
		from
		<include refid="tableName"></include> f
		left join BUS_VIDEOMANAGER bc on bc.VIDEOMANAGER_ID = f.VIDEOMANAGER_ID and bc.ISDELETE = '0'
		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.CHECK_NO != null and pd.CHECK_NO != ''">
			and f.CHECK_NO = #{pd.CHECK_NO}
		</if>
		<if test="pd.CREATOR != null and pd.CREATOR != ''">
			and f.CREATOR = #{pd.CREATOR}
		</if>

		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
			(
			bc.VIDEONAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			or
			bc.GBS_NUM LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
			)
		</if>
		ORDER BY f.CREATTIME DESC
	</select>
	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		v.VIDEONAME,
		v.VIDEOURL,
		v.CODE,
		v.PLS_ID
		from
		<include refid="tableName"></include> f
		LEFT JOIN bus_videomanager v ON f.VIDEOMANAGER_ID = v.VIDEOMANAGER_ID and v.ISDELETE = 0
		where
		f.ISDELETE = 0
		 <if test="CORPINFO_ID != null and CORPINFO_ID != ''">
			and f.CORPINFO_ID = #{CORPINFO_ID}
		</if>
	</select>

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


</mapper>
