65 lines
1.9 KiB
Java
65 lines
1.9 KiB
Java
package com.labfusion.model;
|
|
|
|
import jakarta.persistence.*;
|
|
import java.time.LocalDateTime;
|
|
|
|
@Entity
|
|
@Table(name = "device_states")
|
|
public class DeviceState {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(name = "timestamp", nullable = false)
|
|
private LocalDateTime timestamp;
|
|
|
|
@Column(name = "entity_id", nullable = false)
|
|
private String entityId;
|
|
|
|
@Column(name = "value", columnDefinition = "TEXT")
|
|
private String value;
|
|
|
|
@Column(name = "service", nullable = false)
|
|
private String service;
|
|
|
|
@Column(name = "created_at")
|
|
private LocalDateTime createdAt;
|
|
|
|
@PrePersist
|
|
protected void onCreate() {
|
|
createdAt = LocalDateTime.now();
|
|
if (timestamp == null) {
|
|
timestamp = LocalDateTime.now();
|
|
}
|
|
}
|
|
|
|
// Constructors
|
|
public DeviceState() {}
|
|
|
|
public DeviceState(String entityId, String value, String service) {
|
|
this.entityId = entityId;
|
|
this.value = value;
|
|
this.service = service;
|
|
this.timestamp = LocalDateTime.now();
|
|
}
|
|
|
|
// Getters and Setters
|
|
public Long getId() { return id; }
|
|
public void setId(Long id) { this.id = id; }
|
|
|
|
public LocalDateTime getTimestamp() { return timestamp; }
|
|
public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; }
|
|
|
|
public String getEntityId() { return entityId; }
|
|
public void setEntityId(String entityId) { this.entityId = entityId; }
|
|
|
|
public String getValue() { return value; }
|
|
public void setValue(String value) { this.value = value; }
|
|
|
|
public String getService() { return service; }
|
|
public void setService(String service) { this.service = service; }
|
|
|
|
public LocalDateTime getCreatedAt() { return createdAt; }
|
|
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
|
|
}
|