<?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.education.PersonObtainEvidenceMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.DEPARTMENT_ID,
		f.POST_ID,
		f.TYPE,
		f.PERSONNAME,
		f.CERTIFICATENAME,
		f.CERTIFICATENUMBER,
		f.EXPIRATIONDATE,
		f.REMINDERDATE,
		f.REMINDPEOPLE,
		f.IMGPATH,
		f.DESCR,
		f.CORPINFO_ID,
		f.CREATOR,
		f.CREATTIME,
		f.OPERATOR,
		f.OPERATTIME,
		f.ISDELETE,
		f.REMINDPEOPLEPHONE,
		f.ISNEAREXPIRATION,
		f.PERSONOBTAINEVIDENCE_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		DEPARTMENT_ID,
		POST_ID,
		TYPE,
		PERSONNAME,
		CERTIFICATENAME,
		CERTIFICATENUMBER,
		EXPIRATIONDATE,
		REMINDERDATE,
		REMINDPEOPLE,
		IMGPATH,
		DESCR,
		CORPINFO_ID,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		ISDELETE,
		REMINDPEOPLEPHONE,
		ISNEAREXPIRATION,
		PERSONOBTAINEVIDENCE_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{DEPARTMENT_ID},
		#{POST_ID},
		#{TYPE},
		#{PERSONNAME},
		#{CERTIFICATENAME},
		#{CERTIFICATENUMBER},
		#{EXPIRATIONDATE},
		#{REMINDERDATE},
		#{REMINDPEOPLE},
		#{IMGPATH},
		#{DESCR},
		#{CORPINFO_ID},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{ISDELETE},
		#{REMINDPEOPLEPHONE},
		#{ISNEAREXPIRATION},
		#{PERSONOBTAINEVIDENCE_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',
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME}
		where
			PERSONOBTAINEVIDENCE_ID = #{PERSONOBTAINEVIDENCE_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			DEPARTMENT_ID = #{DEPARTMENT_ID},
			POST_ID = #{POST_ID},
			TYPE = #{TYPE},
			PERSONNAME = #{PERSONNAME},
			CERTIFICATENAME = #{CERTIFICATENAME},
			CERTIFICATENUMBER = #{CERTIFICATENUMBER},
			EXPIRATIONDATE = #{EXPIRATIONDATE},
			REMINDERDATE = #{REMINDERDATE},
			REMINDPEOPLE = #{REMINDPEOPLE},
			<if test="IMGPATH != null and IMGPATH != ''"><!-- 关键词检索 -->
				IMGPATH = #{IMGPATH},
			</if>

			DESCR = #{DESCR},
			OPERATOR = #{OPERATOR},
			OPERATTIME = #{OPERATTIME},
			ISNEAREXPIRATION = #{ISNEAREXPIRATION},
			REMINDPEOPLEPHONE = #{REMINDPEOPLEPHONE},
			PERSONOBTAINEVIDENCE_ID = PERSONOBTAINEVIDENCE_ID
		where
			PERSONOBTAINEVIDENCE_ID = #{PERSONOBTAINEVIDENCE_ID}
	</update>

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

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>,
		d.NAME DEPTNAME,
		getFullName(d.DEPARTMENT_ID) DEPARTMENTNAME_ALL,
		p.NAME POSTNAME
		from
		<include refid="tableName"></include> f
		left join oa_department d on d.DEPARTMENT_ID = f.DEPARTMENT_ID
		left join sys_post p on p.POST_ID = f.POST_ID and p.STATUS = '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.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
			and
				(
					f.PERSONNAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
					 or
					f.CERTIFICATENAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
				)
		</if>
		<if test="pd.DEPARTMENT_ID != null and pd.DEPARTMENT_ID != ''"><!-- 关键词检索 -->
			and f.DEPARTMENT_ID = #{pd.DEPARTMENT_ID}
		</if>
		<if test="pd.POST_ID != null and pd.POST_ID != ''"><!-- 关键词检索 -->
			and f.POST_ID = #{pd.POST_ID}
		</if>
		<if test="pd.STARTTIME != null and pd.STARTTIME != ''"><!-- 关键词检索 -->
			and f.EXPIRATIONDATE &gt;= #{pd.STARTTIME}
		</if>
		<if test="pd.ENDTIME != null and pd.ENDTIME != ''">
			and f.EXPIRATIONDATE &lt;= #{pd.ENDTIME}
		</if>
		<if test="pd.STATE != null and pd.STATE != ''"><!-- 关键词检索 -->
			<choose>
		    	<when test="pd.STATE == 1">
		    		and f.EXPIRATIONDATE &lt; DATE_FORMAT(NOW(),'%Y-%m-%d')
			    </when>
		    	<when test="pd.STATE == 2">
		    		and f.REMINDERDATE &lt; DATE_FORMAT(NOW(),'%Y-%m-%d')
			    </when>
			</choose>
		</if>
		order by f.OPERATTIME desc
	</select>

	<!-- 列表(全部) -->
	<select id="listAll" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f where 1=1 and f.ISDELETE = '0'
	</select>

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

</mapper>
