<?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.ApiReflectionDaoImpl">
	<resultMap id="get-ApiReflectionEntity-result" type="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		<!--主键id -->
		<result property="id" column="id" />
		<!--源接口ID -->
		<result property="source_api_id" column="source_api_id" />
		<!--目标接口ID -->
		<result property="target_api_id" column="target_api_id" />
		<!--备注 -->
		<result property="remark" column="remark" />
		<!--操作人id -->
		<result property="create_user_id" column="create_user_id" />
		<!--保存时间 -->
		<result property="create_time" column="create_time" />
		<!--修改人 -->
		<result property="modify_user_id" column="modify_user_id" />
		<!--修改时间 -->
		<result property="modify_time" column="modify_time" />
		<!--状态 -->
		<result property="sts" column="sts" />
		<!--排序 -->
		<result property="sorts" column="sorts" />
		<!--无备注 -->
		<result property="org_id" column="org_id" />
		<!--无备注 -->
		<result property="source_api_app" column="source_api_app" />
		<!--无备注 -->
		<result property="target_api_app" column="target_api_app" />
		<!--无备注 -->
		<result property="ref_code" column="ref_code" />
		<!--无备注 -->
		<result property="ref_name" column="ref_name" />
		<!--无备注 -->
		<result property="ref_type" column="ref_type" />
		<!--无备注 -->
		<result property="description" column="description" />
		<!--是否插件 -->
		<result property="plug" column="plug" />
		<!--插件id -->
		<result property="plug_id" column="plug_id" />
	</resultMap>
<!--关联查sys_app_api表-->
	<resultMap id="get-ApiReflectionView-result" type="com.hzya.frame.sys.apireflection.entity.ApiReflectionDTO">
		<result property="ref_id" column="ref_id" />
		<result property="source_api_id" column="source_api_id" />
		<result property="target_api_id" column="target_api_id" />
		<result property="source_api" column="source_api" />
		<result property="target_api" column="target_api" />
		<result property="source_body_in" column="source_body_in" />
		<result property="source_body_out" column="source_body_out" />
		<result property="source_header" column="source_header" />
		<result property="source_query" column="source_query" />
		<result property="target_body_in" column="target_body_in" />
		<result property="target_body_out" column="target_body_out" />
		<result property="target_header" column="target_header" />
		<result property="target_query" column="target_query" />
		<result property="source_method" column="source_method" />
		<result property="target_method" column="target_method" />
		<result property="need_login" column="need_login" />
		<result property="authentication_port" column="authentication_port" />
		<result property="source_timeout" column="source_timeout" />
		<result property="target_timeout" column="target_timeout" />
	</resultMap>
	<sql id="ApiReflectionEntity_Base_Column_List">
		id,
		source_api_id,
		target_api_id,
		remark,
		create_user_id,
		create_time,
		modify_user_id,
		modify_time,
		sts,
		sorts,
		org_id,
		source_api_app,
		target_api_app,
		ref_code,
		ref_name,
		ref_type,
		description,
		plug,
		plug_id
	</sql>

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

	<!-- 查询 采用==查询 -->
	<select id="entity_list_base" resultMap="get-ApiReflectionEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		select
		<include refid="ApiReflectionEntity_Base_Column_List" />
		from sys_api_reflection
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="source_api_id != null and source_api_id !='' "> and source_api_id = #{source_api_id}</if>
			<if test="target_api_id != null and target_api_id !='' "> and target_api_id = #{target_api_id}</if>
			<if test="remark != null and remark !='' "> and remark = #{remark}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null "> and modify_time = #{modify_time}</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>
			<if test="source_api_app != null and source_api_app !='' "> and source_api_app = #{source_api_app}</if>
			<if test="target_api_app != null and target_api_app !='' "> and target_api_app = #{target_api_app}</if>
			<if test="ref_code != null and ref_code !='' "> and ref_code = #{ref_code}</if>
			<if test="ref_name != null and ref_name !='' "> and ref_name = #{ref_name}</if>
			<if test="ref_type != null and ref_type !='' "> and ref_type = #{ref_type}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="plug != null and plug !='' "> and plug = #{plug}</if>
			<if test="plug_id != null and plug_id !='' "> and plug_id = #{plug_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="ApiReflectionEntity_list_view" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionDTO" resultMap="get-ApiReflectionView-result">
        SELECT
        ref.id as ref_id,
        ref.source_api_id,
        ref.target_api_id,
        s.destination_address as source_api,
	    t.destination_address as target_api,
        IF(s.body_in = '[]',NULL,s.body_in) as source_body_in,
        IF(s.body_out = '[]',NULL,s.body_out) as source_body_out,
	    IF(s.header_in = '[]',NULL,s.header_in) as source_header,
	    IF(s.query_in = '[]',NULL,s.query_in) as source_query,
	    IF(t.body_in = '[]',NULL,t.body_in) as target_body_in,
	    IF(t.body_out = '[]',NULL,t.body_out) as target_body_out,
	    IF(t.header_in = '[]',NULL,t.header_in) as target_header,
	    IF(t.query_in = '[]',NULL,t.query_in) as target_query,
        sd.column_content as source_method,
        td.column_content as target_method,
        t.need_login,
	    t.authentication_port,
	    s.timeout_period as source_timeout,
		t.timeout_period as target_timeout
    FROM
        sys_api_reflection ref
        LEFT JOIN sys_app_api s ON s.id = ref.source_api_id
        LEFT JOIN sys_app_api t ON t.id = ref.target_api_id
        LEFT JOIN sys_dictionaryshop_new sd on sd.column_value = s.request_method and sd.tab_name = 'sys_app_api' and sd.column_name = 'request_method'
        LEFT JOIN sys_dictionaryshop_new td on td.column_value = t.request_method and td.tab_name = 'sys_app_api' and td.column_name = 'request_method'
    <trim prefix="where" prefixOverrides="and">
			<if test="ref_id != null and ref_id !='' ">ref.id = #{ref_id} </if>
			<if test="source_api_id != null and source_api_id !='' ">and ref.source_api_id = #{source_api_id} </if>
			<if test="target_api_id != null and target_api_id !='' ">and ref.target_api_id = #{target_api_id} </if>
			and ref.sts='Y'
		</trim>
    </select>
	<!-- 查询符合条件的数量 -->
	<select id="entity_count" resultType="Integer" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		select count(1) from sys_api_reflection
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="source_api_id != null and source_api_id !='' "> and source_api_id = #{source_api_id} </if>
			<if test="target_api_id != null and target_api_id !='' "> and target_api_id = #{target_api_id} </if>
			<if test="remark != null and remark !='' "> and remark = #{remark} </if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id} </if>
			<if test="create_time != null "> and create_time = #{create_time}  </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id} </if>
			<if test="modify_time != null "> and modify_time = #{modify_time}  </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>
			<if test="source_api_app != null and source_api_app !='' "> and source_api_app = #{source_api_app} </if>
			<if test="target_api_app != null and target_api_app !='' "> and target_api_app = #{target_api_app} </if>
			<if test="ref_code != null and ref_code !='' "> and ref_code = #{ref_code} </if>
			<if test="ref_name != null and ref_name !='' "> and ref_name = #{ref_name} </if>
			<if test="ref_type != null and ref_type !='' "> and ref_type = #{ref_type} </if>
			<if test="description != null and description !='' "> and description = #{description} </if>
			<if test="plug != null and plug !='' "> and plug = #{plug} </if>
			<if test="plug_id != null and plug_id !='' "> and plug_id = #{plug_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-ApiReflectionEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		select
		<include refid="ApiReflectionEntity_Base_Column_List" />
		from sys_api_reflection
		<trim prefix="where" prefixOverrides="and">
			<if test="id != null and id !='' "> id like concat('%',#{id},'%') </if>
			<if test="source_api_id != null and source_api_id !='' "> and source_api_id like concat('%',#{source_api_id},'%') </if>
			<if test="target_api_id != null and target_api_id !='' "> and target_api_id like concat('%',#{target_api_id},'%') </if>
			<if test="remark != null and remark !='' "> and remark like concat('%',#{remark},'%') </if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id like concat('%',#{create_user_id},'%') </if>
			<if test="create_time != null and create_time !='' "> and create_time like concat('%',#{create_time},'%') </if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id like concat('%',#{modify_user_id},'%') </if>
			<if test="modify_time != null and modify_time !='' "> and modify_time like concat('%',#{modify_time},'%') </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>
			<if test="source_api_app != null and source_api_app !='' "> and source_api_app like concat('%',#{source_api_app},'%') </if>
			<if test="target_api_app != null and target_api_app !='' "> and target_api_app like concat('%',#{target_api_app},'%') </if>
			<if test="ref_code != null and ref_code !='' "> and ref_code like concat('%',#{ref_code},'%') </if>
			<if test="ref_name != null and ref_name !='' "> and ref_name like concat('%',#{ref_name},'%') </if>
			<if test="ref_type != null and ref_type !='' "> and ref_type like concat('%',#{ref_type},'%') </if>
			<if test="description != null and description !='' "> and description like concat('%',#{description},'%') </if>
			<if test="plug != null and plug !='' "> and plug like concat('%',#{plug},'%') </if>
			<if test="plug_id != null and plug_id !='' "> and plug_id like concat('%',#{plug_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-ApiReflectionEntity-result" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		select
		<include refid="ApiReflectionEntity_Base_Column_List" />
		from sys_api_reflection
		<trim prefix="where" prefixOverrides="or">
			<if test="id != null and id !='' ">id = #{id} </if>
			<if test="source_api_id != null and source_api_id !='' "> or source_api_id = #{source_api_id} </if>
			<if test="target_api_id != null and target_api_id !='' "> or target_api_id = #{target_api_id} </if>
			<if test="remark != null and remark !='' "> or remark = #{remark} </if>
			<if test="create_user_id != null and create_user_id !='' "> or create_user_id = #{create_user_id} </if>
			<if test="create_time != null and create_time !='' "> or create_time = #{create_time} </if>
			<if test="modify_user_id != null and modify_user_id !='' "> or modify_user_id = #{modify_user_id} </if>
			<if test="modify_time != null and modify_time !='' "> or modify_time = #{modify_time} </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>
			<if test="source_api_app != null and source_api_app !='' "> or source_api_app = #{source_api_app} </if>
			<if test="target_api_app != null and target_api_app !='' "> or target_api_app = #{target_api_app} </if>
			<if test="ref_code != null and ref_code !='' "> or ref_code = #{ref_code} </if>
			<if test="ref_name != null and ref_name !='' "> or ref_name = #{ref_name} </if>
			<if test="ref_type != null and ref_type !='' "> or ref_type = #{ref_type} </if>
			<if test="description != null and description !='' "> or description = #{description} </if>
			<if test="plug != null and plug !='' "> or plug = #{plug} </if>
			<if test="plug_id != null and plug_id !='' "> or plug_id = #{plug_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.ApiReflectionEntity">
		insert into sys_api_reflection(
		<trim suffix="" suffixOverrides=",">
			<if test="id != null and id !='' "> id, </if>
			<if test="source_api_id != null and source_api_id !='' "> source_api_id, </if>
			<if test="target_api_id != null and target_api_id !='' "> target_api_id, </if>
			<if test="remark != null and remark !='' "> remark, </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="source_api_app != null and source_api_app !='' "> source_api_app, </if>
			<if test="target_api_app != null and target_api_app !='' "> target_api_app, </if>
			<if test="ref_code != null and ref_code !='' "> ref_code, </if>
			<if test="ref_name != null and ref_name !='' "> ref_name, </if>
			<if test="ref_type != null and ref_type !='' "> ref_type, </if>
			<if test="description != null and description !='' "> description, </if>
			<if test="plug != null and plug !='' "> plug, </if>
			<if test="plug_id != null and plug_id !='' "> plug_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="source_api_id != null and source_api_id !='' "> #{source_api_id}, </if>
			<if test="target_api_id != null and target_api_id !='' "> #{target_api_id}, </if>
			<if test="remark != null and remark !='' "> #{remark}, </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="source_api_app != null and source_api_app !='' "> #{source_api_app}, </if>
			<if test="target_api_app != null and target_api_app !='' "> #{target_api_app}, </if>
			<if test="ref_code != null and ref_code !='' "> #{ref_code}, </if>
			<if test="ref_name != null and ref_name !='' "> #{ref_name}, </if>
			<if test="ref_type != null and ref_type !='' "> #{ref_type}, </if>
			<if test="description != null and description !='' "> #{description}, </if>
			<if test="plug != null and plug !='' "> #{plug}, </if>
			<if test="plug_id != null and plug_id !='' "> #{plug_id}, </if>
			<if test="sorts == null ">(select (max(IFNULL( a.sorts, 0 )) + 1) as sort from sys_api_reflection 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="ApiReflectionEntity_update" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		update sys_api_reflection set
		<trim suffix="" suffixOverrides=",">
			<if test="source_api_id != null and source_api_id !='' "> source_api_id = #{source_api_id},</if>
			<if test="target_api_id != null and target_api_id !='' "> target_api_id = #{target_api_id},</if>
			<if test="remark != null and remark !='' "> remark = #{remark},</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="source_api_app != null and source_api_app !='' "> source_api_app = #{source_api_app},</if>
			<if test="target_api_app != null and target_api_app !='' "> target_api_app = #{target_api_app},</if>
			<if test="ref_code != null and ref_code !='' "> ref_code = #{ref_code},</if>
			<if test="ref_name != null and ref_name !='' "> ref_name = #{ref_name},</if>
			<if test="ref_type != null and ref_type !='' "> ref_type = #{ref_type},</if>
			<if test="description != null and description !='' "> description = #{description},</if>
			<if test="plug != null and plug !='' "> plug = #{plug},</if>
			<if test="plug_id != null and plug_id !='' "> plug_id = #{plug_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="ApiReflectionEntity_logicDelete" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		update sys_api_reflection set
		sts='N',modify_time = now(),modify_user_id = #{modify_user_id} where
		id = #{id}
	</update>

	<!-- 逻辑删除多条件 -->
	<update id="entity_logicDelete_Multi_Condition" parameterType="com.hzya.frame.sys.apireflection.entity.ApiReflectionEntity">
		update sys_api_reflection 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="source_api_id != null and source_api_id !='' "> and source_api_id = #{source_api_id}</if>
			<if test="target_api_id != null and target_api_id !='' "> and target_api_id = #{target_api_id}</if>
			<if test="remark != null and remark !='' "> and remark = #{remark}</if>
			<if test="create_user_id != null and create_user_id !='' "> and create_user_id = #{create_user_id}</if>
			<if test="create_time != null and create_time !='' "> and create_time = #{create_time}</if>
			<if test="modify_user_id != null and modify_user_id !='' "> and modify_user_id = #{modify_user_id}</if>
			<if test="modify_time != null and modify_time !='' "> and modify_time = #{modify_time}</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>
			<if test="source_api_app != null and source_api_app !='' "> and source_api_app = #{source_api_app}</if>
			<if test="target_api_app != null and target_api_app !='' "> and target_api_app = #{target_api_app}</if>
			<if test="ref_code != null and ref_code !='' "> and ref_code = #{ref_code}</if>
			<if test="ref_name != null and ref_name !='' "> and ref_name = #{ref_name}</if>
			<if test="ref_type != null and ref_type !='' "> and ref_type = #{ref_type}</if>
			<if test="description != null and description !='' "> and description = #{description}</if>
			<if test="plug != null and plug !='' "> and plug = #{plug}</if>
			<if test="plug_id != null and plug_id !='' "> and plug_id = #{plug_id}</if>
		</trim>
	</update>

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