<?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.jeeplus.modules.extension.mapper.FlowButtonMapper">

	<sql id="flowButtonColumns">
		a.id AS "id",
		a.name AS "name",
		a.code AS "code",
		a.ishide AS "isHide",
		a.next AS "next",
		a.sort AS "sort",
		a.task_def_id AS "taskDef.id"
	</sql>

	<sql id="flowButtonJoins">

			LEFT JOIN act_extension_taskdef b ON b.id = a.task_def_id
	</sql>


	<select id="get" resultType="FlowButton" >
		SELECT
			<include refid="flowButtonColumns"/>
		FROM act_extension_buttons a
		<include refid="flowButtonJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="FlowButton" >
		SELECT
			<include refid="flowButtonColumns"/>
		FROM act_extension_buttons a
		<include refid="flowButtonJoins"/>
		<where>

			${dataScope}
			<if test="name != null and name != ''">
				AND a.name = #{name}
			</if>
			<if test="code != null and code != ''">
				AND a.code = #{code}
			</if>
			<if test="isHide != null and isHide != ''">
				AND a.ishide = #{isHide}
			</if>
			<if test="next != null and next != ''">
				AND a.next = #{next}
			</if>
			<if test="taskDef != null and taskDef.id != null and taskDef.id != ''">
				AND a.task_def_id = #{taskDef.id}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.sort
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultType="FlowButton" >
		SELECT
			<include refid="flowButtonColumns"/>
		FROM act_extension_buttons a
		<include refid="flowButtonJoins"/>
		<where>

			${dataScope}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
			</otherwise>
		</choose>
	</select>

	<insert id="insert">
		INSERT INTO act_extension_buttons(
			id,
			name,
			code,
			ishide,
			next,
			sort,
			task_def_id
		) VALUES (
			#{id},
			#{name},
			#{code},
			#{isHide},
			#{next},
			#{sort},
			#{taskDef.id}
		)
	</insert>

	<update id="update">
		UPDATE act_extension_buttons SET
			name = #{name},
			code = #{code},
			ishide = #{isHide},
			next = #{next},
			sort = #{sort},
			task_def_id = #{taskDef.id}
		WHERE id = #{id}
	</update>


	<!--物理删除-->
	<update id="delete">
		DELETE FROM act_extension_buttons
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE task_def_id = #{taskDef.id}
			</otherwise>
		</choose>
	</update>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE act_extension_buttons SET
			del_flag = #{DEL_FLAG_DELETE}
		<choose>
			<when test="id !=null and id != ''">
				WHERE id = #{id}
			</when>
			<otherwise>
				WHERE task_def_id = #{taskDef.id}
			</otherwise>
		</choose>
	</update>


	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="FlowButton" statementType="STATEMENT">
		select * FROM act_extension_buttons  where ${propertyName} = '${value}'
	</select>

</mapper>
