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

    <resultMap type="com.ruoyi.platform.domain.WorkflowParam" id="WorkflowParamMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="workflowId" column="workflow_id" jdbcType="INTEGER"/>
        <result property="paramName" column="param_name" jdbcType="VARCHAR"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
        <result property="paramType" column="param_type" jdbcType="VARCHAR"/>
        <result property="paramValue" column="param_value" jdbcType="VARCHAR"/>
        <result property="isSensitive" column="is_sensitive" jdbcType="INTEGER"/>
        <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="WorkflowParamMap">
        select
        id,workflow_id,param_name,description,param_type,param_value,is_sensitive,create_by,create_time,update_by,update_time,state
        from workflow_param
        where id = #{id} and state = 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="WorkflowParamMap">
        select
        id, workflow_id, param_name, description, param_type, param_value, is_sensitive, create_by, create_time, update_by, update_time, state
        from workflow_param
        <where>
            state = 1
            <if test="workflowParam.id != null">
                and id = #{workflowParam.id}
            </if>
            <if test="workflowParam.workflowId != null">
                and workflow_id = #{workflowParam.workflowId}
            </if>
            <if test="workflowParam.paramName != null and workflowParam.paramName != ''">
                and param_name = #{workflowParam.paramName}
            </if>
            <if test="workflowParam.description != null and workflowParam.description != ''">
                and description = #{workflowParam.description}
            </if>
            <if test="workflowParam.paramType != null">
                and param_type = #{workflowParam.paramType}
            </if>
            <if test="workflowParam.paramValue != null and workflowParam.paramValue != ''">
                and param_value = #{workflowParam.paramValue}
            </if>
            <if test="workflowParam.isSensitive != null">
                and is_sensitive = #{workflowParam.isSensitive}
            </if>
            <if test="workflowParam.createBy != null and workflowParam.createBy != ''">
                and create_by = #{workflowParam.createBy}
            </if>
            <if test="workflowParam.createTime != null">
                and create_time = #{workflowParam.createTime}
            </if>
            <if test="workflowParam.updateBy != null and workflowParam.updateBy != ''">
                and update_by = #{workflowParam.updateBy}
            </if>
            <if test="workflowParam.updateTime != null">
                and update_time = #{workflowParam.updateTime}
            </if>
            <if test="workflowParam.state != null">
                and state = #{workflowParam.state}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>


    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from workflow_param
        <where>
            state = 1
            <if test="workflowParam.id != null">
                and id = #{workflowParam.id}
            </if>
            <if test="workflowParam.workflowId != null">
                and workflow_id = #{workflowParam.workflowId}
            </if>
            <if test="workflowParam.paramName != null and workflowParam.paramName != ''">
                and param_name = #{workflowParam.paramName}
            </if>
            <if test="workflowParam.description != null and workflowParam.description != ''">
                and description = #{workflowParam.description}
            </if>
            <if test="workflowParam.paramType != null">
                and param_type = #{workflowParam.paramType}
            </if>
            <if test="workflowParam.paramValue != null and workflowParam.paramValue != ''">
                and param_value = #{workflowParam.paramValue}
            </if>
            <if test="workflowParam.isSensitive != null">
                and is_sensitive = #{workflowParam.isSensitive}
            </if>
            <if test="workflowParam.createBy != null and workflowParam.createBy != ''">
                and create_by = #{workflowParam.createBy}
            </if>
            <if test="workflowParam.createTime != null">
                and create_time = #{workflowParam.createTime}
            </if>
            <if test="workflowParam.updateBy != null and workflowParam.updateBy != ''">
                and update_by = #{workflowParam.updateBy}
            </if>
            <if test="workflowParam.updateTime != null">
                and update_time = #{workflowParam.updateTime}
            </if>
            <if test="workflowParam.state != null">
                and state = #{workflowParam.state}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into workflow_param(workflow_id, param_name, description, param_type, param_value, is_sensitive, create_by, create_time, update_by, update_time, state)
        values (#{workflowParam.workflowId}, #{workflowParam.paramName}, #{workflowParam.description}, #{workflowParam.paramType}, #{workflowParam.paramValue}, #{workflowParam.isSensitive}, #{workflowParam.createBy}, #{workflowParam.createTime}, #{workflowParam.updateBy}, #{workflowParam.updateTime}, #{workflowParam.state})
    </insert>


    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into workflow_param(workflow_id,param_name,description,param_type,param_value,is_sensitive,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.workflowId},#{entity.paramName},#{entity.description},#{entity.paramType},#{entity.paramValue},#{entity.isSensitive},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into workflow_param(workflow_id,param_name,description,param_type,param_value,is_sensitive,create_by,create_time,update_by,update_time,state)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.workflowId},#{entity.paramName},#{entity.description},#{entity.paramType},#{entity.paramValue},#{entity.isSensitive},#{entity.createBy},#{entity.createTime},#{entity.updateBy},#{entity.updateTime},#{entity.state})
        </foreach>
        on duplicate key update
workflow_id = values(workflow_id)param_name = values(param_name)description = values(description)param_type = values(param_type)param_value = values(param_value)is_sensitive = values(is_sensitive)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 workflow_param
        <set>
            <if test="workflowParam.workflowId != null">
                workflow_id = #{workflowParam.workflowId},
            </if>
            <if test="workflowParam.paramName != null and workflowParam.paramName != ''">
                param_name = #{workflowParam.paramName},
            </if>
            <if test="workflowParam.description != null and workflowParam.description != ''">
                description = #{workflowParam.description},
            </if>
            <if test="workflowParam.paramType != null">
                param_type = #{workflowParam.paramType},
            </if>
            <if test="workflowParam.paramValue != null and workflowParam.paramValue != ''">
                param_value = #{workflowParam.paramValue},
            </if>
            <if test="workflowParam.isSensitive != null">
                is_sensitive = #{workflowParam.isSensitive},
            </if>
            <if test="workflowParam.createBy != null and workflowParam.createBy != ''">
                create_by = #{workflowParam.createBy},
            </if>
            <if test="workflowParam.createTime != null">
                create_time = #{workflowParam.createTime},
            </if>
            <if test="workflowParam.updateBy != null and workflowParam.updateBy != ''">
                update_by = #{workflowParam.updateBy},
            </if>
            <if test="workflowParam.updateTime != null">
                update_time = #{workflowParam.updateTime},
            </if>
            <if test="workflowParam.state != null">
                state = #{workflowParam.state},
            </if>
        </set>
        where id = #{workflowParam.id}
    </update>


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

</mapper>

