<?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="multiConnection">

  <sql id="multiConnectionSearchCondition">
    <if test="keyword != null and keyword != ''">
      AND (NAME ILIKE '%' || #{keyword} || '%')
    </if>
    <if test="status != null and status != ''">
      AND STATUS = #{status}
    </if>
  </sql>

  <select id="getMultiConnectionList" parameterType="map" resultType="map">
    SELECT * FROM MULTI_CONNECTION
    WHERE 1=1
    <include refid="common.companyCodeFilter"/>
    <include refid="multiConnectionSearchCondition"/>
    <include refid="common.dynamicOrderBy"/>
    <include refid="common.pagination"/>
  </select>

  <select id="getMultiConnectionListCnt" parameterType="map" resultType="int">
    SELECT COUNT(*) FROM MULTI_CONNECTION
    WHERE 1=1
    <include refid="common.companyCodeFilter"/>
    <include refid="multiConnectionSearchCondition"/>
  </select>

  <select id="getMultiConnectionInfo" parameterType="map" resultType="map">
    SELECT * FROM MULTI_CONNECTION
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </select>

  <insert id="insertMultiConnection" parameterType="map" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO MULTI_CONNECTION (COMPANY_CODE, CREATED_DATE, UPDATED_DATE)
    VALUES (#{company_code}, NOW(), NOW())
  </insert>

  <update id="updateMultiConnection" parameterType="map">
    UPDATE MULTI_CONNECTION
    SET UPDATED_DATE = NOW()
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </update>

  <delete id="deleteMultiConnection" parameterType="map">
    DELETE FROM MULTI_CONNECTION
    WHERE ID = #{id}
    <include refid="common.companyCodeFilter"/>
  </delete>

</mapper>
