<?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.ExperimentDao">

    <resultMap type="com.ruoyi.platform.domain.Experiment" id="ExperimentMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="workflowId" column="workflow_id" jdbcType="INTEGER"/>
        <result property="globalParam" column="global_param" jdbcType="VARCHAR"/>
        <result property="statusList" column="status_list" jdbcType="VARCHAR"/>
        <result property="description" column="description" 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="ExperimentMap">
        select
          id, name,workflow_id, global_param, status_list,status_list, description, create_by, create_time, update_by, update_time, state
        from experiment
        where id = #{id} and state = 1
    </select>

    <!--查询单个-->
    <select id="findByName" resultMap="ExperimentMap">
        select
        id,name, workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state
        from experiment
        where name = #{name} and state = 1 limit 1
    </select>

    <!--根据experiment查询-->
    <select id="queryByExperiment" resultMap="ExperimentMap">
        select
          id,name, workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state
        from experiment
        <where>
            state = 1
            <if test="experiment.id != null">
                and id = #{experiment.id}
            </if>
            <if test="experiment.name != null and experiment.name != ''">
                and name = #{experiment.name}
            </if>
            <if test="experiment.workflowId != null">
                and workflow_id = #{experiment.workflowId}
            </if>
            <if test="experiment.globalParam != null and experiment.globalParam != ''">
                and global_param = #{experiment.globalParam}
            </if>
            <if test="experiment.statusList != null and experiment.statusList != ''">
                status_list = #{experiment.statusList},
            </if>
            <if test="experiment.description != null and experiment.description != ''">
                and description = #{experiment.description}
            </if>
            <if test="experiment.createBy != null and experiment.createBy != ''">
                and create_by = #{experiment.createBy}
            </if>
            <if test="experiment.createTime != null">
                and create_time = #{experiment.createTime}
            </if>
            <if test="experiment.updateBy != null and experiment.updateBy != ''">
                and update_by = #{experiment.updateBy}
            </if>
            <if test="experiment.updateTime != null">
                and update_time = #{experiment.updateTime}
            </if>
        </where>
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="ExperimentMap">
        select
        id,name, workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state
        from experiment
        <where>
            state = 1
            <if test="experiment.id != null">
                and id = #{experiment.id}
            </if>
            <if test="experiment.name != null and experiment.name != ''">
                and name = #{experiment.name}
            </if>
            <if test="experiment.workflowId != null">
                and workflow_id = #{experiment.workflowId}
            </if>
            <if test="experiment.globalParam != null and experiment.globalParam != ''">
                and global_param = #{experiment.globalParam}
            </if>
            <if test="experiment.statusList != null and experiment.statusList != ''">
                status_list = #{experiment.statusList}
            </if>
            <if test="experiment.description != null and experiment.description != ''">
                and description = #{experiment.description}
            </if>
            <if test="experiment.createBy != null and experiment.createBy != ''">
                and create_by = #{experiment.createBy}
            </if>
            <if test="experiment.createTime != null">
                and create_time = #{experiment.createTime}
            </if>
            <if test="experiment.updateBy != null and experiment.updateBy != ''">
                and update_by = #{experiment.updateBy}
            </if>
            <if test="experiment.updateTime != null">
                and update_time = #{experiment.updateTime}
            </if>
        </where>
        order by update_time DESC
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from experiment
        <where>
            state = 1
            <if test="experiment.id != null">
                and id = #{experiment.id}
            </if>
            <if test="experiment.name != null and experiment.name != ''">
                and name = #{experiment.name}
            </if>
            <if test="experiment.workflowId != null">
                and workflow_id = #{experiment.workflowId}
            </if>
            <if test="experiment.globalParam != null and experiment.globalParam != ''">
                and global_param = #{experiment.globalParam}
            </if>
            <if test="experiment.statusList != null and experiment.statusList != ''">
                status_list = #{experiment.statusList}
            </if>
            <if test="experiment.description != null and experiment.description != ''">
                and description = #{experiment.description}
            </if>
            <if test="experiment.createBy != null and experiment.createBy != ''">
                and create_by = #{experiment.createBy}
            </if>
            <if test="experiment.createTime != null">
                and create_time = #{experiment.createTime}
            </if>
            <if test="experiment.updateBy != null and experiment.updateBy != ''">
                and update_by = #{experiment.updateBy}
            </if>
            <if test="experiment.updateTime != null">
                and update_time = #{experiment.updateTime}
            </if>
        </where>
    </select>


    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into experiment(name,workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state)
        values (#{experiment.name},#{experiment.workflowId}, #{experiment.globalParam},#{experiment.statusList}, #{experiment.description}, #{experiment.createBy}, #{experiment.createTime}, #{experiment.updateBy}, #{experiment.updateTime}, #{experiment.state})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into experiment(name,workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name},#{entity.workflowId}, #{entity.globalParam},#{entity.statusList},  #{entity.description}, #{entity.createBy}, #{entity.createTime},
            #{entity.updateBy}, #{entity.updateTime}, #{entity.state})
        </foreach>
    </insert>

    <update id="insertOrUpdateBatch">
        insert into experiment (id, name, workflow_id, global_param, status_list, description, create_by, create_time, update_by, update_time, state)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id}, #{item.name}, #{item.workflowId}, #{item.globalParam}, #{item.statusList}, #{item.description}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.state})
        </foreach>
        ON DUPLICATE KEY UPDATE
        name = VALUES(name),
        workflow_id = VALUES(workflow_id),
        global_param = VALUES(global_param),
        status_list = VALUES(status_list),
        description = VALUES(description),
        create_by = VALUES(create_by),
        create_time = VALUES(create_time),
        update_by = VALUES(update_by),
        update_time = VALUES(update_time),
        state = VALUES(state);
    </update>


    <!--通过主键修改数据-->
    <update id="update">
        update experiment
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="workflowId != null">
                workflow_id = #{workflowId},
            </if>
            <if test="globalParam != null and globalParam != ''">
                global_param = #{globalParam},
            </if>
            <if test="statusList != null and statusList != ''">
                status_list = #{statusList},
            </if>
            <if test="description != null and description != ''">
                description = #{description},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="state != null">
                state = #{state},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>

