<?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.system.UserInfoMapper">

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

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

	<!-- 字段 -->
	<sql id="Field">
		f.NATION,
		f.SEX,
		f.POLITICAL_OUTLOOK,
		f.DATE_OF_BIRTH,
		f.DEGREE_OF_EDUCATION,
		f.DUTIES,
		f.TYPE_OF_WORK,
		f.ENTRY_DATE,
		f.WORKING_DATE,
		f.INCUMBENCY,
		f.ISSTATE,
		f.TITLE,
		f.PERSONNEL_TYPE,
		f.USER_ID_CARD,
		f.USER_SIGN_FILE_PATH,
		f.IS_RECORDER,
		f.IS_CHARGE,
		f.USER_ID
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		NATION,
		SEX,
		POLITICAL_OUTLOOK,
		DATE_OF_BIRTH,
		DEGREE_OF_EDUCATION,
		DUTIES,
		TYPE_OF_WORK,
		ENTRY_DATE,
		WORKING_DATE,
		INCUMBENCY,
		ISSTATE,
		TITLE,
		PERSONNEL_TYPE,
		USER_ID_CARD,
		USER_SIGN_FILE_PATH,
		IS_RECORDER,
		IS_CHARGE,
		USER_ID
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{NATION},
		#{SEX},
		#{POLITICAL_OUTLOOK},
		#{DATE_OF_BIRTH},
		#{DEGREE_OF_EDUCATION},
		#{DUTIES},
		#{TYPE_OF_WORK},
		#{ENTRY_DATE},
		#{WORKING_DATE},
		#{INCUMBENCY},
		#{ISSTATE},
		#{TITLE},
		#{PERSONNEL_TYPE},
		#{USER_ID_CARD},
		#{USER_SIGN_FILE_PATH},
		#{IS_RECORDER},
		#{IS_CHARGE},
		#{USER_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-->
<!--			USER_ID = #{USER_ID}-->
		delete from SYS_USERINFO  where USER_ID = #{USER_ID}
	</delete>

	<!-- 修改 -->
	<update id="edit" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
			NATION = #{NATION},
			SEX = #{SEX},
			POLITICAL_OUTLOOK = #{POLITICAL_OUTLOOK},
			DATE_OF_BIRTH = #{DATE_OF_BIRTH},
			DEGREE_OF_EDUCATION = #{DEGREE_OF_EDUCATION},
			DUTIES = #{DUTIES},
			TYPE_OF_WORK = #{TYPE_OF_WORK},
			ENTRY_DATE = #{ENTRY_DATE},
			WORKING_DATE = #{WORKING_DATE},
			INCUMBENCY = #{INCUMBENCY},
			ISSTATE = #{ISSTATE},
			TITLE = #{TITLE},
			USER_ID = USER_ID
		where
			USER_ID = #{USER_ID}
	</update>

	<!-- 通过ID获取数据 -->
	<select id="findById" parameterType="pd" resultType="pd">
		select
		<include refid="Field"></include>,
		n.NAME AS NATION_NAME,
		p.NAME AS POLITICAL_OUTLOOK_NAME,
		d.NAME AS DEGREE_OF_EDUCATION_NAME,
		du.NAME AS DUTIES_NAME,
		w.NAME AS TYPE_OF_WORK_NAME,
		pt.NAME AS PERSONNEL_TYPE_NAME

		from
		<include refid="tableName"></include> f
		left join SYS_DICTIONARIES n on n.DICTIONARIES_ID = f.NATION
		left join SYS_DICTIONARIES p on p.DICTIONARIES_ID = f.POLITICAL_OUTLOOK
		left join SYS_DICTIONARIES d on d.DICTIONARIES_ID = f.DEGREE_OF_EDUCATION
		left join SYS_DICTIONARIES_CORP du on du.DICTIONARIES_ID = f.DUTIES
		left join SYS_DICTIONARIES_CORP w on w.DICTIONARIES_ID = f.TYPE_OF_WORK
		left join SYS_DICTIONARIES pt on pt.DICTIONARIES_ID = f.PERSONNEL_TYPE
		where
			f.USER_ID = #{USER_ID}
	</select>

	<!-- 列表 -->
	<select id="datalistPage" parameterType="page" resultType="pd">
		select
		<include refid="Field"></include>
		from
		<include refid="tableName"></include> f
		where f.ISDELETE = '0'
		<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
		<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
			USER_ID in
		<foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
                 #{item}
		</foreach>
	</delete>


	<!--清除人员字典信息（职务、职称、工种） -->
	<update id="clearDict" parameterType="pd" >
		update
		<include refid="tableName"></include>
		SET
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'POSITION'"><!-- 职务 -->
			DUTIES = NULL
		</if>
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'JOB_TITLE'"><!-- 职称 -->
			TITLE = NULL
		</if>
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'WORK_TYPE'"><!-- 工种 -->
			TYPE_OF_WORK = NULL
		</if>
		where
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'POSITION'"><!-- 职务 -->
			DUTIES = #{DICTIONARIES_ID}
		</if>
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'JOB_TITLE'"><!-- 职称 -->
			TITLE = #{DICTIONARIES_ID}
		</if>
		<if test="DICTTYPE != null and DICTTYPE != '' and DICTTYPE == 'WORK_TYPE'"><!-- 工种 -->
			TYPE_OF_WORK = #{DICTIONARIES_ID}
		</if>
	</update>
	<!-- 修改 -->
	<update id="editUserSign" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		USER_SIGN_FILE_PATH = #{USER_SIGN_FILE_PATH}
		where
		USER_ID = #{USER_ID}
	</update>
	<update id="editUserSignType" parameterType="pd">
		update
		<include refid="tableName"></include>
		set
		<if test="IS_RECORDER != null and IS_RECORDER != ''">
			IS_RECORDER = #{IS_RECORDER},
		</if>
		<if test="IS_CHARGE != null and IS_CHARGE != ''">
			IS_CHARGE = #{IS_CHARGE},
		</if>
		USER_ID = #{USER_ID}
		where
		USER_ID = #{USER_ID}
	</update>
</mapper>
