<!--
  ~
  ~  Copyright 2020 WeBank
  ~
  ~  Licensed under the Apache License, Version 2.0 (the "License");
  ~  you may not use this file except in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~  http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.webank.wedatasphere.exchangis.job.server.mapper.JobFunctionDao">
    <resultMap id="resultJobFunc" type="com.webank.wedatasphere.exchangis.job.server.vo.JobFunction">
        <result column="id" property="id"/>
        <result column="func_type" property="funcType"/>
        <result column="func_name" property="funcName"/>
        <result column="tab_name" property="tabName"/>
        <result column="name_display" property="nameDisplay"/>
        <result column="param_num" property="paramNum"/>
        <result column="ref_name" property="refName"/>
        <result column="description" property="description"/>
        <result column="modify_time" property="modifyTime"/>
        <result column="create_time" property="createTime"/>
        <collection property="paramNames" column="id" select="selectParamsByFunc"/>
    </resultMap>

    <select id="listRefNames" resultType="String">
        <![CDATA[SELECT ref_name FROM `exchangis_job_func` WHERE `tab_name` = #{tabName} AND `func_type` = #{type};]]>
    </select>

    <select id="listFunctions" resultMap="resultJobFunc">
        <![CDATA[SELECT * FROM `exchangis_job_func` WHERE `tab_name` = #{tabName} AND `func_type` = #{type};]]>
    </select>

    <select id="selectParamsByFunc" resultType="String">
        <![CDATA[SELECT name_display FROM `exchangis_job_func_params` WHERE `func_id` = #{id} ORDER BY `order` ASC;]]>
    </select>
</mapper>
