<?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="cn.reghao.tnb.file.app.zoss.db.mapper.StoreNodeMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into file_store_node
        (`node_addr`,`http_port`,`rpc_port`,`enabled`)
        values
        (#{nodeAddr},#{httpPort},#{rpcPort},#{enabled})
    </insert>

    <select id="findAll" resultType="cn.reghao.tnb.file.app.zoss.model.po.StoreNode">
        select *
        from file_store_node
        limit 1000
    </select>
    <select id="findFirstStore" resultType="cn.reghao.tnb.file.app.zoss.model.po.StoreNode">
        select *
        from file_store_node
        limit 1
    </select>
    <select id="findByNodeAddrAndHttpPort" resultType="cn.reghao.tnb.file.app.zoss.model.po.StoreNode">
        select *
        from file_store_node
        where node_addr=#{nodeAddr} and http_port=#{httpPort}
    </select>
    <select id="findById" resultType="cn.reghao.tnb.file.app.zoss.model.po.StoreNode">
        select *
        from file_store_node
        where id=#{id}
    </select>
    <resultMap id="imageAlbumCard" type="cn.reghao.tnb.file.app.zoss.model.po.StoreNode">
        <result property="userId" column="user_id"/>
        <result property="albumId" column="album_id"/>
        <result property="albumName" column="album_name"/>
        <collection property="imageFiles" column="album_id" ofType="cn.reghao.tnb.file.app.zoss.model.po.StoreVolume" select="findStoreVolumes"/>
    </resultMap>
    <select id="findStoreVolumes" resultType="cn.reghao.tnb.file.app.zoss.model.po.StoreVolume">
        select *
        from file_store_volume
        where store_node_id=#{storeNodeId}
    </select>
</mapper>
