<?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.hzs.system.base.mapper.BdTransactionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.base.BdTransaction">
        <id column="PK_ID" property="pkId"/>
        <result column="CHINESE" property="chinese"/>
        <result column="TRADITIONAL" property="traditional"/>
        <result column="KEY" property="key"/>
        <result column="ENGLISH" property="english"/>
        <result column="RUSSIAN" property="russian"/>
        <result column="KAZAKH" property="kazakh"/>
        <result column="INDONESIA" property="indonesia"/>
        <result column="FRENCH" property="french"/>
        <result column="PORTUGUESE" property="portuguese"/>
        <result column="SPANISH" property="spanish"/>
        <result column="ARABIC" property="arabic"/>
        <result column="CUSTOM1" property="custom1"/>
        <result column="CUSTOM2" property="custom2"/>
        <result column="CUSTOM3" property="custom3"/>
        <result column="CUSTOM4" property="custom4"/>
        <result column="CUSTOM5" property="custom5"/>
        <result column="CUSTOM6" property="custom6"/>
        <result column="CUSTOM7" property="custom7"/>
        <result column="CUSTOM8" property="custom8"/>
        <result column="CUSTOM9" property="custom9"/>
        <result column="CUSTOM10" property="custom10"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="IS_CACHE" property="isCache"/>
        <result column="IS_UPLOAD" property="isUpload"/>
    </resultMap>

    <!-- 获取翻译 -->
    <select id="getBdTransaction" parameterType="com.hzs.common.domain.system.base.BdTransaction"
            resultType="com.hzs.common.domain.system.base.BdTransaction">
        SELECT *
        FROM BD_TRANSACTION
        WHERE DEL_FLAG = 0
          AND key = #{key}
    </select>

    <!-- 插入国际化内容 -->
    <insert id="insertTransactionExt" parameterType="com.hzs.common.domain.system.base.ext.TransactionParam"
            useGeneratedKeys="true" keyProperty="pkId">
        <selectKey resultType="java.lang.Integer" order="BEFORE" keyProperty="pkId">
            SELECT BD_TRANSACTION_SEQ.nextval AS pkId FROM dual
        </selectKey>
        INSERT INTO BD_TRANSACTION (PK_ID, KEY, ${column}, IS_CACHE, IS_UPLOAD, PK_CREATOR)
        VALUES(#{pkId}, #{key} || #{pkId}, #{columnValue}, #{isCache}, #{isUpload}, #{pkCreator})
    </insert>

    <!-- 更新国际化内容 -->
    <update id="updateTransactionExt" parameterType="com.hzs.common.domain.system.base.ext.TransactionParam">
        update BD_TRANSACTION
        set ${column}     = #{columnValue},
            PK_MODIFIED   = #{pkModified},
            MODIFIED_TIME = sysdate
        where PK_ID = #{pkId}
    </update>

    <!-- 查询国际化指定内容列表 -->
    <select id="queryTransactionContentList" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select key, ${from} as fromContent, ${to} as toContent
        from BD_TRANSACTION t
        where DEL_FLAG = 0
        and IS_CACHE = 1
        and ${from} in
        <foreach collection="contentList" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <!-- 查询国际化指定KEY列表 -->
    <select id="queryTransactionKey" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select key, ${to} as toContent
        from BD_TRANSACTION t
        where DEL_FLAG = 0
          and key = #{key}
    </select>

    <!-- 查询国际化指定KEY模糊查询 -->
    <select id="queryTransactionListByKeyPrefix" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select pk_id, key, ${to} as toContent
        from BD_TRANSACTION t
        where t.del_flag = 0
        and
        <foreach collection="keyPrefixList" item="item" open=" (" close=") " separator=" or ">
            t.key like #{item} || '%'
        </foreach>
    </select>

    <!-- 查询国际化指定pkId查询 -->
    <select id="queryTransactionListByPkId" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select pk_id, key, ${to} as toContent
        from BD_TRANSACTION t
        where t.del_flag = 0
        and t.pk_id in
        <foreach collection="pkIdList" item="item" open=" (" close=") " separator=",">
            #{item}
        </foreach>
    </select>

    <!-- 查询列表（可指定列） -->
    <select id="queryListByColumn" resultMap="BaseResultMap">
        select
        <choose>
            <when test="column != null and column != ''">
                bt.key,
                bt.${column}
            </when>
            <otherwise>
                bt.key,
                bt.chinese,
                bt.traditional,
                bt.english,
                bt.russian,
                bt.kazakh,
                bt.indonesia,
                bt.french,
                bt.portuguese,
                bt.spanish,
                bt.arabic,
                bt.is_cache,
                bt.is_upload
            </otherwise>
        </choose>
        from BD_TRANSACTION bt
        where bt.del_flag = 0
        <if test="isCache">
            and bt.is_cache = 0
        </if>
        <if test="isUpload">
            and bt.is_upload = 0
        </if>
        order by bt.key
    </select>

    <!-- 查询指定语种数据 -->
    <select id="queryToColumnList" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select bt.pk_id, bt.chinese fromContent, ${column} toContent
        from bd_transaction bt
        where bt.del_flag = 0
          and ${column} is null
    </select>

    <!-- 查询指定语种指定数据 -->
    <select id="queryFromColumnList" resultType="com.hzs.common.domain.system.base.ext.TransactionResult">
        select bt.pk_id, ${column} fromContent
        from bd_transaction bt
        where bt.del_flag = 0
        and bt.pk_id in
        <foreach collection="pkIdList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and ${column} is not null
    </select>

</mapper>
