<?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.ProcinstActUserDAO">
	<resultMap id="ProcinstActUserMap" type="com.jpsoft.shinestar.modules.workflow.entity.ProcinstActUser">
		<id property="id" column="id_" />
			<result property="procinstActivityId" column="procinst_activity_id" />
			<result property="userId" column="user_id" />
			<result property="action" column="action_"/>
			<result property="type" column="type_"/>
			<result property="remark" column="remark_" />
			<result property="finishTime" column="finish_time" />
			<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" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcinstActUser">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into wf_procinst_act_user
	    (id_,procinst_activity_id,user_id,action_,type_,remark_,finish_time,create_by,create_time,update_by,update_time,del_flag)
		values
		(
#{id,jdbcType=VARCHAR}
,#{procinstActivityId,jdbcType=VARCHAR}
,#{userId,jdbcType=VARCHAR}
,#{action,jdbcType=VARCHAR}
,#{type,jdbcType=VARCHAR}
,#{remark,jdbcType=VARCHAR}
,#{finishTime,jdbcType= TIMESTAMP }
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from wf_procinst_act_user where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcinstActUser">
		update wf_procinst_act_user
		<set>
				<if test="procinstActivityId!=null">
		procinst_activity_id=#{procinstActivityId,jdbcType=VARCHAR},
		</if>
				<if test="userId!=null">
		user_id=#{userId,jdbcType=VARCHAR},
		</if>
			<if test="action!=null">
				action_=#{action,jdbcType=VARCHAR},
			</if>
			<if test="type!=null">
				type_=#{type,jdbcType=VARCHAR},
			</if>
				<if test="remark!=null">
		remark_=#{remark,jdbcType=VARCHAR},
		</if>
				<if test="finishTime!=null">
		finish_time=#{finishTime,jdbcType= TIMESTAMP },
		</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>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="ProcinstActUserMap">
		select  *	from wf_procinst_act_user where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from wf_procinst_act_user where id_=#{0}
	</select>
	<select id="list" resultMap="ProcinstActUserMap">
		select * from wf_procinst_act_user
	</select>
	<select id="search" parameterType="hashmap" resultMap="ProcinstActUserMap">
		<![CDATA[
			select a.* from wf_procinst_act_user a
			left join wf_procinst_activity b on a.procinst_activity_id = b.id_
			left join wf_procinst c on b.procinst_id = c.id_
			left join base_person_info d on c.person_id = d.id_
		]]>
		<where>
			a.del_flag = 0
			and b.del_flag = 0
			and c.del_flag = 0
			<if test="searchParams.id != null">
				and ID_ like #{searchParams.id}
			</if>
			<if test="searchParams.procinstType != null">
				and c.type_ = #{searchParams.procinstType}
			</if>
			<if test="searchParams.status != null">
				and b.status_ = #{searchParams.status}
			</if>
			<if test="searchParams.name != null">
				and d.name_ like #{searchParams.name}
			</if>
			<if test="searchParams.userId != null">
				and a.user_id = #{searchParams.userId}
			</if>
			<if test="searchParams.action != null">
				and a.action_ = #{searchParams.action}
			</if>
			<if test="searchParams.noAction != null">
				and a.action_ != #{searchParams.noAction}
			</if>
			<if test="searchParams.type != null">
				and a.type_ = #{searchParams.type}
			</if>
			<if test="searchParams.businessKey != null">
				and c.business_key = #{searchParams.businessKey}
			</if>
			<if test="searchParams.procinstId != null">
				and b.procinst_id = #{searchParams.procinstId}
			</if>
			<if test="searchParams.activityOrder != null">
				and b.activity_index = #{searchParams.activityOrder}
			</if>

		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>

	<select id="findByProcinstActivityId" resultMap="ProcinstActUserMap">
		<![CDATA[
		select * from wf_procinst_act_user
		where del_flag = 0
		and procinst_activity_id = #{procinstActivityId}
		]]>
	</select>

	<select id="findByProcinstActivityIdActionType" resultMap="ProcinstActUserMap">
		<![CDATA[
		select * from wf_procinst_act_user
		]]>
		<where>
			del_flag = 0
			<if test=" procinstActivityId!= null">
				and procinst_activity_id = #{procinstActivityId}
			</if>
			<if test=" action!= null">
				and action_ = #{action}
			</if>
			<if test=" type!= null">
				and type_ = #{type}
			</if>
		</where>

	</select>
</mapper>