<?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.usky.rule.mapper.RuleEngineDeviceMapper">
    <resultMap id="Base" type="com.usky.rule.domain.RuleEngineDevice">
        <id column="id" property="id"/>
        <result column="device_id" property="deviceId"/>
        <result column="device_uuid" property="deviceUuid"/>
        <result column="identifier" property="identifier"/>
        <result column="rule_engine_id" property="ruleEngineId"/>
        <result column="product_id" property="productId"/>
        <result column="updated_by" property="updatedBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="created_by" property="createdBy"/>
        <result column="create_time" property="createTime"/>
        <result column="tenant_id" property="tenantId"/>
    </resultMap>
    <select id="selectByDeviceAndIdentifier" resultMap="Base">
        SELECT * FROM rule_engine_device
        WHERE device_id = #{deviceId} AND identifier = #{identifier} and rule_engine_id = #{ruleEngineId}
        <if test="tenantId != null">AND tenant_id = #{tenantId}</if>
    </select>
    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO rule_engine_device (device_id, device_uuid, identifier, rule_engine_id, product_id, created_by, create_time, updated_by, update_time, tenant_id)
        VALUES (#{deviceId}, #{deviceUuid}, #{identifier}, #{ruleEngineId}, #{productId}, #{createdBy}, NOW(), #{updatedBy}, NOW(), #{tenantId})
    </insert>
    <delete id="deleteByRuleEngineId">DELETE FROM rule_engine_device WHERE rule_engine_id = #{ruleEngineId}</delete>
    <select id="selectByRuleEngineId" resultMap="Base">SELECT * FROM rule_engine_device WHERE rule_engine_id = #{ruleEngineId}</select>
    <select id="selectByDeviceId" resultMap="Base">SELECT * FROM rule_engine_device WHERE device_id = #{deviceId}</select>
    <select id="selectByDeviceUuid" resultMap="Base">SELECT * FROM rule_engine_device WHERE device_uuid = #{deviceUuid}</select>
</mapper>
