<?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.zm.order.tool.server.dao.ToolInterfaceDao">
    <resultMap id="ToolInterfaceMap" type="com.zm.order.tool.server.model.ToolInterface">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="project_name" jdbcType="VARCHAR" property="projectName"/>
        <result column="interface_name" jdbcType="VARCHAR" property="interfaceName"/>
        <result column="interface_url" jdbcType="VARCHAR" property="interfaceUrl"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
    </resultMap>

    <sql id="tb">
        tool_interface
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        project_name, interface_name, interface_url, created_at, updated_at,is_deleted
    </sql>

    <sql id="values">
      #{id}, #{projectName}, #{interfaceName},
      #{interfaceUrl}, now(), now(), 0
  </sql>


    <insert id="insert" parameterType="com.zm.order.tool.server.model.ToolInterface" keyColumn="id" keyProperty="id"
            useGeneratedKeys="true">
        insert into
        <include refid="tb"/>
        (<include refid="cols_all"/>)
        values
        (<include refid="values"/>)
    </insert>

    <select id="selectList"  resultMap="ToolInterfaceMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
          where
           is_deleted = 0

    </select>

    <update id="update" parameterType="com.zm.order.tool.server.model.ToolInterface">
        update
        <include refid="tb"/>
        set
        project_name = #{projectName},
        interface_name= #{interfaceName},
        interface_url =#{interfaceUrl},
        updated_at =now()
        where
        id =#{id}

    </update>

    <update id="delete" parameterType="map">
        update
        <include refid="tb"/>
        set is_deleted = 1,
        updated_at = now()
        where id = #{id}
    </update>
</mapper>