IotThingsModelMapper.xml 10.0 KB
<?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.zhonglai.luhui.device.mapper.IotThingsModelMapper">
    
    <resultMap type="IotThingsModel" id="IotThingsModelResult">
        <result property="create_by"    column="create_by"    />
        <result property="create_time"    column="create_time"    />
        <result property="data_type"    column="data_type"    />
        <result property="del_flag"    column="del_flag"    />
        <result property="identifier"    column="identifier"    />
        <result property="is_monitor"    column="is_monitor"    />
        <result property="is_save_log"    column="is_save_log"    />
        <result property="is_top"    column="is_top"    />
        <result property="model_id"    column="model_id"    />
        <result property="model_name"    column="model_name"    />
        <result property="remark"    column="remark"    />
        <result property="specs"    column="specs"    />
        <result property="type"    column="type"    />
        <result property="update_by"    column="update_by"    />
        <result property="update_time"    column="update_time"    />
        <result property="product_id"    column="product_id"    />
        <result property="is_config"    column="is_config"    />
        <result property="mqtt_username"    column="mqtt_username"    />
        <result property="config_names"    column="config_names"    />
        <result property="view_type"    column="view_type"    />
        <result property="ascription"    column="ascription"    />
    </resultMap>

    <sql id="selectIotThingsModelVo">
        select create_by, create_time, data_type, del_flag, identifier, is_monitor, is_save_log, is_top, model_id, model_name, remark, specs, `type`, update_by, update_time, product_id,is_config,config_names,view_type,mqtt_username,ascription from iot_things_model
    </sql>

    <select id="selectIotThingsModelList" parameterType="IotThingsModel" resultMap="IotThingsModelResult">
        <include refid="selectIotThingsModelVo"/>
        <where>
            <if test="create_by !=null and create_by != ''">
                and create_by = #{create_by}
            </if>
            <if test="data_type !=null and data_type != ''">
                and data_type = #{data_type}
            </if>
            <if test="identifier !=null and identifier != ''">
                and identifier = #{identifier}
            </if>
            <if test="is_save_log !=null and is_save_log != ''">
                and is_save_log = #{is_save_log}
            </if>
            <if test="is_monitor !=null and is_monitor != ''">
                and is_monitor = #{is_monitor}
            </if>
            <if test="model_id !=null and model_id != ''">
                and model_id = #{model_id}
            </if>
            <if test="model_name !=null and model_name != ''">
                and model_name = #{model_name}
            </if>
            <if test="type !=null and type != ''">
                and `type` = #{type}
            </if>
            <if test="product_id !=null and product_id != ''">
                and product_id = #{product_id}
            </if>
            <if test="mqtt_username !=null and mqtt_username != ''">
                and mqtt_username = #{mqtt_username}
            </if>
            <if test="ascription !=null and ascription != ''">
                and ascription = #{ascription}
            </if>
        </where>
    </select>

    <select id="selectIotThingsModelListByIds" parameterType="Integer" resultMap="IotThingsModelResult">
        select a.create_by, a.create_time, a.data_type, a.del_flag, a.identifier, a.is_monitor, a.is_save_log, a.is_top, a.model_id, a.model_name, a.remark, a.specs, a.`type`, a.update_by, a.update_time, a.product_id,a.is_config,a.view_type,a.ascription,b.mqtt_username mqtt_username FROM `mqtt_broker`.`iot_things_model` a LEFT JOIN `mqtt_broker`.`iot_product` b ON a.`product_id`=b.`id`
        where a.model_id in
        <foreach item="model_id" collection="array" open="(" separator="," close=")">
            #{model_id}
        </foreach>
    </select>
    
    <select id="selectIotThingsModelByModel_id" parameterType="Integer" resultMap="IotThingsModelResult">
        <include refid="selectIotThingsModelVo"/>
        where model_id = #{model_id}
    </select>
        
    <insert id="insertIotThingsModel" parameterType="IotThingsModel" useGeneratedKeys="true" keyProperty="model_id">
        insert into iot_things_model
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="create_by != null">create_by,</if>
            <if test="data_type != null and data_type != ''">data_type,</if>
            <if test="del_flag != null">del_flag,</if>
            <if test="identifier != null and identifier != ''">identifier,</if>
            <if test="is_monitor != null">is_monitor,</if>
            <if test="is_save_log != null">is_save_log,</if>
            <if test="is_top != null">is_top,</if>
            <if test="model_name != null and model_name != ''">model_name,</if>
            <if test="remark != null">remark,</if>
            <if test="specs != null">specs,</if>
            <if test="type != null">`type`,</if>
            <if test="update_by != null">update_by,</if>
            <if test="update_time != null">update_time,</if>
            <if test="product_id != null">product_id,</if>
            <if test="is_config != null">is_config,</if>
            <if test="config_names != null">config_names,</if>
            <if test="view_type != null">view_type,</if>
            <if test="mqtt_username != null">mqtt_username,</if>
            <if test="ascription != null">ascription,</if>
            create_time,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="create_by != null">#{create_by},</if>
            <if test="data_type != null and data_type != ''">#{data_type},</if>
            <if test="del_flag != null">#{del_flag},</if>
            <if test="identifier != null and identifier != ''">#{identifier},</if>
            <if test="is_monitor != null">#{is_monitor},</if>
            <if test="is_save_log != null">#{is_save_log},</if>
            <if test="is_top != null">#{is_top},</if>
            <if test="model_name != null and model_name != ''">#{model_name},</if>
            <if test="remark != null">#{remark},</if>
            <if test="specs != null">#{specs},</if>
            <if test="type != null">#{type},</if>
            <if test="update_by != null">#{update_by},</if>
            <if test="update_time != null">#{update_time},</if>
            <if test="product_id != null">#{product_id},</if>
            <if test="is_config != null">#{is_config},</if>
            <if test="config_names != null">#{config_names},</if>
            <if test="view_type != null">#{view_type},</if>
            <if test="mqtt_username != null">#{mqtt_username},</if>
            <if test="ascription != null">#{ascription},</if>
            TIMESTAMP(NOW()),
         </trim>
    </insert>

    <update id="updateIotThingsModel" parameterType="IotThingsModel">
        update iot_things_model
        <trim prefix="SET" suffixOverrides=",">
            <if test="create_by != null">create_by = #{create_by},</if>
            <if test="create_time != null">create_time = #{create_time},</if>
            <if test="data_type != null and data_type != ''">data_type = #{data_type},</if>
            <if test="del_flag != null">del_flag = #{del_flag},</if>
            <if test="identifier != null and identifier != ''">identifier = #{identifier},</if>
            <if test="is_monitor != null">is_monitor = #{is_monitor},</if>
            <if test="is_save_log != null">is_save_log = #{is_save_log},</if>
            <if test="is_top != null">is_top = #{is_top},</if>
            <if test="model_name != null and model_name != ''">model_name = #{model_name},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="specs != null">specs = #{specs},</if>
            <if test="type != null">type = #{type},</if>
            <if test="update_by != null">update_by = #{update_by},</if>
            <if test="update_time != null">update_time = #{update_time},</if>
            <if test="product_id != null">product_id = #{product_id},</if>
            <if test="is_config != null">is_config = #{is_config},</if>
            <if test="config_names != null">config_names = #{config_names},</if>
            <if test="view_type != null">view_type = #{view_type},</if>
            <if test="mqtt_username != null">mqtt_username = #{mqtt_username},</if>
            <if test="ascription != null">ascription = #{ascription},</if>
        </trim>
        where model_id = #{model_id}
    </update>

    <delete id="deleteIotThingsModelByModel_id" parameterType="Integer">
        delete from iot_things_model where model_id = #{model_id}
    </delete>

    <delete id="deleteIotThingsModelByModel_ids" parameterType="Integer">
        delete from iot_things_model where model_id in 
        <foreach item="model_id" collection="array" open="(" separator="," close=")">
            #{model_id}
        </foreach>
    </delete>

    <insert id="distributionIotThingsModelTemplate" parameterType="DistributionCurrencyModel">
       INSERT INTO `iot_things_model`(`model_name`,`identifier`,`type`,`data_type`,`specs`,`is_top`,`is_monitor`,`del_flag`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`,`product_id`,`mqtt_username`,`is_save_log`,`is_config`,`config_names`,`view_type`,`ascription`) SELECT `model_name`,`identifier`,`type`,`data_type`,`specs`,`is_top`,`is_monitor`,`del_flag`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`,#{product_id,jdbcType=INTEGER} `product_id`,#{mqtt_username,jdbcType=VARCHAR} `mqtt_username`,`is_save_log`,`is_config`,`config_names`,`view_type`,`ascription` FROM `iot_things_model_template` WHERE `model_id` IN
        <foreach item="model_id" collection="model_ids" open="(" separator="," close=")">
            #{model_id}
        </foreach>
    </insert>
</mapper>