<?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.iformall.mapper.WxFlowConfigMapper">

	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxFlowConfig">
		<id column="id" jdbcType="BIGINT" property="id" />
		<result column="tenantId" property="tenantId" />
		<result column="parent_id" property="parentId" />
		<result column="name" property="name" />
		<result column="type" property="type" />
		<result column="sort" property="sort" />
		<result column="model_id" property="modelId" />
		<result column="create_date" property="createDate" />
		<result column="update_date" property="updateDate" />

		<collection fetchType="eager" property="childs" ofType="WxFlowConfig" column="id" select="findChildList"/>
	</resultMap>


	<sql id="dynamicWhereConditions">
		where 1=1
		<if test=" null != parentId ">and `parent_id` = #{parentId}</if>
		<if test=" null != tenantId ">and `tenant_id` = #{tenantId}</if>
		<if test=" null != id "> and `id` = #{id} </if>
		<if test=" null != modelId"> and `model_id` = #{modelId} </if>
		<if test="null != name and '' != name "> and `name` like concat('%', #{name},'%') </if>
		<if test=" null != sortColumns"> order by ${sortColumns} </if>
		<if test=" null == sortColumns"> order by sort asc </if>
	</sql>

	<select id="findList" parameterType="com.iformall.domain.po.WxFlowConfig" resultMap="BaseResultMap">
		select * from wx_flow_config
		<include refid="dynamicWhereConditions" />
	</select>

	<select id="findChildList" resultType="WxFlowConfig">
		SELECT * FROM wx_flow_config WHERE parent_id = #{id} ORDER BY sort ASC
	</select>

	<update id="updateTime" parameterType="com.iformall.domain.po.WxFlowConfig">
		update wx_flow_config set update_date = now() where model_id = #{modelId}
	</update>




</mapper>
