<?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.huatek.busi.mapper.ServerFilePathMapper">
    <sql id="Base_Column_List">
        id,
        site_id AS siteId,
        site_path as sitePath,
        main_equ_id AS mainEquId,
        main_equ_path AS mainEquPath,
        file_type AS fileType,
        create_user AS createUser,
        create_time AS createTime,
        update_user AS updateUser,
        update_time AS updateTime,
        deleted
    </sql>

    <select id="list" parameterType="com.huatek.busi.where.ServerFilePathSelectVo" resultType="com.huatek.busi.dto.ServerFilePathDto">
        SELECT
            A.id,
            A.site_id AS siteId,
            B.site_name AS siteName,
            A.site_path as sitePath,
            A.main_equ_id AS mainEquId,
            c.`name` AS mainEquName,
            A.main_equ_path AS mainEquPath,
            A.file_type AS fileType,
            D.dname as dName,
            A.create_user AS createUser,
            A.create_time AS createTime,
            A.update_user AS updateUser,
            A.update_time AS updateTime
        FROM
            x_server_file_path A
        LEFT JOIN busi_site B ON A.site_id = B.id
        LEFT JOIN busi_site_tree C ON A.main_equ_id = C.system_code
        LEFT JOIN sys_dictionnaire_detail D ON A.file_type = D.dcode
        LEFT JOIN sys_dictionnaire E ON D.pid = E.id
        WHERE
            A.deleted = 0
        AND B.`status` = 1
        AND C.`status` = 1
        AND E.deleted = 0
        AND D.deleted = 0
        <if test="code != null and code != ''">
            AND D.dcode = #{code}
        </if>
    </select>

    <update id="batchDel">
        update x_server_file_path set deleted = 1 where id in
        <foreach item="item" index="index" collection="ids"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </update>

    <update id="update" parameterType="com.huatek.busi.entity.ServerFilePath">
        update x_server_file_path
        <set>
            <if test="id != null">
                id = #{id,jdbcType=VARCHAR},
            </if>
            <if test="siteId != null">
                site_id = #{siteId,jdbcType=VARCHAR},
            </if>
            <if test="sitePath != null">
                site_path = #{sitePath,jdbcType=VARCHAR},
            </if>
            <if test="mainEquPath != null">
                main_equ_id = #{mainEquId,jdbcType=VARCHAR},
            </if>
            <if test="mainEquPath != null">
                main_equ_path = #{mainEquPath,jdbcType=VARCHAR},
            </if>
            <if test="fileType != null">
                file_type = #{fileType,jdbcType=VARCHAR},
            </if>
            <if test="createUser != null">
                create_user = #{createUser,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser,jdbcType=VARCHAR},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="deleted != null">
                deleted = #{deleted,jdbcType=VARCHAR}
            </if>
        </set>
        where id = #{id,jdbcType=VARCHAR}
    </update>

    <select id="findBySiteIdAndSystemCode" parameterType="java.lang.String" resultType="com.huatek.busi.entity.ServerFilePath">
        SELECT
            <include refid="Base_Column_List"/>
        FROM
            x_server_file_path
        WHERE
            deleted = 0
        AND site_id = #{siteId}
        AND main_equ_id = #{systemCode}
    </select>
</mapper>