<?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.ruoyi.platform.mapper.ComponentDao">

    <resultMap type="com.ruoyi.platform.domain.Component" id="ComponentMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="categoryId" column="category_id" jdbcType="INTEGER"/>
        <result property="componentName" column="component_name" jdbcType="VARCHAR"/>
        <result property="componentLabel" column="component_label" jdbcType="VARCHAR"/>
        <result property="images" column="images" jdbcType="VARCHAR"/>
        <result property="workingDirectory" column="working_directory" jdbcType="VARCHAR"/>
        <result property="command" column="command" jdbcType="VARCHAR"/>
        <result property="envVirables" column="env_virables" jdbcType="VARCHAR"/>
        <result property="resourcesStandard" column="resources_standard" jdbcType="VARCHAR"/>
        <result property="controlStrategy" column="control_strategy" jdbcType="VARCHAR"/>
        <result property="mountPath" column="mount_path" jdbcType="VARCHAR"/>
        <result property="inParameters" column="in_parameters" jdbcType="VARCHAR"/>
        <result property="outParameters" column="out_parameters" jdbcType="VARCHAR"/>
        <result property="availableRange" column="available_range" jdbcType="INTEGER"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="iconPath" column="icon_path" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="state" column="state" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="ComponentMap">
        select
        id,category_id,component_name,component_Label,images,working_directory,command,env_virables,resources_standard,control_strategy,mount_path,in_parameters,out_parameters,available_range,description,icon_path,create_by,create_time,update_by,update_time,state
        from component
        where id = #{id} and state = 1
    </select>

    <!--查询所有的结果-->
    <select id="queryAll" resultMap="ComponentMap">
        SELECT * FROM component WHERE state = 1
    </select>


    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="ComponentMap">
        select
        id,category_id,component_name,component_Label,images,working_directory,command,env_virables,resources_standard,control_strategy,mount_path,in_parameters,out_parameters,available_range,description,icon_path,create_by,create_time,update_by,update_time,state
        from component
        <where>
            state = 1
            <if test="component.id != null">
                and id = #{component.id}
            </if>
            <if test="component.categoryId != null">
                and category_id = #{component.categoryId}
            </if>
            <if test="component.componentName != null and component.componentName != ''">
                and component_name = #{component.componentName}
            </if>
            <if test="component.componentLabel != null and component.componentLabel != ''">
                and component_label = #{component.componentLabel}
            </if>
            <if test="component.images != null and component.images != ''">
                and images = #{component.images}
            </if>
            <if test="component.workingDirectory != null and component.workingDirectory != ''">
                and working_directory = #{component.workingDirectory}
            </if>
            <if test="component.command != null and component.command != ''">
                and command = #{component.command}
            </if>
            <if test="component.envVirables != null and component.envVirables != ''">
                and env_virables = #{component.envVirables}
            </if>
            <if test="component.resourcesStandard != null and component.resourcesStandard != ''">
                and resources_standard = #{component.resourcesStandard}
            </if>
            <if test="component.controlStrategy != null and component.controlStrategy != ''">
                and control_strategy = #{component.controlStrategy}
            </if>
            <if test="component.mountPath != null and component.mountPath != ''">
                and mount_path = #{component.mountPath}
            </if>
            <if test="component.inParameters != null and component.inParameters != ''">
                and in_parameters = #{component.inParameters}
            </if>
            <if test="component.outParameters != null and component.outParameters != ''">
                and out_parameters = #{component.outParameters}
            </if>
            <if test="component.availableRange != null">
                and available_range = #{component.availableRange}
            </if>
            <if test="component.description != null and component.description != ''">
                and description = #{component.description}
            </if>
            <if test="component.iconPath != null and component.iconPath != ''">
                and icon_path = #{component.iconPath}
            </if>
            <if test="component.createBy != null and component.createBy != ''">
                and create_by = #{component.createBy}
            </if>
            <if test="component.createTime != null">
                and create_time = #{component.createTime}
            </if>
            <if test="component.updateBy != null and component.updateBy != ''">
                and update_by = #{component.updateBy}
            </if>
            <if test="component.updateTime != null">
                and update_time = #{component.updateTime}
            </if>
            <if test="component.state != null">
                and state = #{component.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from component
        <where>
            state = 1
            <if test="component.id != null">
                and id = #{component.id}
            </if>
            <if test="component.categoryId != null">
                and category_id = #{component.categoryId}
            </if>
            <if test="component.componentName != null and component.componentName != ''">
                and component_name = #{component.componentName}
            </if>
            <if test="component.componentLabel != null and component.componentLabel != ''">
                and component_label = #{component.componentLabel}
            </if>
            <if test="component.images != null and component.images != ''">
                and images = #{component.images}
            </if>
            <if test="component.workingDirectory != null and component.workingDirectory != ''">
                and working_directory = #{component.workingDirectory}
            </if>
            <if test="component.command != null and component.command != ''">
                and command = #{component.command}
            </if>
            <if test="component.envVirables != null and component.envVirables != ''">
                and env_virables = #{component.envVirables}
            </if>
            <if test="component.resourcesStandard != null and component.resourcesStandard != ''">
                and resources_standard = #{component.resourcesStandard}
            </if>
            <if test="component.controlStrategy != null and component.controlStrategy != ''">
                and control_strategy = #{component.controlStrategy}
            </if>
            <if test="component.mountPath != null and component.mountPath != ''">
                and mount_path = #{component.mountPath}
            </if>
            <if test="component.inParameters != null and component.inParameters != ''">
                and in_parameters = #{component.inParameters}
            </if>
            <if test="component.outParameters != null and component.outParameters != ''">
                and out_parameters = #{component.outParameters}
            </if>
            <if test="component.availableRange != null">
                and available_range = #{component.availableRange}
            </if>
            <if test="component.description != null and component.description != ''">
                and description = #{component.description}
            </if>
            <if test="component.iconPath != null and component.iconPath != ''">
                and icon_path = #{component.iconPath}
            </if>
            <if test="component.createBy != null and component.createBy != ''">
                and create_by = #{component.createBy}
            </if>
            <if test="component.createTime != null">
                and create_time = #{component.createTime}
            </if>
            <if test="component.updateBy != null and component.updateBy != ''">
                and update_by = #{component.updateBy}
            </if>
            <if test="component.updateTime != null">
                and update_time = #{component.updateTime}
            </if>
            <if test="component.state != null">
                and state = #{component.state}
            </if>
        </where>
    </select>

    <select id="countByNameAndCategoryId" resultType="java.lang.Integer">
        select count(1)
        from component
        where category_id = #{categoryId}
        and component_name = #{componentName}
        and state = 1
    </select>


    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into component(category_id,component_name,component_Label,images,working_directory,command,env_virables,resources_standard,control_strategy,mount_path,in_parameters,out_parameters,available_range,description,icon_path,create_by,create_time,update_by,update_time,state)
        values (#{component.categoryId},#{component.componentName},#{component.componentLabel},#{component.images},#{component.workingDirectory},#{component.command},#{component.envVirables},#{component.resourcesStandard},#{component.controlStrategy},#{component.mountPath},#{component.inParameters},#{component.outParameters},#{component.availableRange},#{component.description},#{component.iconPath},#{component.createBy},#{component.createTime},#{component.updateBy},#{component.updateTime},#{component.state})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into component(category_id,component_name,component_Label,images,working_directory,command,env_virables,resources_standard,control_strategy,mount_path,in_parameters,out_parameters,available_range,description,icon_path,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.categoryId},#{entity.componentName},#{entity.componentLabel},#{entity.images},#{entity.workingDirectory},#{entity.command},#{entity.envVirables},#{entity.resourcesStandard},#{entity.controlStrategy},#{entity.mountPath},#{entity.inParameters},#{entity.outParameters},#{entity.availableRange},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into component(category_id,component_name,component_Label,images,working_directory,command,env_virables,resources_standard,control_strategy,mount_path,in_parameters,out_parameters,available_range,description,icon_path,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.categoryId},#{entity.componentName},#{entity.componentLabel},#{entity.images},#{entity.workingDirectory},#{entity.command},#{entity.envVirables},#{entity.resourcesStandard},#{entity.controlStrategy},#{entity.mountPath},#{entity.inParameters},#{entity.outParameters},#{entity.availableRange},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
        on duplicate key update
category_id = values(category_id)component_name = values(component_name)component_id = values(component_id)images = values(images)working_directory = values(working_directory)command = values(command)env_virables = values(env_virables)resources_standard = values(resources_standard)control_strategy = values(control_strategy)mount_path = values(mount_path)in_parameters = values(in_parameters)out_parameters = values(out_parameters)create_by = values(create_by)create_time = values(create_time)update_by = values(update_by)update_time = values(update_time)state = values(state)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update component
        <set>
            <if test="component.id != null">
                id = #{component.id},
            </if>
            <if test="component.categoryId != null">
                category_id = #{component.categoryId},
            </if>
            <if test="component.componentName != null and component.componentName != ''">
                component_name = #{component.componentName},
            </if>
            <if test="component.componentLabel != null and component.componentLabel != ''">
                component_label = #{component.componentLabel},
            </if>
            <if test="component.images != null and component.images != ''">
                images = #{component.images},
            </if>
            <if test="component.workingDirectory != null and component.workingDirectory != ''">
                working_directory = #{component.workingDirectory},
            </if>
            <if test="component.command != null and component.command != ''">
                command = #{component.command},
            </if>
            <if test="component.envVirables != null and component.envVirables != ''">
                env_virables = #{component.envVirables},
            </if>
            <if test="component.resourcesStandard != null and component.resourcesStandard != ''">
                resources_standard = #{component.resourcesStandard},
            </if>
            <if test="component.controlStrategy != null and component.controlStrategy != ''">
                control_strategy = #{component.controlStrategy},
            </if>
            <if test="component.mountPath != null and component.mountPath != ''">
                mount_path = #{component.mountPath},
            </if>
            <if test="component.inParameters != null and component.inParameters != ''">
                in_parameters = #{component.inParameters},
            </if>
            <if test="component.outParameters != null and component.outParameters != ''">
                out_parameters = #{component.outParameters},
            </if>
            <if test="component.availableRange != null">
                available_range = #{component.availableRange},
            </if>
            <if test="component.description != null and component.description != ''">
                description = #{component.description},
            </if>
            <if test="component.iconPath != null and component.iconPath != ''">
                icon_path = #{component.iconPath},
            </if>
            <if test="component.createBy != null and component.createBy != ''">
                create_by = #{component.createBy},
            </if>
            <if test="component.createTime != null">
                create_time = #{component.createTime},
            </if>
            <if test="component.updateBy != null and component.updateBy != ''">
                update_by = #{component.updateBy},
            </if>
            <if test="component.updateTime != null">
                update_time = #{component.updateTime},
            </if>
            <if test="component.state != null">
                state = #{component.state}
            </if>
        </set>
        where id = #{component.id}
    </update>


    <!--通过主键删除-->
    <delete id="deleteById">
        delete from component where id = #{id}
    </delete>

</mapper>

