diff --git a/lib/content_views/accepted_jobs_page.dart b/lib/content_views/accepted_jobs_page.dart index 09ff564..f3f3e7f 100644 --- a/lib/content_views/accepted_jobs_page.dart +++ b/lib/content_views/accepted_jobs_page.dart @@ -39,8 +39,8 @@ class _AcceptedJobsPageState extends State .stateEqualTo(Constants.stateAccepted) .findAll(); _jobs.sort((job1, job2) { - var date1 = DateTime.parse(job1.ordertime).millisecondsSinceEpoch; - var date2 = DateTime.parse(job2.ordertime).millisecondsSinceEpoch; + var date1 = DateTime.fromMillisecondsSinceEpoch(job1.ordertime * 1000, isUtc: true).millisecondsSinceEpoch; + var date2 = DateTime.fromMillisecondsSinceEpoch(job2.ordertime * 1000, isUtc: true).millisecondsSinceEpoch; return date1 - date2; }); @@ -97,7 +97,7 @@ class _AcceptedJobsPageState extends State children: [ Text( DateFormat('dd.MM.yyyy HH:mm') - .format(DateTime.parse(job.ordertime).toLocal()) + .format(DateTime.fromMillisecondsSinceEpoch(job.ordertime * 1000, isUtc: true).toLocal()) .toString(), style: TextStyle( backgroundColor: isJobTooFarInFuture(job) diff --git a/lib/content_views/assigned_jobs_page.dart b/lib/content_views/assigned_jobs_page.dart index 2c422cc..71ce931 100644 --- a/lib/content_views/assigned_jobs_page.dart +++ b/lib/content_views/assigned_jobs_page.dart @@ -125,7 +125,7 @@ class _AssignedJobsPageState extends State with ProducerMixin, child: Column( children: [ Text( - DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(), + DateFormat('dd.MM.yyyy HH:mm').format(DateTime.fromMillisecondsSinceEpoch(job.ordertime * 1000, isUtc: true).toLocal()).toString(), textAlign: TextAlign.left, style: TextStyle(backgroundColor: isJobTooFarInFuture(job) ? Colors.red : Colors.white), ), diff --git a/lib/content_views/finished_jobs_page.dart b/lib/content_views/finished_jobs_page.dart index 823d5f9..df91250 100644 --- a/lib/content_views/finished_jobs_page.dart +++ b/lib/content_views/finished_jobs_page.dart @@ -91,7 +91,7 @@ class _FinishedJobsPageState extends State children: [ Text( DateFormat('dd.MM.yyyy HH:mm') - .format(DateTime.parse(job.ordertime).toLocal()) + .format(DateTime.fromMillisecondsSinceEpoch(job.ordertime * 1000, isUtc: true).toLocal()) .toString(), textAlign: TextAlign.left, ), diff --git a/lib/content_views/task_list_page.dart b/lib/content_views/task_list_page.dart index ac15e12..a4bdae9 100644 --- a/lib/content_views/task_list_page.dart +++ b/lib/content_views/task_list_page.dart @@ -536,6 +536,7 @@ class _TaskListPageState extends State with ProducerMixin { finTourMessage.track = Track(); finTourMessage.track!.time = Util.nowUnixSecondsUtc(); finTourMessage.track!.pos = FinTaskPos(); + finTourMessage.track!.pos!.time = Util.toUnixSecondsUtc(position.timestamp); finTourMessage.track!.pos!.lat = position.latitude; finTourMessage.track!.pos!.long = position.longitude; } @@ -574,7 +575,7 @@ class _TaskListPageState extends State with ProducerMixin { var message = PicData(); message.trId = picture.tourId; message.num = picture.number; - message.time = DateTime.now().millisecondsSinceEpoch; + message.time = Util.nowUnixSecondsUtc(); message.data = picture.data; sendMessage( diff --git a/lib/model/job.dart b/lib/model/job.dart index 8c93855..99021ca 100644 --- a/lib/model/job.dart +++ b/lib/model/job.dart @@ -18,7 +18,7 @@ class Job with ProducerMixin { @JsonKey(name: 'cr_filter') late String? crFilter; @JsonKey(name: 'ordertime') - late String ordertime; + late int ordertime; @JsonKey(name: 'offs_warn') late int offsWarn; @JsonKey(name: 'global') diff --git a/lib/model/job.g.dart b/lib/model/job.g.dart index 3dab33a..ef9938c 100644 --- a/lib/model/job.g.dart +++ b/lib/model/job.g.dart @@ -40,7 +40,7 @@ const JobSchema = CollectionSchema( r'ordertime': PropertySchema( id: 4, name: r'ordertime', - type: IsarType.string, + type: IsarType.long, ), r'rem': PropertySchema( id: 5, @@ -100,7 +100,6 @@ int _jobEstimateSize( bytesCount += 3 + value.length * 3; } } - bytesCount += 3 + object.ordertime.length * 3; bytesCount += 3 + object.rem.length * 3; bytesCount += 3 + object.tours.length * 3; { @@ -124,7 +123,7 @@ void _jobSerialize( writer.writeLong(offsets[1], object.delayOrderTime); writer.writeBool(offsets[2], object.global); writer.writeLong(offsets[3], object.offsWarn); - writer.writeString(offsets[4], object.ordertime); + writer.writeLong(offsets[4], object.ordertime); writer.writeString(offsets[5], object.rem); writer.writeLong(offsets[6], object.state); writer.writeObjectList( @@ -149,7 +148,7 @@ Job _jobDeserialize( object.global = reader.readBool(offsets[2]); object.id = id; object.offsWarn = reader.readLong(offsets[3]); - object.ordertime = reader.readString(offsets[4]); + object.ordertime = reader.readLong(offsets[4]); object.rem = reader.readString(offsets[5]); object.state = reader.readLong(offsets[6]); object.tours = reader.readObjectList( @@ -180,7 +179,7 @@ P _jobDeserializeProp

( case 3: return (reader.readLong(offset)) as P; case 4: - return (reader.readString(offset)) as P; + return (reader.readLong(offset)) as P; case 5: return (reader.readString(offset)) as P; case 6: @@ -600,55 +599,46 @@ extension JobQueryFilter on QueryBuilder { }); } - QueryBuilder ordertimeEqualTo( - String value, { - bool caseSensitive = true, - }) { + QueryBuilder ordertimeEqualTo(int value) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.equalTo( property: r'ordertime', value: value, - caseSensitive: caseSensitive, )); }); } QueryBuilder ordertimeGreaterThan( - String value, { + int value, { bool include = false, - bool caseSensitive = true, }) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.greaterThan( include: include, property: r'ordertime', value: value, - caseSensitive: caseSensitive, )); }); } QueryBuilder ordertimeLessThan( - String value, { + int value, { bool include = false, - bool caseSensitive = true, }) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.lessThan( include: include, property: r'ordertime', value: value, - caseSensitive: caseSensitive, )); }); } QueryBuilder ordertimeBetween( - String lower, - String upper, { + int lower, + int upper, { bool includeLower = true, bool includeUpper = true, - bool caseSensitive = true, }) { return QueryBuilder.apply(this, (query) { return query.addFilterCondition(FilterCondition.between( @@ -657,73 +647,6 @@ extension JobQueryFilter on QueryBuilder { includeLower: includeLower, upper: upper, includeUpper: includeUpper, - caseSensitive: caseSensitive, - )); - }); - } - - QueryBuilder ordertimeStartsWith( - String value, { - bool caseSensitive = true, - }) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.startsWith( - property: r'ordertime', - value: value, - caseSensitive: caseSensitive, - )); - }); - } - - QueryBuilder ordertimeEndsWith( - String value, { - bool caseSensitive = true, - }) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.endsWith( - property: r'ordertime', - value: value, - caseSensitive: caseSensitive, - )); - }); - } - - QueryBuilder ordertimeContains(String value, - {bool caseSensitive = true}) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.contains( - property: r'ordertime', - value: value, - caseSensitive: caseSensitive, - )); - }); - } - - QueryBuilder ordertimeMatches(String pattern, - {bool caseSensitive = true}) { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.matches( - property: r'ordertime', - wildcard: pattern, - caseSensitive: caseSensitive, - )); - }); - } - - QueryBuilder ordertimeIsEmpty() { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.equalTo( - property: r'ordertime', - value: '', - )); - }); - } - - QueryBuilder ordertimeIsNotEmpty() { - return QueryBuilder.apply(this, (query) { - return query.addFilterCondition(FilterCondition.greaterThan( - property: r'ordertime', - value: '', )); }); } @@ -1441,10 +1364,9 @@ extension JobQueryWhereDistinct on QueryBuilder { }); } - QueryBuilder distinctByOrdertime( - {bool caseSensitive = true}) { + QueryBuilder distinctByOrdertime() { return QueryBuilder.apply(this, (query) { - return query.addDistinctBy(r'ordertime', caseSensitive: caseSensitive); + return query.addDistinctBy(r'ordertime'); }); } @@ -1504,7 +1426,7 @@ extension JobQueryProperty on QueryBuilder { }); } - QueryBuilder ordertimeProperty() { + QueryBuilder ordertimeProperty() { return QueryBuilder.apply(this, (query) { return query.addPropertyName(r'ordertime'); }); @@ -1550,7 +1472,7 @@ Job _$JobFromJson(Map json) => Job() ..ver = json['ver'] as String ..state = (json['state'] as num).toInt() ..crFilter = json['cr_filter'] as String? - ..ordertime = json['ordertime'] as String + ..ordertime = (json['ordertime'] as num).toInt() ..offsWarn = (json['offs_warn'] as num).toInt() ..global = json['global'] as bool ..vhtId = (json['vht_id'] as num).toInt() diff --git a/lib/popups/accept_jobs_popup.dart b/lib/popups/accept_jobs_popup.dart index 65d27bc..d151ef5 100644 --- a/lib/popups/accept_jobs_popup.dart +++ b/lib/popups/accept_jobs_popup.dart @@ -161,7 +161,7 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini SizedBox( width: double.infinity, child: Text( - DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(), + DateFormat('dd.MM.yyyy HH:mm').format(DateTime.fromMillisecondsSinceEpoch(job.ordertime * 1000, isUtc: true).toLocal()).toString(), textAlign: TextAlign.left, style: TextStyle(backgroundColor: isJobTooFarInFuture(job) ? Colors.red : Colors.transparent), ), @@ -263,7 +263,7 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini SizedBox( width: double.infinity, child: Text( - DateFormat('dd.MM.yyyy HH:mm').format(DateTime.parse(job.ordertime).toLocal()).toString(), + DateFormat('dd.MM.yyyy HH:mm').format(DateTime.fromMillisecondsSinceEpoch(job.ordertime, isUtc: true).toLocal()).toString(), textAlign: TextAlign.left, style: TextStyle(backgroundColor: isJobTooFarInFuture(job) ? Colors.red : Colors.transparent), ), @@ -377,6 +377,7 @@ _sendAnswer(SharedMapReference mapReference, Job job, int item) async { message.track = Track(); message.track.time = Util.nowUnixSecondsUtc(); message.track.pos = FinTaskPos(); + message.track.pos!.time = currentPosition != null ? Util.toUnixSecondsUtc(currentPosition.timestamp) : 0; message.track.pos!.lat = currentPosition != null ? currentPosition.latitude : 0.0; message.track.pos!.long = currentPosition != null ? currentPosition.longitude : 0.0; message.track.pos!.acc = currentPosition != null ? currentPosition.accuracy.toInt() : 0; diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index 27f33a0..176c0bd 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -196,6 +196,10 @@ class MqttCore with ProducerMixin, ConsumerMixin { var buffer = Uint8Buffer(); buffer.addAll(GZipEncoder().encode(const Utf8Encoder().convert(encapsulatedMessageText)) as Iterable); + // Ensure no trailing slash in topic portion + if (topic.endsWith('/')) { + topic = topic.substring(0, topic.length - 1); + } var messageTopic = "$_toServerTopic$_clientId/$topic"; _mqttClient!.publishMessage(messageTopic, MqttQos.atMostOnce, buffer); @@ -205,7 +209,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { return true; } catch (ex) { - Util.logInfo("send failed!"); + Util.logInfo("send failed: $ex"); } return false; @@ -221,7 +225,13 @@ class MqttCore with ProducerMixin, ConsumerMixin { var topicArray = message.variableHeader?.topicName; var topicArraySplited = topicArray!.split("/"); - var topic = topicArraySplited[7]; + + var topic = topicArraySplited.length > 7 + ? topicArraySplited.sublist(7).join('/') + : (topicArraySplited.length == 8 ? topicArraySplited[7] : ""); + if (topic.endsWith('/')) { + topic = topic.substring(0, topic.length - 1); + } Util.logInfo('message received\ntopic: $topic\n'); Util.logInfo("size in bytes: ${message.payload.message!.length.toString()}"); @@ -592,7 +602,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { var jobs = await MyApp.isarInstance.jobs.filter().stateGreaterThan(-1).findAll(); var answer = SyncJobsMessage(); - answer.utcUnixTime = DateTime.now().toUtc().millisecondsSinceEpoch ~/ 1000; + answer.utcUnixTime = Util.nowUnixSecondsUtc(); answer.pos = SyncMessagePos(); answer.pos!.time = currentPosition != null ? Util.toUnixSecondsUtc(currentPosition.timestamp.toUtc()) : 0; @@ -682,7 +692,7 @@ class MqttCore with ProducerMixin, ConsumerMixin { message.id = job.id; message.state = job.state; message.ver = job.ver; - message.utc = DateTime.now().millisecondsSinceEpoch; + message.utc = Util.nowUnixSecondsUtc(); _publishMessage('job_received', message.toJson(), false); } diff --git a/lib/tools/util.dart b/lib/tools/util.dart index cbd7d99..90f1dd3 100644 --- a/lib/tools/util.dart +++ b/lib/tools/util.dart @@ -456,7 +456,7 @@ class DecimalTextInputFormatter extends TextInputFormatter { } bool isJobTooFarInFuture(Job job) { - var ordertime = DateTime.parse(job.ordertime).toUtc().millisecondsSinceEpoch; + var ordertime = job.ordertime * 1000; // convert seconds to milliseconds var dateTimeThreshold = DateTime.now().add(Duration(minutes: job.offsWarn)).toUtc().millisecondsSinceEpoch; return ordertime > dateTimeThreshold; diff --git a/pubspec.yaml b/pubspec.yaml index fc91471..b51352b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,10 +16,10 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 340.0.0+340 +version: 343.0.0+343 environment: - sdk: '>=2.19.6 <3.0.0' + sdk: '>=3.5.0 <4.0.0' isar_version: &isar_version 3.1.8 # define the version to be used