<?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.sckw.mine.mapper.NodeMapper">

    <sql id="Base_Column_List">
        id,
                node_code,
                node_name,
                node_type,
                node_sort,
                node_use_count,
                `status`,
                create_by,
                update_by,
                create_time,
                update_time
    </sql>

    <update id="nodeDelete">
        update kw_business_node set del_flag = 1 where id = #{id}
    </update>

    <select id="nodePageList"
            resultType="com.sckw.mine.entity.res.NodePageListRes">
        select <include refid="Base_Column_List" /> from kw_business_node
        <where>
            del_flag = 0
            <if test="param.nodeName != '' and param.nodeName != null">
                and node_name like concat('%',#{param.nodeName},'%')
            </if>
            <if test="param.nodeCode != '' and param.nodeCode != null">
                and node_code like concat('%',#{param.nodeCode},'%')
            </if>
            <if test="param.tenantId != '' and param.tenantId != null">
                and tenant_id = #{param.tenantId}
            </if>
            <if test="param.status != null">
                and `status` = #{param.status}
            </if>
        </where>
        order by node_sort desc,create_time desc
    </select>
    <select id="load" resultType="com.sckw.mine.entity.res.NodeDetailRes">
        select <include refid="Base_Column_List" /> from kw_business_node where id = #{id}
    </select>
    <select id="selectListNode" resultType="com.sckw.mine.entity.dto.NodeStatusDTO">
        select id `code`,node_name msg,node_code,node_type,node_sort,node_use_count,`status` from kw_business_node
        <where>
            del_flag = 0 and `status` = 1
            <if test="tenantId != '' and tenantId != null">
                and tenant_id = #{tenantId}
            </if>
        </where>
        order by node_sort desc

    </select>


    <update id="nodeUpdate" parameterType="com.sckw.mine.entity.req.NodeUpdateParam">
        UPDATE kw_business_node
        <set>
            <trim suffixOverrides=",">
                <if test="null != param.nodeName and '' != param.nodeName">node_name = #{param.nodeName},</if>
                <if test="null != param.nodeType">node_type = #{param.nodeType},</if>
                <if test="null != param.nodeSort">node_sort = #{param.nodeSort},</if>
                <if test="null != param.nodeUseCount">node_use_count = #{param.nodeUseCount}</if>
            </trim>
        </set>
        WHERE id = #{param.id}
    </update>
    <update id="statusAction">
        update kw_business_node set status = #{status} where id = #{id}
    </update>

</mapper>