<?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.base.mapper.BasePlcParamMapper">
    
    <resultMap type="BasePlcParam" id="BasePlcParamResult">
        <result property="objId"    column="obj_id"    />
        <result property="paramCode"    column="param_code"    />
        <result property="paramAlias"    column="param_alias"    />
        <result property="paramAddr"    column="param_addr"    />
        <result property="paramType"    column="param_type"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="createdBy"    column="created_by"    />
        <result property="createdTime"    column="created_time"    />
        <result property="updatedBy"    column="updated_by"    />
        <result property="updatedTime"    column="updated_time"    />
    </resultMap>

    <sql id="selectBasePlcParamVo">
        select obj_id, param_code, param_alias, param_addr, param_type, is_flag, created_by, created_time, updated_by, updated_time from base_plc_param
    </sql>

    <select id="selectBasePlcParamList" parameterType="BasePlcParam" resultMap="BasePlcParamResult">
        <include refid="selectBasePlcParamVo"/>
        <where>  
            <if test="objId != null "> and obj_id = #{objId}</if>
            <if test="paramCode != null  and paramCode != ''"> and param_code = #{paramCode}</if>
            <if test="paramAlias != null  and paramAlias != ''"> and param_alias like concat('%', #{paramAlias}, '%')</if>
            <if test="paramAddr != null  and paramAddr != ''"> and param_addr = #{paramAddr}</if>
            <if test="paramType != null  and paramType != ''"> and param_type = #{paramType}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''"> and created_by = #{createdBy}</if>
            <if test="params.beginCreatedTime != null and params.beginCreatedTime != '' and params.endCreatedTime != null and params.endCreatedTime != ''"> and created_time between #{params.beginCreatedTime} and #{params.endCreatedTime}</if>
            <if test="updatedBy != null  and updatedBy != ''"> and updated_by = #{updatedBy}</if>
            <if test="params.beginUpdatedTime != null and params.beginUpdatedTime != '' and params.endUpdatedTime != null and params.endUpdatedTime != ''"> and updated_time between #{params.beginUpdatedTime} and #{params.endUpdatedTime}</if>
        </where>
    </select>
    
    <select id="selectBasePlcParamByObjId" parameterType="Long" resultMap="BasePlcParamResult">
        <include refid="selectBasePlcParamVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBasePlcParam" parameterType="BasePlcParam">
        insert into base_plc_param
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="paramCode != null">param_code,</if>
            <if test="paramAlias != null">param_alias,</if>
            <if test="paramAddr != null">param_addr,</if>
            <if test="paramType != null">param_type,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="paramCode != null">#{paramCode},</if>
            <if test="paramAlias != null">#{paramAlias},</if>
            <if test="paramAddr != null">#{paramAddr},</if>
            <if test="paramType != null">#{paramType},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
         </trim>
    </insert>

    <update id="updateBasePlcParam" parameterType="BasePlcParam">
        update base_plc_param
        <trim prefix="SET" suffixOverrides=",">
            <if test="paramCode != null">param_code = #{paramCode},</if>
            <if test="paramAlias != null">param_alias = #{paramAlias},</if>
            <if test="paramAddr != null">param_addr = #{paramAddr},</if>
            <if test="paramType != null">param_type = #{paramType},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBasePlcParamByObjId" parameterType="Long">
        delete from base_plc_param where obj_id = #{objId}
    </delete>

    <delete id="deleteBasePlcParamByObjIds" parameterType="String">
        delete from base_plc_param where obj_id in 
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>
</mapper>