<?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.ProcinstActivityDAO">
	<resultMap id="ProcinstActivityMap" type="com.jpsoft.shinestar.modules.workflow.entity.ProcinstActivity">
		<id property="id" column="id_" />
			<result property="procinstId" column="procinst_id" />
			<result property="activityIndex" column="activity_index" />
			<result property="activityId" column="activity_id" />
			<result property="action" column="action_" />
			<result property="status" column="status_"/>
			<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.ProcinstActivity">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into wf_procinst_activity
	    (id_,procinst_id,activity_index,activity_id,action_,status_,remark_,finish_time,create_by,create_time,update_by,update_time,del_flag)
		values
		(
#{id,jdbcType=VARCHAR}
,#{procinstId,jdbcType=VARCHAR}
,#{activityIndex,jdbcType= NUMERIC }
,#{activityId,jdbcType=VARCHAR}
,#{action,jdbcType=VARCHAR}
,#{status,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_activity where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcinstActivity">
		update wf_procinst_activity
		<set>
				<if test="procinstId!=null">
		procinst_id=#{procinstId,jdbcType=VARCHAR},
		</if>
				<if test="activityIndex!=null">
		activity_index=#{activityIndex,jdbcType= NUMERIC },
		</if>
				<if test="activityId!=null">
		activity_id=#{activityId,jdbcType=VARCHAR},
		</if>
				<if test="action!=null">
		action_=#{action,jdbcType=VARCHAR},
		</if>
			<if test="status!=null">
				status_=#{status,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="ProcinstActivityMap">
		select *	from wf_procinst_activity where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from wf_procinst_activity where id_=#{0}
	</select>
	<select id="list" resultMap="ProcinstActivityMap">
		select * from wf_procinst_activity
	</select>
	<select id="search" parameterType="hashmap" resultMap="ProcinstActivityMap">
		<![CDATA[
			select * from wf_procinst_activity
		]]>
		<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="searchRecode" parameterType="hashmap" resultMap="ProcinstActivityMap">
		<![CDATA[
			select * from wf_procinst_activity a inner join wf_procinst b on a.procinst_id = b.id_
		]]>
		<where>
			<if test="searchParams.businessKey != null">
				and b.business_key = #{searchParams.businessKey}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>

	<select id="findByProcinstId" resultMap="ProcinstActivityMap">
		<![CDATA[
		select * from wf_procinst_activity
		where del_flag = 0
		and procinst_id = #{procinstId}
		order by activity_index asc
		]]>
	</select>

	<select id="findByActivityIndexAndActivityId" resultMap="ProcinstActivityMap">
		<![CDATA[
		select * from wf_procinst_activity
		where del_flag = 0
		and activity_index = #{activityIndex}
		and activity_id = #{activityId}
		limit 1
		]]>
	</select>

	<select id="findProcinstIdAndAction" resultMap="ProcinstActivityMap">
		<![CDATA[
		select  * from wf_procinst_activity
		where del_flag = 0
		and procinst_id = #{procinstId}
		and action_ = #{action}
		]]>
	</select>

	<select id="findByActivityIndexAndProcinstId" resultMap="ProcinstActivityMap">
		<![CDATA[
		select * from wf_procinst_activity
		where del_flag = 0
		and activity_index = #{activityIndex}
		and procinst_id = #{procinstId}
		limit 1
		]]>
	</select>
	<select id="findProcinstIdAndStatus" resultMap="ProcinstActivityMap">
		<![CDATA[
		select  * from wf_procinst_activity
		where del_flag = 0
		and procinst_id = #{procinstId}
		and status_ = #{status}
		limit 1
		]]>
	</select>
</mapper>