Browse Source

添加消息

lihui001 3 years ago
parent
commit
189ef1123f

+ 3 - 0
zoniot-water/zoniot-water-api/src/main/java/com/bz/zoneiot/water/api/vo/DeviceSceneVo.java

@@ -31,6 +31,9 @@ public class DeviceSceneVo {
     @ApiModelProperty(value = "场景名字")
     private String sceneName;
 
+    @ApiModelProperty(value = "设备ID")
+    private Integer deviceId;
+
     @ApiModelProperty(value = "设备名字")
     private String deviceName;
 

+ 5 - 3
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/dao/DeviceSceneMapper.java

@@ -50,10 +50,12 @@ public interface DeviceSceneMapper extends BaseMapper<DeviceSceneEntity> {
      /**
      * 查找该设备的场景:场景->父场景
      * @author Andy
-     * @date 16:45 2021/10/19
+     * @date 11:30 2021/11/17
      * @param deviceId:
-     * @return java.util.List<DeviceSceneVo>
+     * @param deviceTypeId:
+     * @param tenantId:
+     * @return java.util.List<com.bz.zoneiot.water.api.vo.DeviceSceneVo>
      **/
-     List<DeviceSceneVo> findSceneByDeviceId(Long deviceId);
+     List<DeviceSceneVo> findScene(Long deviceId, Integer deviceTypeId, String tenantId);
 
 }

+ 6 - 2
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/DeviceAttributeMapper.xml

@@ -50,12 +50,15 @@
         SELECT
         <include refid="deviceAttributeColumns"/>
         FROM sms_device_attribute a
-
         <where>
-
+            1 = 1
+            <if test="deviceTypeId != null">
+               and a.device_type_id = #{deviceTypeId}
+            </if>
             <if test="name != null  and name != ''">
                 and a.name LIKE concat('%',#{name},'%')
             </if>
+            and a.status = 1
         </where>
     </select>
 
@@ -77,4 +80,5 @@
         inner join sms_device_attribute t2 on t1.device_type_id=t2.device_type_id and t2.status =1
         where t1.id = #{deviceId}  and t1.status = 1
     </select>
+
 </mapper>

+ 12 - 3
zoniot-water/zoniot-water-core/src/main/java/com/bz/zoneiot/water/core/mapper/DeviceSceneMapper.xml

@@ -73,10 +73,10 @@
         order by t4.scene_name,t8.seq limit 1
     </select>
 
-    <select id="findSceneByDeviceId" resultType="com.bz.zoneiot.water.api.vo.DeviceSceneVo">
+    <select id="findScene" resultType="com.bz.zoneiot.water.api.vo.DeviceSceneVo">
         SELECT
 
-        s.COMPANY_ORG_ID, s.DEVICE_NAME, s.TENANT_ID, s.DEPT_ORG_ID, sds.SCENE_ID, sds.PARENT_SCENE_ID, ss1.SCENE_NAME, ss2.SCENE_NAME as parent_scene_name
+        s.id as deviceId,s.COMPANY_ORG_ID, s.DEVICE_NAME, s.TENANT_ID, s.DEPT_ORG_ID, sds.SCENE_ID, sds.PARENT_SCENE_ID, ss1.SCENE_NAME, ss2.SCENE_NAME as parent_scene_name
 
         from sms_device s
 
@@ -86,6 +86,15 @@
 
         INNER JOIN sms_scene ss2 on ss2.id  = sds.PARENT_SCENE_ID
 
-        where sds.DEVICE_ID  = #{deviceId}
+        <where>
+            s.TENANT_ID = #{tenantId}
+            <if test="deviceId != null">
+                and s.id  = #{deviceId}
+            </if>
+            <if test="deviceTypeId != null">
+                and s.device_type_id  = #{deviceTypeId}
+            </if>
+        </where>
+        and s.status = 1 and sds.status = 1 and ss1.status =1 and ss2.status = 1
     </select>
 </mapper>

+ 13 - 0
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/controller/AttributesController.java

@@ -43,6 +43,19 @@ public class AttributesController {
         return AjaxMessage.success(deviceAttributeService.selectAttributes(deviceId));
     }
 
+    @RequestMapping(value = "listBydeviceTypeId", method = RequestMethod.GET)
+    @ApiOperation(value = "根据产品id查询属性信息")
+    public AjaxMessage listBydeviceTypeId(@ApiParam(value = "产品ID", required = true)@RequestParam Long deviceTypeId) {
+        if (deviceTypeId == null) {
+            return AjaxMessage.fail(WaterErrorEnum.PARAM_ERROR);
+        }
+        DeviceAttributeEntity deviceAttributeEntity = new DeviceAttributeEntity();
+        deviceAttributeEntity.setDeviceTypeId(deviceTypeId);
+        return AjaxMessage.success(deviceAttributeService.findList(deviceAttributeEntity));
+    }
+
+
+
 
     @RequestMapping(value = "/specs/list", method = RequestMethod.GET)
     @ApiOperation(value = "根据设备id查询属性信息")

+ 15 - 4
zoniot-water/zoniot-water-web/src/main/java/com/bz/zoneiot/water/web/service/impl/AlarmTypeDetailsServiceImpl.java

@@ -155,16 +155,21 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
         String deviceName;
         Integer sceneType;
         String attrName = null;
+        Integer productId = null;
         AlarmType alarmType = alarmTypeService.findByIotAlarmId(dto.getAlarmTypeId());
         if (alarmType == null) {
             log.error("【接收告警信息失败】:告警信息为空 ,请求参数:{}", dto.toString());
             return null;
         }
         sceneType = alarmType.getSceneType();
+        Long deviceId = alarmType.getDeviceId();
+        if (deviceId == null) {
+            productId = alarmType.getProductId();
+        }
         Long alarmId = alarmTypeDetailMapper.selectLastAlarmId(alarmType.getId());
         List<AlarmDetailsEntity> result = new ArrayList<>();
         // 离线告警
-        if (alarmType.getAlarmCategory() == 2 || alarmType.getAttributeId() == null) {
+        if (alarmType.getAlarmCategory() == 2) {
             value = new BigDecimal("0");
         } else {
             DeviceAttributeEntity attributeEntity = deviceAttributeService.findDeviceAttributeById(alarmType.getAttributeId());
@@ -173,9 +178,15 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
                 return null;
             }
             attrName = attributeEntity.getName();
-            value = new BigDecimal(dto.getData().get(attributeEntity.getIdentifier()).toString());
+            Object obj = dto.getData().get(attributeEntity.getIdentifier());
+            if (obj == null) {
+                value = new BigDecimal("0");
+            } else {
+                value = new BigDecimal(obj.toString());
+            }
         }
-        List<DeviceSceneVo> sceneVos = deviceSceneMapper.findSceneByDeviceId(alarmType.getDeviceId());
+
+        List<DeviceSceneVo> sceneVos = deviceSceneMapper.findScene(deviceId, productId, alarmType.getTenantId());
         for (DeviceSceneVo sceneVo : sceneVos) {
             AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsEntity();
             if (alarmId != null) {
@@ -195,7 +206,7 @@ public class AlarmTypeDetailsServiceImpl implements AlarmTypeDetailsService {
             alarmDetailsEntity.setTenantId(alarmType.getTenantId());
             alarmDetailsEntity.setAlarmId(Long.parseLong(alarmType.getId().toString()));
             alarmDetailsEntity.setAlarmType(alarmType.getAlarmCategory() == 1 ? "参数报警" : "状态报警");
-            alarmDetailsEntity.setDeviceId(Integer.parseInt(alarmType.getDeviceId().toString()));
+            alarmDetailsEntity.setDeviceId(sceneVo.getDeviceId());
 
             if (alarmType.getAttributeId() != null){
                 alarmDetailsEntity.setAttributeId(Integer.parseInt(alarmType.getAttributeId().toString()));