<?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.jeeplus.modules.sg.managementcenter.activiti.mapper.ProcessPersonnelMapper">

	<select id="get" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.PersonnelManagement" >
		SELECT *
		FROM xm_process_personnel a
		WHERE a.uId = #{uId}
	</select>
	
	<select id="findList" resultType="PersonnelManagement" >
		SELECT *
		FROM xm_process_personnel a
		<where>
			<if test="dataScope != null and dataScope != ''">
				${dataScope}
			</if>
			<if test="uId != null and uId != ''">
				AND a.uId = #{uId}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="PersonnelManagement" >
		SELECT *
		FROM xm_process_personnel a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO xm_process_personnel(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			proc_ins_id,
			projectManager,
			operatingPersonnel,
			theDesigner,
			fullStaff,
			administrative,
			ruralCivil
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{procInsId},
			#{projectManager},
			#{operatingPersonnel},
			#{theDesigner},
			#{fullStaff},
			#{administrative},
			#{ruralCivil}
		)
	</insert>

	<update id="update">
		UPDATE xm_process_personnel
		<set>
		<if test="updateBy.id!=null and updateBy.id!=''">
			update_by = #{updateBy.id},
		</if>
		<if test="updateDate!=null and updateDate=''">
			update_date = #{updateDate},
		</if>
		<if test="remarks!=null and remarks!=''">
			remarks = #{remarks},
		</if>
		<if test="projectManager!=null and projectManager!=''">
			projectManager = #{projectManager},
		</if>
		<if test="operatingPersonnel!=null and operatingPersonnel!=''">
			operatingPersonnel = #{operatingPersonnel},
		</if>
		<if test="theDesigner!=null and theDesigner!=''">
			theDesigner = #{theDesigner},
		</if>
		<if test="fullStaff!=null and fullStaff!=''">
			fullStaff = #{fullStaff},
		</if>
		<if test="administrative!=null and administrative!=''">
			administrative = #{administrative},
		</if>
		<if test="ruralCivil!=null and ruralCivil!=''">
			ruralCivil = #{ruralCivil}
		</if>
		</set>
		WHERE proc_ins_id=#{procInsId}
	</update>

	<!--物理删除-->
	<update id="delete">
		DELETE FROM xm_process_personnel
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE xm_process_personnel SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>

	<select id="findLoginName" resultType="com.jeeplus.modules.sg.managementcenter.activiti.entity.ProcessPersonnel">
		select * from xm_process_personnel where proc_ins_id  =#{procInsId};
	</select>

	<update id="newUpdate">
		UPDATE xm_process_personnel
		<set>
			<if test="projectManager!=null and projectManager!=''">
				projectManager = #{projectManager},
			</if>
			<if test="operatingPersonnel!=null and operatingPersonnel!=''">
				operatingPersonnel = #{operatingPersonnel},
			</if>
			<if test="theDesigner!=null and theDesigner!=''">
				theDesigner = #{theDesigner},
			</if>
			<if test="fullStaff!=null and fullStaff!=''">
				fullStaff = #{fullStaff},
			</if>
			<if test="administrative!=null and administrative!=''">
				administrative = #{administrative},
			</if>
			<if test="ruralCivil!=null and ruralCivil!=''">
				ruralCivil = #{ruralCivil}
			</if>
		</set>
		WHERE proc_ins_id=#{procInsId}
	</update>

	
</mapper>