feat: sync treatment record at start (10min), update on early stop
- Treatment start immediately syncs record with full 10min duration - Early stop re-syncs with actual elapsed time (upsert by session_id) - treatment-done page uses same session_id from treating page
这个提交包含在:
@@ -1,4 +1,5 @@
|
|||||||
var ble = require('../../services/ble')
|
var ble = require('../../services/ble')
|
||||||
|
var api = require('../../utils/api')
|
||||||
var commandSync = require('../../services/command-sync')
|
var commandSync = require('../../services/command-sync')
|
||||||
var config = require('../../config/env')
|
var config = require('../../config/env')
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ Page({
|
|||||||
this._onDisconnect = this.onDisconnect.bind(this)
|
this._onDisconnect = this.onDisconnect.bind(this)
|
||||||
this._onReconnect = this.onReconnect.bind(this)
|
this._onReconnect = this.onReconnect.bind(this)
|
||||||
this._onReconnectFailed = this.onReconnectFailed.bind(this)
|
this._onReconnectFailed = this.onReconnectFailed.bind(this)
|
||||||
|
this._sessionId = 'SESS_' + Date.now()
|
||||||
|
|
||||||
ble.on('status', this._onStatus)
|
ble.on('status', this._onStatus)
|
||||||
ble.on('treatment_complete', this._onComplete)
|
ble.on('treatment_complete', this._onComplete)
|
||||||
ble.on('exception', this._onException)
|
ble.on('exception', this._onException)
|
||||||
@@ -60,6 +63,7 @@ Page({
|
|||||||
ble.on('reconnect_failed', this._onReconnectFailed)
|
ble.on('reconnect_failed', this._onReconnectFailed)
|
||||||
this.startLocalTimer()
|
this.startLocalTimer()
|
||||||
this.syncCommands()
|
this.syncCommands()
|
||||||
|
this.syncTreatmentStart()
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload: function () {
|
onUnload: function () {
|
||||||
@@ -117,6 +121,40 @@ Page({
|
|||||||
if (deviceId) commandSync.sync(deviceId)
|
if (deviceId) commandSync.sync(deviceId)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
syncTreatmentStart: function () {
|
||||||
|
var self = this
|
||||||
|
var startTime = new Date(self.data.startedAt)
|
||||||
|
var endTime = new Date(self.data.startedAt + self.data.duration)
|
||||||
|
api.syncTreatment({
|
||||||
|
session_id: self._sessionId,
|
||||||
|
device_id: self._deviceId || '',
|
||||||
|
start_time: startTime.toISOString(),
|
||||||
|
end_time: endTime.toISOString(),
|
||||||
|
regions: self.data.regions,
|
||||||
|
total_duration_ms: self.data.duration,
|
||||||
|
mode: self.data.mode,
|
||||||
|
avg_pd: 0,
|
||||||
|
source: 'treatment_start'
|
||||||
|
}).catch(function () {})
|
||||||
|
},
|
||||||
|
|
||||||
|
syncTreatmentEnd: function (elapsed) {
|
||||||
|
var self = this
|
||||||
|
var startTime = new Date(self.data.startedAt)
|
||||||
|
var endTime = new Date(self.data.startedAt + elapsed)
|
||||||
|
api.syncTreatment({
|
||||||
|
session_id: self._sessionId,
|
||||||
|
device_id: self._deviceId || '',
|
||||||
|
start_time: startTime.toISOString(),
|
||||||
|
end_time: endTime.toISOString(),
|
||||||
|
regions: self.data.regions,
|
||||||
|
total_duration_ms: elapsed,
|
||||||
|
mode: self.data.mode,
|
||||||
|
avg_pd: 0,
|
||||||
|
source: 'treatment_end'
|
||||||
|
}).catch(function () {})
|
||||||
|
},
|
||||||
|
|
||||||
onComplete: function (result) {
|
onComplete: function (result) {
|
||||||
this.setData({ completed: true, progress: 100 })
|
this.setData({ completed: true, progress: 100 })
|
||||||
var app = getApp()
|
var app = getApp()
|
||||||
@@ -137,8 +175,11 @@ Page({
|
|||||||
|
|
||||||
finishAsComplete: function () {
|
finishAsComplete: function () {
|
||||||
var elapsed = Math.min(this.data.duration, Date.now() - this.data.startedAt)
|
var elapsed = Math.min(this.data.duration, Date.now() - this.data.startedAt)
|
||||||
|
if (elapsed < this.data.duration) {
|
||||||
|
this.syncTreatmentEnd(elapsed)
|
||||||
|
}
|
||||||
this.onComplete({
|
this.onComplete({
|
||||||
session_id: 'LOCAL_' + Date.now(),
|
session_id: this._sessionId,
|
||||||
regions: this.data.regions,
|
regions: this.data.regions,
|
||||||
total_duration_ms: elapsed,
|
total_duration_ms: elapsed,
|
||||||
avg_pd: 0,
|
avg_pd: 0,
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ Page({
|
|||||||
http.post('/api/v1/treatment/sync', {
|
http.post('/api/v1/treatment/sync', {
|
||||||
session_id: self.data.sessionId,
|
session_id: self.data.sessionId,
|
||||||
device_id: self._deviceId || '',
|
device_id: self._deviceId || '',
|
||||||
start_time: new Date(Date.now() - self.data.duration).toISOString(),
|
start_time: treatment.start_time || new Date(Date.now() - self.data.duration).toISOString(),
|
||||||
end_time: new Date().toISOString(),
|
end_time: treatment.end_time || new Date().toISOString(),
|
||||||
regions: self.data.regions,
|
regions: self.data.regions,
|
||||||
total_duration_ms: self.data.duration,
|
total_duration_ms: self.data.duration,
|
||||||
mode: self.data.mode,
|
mode: self.data.mode,
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户