<?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.ProcessActivityDAO">
	<resultMap id="ProcessActivityMap" type="com.jpsoft.shinestar.modules.workflow.entity.ProcessActivity">
		<id property="id" column="id_" />
			<result property="activityOrder" column="activity_order" />
			<result property="processTemplateId" column="process_template_id" />
			<result property="name" column="name_" />
			<result property="remark" column="remark_" />
			<result property="operation" column="operation_" />
			<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="personRoleId" column="person_role_id" />
			<result property="condition" column="condition_" />

			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcessActivity">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into wf_process_activity
	    (id_,activity_order,process_template_id,name_,remark_,operation_,create_by,create_time,update_by,update_time,del_flag,person_role_id,condition_)
		values
		(
#{id,jdbcType=VARCHAR}
,#{activityOrder,jdbcType= NUMERIC }
,#{processTemplateId,jdbcType=VARCHAR}
,#{name,jdbcType=VARCHAR}
,#{remark,jdbcType=VARCHAR}
,#{operation,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{personRoleId,jdbcType=VARCHAR}
,#{condition,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from wf_process_activity where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.workflow.entity.ProcessActivity">
		update wf_process_activity
		<set>
				<if test="activityOrder!=null">
		activity_order=#{activityOrder,jdbcType= NUMERIC },
		</if>
				<if test="processTemplateId!=null">
		process_template_id=#{processTemplateId,jdbcType=VARCHAR},
		</if>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="remark!=null">
		remark_=#{remark,jdbcType=VARCHAR},
		</if>
				<if test="operation!=null">
		operation_=#{operation,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="personRoleId!=null">
				person_role_id=#{personRoleId,jdbcType=VARCHAR},
			</if>
			<if test="condition!=null">
				condition_=#{condition,jdbcType=VARCHAR},
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="ProcessActivityMap">
		select * from wf_process_activity where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from wf_process_activity where id_=#{0}
	</select>
	<select id="list" resultMap="ProcessActivityMap">
		select * from wf_process_activity
	</select>
	<select id="findByTemplate" resultMap="ProcessActivityMap">
		select * from wf_process_activity where del_flag=false and process_template_id = #{0} order by activity_order desc
	</select>
	<select id="findByTemplateId" resultMap="ProcessActivityMap">
		select * from wf_process_activity where del_flag=false and process_template_id = #{templateId} and person_role_id=#{personRoleId} order by activity_order desc
	</select>
	<select id="findByActivityOrder" resultMap="ProcessActivityMap">
		select * from wf_process_activity where del_flag = false and activity_order = #{0} limit 1
	</select>

	<select id="search" parameterType="hashmap" resultMap="ProcessActivityMap">
		<![CDATA[
			select * from wf_process_activity
		]]>
		<where>
			del_flag = false
			<if test="searchParams.processTemplateId != null">
				and process_template_id like #{searchParams.processTemplateId}
			</if>
			<if test="searchParams.personRoleId != null">
				and person_role_id = #{searchParams.personRoleId}
			</if>

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

	<select id="findByActivityOrderProcessTemplateId" resultMap="ProcessActivityMap">
		<![CDATA[
		select * from wf_process_activity
		where del_flag = 0
		and activity_order = #{activityOrder}
		and process_template_id = #{processTemplateId}
		and person_role_id = #{personRoleId}
		]]>
	</select>

	<select id="findByTemplateIdAndRoleId" resultMap="ProcessActivityMap">
		<![CDATA[
		select * from wf_process_activity
		where del_flag = 0
		and process_template_id = #{processTemplateId}
		and person_role_id = #{personRoleId}
		]]>
	</select>

	<select id="findByTemplateIdAndRoleIdAndCondition" resultMap="ProcessActivityMap">
		<![CDATA[
		select * from wf_process_activity
		where del_flag = 0
		and process_template_id = #{processTemplateId}
		and person_role_id = #{personRoleId}
		and condition_ = #{condition}
		]]>
	</select>
</mapper>