<?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="org.hzhub.erp.mapper.ErpApiParamMapper">

    <resultMap id="ErpApiParamResult" type="org.hzhub.erp.domain.entity.ErpApiParam">
        <id property="paramId" column="param_id"/>
        <result property="apiId" column="api_id"/>
        <result property="paramName" column="param_name"/>
        <result property="paramDesc" column="param_desc"/>
        <result property="paramType" column="param_type"/>
        <result property="paramPosition" column="param_position"/>
        <result property="isRequired" column="is_required"/>
        <result property="defaultValue" column="default_value"/>
        <result property="sqlParamName" column="sql_param_name"/>
        <result property="sort" column="sort"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectErpApiParamVo">
        select param_id, api_id, param_name, param_desc, param_type, param_position,
               is_required, default_value, sql_param_name, sort, create_time, update_time
        from erp_api_param
    </sql>

    <select id="selectByApiId" parameterType="Long" resultMap="ErpApiParamResult">
        <include refid="selectErpApiParamVo"/>
        where api_id = #{apiId}
        order by sort asc
    </select>

    <insert id="batchInsert" parameterType="java.util.List">
        insert into erp_api_param(api_id, param_name, param_desc, param_type, param_position,
                                  is_required, default_value, sql_param_name, sort, create_time)
        values
        <foreach collection="params" item="param" separator=",">
            (#{param.apiId}, #{param.paramName}, #{param.paramDesc}, #{param.paramType}, #{param.paramPosition},
             #{param.isRequired}, #{param.defaultValue}, #{param.sqlParamName}, #{param.sort}, now())
        </foreach>
    </insert>

    <delete id="deleteByApiId" parameterType="Long">
        delete from erp_api_param where api_id = #{apiId}
    </delete>

</mapper>