<?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="kr.co.jinwoosi.clfd.conts.company.mapper.CompanyMapper">

    <select id="select" parameterType="company" resultType="company">
        SELECT COMPANY_ID, COMPANY_GBN, COMPANY_NM, SAUPJA_NO, OWNER_NAME, TEL_NO, FAX_NO, COMPANY_SITE_URL, ADDR_M, ADDR_D, IMAGE_DIR, COMPANY_LOGO, REG_ID, REG_DT, UPD_ID, UPD_DT, DEL_ID, DEL_DT, REC_ST,
        FN_CD_DTL_NM('companyGbn', COMPANY_GBN) AS COMPANY_GBN_NM
        FROM CF_COMPANY
        WHERE 1 = 1
            <if test="companyId != null"> AND COMPANY_ID = #{companyId} </if>
    </select>

    <insert id="insert" parameterType="company">
        <selectKey keyProperty="companyId" resultType="java.lang.Long" order="BEFORE">
            SELECT COMPANY_ID_SEQ.NEXTVAL AS companyId FROM DUAL
        </selectKey>
        INSERT INTO CF_COMPANY(
            COMPANY_ID, COMPANY_GBN, COMPANY_NM, SAUPJA_NO, OWNER_NAME, TEL_NO, FAX_NO, COMPANY_SITE_URL, ADDR_M, ADDR_D, IMAGE_DIR, COMPANY_LOGO, REG_ID, REG_DT, REC_ST
        ) VALUES (
            #{companyId}, #{companyGbn}, #{companyNm}, #{saupjaNo}, #{ownerName}, #{telNo}, #{faxNo}, #{companySiteUrl}, #{addrM}, #{addrD}, #{imageDir}, #{companyLogo}, #{regId}, SYSDATE, 'Y'
        )
    </insert>

    <update id="update" parameterType="company">
        UPDATE CF_COMPANY
        SET UPD_ID = #{updId}
            , UPD_DT = SYSDATE
            <if test="!empty(companyGbn)"> , COMPANY_GBN = #{companyGbn} </if>
            <if test="!empty(companyNm)"> , COMPANY_NM = #{companyNm} </if>
            <if test="!empty(saupjaNo)"> , SAUPJA_NO = #{saupjaNo} </if>
            <if test="!empty(ownerName)"> , OWNER_NAME = #{ownerName} </if>
            <if test="!empty(telNo)"> , TEL_NO = #{telNo} </if>
            <if test="!empty(faxNo)"> , FAX_NO = #{faxNo} </if>
            <if test="!empty(companySiteUrl)"> , COMPANY_SITE_URL = #{companySiteUrl} </if>
            <if test="!empty(addrM)"> , ADDR_M = #{addrM} </if>
            <if test="!empty(addrD)"> , ADDR_D = #{addrD} </if>
            <if test="!empty(imageDir)"> , IMAGE_DIR = #{imageDir} </if>
            <if test="!empty(companyLogo)"> , COMPANY_LOGO = #{companyLogo} </if>
        WHERE COMPANY_ID = #{companyId}
    </update>

</mapper>
