/timer接口地址: POST /timer/start
功能描述: 启动指定设备的计时器
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
// 请求URL
POST /timer/start?referenceId=DEVICE_001
// 或者使用JSON格式
{
"referenceId": "DEVICE_001"
}
{
"code": 0,
"message": "success",
"data": {
"id": "TIMER_RECORD_001",
"referenceId": "DEVICE_001",
"userId": "USER_001",
"userName": "张三",
"startTime": "2026-02-26T10:30:00",
"status": "RUNNING",
"accumulatedTime": 0
}
}
接口地址: POST /timer/pause
功能描述: 暂停指定设备的计时器
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
// 请求URL
POST /timer/pause?referenceId=DEVICE_001
{
"code": 0,
"message": "success",
"data": {
"id": "TIMER_RECORD_001",
"referenceId": "DEVICE_001",
"userId": "USER_001",
"userName": "张三",
"startTime": "2026-02-26T10:30:00",
"pauseTime": "2026-02-26T11:30:00",
"status": "PAUSED",
"accumulatedTime": 3600000
}
}
接口地址: POST /timer/resume
功能描述: 恢复指定设备的计时器
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
// 请求URL
POST /timer/resume?referenceId=DEVICE_001
{
"code": 0,
"message": "success",
"data": {
"id": "TIMER_RECORD_001",
"referenceId": "DEVICE_001",
"userId": "USER_001",
"userName": "张三",
"startTime": "2026-02-26T10:30:00",
"resumeTime": "2026-02-26T11:45:00",
"status": "RUNNING",
"accumulatedTime": 3600000
}
}
接口地址: POST /timer/stop
功能描述: 停止指定设备的计时器并保存最终累计时间
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
| finalAccumulatedTime | Long | 是 | 最终累计时间(毫秒) |
// 请求URL
POST /timer/stop?referenceId=DEVICE_001&finalAccumulatedTime=7200000
// 或者使用JSON格式
{
"referenceId": "DEVICE_001",
"finalAccumulatedTime": 7200000
}
{
"code": 0,
"message": "success",
"data": {
"id": "TIMER_RECORD_001",
"referenceId": "DEVICE_001",
"userId": "USER_001",
"userName": "张三",
"startTime": "2026-02-26T10:30:00",
"stopTime": "2026-02-26T12:30:00",
"status": "STOPPED",
"accumulatedTime": 7200000
}
}
接口地址: GET /timer/status
功能描述: 查询指定设备的计时器当前状态
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
// 请求URL
GET /timer/status?referenceId=DEVICE_001
{
"code": 0,
"message": "success",
"data": {
"id": "TIMER_RECORD_001",
"referenceId": "DEVICE_001",
"userId": "USER_001",
"userName": "张三",
"startTime": "2026-02-26T10:30:00",
"status": "RUNNING",
"accumulatedTime": 5400000
}
}
接口地址: GET /timer/accumulated-time
功能描述: 获取指定设备的累计计时时间
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| referenceId | String | 是 | 关联ID(设备ID或其他业务标识) |
// 请求URL
GET /timer/accumulated-time?referenceId=DEVICE_001
{
"code": 0,
"message": "success",
"data": 7200000
}
| 状态码 | 说明 |
|---|---|
| RUNNING | 正在计时 |
| PAUSED | 已暂停 |
| STOPPED | 已停止 |
常见错误响应格式:
{
"code": 1,
"message": "错误描述信息",
"data": null
}
// 示例:计时器前端逻辑
class TimerManager {
constructor(deviceId) {
this.deviceId = deviceId;
this.timer = null;
this.displayTime = 0;
}
// 开始计时
async startTimer() {
const response = await fetch(`/timer/start?referenceId=${this.deviceId}`, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + getToken()
}
});
const result = await response.json();
if (result.code === 0) {
this.startLocalTimer();
}
}
// 本地计时器(用于实时显示)
startLocalTimer() {
this.timer = setInterval(() => {
this.displayTime += 1000;
this.updateDisplay();
}, 1000);
}
// 更新显示
updateDisplay() {
const hours = Math.floor(this.displayTime / 3600000);
const minutes = Math.floor((this.displayTime % 3600000) / 60000);
const seconds = Math.floor((this.displayTime % 60000) / 1000);
document.getElementById('timer-display').textContent =
`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
}