Commit 9febc2b0b087bbd97f1e9dafdd7b0ad7f2f6c391
1 parent
a42202e7
feat:【iot】executeSceneRuleAction 更新规则场景的最后触发时间
Showing
2 changed files
with
26 additions
and
0 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/rule/IotSceneRuleDO.java
| ... | ... | @@ -21,6 +21,7 @@ import lombok.Builder; |
| 21 | 21 | import lombok.Data; |
| 22 | 22 | import lombok.NoArgsConstructor; |
| 23 | 23 | |
| 24 | +import java.time.LocalDateTime; | |
| 24 | 25 | import java.util.List; |
| 25 | 26 | |
| 26 | 27 | /** |
| ... | ... | @@ -57,6 +58,11 @@ public class IotSceneRuleDO extends TenantBaseDO { |
| 57 | 58 | private Integer status; |
| 58 | 59 | |
| 59 | 60 | /** |
| 61 | + * 最后触发时间 | |
| 62 | + */ | |
| 63 | + private LocalDateTime lastTriggerTime; | |
| 64 | + | |
| 65 | + /** | |
| 60 | 66 | * 场景定义配置 |
| 61 | 67 | */ |
| 62 | 68 | @TableField(typeHandler = JacksonTypeHandler.class) | ... | ... |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/scene/IotSceneRuleServiceImpl.java
| ... | ... | @@ -30,6 +30,7 @@ import org.springframework.cache.annotation.Cacheable; |
| 30 | 30 | import org.springframework.stereotype.Service; |
| 31 | 31 | import org.springframework.validation.annotation.Validated; |
| 32 | 32 | |
| 33 | +import java.time.LocalDateTime; | |
| 33 | 34 | import java.util.Collection; |
| 34 | 35 | import java.util.List; |
| 35 | 36 | |
| ... | ... | @@ -392,9 +393,28 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService { |
| 392 | 393 | } |
| 393 | 394 | }); |
| 394 | 395 | }); |
| 396 | + | |
| 397 | + // 3. 更新最后触发时间 | |
| 398 | + updateLastTriggerTime(sceneRule.getId()); | |
| 395 | 399 | }); |
| 396 | 400 | } |
| 397 | 401 | |
| 402 | + /** | |
| 403 | + * 更新规则场景的最后触发时间 | |
| 404 | + * | |
| 405 | + * @param id 规则场景编号 | |
| 406 | + */ | |
| 407 | + private void updateLastTriggerTime(Long id) { | |
| 408 | + try { | |
| 409 | + IotSceneRuleDO updateObj = new IotSceneRuleDO() | |
| 410 | + .setId(id) | |
| 411 | + .setLastTriggerTime(LocalDateTime.now()); | |
| 412 | + sceneRuleMapper.updateById(updateObj); | |
| 413 | + } catch (Exception e) { | |
| 414 | + log.error("[updateLastTriggerTime][规则场景编号({}) 更新最后触发时间异常]", id, e); | |
| 415 | + } | |
| 416 | + } | |
| 417 | + | |
| 398 | 418 | private IotSceneRuleServiceImpl getSelf() { |
| 399 | 419 | return SpringUtil.getBean(IotSceneRuleServiceImpl.class); |
| 400 | 420 | } | ... | ... |