<?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.dgtis.dorm.manager.db.dao.AdministrativeItemsDocMapper">

    <sql id="Base_Column_List">
        doc.id,doc.items_id,doc.doc_name,doc.storage_key,doc.type,doc.create_date,doc.create_user
    </sql>

    <select id="selectByItemsId"  resultType="com.dgtis.dorm.manager.db.domain.AdministrativeItemsDoc">
        select
        <include refid="Base_Column_List"/>,
        sto.old_name as storageOldName,sto.url as storageUrl
        from zhll_items_doc doc
        LEFT JOIN zhll_storage sto on sto.key=doc.storage_key
        where doc.items_id=#{itemsId}
        <if test="type != null">
            and doc.type=#{type}
        </if>
        ORDER BY doc_name asc
    </select>

    <insert id="insertBatch">
        insert zhll_items_doc
        (items_id,doc_name,storage_key,type,create_date,create_user)
        values
        <foreach collection="itemsDocs" item="doc" separator=",">
            (#{doc.itemsId},#{doc.docName},#{doc.storageKey},#{doc.type},#{doc.createDate},#{doc.createUser})
        </foreach>
    </insert>

    <delete id="deleteByItemsId">
        delete from  zhll_items_doc
        where items_id=#{itemsId}
    </delete>

    <delete id="deleteByItemsIds">
        delete from  zhll_items_doc
        where items_id in
        <foreach collection="itemsIds" item="itemsId" separator="," open="(" close=")">
            #{itemsId}
        </foreach>
    </delete>
</mapper>