<?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.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
    <resultMap id="get-OerAnnexEntity-result" type="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        <result property="annexid" column="annexid" />
        <result property="mlid" column="mlid" />
        <result property="gsdm" column="gsdm" />
        <result property="kjnd" column="kjnd" />
        <result property="bnxid" column="bnxid" />
        <result property="xh" column="xh" />
        <result property="onlyid" column="onlyid" />
        <result property="annexName" column="annexName" />
        <result property="annexSize" column="annexSize" />
        <result property="showSize" column="showSize" />
        <result property="ole" column="ole" />
        <result property="fjType" column="fjType" />
        <result property="fpid" column="fpid" />
        <result property="maxAnnexid" column="maxAnnexid" />
        <result property="aTextName" column="aTextName" />
    </resultMap>

    <sql id="OerAnnexEntity_Base_Column_List">
        AnnexID,
        MLID,
        GSDM,
        KJND,
        BNXID,
        XH,
        OnlyID,
        AnnexName,
        AnnexSize,
        ShowSize,
        OLE,
        FJType,
        FPID
	</sql>



    <!-- 查询 采用==查询 -->
    <select id="OerAnnexEntity_list_base" resultMap="get-OerAnnexEntity-result" parameterType="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        select
        <include refid="OerAnnexEntity_Base_Column_List" />
        FROM
        OER_ANNEX
        <trim prefix="where" prefixOverrides="and">
            <if test="mlid != null and mlid !='' "> MLID = #{mlid} </if>
            <if test="kjnd != null and kjnd !='' ">and KJND = #{kjnd} </if>
            <if test="gsdm != null and gsdm !='' ">and gsdm = #{gsdm} </if>
        </trim>
    </select>


    <!-- 查询 采用==查询 联查附件表 -->
    <select id="OerAnnexEntity_list_base_join_attachment" resultMap="get-OerAnnexEntity-result" parameterType="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        select
        OER_ANNEX.AnnexID,
        OER_ANNEX.mlid,
        OER_ANNEX.OnlyID,
        OER_ANNEX.AnnexName,
        OER_ANNEX.AnnexSize,
        AT_AttachmentFile.AtextName
        FROM
        OER_ANNEX
        LEFT JOIN AT_AttachmentFile ON AT_AttachmentFile.ATGuid = OER_ANNEX.OnlyID
        <trim prefix="where" prefixOverrides="and">
            <if test="mlid != null and mlid !='' "> MLID = #{mlid} </if>
            <if test="kjnd != null and kjnd !='' ">and KJND = #{kjnd} </if>
            <if test="gsdm != null and gsdm !='' ">and gsdm = #{gsdm} </if>
        </trim>
    </select>

    <!--查询最大id-->
    <select id="OerAnnexEntity_max_id" resultMap="get-OerAnnexEntity-result" parameterType="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        SELECT
        MAX(AnnexID) as maxAnnexid
        FROM
        OER_ANNEX
        <trim prefix="where" prefixOverrides="and">
            <if test="kjnd != null and kjnd !='' "> KJND = #{kjnd} </if>
            <if test="gsdm != null and gsdm !='' ">and GSDM = #{gsdm} </if>
        </trim>
    </select>

    <insert id="OerAnnexEntity_insert" parameterType="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        insert into OER_ANNEX(
        <trim suffix="" suffixOverrides=",">
            <if test="annexid != null and annexid !='' ">AnnexID,</if>
            <if test="mlid != null and mlid !='' "> MLID, </if>
            <if test="gsdm != null and gsdm !='' "> gsdm, </if>
            <if test="kjnd != null and kjnd !='' ">   kjnd ,</if>
            <if test="xh != null and xh !='' ">xh,</if>
            <if test="onlyid != null and onlyid !='' ">onlyid,</if>
            <if test="annexName != null and annexName !='' ">annexName,</if>
            <if test="annexSize != null and annexSize !='' ">annexSize,</if>
            <if test="showSize != null and showSize !='' ">showSize,</if>
            <if test="fjType != null and fjType !='' ">fjType,</if>
            bnxid,
            ole,
            fpid
        </trim>
        )values
        (
        <trim suffix="" suffixOverrides=",">
            <if test="annexid != null and annexid !='' ">#{annexid},</if>
            <if test="mlid != null and mlid !='' "> #{mlid}, </if>
            <if test="gsdm != null and gsdm !='' "> #{gsdm}, </if>
            <if test="kjnd != null and kjnd !='' ">   #{kjnd} ,</if>
            <if test="xh != null and xh !='' ">#{xh},</if>
            <if test="onlyid != null and onlyid !='' ">#{onlyid},</if>
            <if test="annexName != null and annexName !='' ">#{annexName},</if>
            <if test="annexSize != null and annexSize !='' ">#{annexSize},</if>
            <if test="showSize != null and showSize !='' ">#{showSize},</if>
            <if test="fjType != null and fjType !='' ">#{fjType},</if>
            0,
            null,
            ''
        </trim>
        )
    </insert>
    <!-- 删除附件 -->
    <delete id="OerAnnexEntity_delete" parameterType="com.hzya.frame.grpU8.nxproof.oerannex.entity.OerAnnexEntity">
        delete from OER_ANNEX where mlid = #{mlid} and kjnd = #{kjnd} and gsdm = #{gsdm}
    </delete>
</mapper>
