Commit f6b7b85e4c6a6b50b33197a9d2671f667ab64b6d

Authored by xp.Huang
2 parents f7129f32 11e92040

Merge branch 'cherry-pick-f90cd70f' into 'master_dev'

fix:小程序首页统计信息 客户查询数量不正确

See merge request yunteng/thingskit!337
... ... @@ -103,20 +103,24 @@
103 103 </select>
104 104
105 105 <select id="countAlarms" resultMap="aggregationMap">
106   - SELECT status ,COUNT(id) AS value FROM alarm
  106 + SELECT status , COUNT(m.id) AS value FROM alarm m
  107 + <if test="queryMap.customerId !=null">
  108 + LEFT JOIN tk_device d ON m.originator_id = d.tb_device_id::uuid
  109 + LEFT JOIN device bd ON bd.id = d.tb_device_id::uuid
  110 + </if>
107 111 <where>
108 112 1=1
109 113 <if test="queryMap.tenantId !=null">
110   - AND tenant_id= #{queryMap.tenantId}::uuid
  114 + AND m.tenant_id= #{queryMap.tenantId}::uuid
111 115 </if>
112 116 <if test="queryMap.customerId !=null">
113   - AND customer_id= #{queryMap.customerId}::uuid
  117 + AND bd.customer_id= #{queryMap.customerId}::uuid
114 118 </if>
115   - <if test="queryMap.startTime !=null">
116   - AND created_time >= #{queryMap.startTime}
  119 + <if test="queryMap.startTime !=null and queryMap.customerId ==null">
  120 + AND m.created_time >= #{queryMap.startTime}
117 121 </if>
118   - <if test="queryMap.endTime !=null">
119   - AND created_time &lt; #{queryMap.endTime}
  122 + <if test="queryMap.endTime !=null and queryMap.customerId ==null">
  123 + AND m.created_time &lt; #{queryMap.endTime}
120 124 </if>
121 125 </where>
122 126 GROUP BY status;
... ...