leutu
2024-06-03 3ef35e6cd16bbfa206b26bb3271eac40ad020bcb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?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.fastbee.iot.mapper.ProductMapper">
 
    <resultMap type="com.fastbee.iot.domain.Product" id="ProductResult">
        <result property="productId"    column="product_id"    />
        <result property="productName"    column="product_name"    />
        <result property="protocolCode" column="protocol_code"/>
        <result property="categoryId"    column="category_id"    />
        <result property="categoryName"    column="category_name"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="tenantName"    column="tenant_name"    />
        <result property="isSys"    column="is_sys"    />
        <result property="isAuthorize"    column="is_authorize"    />
        <result property="mqttAccount"    column="mqtt_account"    />
        <result property="mqttPassword"    column="mqtt_password"    />
        <result property="mqttSecret"    column="mqtt_secret"    />
        <result property="status"    column="status"    />
        <result property="deviceType"    column="device_type"    />
        <result property="networkMethod"    column="network_method"    />
        <result property="vertificateMethod"    column="vertificate_method"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="transport" column="transport"/>
    </resultMap>
 
    <resultMap type="com.fastbee.iot.model.IdAndName" id="ProductShortResult">
        <result property="id"    column="product_id"    />
        <result property="name"    column="product_name"    />
    </resultMap>
 
    <sql id="selectProductVo">
        select product_id, product_name,protocol_code,transport, category_id, category_name, tenant_id, tenant_name, is_sys, is_authorize, mqtt_account,mqtt_password,mqtt_secret ,status, device_type, network_method, vertificate_method, create_time, update_time, img_url,remark from iot_product
    </sql>
 
    <select id="selectProductList" parameterType="com.fastbee.iot.domain.Product" resultMap="ProductResult">
        <include refid="selectProductVo"/>
        <where>
            <if test="productName != null  and productName != ''"> and product_name like concat('%', #{productName}, '%')</if>
            <if test="categoryId != null "> and category_id = #{categoryId}</if>
            <if test="categoryName != null  and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</if>
            <if test="tenantName != null  and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
            <if test="isAuthorize != null "> and is_authorize = #{isAuthorize}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="deviceType != null "> and device_type = #{deviceType}</if>
            <if test="networkMethod != null "> and network_method = #{networkMethod}</if>
            <if test="tenantId != null  and tenantId != 0"> and tenant_id = #{tenantId}</if>
        </where>
        order by create_time desc
    </select>
 
    <select id="selectProductShortList" parameterType="com.fastbee.iot.domain.Product" resultMap="ProductShortResult">
        select product_id,product_name from iot_product
        <where>
            <if test="tenantId != null  and tenantId != 0"> and tenant_id = #{tenantId}</if>
        </where>
        order by create_time desc
    </select>
 
    <select id="selectProductByProductId" parameterType="Long" resultMap="ProductResult">
        <include refid="selectProductVo"/>
        where product_id = #{productId}
    </select>
 
    <insert id="insertProduct" parameterType="com.fastbee.iot.domain.Product" useGeneratedKeys="true" keyProperty="productId">
        insert into iot_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productName != null and productName != ''">product_name,</if>
            <if test="categoryId != null">category_id,</if>
            <if test="categoryName != null and categoryName != ''">category_name,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="tenantName != null and tenantName != ''">tenant_name,</if>
            <if test="isSys != null">is_sys,</if>
            <if test="isAuthorize != null">is_authorize,</if>
            <if test="mqttAccount != null and mqttAccount != ''">mqtt_account,</if>
            <if test="mqttPassword != null and mqttPassword != ''">mqtt_password,</if>
            <if test="mqttSecret != null and mqttSecret != ''">mqtt_secret,</if>
            <if test="status != null">status,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="networkMethod != null">network_method,</if>
            <if test="vertificateMethod != null">vertificate_method,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="protocolCode != null">protocol_code,</if>
            <if test="transport != null" >transport,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productName != null and productName != ''">#{productName},</if>
            <if test="categoryId != null">#{categoryId},</if>
            <if test="categoryName != null and categoryName != ''">#{categoryName},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="tenantName != null and tenantName != ''">#{tenantName},</if>
            <if test="isSys != null">#{isSys},</if>
            <if test="isAuthorize != null">#{isAuthorize},</if>
            <if test="mqttAccount != null and mqttAccount != ''">#{mqttAccount},</if>
            <if test="mqttPassword != null and mqttPassword != ''">#{mqttPassword},</if>
            <if test="mqttSecret != null and mqttSecret != ''">#{mqttSecret},</if>
            <if test="status != null">#{status},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="networkMethod != null">#{networkMethod},</if>
            <if test="vertificateMethod != null">#{vertificateMethod},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="protocolCode != null">#{protocolCode,jdbcType=VARCHAR}, </if>
            <if test="transport != null" >#{transport,jdbcType=VARCHAR},</if>
         </trim>
    </insert>
 
    <update id="updateProduct" parameterType="com.fastbee.iot.domain.Product">
        update iot_product
        <trim prefix="SET" suffixOverrides=",">
            <if test="productName != null and productName != ''">product_name = #{productName},</if>
            <if test="categoryId != null">category_id = #{categoryId},</if>
            <if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
            <if test="isSys != null">is_sys = #{isSys},</if>
            <if test="isAuthorize != null">is_authorize = #{isAuthorize},</if>
            <if test="mqttAccount != null and mqttAccount != ''">mqtt_account = #{mqttAccount},</if>
            <if test="mqttPassword != null and mqttPassword != ''">mqtt_password = #{mqttPassword},</if>
            <if test="mqttSecret != null and mqttSecret != ''">mqtt_secret = #{mqttSecret},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="networkMethod != null">network_method = #{networkMethod},</if>
            <if test="vertificateMethod != null">vertificate_method = #{vertificateMethod},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="protocolCode != null">protocol_code = #{protocolCode,jdbcType=VARCHAR}, </if>
            <if test="transport != null" >transport = #{transport,jdbcType=VARCHAR},</if>
        </trim>
        where product_id = #{productId}
    </update>
 
    <update id="changeProductStatus" parameterType="com.fastbee.iot.model.ChangeProductStatusModel">
        update iot_product set status=#{status}
        where product_id = #{productId}
    </update>
 
    <update id="updateThingsModelJson" parameterType="com.fastbee.iot.domain.Product">
        update iot_product set things_models_json=#{thingsModelsJson}
        where product_id = #{productId}
    </update>
 
    <delete id="deleteProductByProductId" parameterType="Long">
        delete from iot_product where product_id = #{productId}
    </delete>
 
    <delete id="deleteProductByProductIds" parameterType="String">
        delete from iot_product where product_id in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </delete>
 
    <delete id="deleteProductThingsModelByProductIds" parameterType="String">
        delete from iot_things_model where product_id in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </delete>
 
    <select id="deviceCountInProducts" parameterType="String" resultType="int">
        select count(*) from iot_device where product_id in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </select>
 
    <select id="thingsCountInProduct" parameterType="Long" resultType="int">
        select count(model_id) from iot_things_model
        where product_id = #{productId}
    </select>
 
    <select id="thingsRepeatCountInProduct" parameterType="Long" resultType="int">
        SELECT count( identifier )
        FROM ( SELECT identifier
               FROM iot_things_model
               WHERE product_id = #{productId}
               GROUP BY identifier,product_id
               HAVING count( identifier )> 1 ) AS identifiers
    </select>
 
    <select id="getProductBySerialNumber" resultMap="ProductResult" parameterType="String">
        <include refid="selectProductVo" />
        where product_id =
        (select product_id from iot_device
          where serial_number = #{serialNumber,jdbcType=VARCHAR}
        )
    </select>
 
    <select id="getProtocolBySerialNumber" resultType="com.fastbee.iot.model.ProductCode">
        select p.protocol_code as protocolCode,
               p.product_id as productId
          from
           iot_product p
           inner join iot_device d on p.product_id = d.product_id
           and d.serial_number = #{serialNumber,jdbcType=VARCHAR}
    </select>
 
    <select id="getProtocolByProductId" resultType="java.lang.String">
        select p.protocol_code from
        iot_product p
        where p.product_id = #{productId,jdbcType=BIGINT}
    </select>
 
    <select id="selectByTempleId" resultMap="ProductResult">
        select p.product_id,p.product_name,p.protocol_code,p.transport from iot_device_template t inner join
                                                                            iot_product p on t.product_id = p.product_id
        where t.template_id = #{templeId}
    </select>
</mapper>