ObjectBox
This commit is contained in:
1 parent
f8317be627
commit
809bffc7a2
9 files changed
+125
-42
No files matched your search
@@ -394,6 +394,17 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
Job newJob = Job.fromJson(payloadData);
|
||||
|
||||
final box = MyApp.objectBoxStore.box<Job>();
|
||||
|
||||
// Check if job already exists by externalId
|
||||
final query = box.query(Job_.externalId.equals(newJob.externalId)).build();
|
||||
final existingJob = query.findFirst();
|
||||
query.close();
|
||||
|
||||
if (existingJob != null) {
|
||||
// Update existing job
|
||||
newJob.id = existingJob.id;
|
||||
}
|
||||
|
||||
box.put(newJob);
|
||||
|
||||
if (newJob.state == Constants.stateAssigned) {
|
||||
@@ -416,10 +427,14 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
var jobDelMessage = JobDelMessage.fromJson(payloadData);
|
||||
|
||||
final box = MyApp.objectBoxStore.box<Job>();
|
||||
var job = box.get(jobDelMessage.id);
|
||||
|
||||
// Find job by external ID
|
||||
final query = box.query(Job_.externalId.equals(jobDelMessage.id)).build();
|
||||
final job = query.findFirst();
|
||||
query.close();
|
||||
|
||||
if (job != null) {
|
||||
box.remove(jobDelMessage.id);
|
||||
box.remove(job.id); // Use ObjectBox ID for removal
|
||||
|
||||
sendMessage(
|
||||
routingKey: Constants.messageTopicJobDeleted,
|
||||
@@ -613,7 +628,7 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
for (var job in jobs) {
|
||||
SyncJobMessageJob syncJob = SyncJobMessageJob();
|
||||
syncJob.state = job.state;
|
||||
syncJob.id = job.id;
|
||||
syncJob.id = job.externalId; // Use external ID for network communication
|
||||
syncJob.ver = job.ver.toString();
|
||||
answer.sync.jobs.add(syncJob);
|
||||
}
|
||||
@@ -687,7 +702,7 @@ class MqttCore with ProducerMixin, ConsumerMixin {
|
||||
|
||||
void _acknowlegdeJob(Job job) {
|
||||
var message = AcknowledgeJobReceived();
|
||||
message.id = job.id;
|
||||
message.id = job.externalId; // Use external ID for network communication
|
||||
message.state = job.state;
|
||||
message.ver = job.ver;
|
||||
message.utc = Util.nowUnixSecondsUtc();
|
||||
|
||||
Reference in new issue
Block a user