<?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.foreverwin.mesnac.meapi.mapper.DataFieldListMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.meapi.model.DataFieldList">
        <result column="HANDLE" property="handle" />
        <result column="SEQUENCE" property="sequence" />
        <result column="DATA_FIELD_BO" property="dataFieldBo" />
        <result column="DATA_VALUE" property="dataValue" />
        <result column="IS_DEFAULT" property="isDefault" />
        <result column="VALUATION" property="valuation" />
        <result column="ERP_CODE_GROUP" property="erpCodeGroup" />
        <result column="CREATED_DATE_TIME" property="createdDateTime" />
        <result column="MODIFIED_DATE_TIME" property="modifiedDateTime" />
        <result column="DESCRIPTION" property="description"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, SEQUENCE, DATA_FIELD_BO, DATA_VALUE, IS_DEFAULT, VALUATION, ERP_CODE_GROUP, CREATED_DATE_TIME, MODIFIED_DATE_TIME
    </sql>

    <!-- BaseMapper标准查询/修改/删除 -->

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM DATA_FIELD_LIST
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </select>


    <select id="selectOne" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM DATA_FIELD_LIST
        <where>
            <if test="ew.entity.handle!=null">
              HANDLE=#{ew.handle}
            </if>
            <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
            <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
            <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
            <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
            <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
            <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
            <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
            <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
        </where>
    </select>

    <select id="selectCount" resultType="Integer">
        SELECT COUNT(1) FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                <if test="ew.entity.handle!=null">
                    HANDLE=#{ew.entity.handle}
                </if>
                <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMaps" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectObjs" resultType="Object">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectPage" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMapsPage" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <insert id="insert" parameterType="com.foreverwin.mesnac.meapi.model.DataFieldList">
        INSERT INTO DATA_FIELD_LIST
        <trim prefix="(" suffix=")" suffixOverrides=",">
            HANDLE,
            <if test="sequence!=null">SEQUENCE,</if>
            <if test="dataFieldBo!=null">DATA_FIELD_BO,</if>
            <if test="dataValue!=null">DATA_VALUE,</if>
            <if test="isDefault!=null">IS_DEFAULT,</if>
            <if test="valuation!=null">VALUATION,</if>
            <if test="erpCodeGroup!=null">ERP_CODE_GROUP,</if>
            <if test="createdDateTime!=null">CREATED_DATE_TIME,</if>
            <if test="modifiedDateTime!=null">MODIFIED_DATE_TIME,</if>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            <if test="sequence!=null">#{sequence},</if>
            <if test="dataFieldBo!=null">#{dataFieldBo},</if>
            <if test="dataValue!=null">#{dataValue},</if>
            <if test="isDefault!=null">#{isDefault},</if>
            <if test="valuation!=null">#{valuation},</if>
            <if test="erpCodeGroup!=null">#{erpCodeGroup},</if>
            <if test="createdDateTime!=null">#{createdDateTime},</if>
            <if test="modifiedDateTime!=null">#{modifiedDateTime},</if>
        </trim>
    </insert>

    <insert id="insertAllColumn" parameterType="com.foreverwin.mesnac.meapi.model.DataFieldList">
        INSERT INTO DATA_FIELD_LIST
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{sequence},
            #{dataFieldBo},
            #{dataValue},
            #{isDefault},
            #{valuation},
            #{erpCodeGroup},
            #{createdDateTime},
            #{modifiedDateTime},
        </trim>
    </insert>






    <update id="update">
        UPDATE DATA_FIELD_LIST <trim prefix="SET" suffixOverrides=",">
        <if test="et.handle!=null">HANDLE=#{et.handle},</if>
        <if test="et.sequence!=null">SEQUENCE=#{et.sequence},</if>
        <if test="et.dataFieldBo!=null">DATA_FIELD_BO=#{et.dataFieldBo},</if>
        <if test="et.dataValue!=null">DATA_VALUE=#{et.dataValue},</if>
        <if test="et.isDefault!=null">IS_DEFAULT=#{et.isDefault},</if>
        <if test="et.valuation!=null">VALUATION=#{et.valuation},</if>
        <if test="et.erpCodeGroup!=null">ERP_CODE_GROUP=#{et.erpCodeGroup},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
        <if test="et.modifiedDateTime!=null">MODIFIED_DATE_TIME=#{et.modifiedDateTime},</if>
    </trim>
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    HANDLE=#{ew.entity.handle}
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </update>


    <delete id="deleteByMap">
        DELETE FROM DATA_FIELD_LIST
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </delete>

    <delete id="delete">
        DELETE FROM DATA_FIELD_LIST
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.sequence!=null"> AND SEQUENCE=#{ew.entity.sequence}</if>
                    <if test="ew.entity.dataFieldBo!=null"> AND DATA_FIELD_BO=#{ew.entity.dataFieldBo}</if>
                    <if test="ew.entity.dataValue!=null"> AND DATA_VALUE=#{ew.entity.dataValue}</if>
                    <if test="ew.entity.isDefault!=null"> AND IS_DEFAULT=#{ew.entity.isDefault}</if>
                    <if test="ew.entity.valuation!=null"> AND VALUATION=#{ew.entity.valuation}</if>
                    <if test="ew.entity.erpCodeGroup!=null"> AND ERP_CODE_GROUP=#{ew.entity.erpCodeGroup}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </delete>

    <!-- BaseMapper标准查询/修改/删除 -->
    <select id="findDataFieldListById" resultMap="BaseResultMap">
        SELECT DFL.DATA_VALUE DATA_VALUE,DFLT.DATA_TAG DESCRIPTION
        FROM DATA_FIELD DF
        INNER JOIN DATA_FIELD_LIST DFL ON DF.HANDLE = DFL.DATA_FIELD_BO
        LEFT JOIN DATA_FIELD_LIST_T DFLT ON DFL.HANDLE = DFLT.DATA_FIELD_LIST_BO AND DFLT.LOCALE = #{locale}
        <where>
            <if test="dataField != null">
                <if test="dataField.handle != null and dataField.handle != ''">
                    DF.HANDLE = #{dataField.handle}
                </if>
                <if test="dataField.site != null and dataField.site != ''">
                    AND DF.SITE = #{dataField.site}
                </if>
                <if test="dataField.dataField != null and dataField.dataField != ''">
                    AND DF.DATA_FIELD = #{dataField.dataField}
                </if>
            </if>
        </where>
    </select>
    <select id="findDataFieldListByDataField" resultType="String" >
        SELECT
        SUBSTR(LISTAGG(DFLT.DATA_TAG || ',') WITHIN GROUP(ORDER BY DF.DATA_FIELD),0,LENGTH(LISTAGG(DFLT.DATA_TAG || ',') WITHIN GROUP(ORDER BY DF.DATA_FIELD))-1)
        FROM DATA_FIELD DF
        INNER JOIN DATA_FIELD_LIST DFL ON DF.HANDLE = DFL.DATA_FIELD_BO
        LEFT JOIN DATA_FIELD_LIST_T DFLT ON DFL.HANDLE = DFLT.DATA_FIELD_LIST_BO AND DFLT.LOCALE = #{locale}
        <where>
            <if test="dataField != null">
                <if test="dataField.handle != null and dataField.handle != ''">
                    DF.HANDLE = #{dataField.handle}
                </if>
                <if test="dataField.site != null and dataField.site != ''">
                    AND DF.SITE = #{dataField.site}
                </if>
                <if test="dataField.dataField != null and dataField.dataField != ''">
                    AND DF.DATA_FIELD = #{dataField.dataField}
                </if>
            </if>
            <if test="dataField.dataValue != null and dataField.dataValue.size > 0">
                AND DFL.DATA_VALUE IN
                <foreach item="item" index="index" collection="dataField.dataValue" separator="," open="(" close=")">
                    UPPER(#{item})
                </foreach>
            </if>
        </where>
    </select>

    <select id="findDataFieldList" resultMap="BaseResultMap">
        SELECT DFL.DATA_VALUE DATA_VALUE,DFLT.DATA_TAG DESCRIPTION
        FROM DATA_FIELD DF
        INNER JOIN DATA_FIELD_LIST DFL ON DF.HANDLE = DFL.DATA_FIELD_BO
        LEFT JOIN DATA_FIELD_LIST_T DFLT ON DFL.HANDLE = DFLT.DATA_FIELD_LIST_BO AND DFLT.LOCALE = 'zh'
        <where>
            <if test="dataField != null">
                <if test="dataField.handle != null and dataField.handle != ''">
                    DF.HANDLE = #{dataField.handle}
                </if>
                <if test="dataField.site != null and dataField.site != ''">
                    AND DF.SITE = #{dataField.site}
                </if>
                <if test="dataField.dataField != null and dataField.dataField != ''">
                    AND DF.DATA_FIELD = #{dataField.dataField}
                </if>
            </if>
        </where>
    </select>
</mapper>
