<?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.fzm.mall.server.admin.system.mapper.SysBlockChainManagementMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.system.model.SysBlockChainManagement">
        <id column="id" property="id"/>
        <result column="block_chain_id" property="blockChainId"/>
        <result column="block_chain_name" property="blockChainName"/>
        <result column="status" property="status"/>
        <result column="ip" property="ip"/>
        <result column="port" property="port"/>
        <result column="title" property="title"/>
        <result column="start_height" property="startHeight"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <resultMap id="PageResultMap" type="com.fzm.mall.server.admin.system.entity.dto.SysBlockChainManagementDTO">
        <id column="id" property="id"/>
        <result column="block_chain_id" property="blockChainId"/>
        <result column="block_chain_name" property="blockChainName"/>
        <result column="status" property="status"/>
        <result column="ip" property="ip"/>
        <result column="port" property="port"/>
        <result column="title" property="title"/>
        <result column="start_height" property="startHeight"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>

        <collection property="passList" javaType="java.util.ArrayList"
                    ofType="com.fzm.mall.server.admin.system.entity.dto.SysBlockChainPassDTO">
            <result column="pass_id" property="passId"/>
            <result column="p_status" property="status"/>
        </collection>
    </resultMap>

    <select id="list" resultMap="PageResultMap">
        select m.*, p.pass_id, p.status as p_status
        from sys_block_chain_management m
        left join sys_block_chain_pass p on m.block_chain_id = p.block_chain_id
        <where>
            m.status in ('1', '2')
            <if test="keyword != null and keyword != ''">
                and (
                m.block_chain_name like CONCAT('%', #{keyword},'%')
                or
                p.pass_identification like CONCAT('%', #{keyword},'%')
                )
            </if>
        </where>
        order by m.create_time desc
    </select>
</mapper>
