<?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.notice.NoticeLogMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.USER_ID,
		f.NOTICE_ID,
		f.NOTICE,
		f.STATUS,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.NOTICELOG_ID,
		c.SYNOPSIS,
		c.CONTENT,
		d.NAME AS USER_NAME
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		USER_ID,
		NOTICE_ID,
		NOTICE,
		STATUS,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		ISDELETE,
		NOTICELOG_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{USER_ID},
		#{NOTICE_ID},
		#{NOTICE},
		#{STATUS},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{ISDELETE},
		#{NOTICELOG_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
			NOTICELOG_ID = #{NOTICELOG_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			USER_ID = #{USER_ID},
			NOTICE_ID = #{NOTICE_ID},
			NOTICE = #{NOTICE},
			STATUS = #{STATUS},
			CREATOR = #{CREATOR},
			CREATTIME = #{CREATTIME},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			ISDELETE = #{ISDELETE},
			NOTICELOG_ID = NOTICELOG_ID
		where
			NOTICELOG_ID = #{NOTICELOG_ID}
	</update>

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

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		left join BUS_NOTICE c on c.NOTICE_ID=f.NOTICE_ID
		left join SYS_USER d on d.USER_ID = f.USER_ID
		where f.ISDELETE = '0'
		<if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					f.NOTICE LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					 or
					f.USER_ID LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
		<if test="pd.USER_ID!=null and pd.USER_ID!=''"><!-- 根据用户名过滤 -->
			and f.USER_ID = #{pd.USER_ID}
		</if>
		order by c.ISTOP desc, f.CREATTIME desc

	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field2"></include>
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0' and f.STATUS='0'
		<if test="USER_ID != null and USER_ID != ''"><!-- 用户 -->
			and
				f.USER_ID = #{USER_ID}
		</if>
		<if test="NOTICE_ID != null and NOTICE_ID != ''"><!-- 通知 -->
			and
				f.NOTICE_ID = #{NOTICE_ID}
		</if>
	</select>

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

	<!-- 批量删除 -->
	<delete id="deleteAllByNoticeId" parameterType="pd">
		update
		<include refid="tableName"></include> f
		set
			ISDELETE = '1'
		where
			f.NOTICE_ID = #{NOTICE_ID}
	</delete>

</mapper>
