TRX 1 yıl önce
ebeveyn
işleme
07b1bf4ccd

+ 8 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/DeviceDataController.java

@@ -3,9 +3,9 @@ package com.zhongshu.iot.server.core.controller.devices;
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.models.baseParam.IDParam;
-import com.zhongshu.iot.client.model.device.IotDeviceDataModel;
 import com.github.microservice.models.iotDeviceData.IotDeviceDataSearch;
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.iot.client.model.device.IotDeviceDataModel;
 import com.zhongshu.iot.server.core.service.iot.IotDeviceDataService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -58,4 +58,11 @@ public class DeviceDataController {
         return iotDeviceDataService.delete(param.getId());
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "删除物模型下所有的属性历史值")
+    @RequestMapping(value = "deleteAllData", method = {RequestMethod.POST})
+    public ResultContent deleteAllData(@RequestBody IDParam param) {
+        return iotDeviceDataService.deleteAllData(param.getId());
+    }
+
 }

+ 3 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/IotDeviceDataDao.java

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.dao.iot;
 
 import com.github.microservice.types.deviceUse.IotDeviceDataType;
+import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.server.core.dao.iot.extend.IotDeviceDataDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.IotDeviceData;
 import com.zhongshu.iot.server.core.domain.iot.IotMain;
@@ -20,4 +21,6 @@ public interface IotDeviceDataDao extends MongoRepository<IotDeviceData, String>
 
     IotDeviceData findTopByDeviceIdAndPropertyAndDataTypeOrderByCreateTimeDesc(String deviceId, String property, IotDeviceDataType dataType);
 
+    void deleteByIotThingIdAndDataType(String thingId, IotDeviceDataType dataType);
+
 }

+ 10 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotDeviceDataService.java

@@ -165,6 +165,16 @@ public class IotDeviceDataService {
         return ResultContent.buildSuccess();
     }
 
+    /**
+     * 删除物模型所有属性的历史数据
+     * @param iotThingId
+     * @return
+     */
+    public ResultContent deleteAllData(String iotThingId) {
+        iotDeviceDataDao.deleteByIotThingIdAndDataType(iotThingId, IotDeviceDataType.History);
+        return ResultContent.buildSuccess();
+    }
+
     public IotDeviceDataModel toModel(IotDeviceData entity) {
         IotDeviceDataModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {

+ 3 - 4
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotPropertyService.java

@@ -84,13 +84,12 @@ public class IotPropertyService extends SuperService {
 
     private void saveProperty(String deviceId, String property,
             Object value, PropertyResult.DeviceAttrs deviceAttrs,
-            Object mqttParam
-    ) {
+            Object mqttParam) {
         ResultContent resultContent = iotDeviceDataService.saveProperty(deviceId, property, value, mqttParam);
         if (resultContent.isSuccess()) {
-            deviceAttrs.setSuccess();
+            deviceAttrs.addSuccess(property);
         } else {
-            deviceAttrs.setFailed(resultContent.getMsg());
+            deviceAttrs.addFailed(property, resultContent.getMsg());
         }
     }
 }