<?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.zcloud.mapper.datasource.eightwork.EightWorkTaskFlowMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_EIGHTWORK_TASK_FLOW
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		f.FLOW_ID,
		f.TASK_ID,
		f.STEP_ID,
		f.NEXT_STEP_ID,
		f.ACTOR_FIELD,
		f.ORDER_BY
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		FLOW_ID,
		TASK_ID,
		STEP_ID,
		NEXT_STEP_ID,
		ACTOR_FIELD,
		ORDER_BY
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{FLOW_ID},
		#{TASK_ID},
		#{STEP_ID},
		#{NEXT_STEP_ID},
		#{ACTOR_FIELD},
		#{ORDER_BY}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<select id="getStep" parameterType="pd" resultType="pd" >
		select
			<include refid="Field"></include>,
			ns.STEP_NAME as NEXT_STEP_NAME,
		    n.ACTOR_FIELD as NEXT_ACTOR_FIELD,
		    n.CAN_SKIP
		from
			<include refid="tableName"></include> f
		left join
			<include refid="tableName"></include> n
		on
			f.NEXT_STEP_ID = n.STEP_ID and f.TASK_ID = n.TASK_ID
		left join bus_eightwork_step ns on ns.STEP_ID = f.NEXT_STEP_ID
		where
			f.TASK_ID = #{TASK_ID}
		and
			f.STEP_ID = #{STEP_ID}
	</select>

	<select id="getTaskSetps" parameterType="pd" resultType="pd" >
		select
		<include refid="Field"></include>,
		step.STEP_NAME
		from
		<include refid="tableName"></include> f
		left join bus_eightwork_step step on f.STEP_ID = step.STEP_ID
		where
		f.TASK_ID = #{TASK_ID}
		order by f.ORDER_BY
	</select>

</mapper>
