<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.workflow.dao.ProcessActUserDAO">
	<resultMap id="ProcessActUserMap" type="com.jpsoft.shinestar.modules.workflow.entity.ProcessActUser">
		<id property="id" column="id_" />
			<result property="activityId" column="activity_id" />
			<result property="userType" column="user_type" />
			<result property="personId" column="person_id" />
			<result property="departmentId" column="department_id" />
			<result property="personRoleId" column="person_role_id" />
			<result property="relativePosition" column="relative_position" />
			<result property="createBy" column="create_by" />
			<result property="createTime" column="create_time" />
			<result property="updateBy" column="update_by" />
			<result property="updateTime" column="update_time" />
			<result property="delFlag" column="del_flag" />
			<result property="source" column="source_" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcessActUser">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into wf_process_act_user
	    (id_,activity_id,user_type,person_id,department_id,person_role_id,relative_position,create_by,create_time,update_by,update_time,del_flag,source_)
		values
		(
#{id,jdbcType=VARCHAR}
,#{activityId,jdbcType=VARCHAR}
,#{userType,jdbcType=VARCHAR}
,#{personId,jdbcType=VARCHAR}
,#{departmentId,jdbcType=VARCHAR}
,#{personRoleId,jdbcType=VARCHAR}
,#{relativePosition,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{source,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from wf_process_act_user where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcessActUser">
		update wf_process_act_user
		<set>
				<if test="activityId!=null">
		activity_id=#{activityId,jdbcType=VARCHAR},
		</if>
				<if test="userType!=null">
		user_type=#{userType,jdbcType=VARCHAR},
		</if>
				<if test="personId!=null">
		person_id=#{personId,jdbcType=VARCHAR},
		</if>
				<if test="departmentId!=null">
		department_id=#{departmentId,jdbcType=VARCHAR},
		</if>
				<if test="personRoleId!=null">
		person_role_id=#{personRoleId,jdbcType=VARCHAR},
		</if>
				<if test="relativePosition!=null">
		relative_position=#{relativePosition,jdbcType=VARCHAR},
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
			<if test="source!=null">
				source_=#{source,jdbcType= NUMERIC },
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="ProcessActUserMap">
		select * from wf_process_act_user where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from wf_process_act_user where id_=#{0}
	</select>
	<select id="list" resultMap="ProcessActUserMap">
		select * from wf_process_act_user
	</select>
	<select id="findByActivityId" resultMap="ProcessActUserMap">
		select * from wf_process_act_user where del_flag=false and activity_id = #{0}
	</select>
	<select id="findByActIdAndUserType" resultType="String">
		select person_id from wf_process_act_user where del_flag=false and activity_id = #{actId} and user_type = #{userType}
	</select>
	<select id="findItemByActIdAndUserType" resultMap="ProcessActUserMap">
		select * from wf_process_act_user where del_flag=false and activity_id = #{actId} and user_type = #{userType}
	</select>
	<select id="findRelativePositionByActIdAndUserType" resultType="String">
		select relative_position from wf_process_act_user where del_flag=false and activity_id = #{actId} and user_type = #{userType}
	</select>
	<select id="findItemByActIdAndUserTypeAndSource" resultMap="ProcessActUserMap">
		select * from wf_process_act_user where del_flag=false and activity_id = #{actId} and user_type = #{userType} and source_ = #{source}
	</select>


	<select id="search" parameterType="hashmap" resultMap="ProcessActUserMap">
		<![CDATA[
			select * from wf_process_act_user
		]]>
		<where>
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByActivityIdAndUserType" resultMap="ProcessActUserMap">
		<![CDATA[
		select  * from wf_process_act_user
		where del_flag = 0
		and activity_id = #{activityId}
		and user_type = #{userType}
		]]>
	</select>
</mapper>