<?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.study.TempStudyUsersMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.TEMPSTUDY_ID,
		f.USER_ID,
		f.STATUS,
		f.STUDY_TIME,
		f.TEMPSTUDYUSERS_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		TEMPSTUDY_ID,
		USER_ID,
		STATUS,
		STUDY_TIME,
		TEMPSTUDYUSERS_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{TEMPSTUDY_ID},
		#{USER_ID},
		#{STATUS},
		#{STUDY_TIME},
		#{TEMPSTUDYUSERS_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">
		delete from
		<include refid="tableName"></include>
		where
		TEMPSTUDY_ID = #{TEMPSTUDY_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			TEMPSTUDY_ID = #{TEMPSTUDY_ID},
			USER_ID = #{USER_ID},
			STATUS = #{STATUS},
			STUDY_TIME = #{STUDY_TIME},
			TEMPSTUDYUSERS_ID = TEMPSTUDYUSERS_ID
		where
			TEMPSTUDYUSERS_ID = #{TEMPSTUDYUSERS_ID}
	</update>

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

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
			f.STATUS as STUDY_STATUS,
			f.STUDY_TIME,
			f.TEMPSTUDYUSERS_ID,
			u.NAME as USER_NAME,
			t.*
		from
		<include refid="tableName"></include> f
		left join BUS_TEMPSTUDY t on t.TEMPSTUDY_ID = f.TEMPSTUDY_ID
		left join BUS_STUDYSECTION s on s.STUDYSECTION_ID = t.COURSEWARE_ID
		left join SYS_USER u on u.USER_ID = f.USER_ID
		where t.ISDELETE = 0 and s.ISDELETE = 0
		<if test="pd.USER_ID != null and pd.USER_ID != ''"><!-- 关键词检索 -->
			and f.USER_ID = #{pd.USER_ID} and t.STATUS = 0
		</if>
		<if test="pd.TEMPSTUDY_ID != null and pd.TEMPSTUDY_ID != ''"><!-- 关键词检索 -->
			and t.TEMPSTUDY_ID = #{pd.TEMPSTUDY_ID}
		</if>
		order by t.CREATTIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
	</select>

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

</mapper>
