<?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.hzya.frame.sys.apireflection.dao.impl.ApiReflectionDetailDaoImpl">
	<resultMap id="get-ApiReflectionDetailEntity-result" type="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		<!--主键id -->
		<result property="id" column="id" />
		<!--主表id -->
		<result property="mainid" column="mainid" />
		<!--源API字段 -->
		<result property="source_field" column="source_field" />
		<!--源API字段名 -->
		<result property="source_name" column="source_name" />
		<!--目标API字段 -->
		<result property="target_field" column="target_field" />
		<!--目标API字段名 -->
		<result property="target_name" column="target_name" />
		<!--目标API字段默认值 -->
		<result property="default_vaule" column="default_vaule" />
		<!--源字段层级 -->
		<result property="source_field_path" column="source_field_path" />
		<!--目标字段层级 -->
		<result property="target_field_path" column="target_field_path" />
		<!--创建时间 -->
		<result property="create_time" column="create_time" />
		<!--创建人 -->
		<result property="create_user_id" column="create_user_id" />
		<!--修改时间 -->
		<result property="modify_time" column="modify_time" />
		<!--修改人 -->
		<result property="modify_user_id" column="modify_user_id" />
		<!--状态 -->
		<result property="sts" column="sts" />
		<!--无备注 -->
		<result property="sorts" column="sorts" />
		<!--无备注 -->
		<result property="org_id" column="org_id" />
		<!--无备注 -->
		<result property="source_path" column="source_path" />
		<!--无备注 -->
		<result property="target_path" column="target_path" />
	</resultMap>

	<sql id="ApiReflectionDetailEntity_Base_Column_List">
		id,
		mainid,
		source_field,
		source_name,
		target_field,
		target_name,
		default_vaule,
		source_field_path,
		target_field_path,
		source_path,
		target_path,
		create_time,
		create_user_id,
		modify_time,
		modify_user_id,
		sts,
		sorts,
		org_id,
		coordinate
	</sql>

	<!--通过ID获取数据 -->
	<select id="entity_get" resultMap="get-ApiReflectionDetailEntity-result">
		select
		<include refid="ApiReflectionDetailEntity_Base_Column_List" />
		from sys_api_reflection_detail where id = #{id} and sts='Y'
	</select>

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-ApiReflectionDetailEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		select
		<include refid="ApiReflectionDetailEntity_Base_Column_List" />
		from sys_api_reflection_detail
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="mainid != null and mainid !='' "> and mainid = #{mainid}</if>
			<if test="coordinate != null and coordinate !='' "> and coordinate= #{coordinate} </if>
			<if test="source_field != null and source_field !='' "> and source_field = #{source_field}</if>
			<if test="source_name != null and source_name !='' "> and source_name = #{source_name}</if>
			<if test="target_field != null and target_field !='' "> and target_field = #{target_field}</if>
			<if test="target_name != null and target_name !='' "> and target_name = #{target_name}</if>
			<if test="default_vaule != null and default_vaule !='' "> and default_vaule = #{default_vaule}</if>
			<if test="source_field_path != null and source_field_path !='' "> and source_field_path = #{source_field_path}</if>
			<if test="target_field_path != null and target_field_path !='' "> and target_field_path = #{target_field_path}</if>
			<if test="source_path != null and source_path !='' "> and source_path = #{source_path} </if>
			<if test="target_path != null and target_path !='' "> and target_path = #{target_path }</if>
			<if test="create_time != null "> and create_time = #{create_time}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="modify_time != null "> and modify_time = #{modify_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
			<if test="sorts != null and sorts !='' "> and sorts = #{sorts}</if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id}</if>
			and sts='Y'
		</trim>
		<if test=" sort == null or sort == ''.toString() "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by ${sort} ${order}</if>
	</select>

	<!-- 查询符合条件的数量 -->
	<select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		select count(1) from sys_api_reflection_detail
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="mainid != null and mainid !='' "> and mainid = #{mainid} </if>
			<if test="coordinate != null and coordinate !='' "> and coordinate= #{coordinate} </if>
			<if test="source_field != null and source_field !='' "> and source_field = #{source_field} </if>
			<if test="source_name != null and source_name !='' "> and source_name = #{source_name} </if>
			<if test="target_field != null and target_field !='' "> and target_field = #{target_field} </if>
			<if test="target_name != null and target_name !='' "> and target_name = #{target_name} </if>
			<if test="default_vaule != null and default_vaule !='' "> and default_vaule = #{default_vaule} </if>
			<if test="source_field_path != null and source_field_path !='' "> and source_field_path = #{source_field_path} </if>
			<if test="target_field_path != null and target_field_path !='' "> and target_field_path = #{target_field_path} </if>
			<if test="source_path != null and source_path !='' "> and source_path = #{source_path} </if>
			<if test="target_path != null and target_path !='' "> and target_path = #{target_path }</if>
			<if test="create_time != null "> and create_time = #{create_time}  </if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id} </if>
			<if test="modify_time != null "> and modify_time = #{modify_time}  </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id} </if>
			<if test="sts != null and sts !='' "> and sts = #{sts} </if>
			<if test="sorts != null and sorts !='' "> and sorts = #{sorts} </if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id} </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null "> order by ${sort} ${order}</if>
	</select>

	<!-- 分页查询列表 采用like格式 -->
	<select id="entity_list_like" resultMap="get-ApiReflectionDetailEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		select
		<include refid="ApiReflectionDetailEntity_Base_Column_List" />
		from sys_api_reflection_detail
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="mainid != null and mainid !='' "> and mainid like concat('%',#{mainid},'%') </if>
			<if test="source_field != null and source_field !='' "> and source_field like concat('%',#{source_field},'%') </if>
			<if test="source_name != null and source_name !='' "> and source_name like concat('%',#{source_name},'%') </if>
			<if test="target_field != null and target_field !='' "> and target_field like concat('%',#{target_field},'%') </if>
			<if test="target_name != null and target_name !='' "> and target_name like concat('%',#{target_name},'%') </if>
			<if test="default_vaule != null and default_vaule !='' "> and default_vaule like concat('%',#{default_vaule},'%') </if>
			<if test="source_field_path != null and source_field_path !='' "> and source_field_path like concat('%',#{source_field_path},'%') </if>
			<if test="target_field_path != null and target_field_path !='' "> and target_field_path like concat('%',#{target_field_path},'%') </if>
			<if test="source_path != null and source_path !='' "> and source_path like concat('%',#{source_path},'%') </if>
			<if test="target_path != null and target_path !='' "> and target_path like concat('%',#{target_path},'%') </if>
			<if test="create_time != null and create_time !='' "> and create_time like concat('%',#{create_time},'%') </if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id like concat('%',#{create_user_id},'%') </if>
			<if test="modify_time != null and modify_time !='' "> and modify_time like concat('%',#{modify_time},'%') </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
			<if test="sts != null and sts !='' "> and sts like concat('%',#{sts},'%') </if>
			<if test="sorts != null and sorts !='' "> and sorts like concat('%',#{sorts},'%') </if>
			<if test="org_id != null and org_id !='' "> and org_id like concat('%',#{org_id},'%') </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>

	<!-- 查询列表 字段采用or格式 -->
	<select id="entity_list_or" resultMap="get-ApiReflectionDetailEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		select
		<include refid="ApiReflectionDetailEntity_Base_Column_List" />
		from sys_api_reflection_detail
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="mainid != null and mainid !='' "> or mainid = #{mainid} </if>
			<if test="coordinate != null and coordinate !='' "> or coordinate= #{coordinate} </if>
			<if test="source_field != null and source_field !='' "> or source_field = #{source_field} </if>
			<if test="source_name != null and source_name !='' "> or source_name = #{source_name} </if>
			<if test="target_field != null and target_field !='' "> or target_field = #{target_field} </if>
			<if test="target_name != null and target_name !='' "> or target_name = #{target_name} </if>
			<if test="default_vaule != null and default_vaule !='' "> or default_vaule = #{default_vaule} </if>
			<if test="source_field_path != null and source_field_path !='' "> or source_field_path = #{source_field_path} </if>
			<if test="target_field_path != null and target_field_path !='' "> or target_field_path = #{target_field_path} </if>
			<if test="source_path != null and source_path !='' "> or source_path = #{source_path} </if>
			<if test="target_path != null and target_path !='' "> or target_path = #{target_path} </if>
			<if test="create_time != null and create_time !='' "> or create_time = #{create_time} </if>
			<if test="create_user_id != null and create_user_id !='' "> or create_user_id = #{create_user_id} </if>
			<if test="modify_time != null and modify_time !='' "> or modify_time = #{modify_time} </if>
			<if test="modify_user_id != null and modify_user_id !='' "> or modify_user_id = #{modify_user_id} </if>
			<if test="sts != null and sts !='' "> or sts = #{sts} </if>
			<if test="sorts != null and sorts !='' "> or sorts = #{sorts} </if>
			<if test="org_id != null and org_id !='' "> or org_id = #{org_id} </if>
			and sts='Y'
		</trim>
		<if test=" sort ==''.toString() "> order by sorts asc</if>
		<if test=" sort !='' and sort!=null and order !='' and order!=null ">order by  ${sort} ${order}</if>
	</select>
	<!-- 新增 -->
	<insert id="entity_insert" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		insert into sys_api_reflection_detail(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="mainid != null and mainid !='' "> mainid, </if>
			<if test="coordinate != null and coordinate !='' "> coordinate, </if>
			<if test="source_field != null and source_field !='' "> source_field, </if>
			<if test="source_name != null and source_name !='' "> source_name, </if>
			<if test="target_field != null and target_field !='' "> target_field, </if>
			<if test="target_name != null and target_name !='' "> target_name, </if>
			<if test="default_vaule != null and default_vaule !='' "> default_vaule, </if>
			<if test="source_field_path != null and source_field_path !='' "> source_field_path, </if>
			<if test="source_path != null and source_path !='' "> source_path, </if>
			<if test="target_field_path != null and target_field_path !='' "> target_field_path, </if>
			<if test="target_path != null and target_path !='' "> target_path, </if>
			<if test="create_user_id != null and create_user_id !='' "> create_user_id, </if>
			<if test="modify_user_id != null and modify_user_id !='' "> modify_user_id, </if>
			<if test="sorts != null and sorts !='' "> sorts, </if>
			<if test="org_id != null and org_id !='' "> org_id, </if>
			<if test="sorts == null ">sorts,</if>
			create_time,
			modify_time,
			sts
		</trim>
		)values(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> #{id}, </if>
			<if test="mainid != null and mainid !='' "> #{mainid}, </if>
			<if test="coordinate != null and coordinate !='' "> #{coordinate}, </if>
			<if test="source_field != null and source_field !='' "> #{source_field}, </if>
			<if test="source_name != null and source_name !='' "> #{source_name}, </if>
			<if test="target_field != null and target_field !='' "> #{target_field}, </if>
			<if test="target_name != null and target_name !='' "> #{target_name}, </if>
			<if test="default_vaule != null and default_vaule !='' "> #{default_vaule}, </if>
			<if test="source_field_path != null and source_field_path !='' "> #{source_field_path}, </if>
			<if test="source_path != null and source_path !='' "> #{source_path}, </if>
			<if test="target_field_path != null and target_field_path !='' "> #{target_field_path}, </if>
			<if test="target_path != null and target_path !='' "> #{target_path}, </if>
			<if test="create_user_id != null and create_user_id !='' "> #{create_user_id}, </if>
			<if test="modify_user_id != null and modify_user_id !='' "> #{modify_user_id}, </if>
			<if test="sorts != null and sorts !='' "> #{sorts}, </if>
			<if test="org_id != null and org_id !='' "> #{org_id}, </if>
			<if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from sys_api_reflection_detail a WHERE a.sts = 'Y' ),</if>
			<if test="create_time != null "> #{create_time} ,</if>
			<if test="create_time  == null "> now(),</if>
			<if test="modify_time != null "> #{modify_time},</if>
			<if test="modify_time  == null "> now(),</if>
			'Y'
		</trim>
		)
	</insert>

	<!-- 修改 -->
	<update id="entity_update" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		update sys_api_reflection_detail set
		<trim suffix="" suffixOverrides=",">
			<if test="mainid != null and mainid !='' "> mainid = #{mainid},</if>
			<if test="coordinate != null and coordinate !='' ">coordinate= #{coordinate}, </if>
			<if test="source_field != null and source_field !='' "> source_field = #{source_field},</if>
			<if test="source_name != null and source_name !='' "> source_name = #{source_name},</if>
			<if test="target_field != null and target_field !='' "> target_field = #{target_field},</if>
			<if test="target_name != null and target_name !='' "> target_name = #{target_name},</if>
			<if test="default_vaule != null and default_vaule !='' "> default_vaule = #{default_vaule},</if>
			<if test="source_field_path != null and source_field_path !='' "> source_field_path = #{source_field_path},</if>
			<if test="source_path != null and source_path !='' "> source_path = #{source_path}, </if>
			<if test="target_field_path != null and target_field_path !='' "> target_field_path = #{target_field_path},</if>
			<if test="target_path != null and target_path !='' "> target_path = #{target_path}, </if>
			<if test="create_user_id != null and create_user_id !='' "> create_user_id = #{create_user_id},</if>
			<if test="modify_user_id != null and modify_user_id !='' "> modify_user_id = #{modify_user_id},</if>
			<if test="sorts != null and sorts !='' "> sorts = #{sorts},</if>
			<if test="org_id != null and org_id !='' "> org_id = #{org_id},</if>
			<if test="modify_time != null "> modify_time =#{modify_time}  </if>
			<if test="modify_time  == null "> modify_time = now()</if>
		</trim>
		where id = #{id}
	</update>

	<!-- 逻辑删除 -->
	<update id="entity_logicDelete" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		update sys_api_reflection_detail set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id} where
		id = #{id}
	</update>

	<!-- 逻辑删除多条件 -->
	<update id="ApiReflectionDetailEntity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		update sys_api_reflection_detail set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id}
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="mainid != null and mainid !='' "> and mainid = #{mainid}</if>
			<if test="coordinate != null and coordinate !='' ">coordinate= #{coordinate}, </if>
			<if test="source_field != null and source_field !='' "> and source_field = #{source_field}</if>
			<if test="source_name != null and source_name !='' "> and source_name = #{source_name}</if>
			<if test="target_field != null and target_field !='' "> and target_field = #{target_field}</if>
			<if test="target_name != null and target_name !='' "> and target_name = #{target_name}</if>
			<if test="default_vaule != null and default_vaule !='' "> and default_vaule = #{default_vaule}</if>
			<if test="source_field_path != null and source_field_path !='' "> and source_field_path = #{source_field_path}</if>
			<if test="target_field_path != null and target_field_path !='' "> and target_field_path = #{target_field_path}</if>
			<if test="source_path != null and source_path !='' "> and  source_path = #{source_path} </if>
			<if test="target_path != null and target_path !='' "> and target_path = #{target_path} </if>
			<if test="create_time != null and create_time !='' "> and create_time = #{create_time}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> and modify_time = #{modify_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="sts != null and sts !='' "> and sts = #{sts}</if>
			<if test="sorts != null and sorts !='' "> and sorts = #{sorts}</if>
			<if test="org_id != null and org_id !='' "> and org_id = #{org_id}</if>
		</trim>
	</update>

	<!-- 物理删除 -->
	<delete id="entity_delete" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		delete from sys_api_reflection_detail where id =#{id}
	</delete>

	<!--删除 修改时，先删除明细数据，然后再新增-->
	<update id="ApiReflectionDetailEntity_update_details" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDetailEntity">
		update sys_api_reflection_detail set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id} where
		mainid = #{mainid}
	</update>
</mapper>
