สรุปงาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้ถือว่าคุณเข้าใจวิธีสร้างและใช้งานงานแล้ว โดยมี
ตัวอย่างที่เฉพาะเจาะจงเกี่ยวกับวิธีทำงานการจัดส่งให้เสร็จสมบูรณ์ดังนี้
ปิดงาน: การปิดงานการจัดส่งจะเปลี่ยนสถานะเป็น CLOSED
และ
ระบุว่างานนั้นไม่ได้ใช้งานอีกต่อไป
กำหนดผลลัพธ์ของงาน: เมื่อปิดงานแล้ว ให้สรุปงานโดย
ตั้งค่าผลลัพธ์เป็น SUCCEEDED
หรือ FAILED
ขั้นตอนนี้เป็นส่วนสำคัญ
ในการสรุปงานเพื่อแสดงผลลัพธ์การนำส่งในการแชร์การเดินทาง
และเพื่อให้มั่นใจว่าการเรียกเก็บเงินสำหรับบริการ Fleet Engine จะถูกต้อง
ปิดงาน
คุณปิดงานได้ด้วยวิธีต่อไปนี้
- อัปเดตสถานะการหยุดรถสำหรับยานพาหนะ คุณนำป้ายหยุดรถออกจาก
ยานพาหนะ ซึ่งจะเป็นการปิดงานทั้งหมดที่เชื่อมโยงกับป้ายหยุดรถนั้น ดูรายละเอียดได้ที่สถานะการหยุดอัปเดต
- นำงานออกจากรายการจุดจอดรถ ซึ่งเกี่ยวข้องกับการอัปเดต
รายการงานสำหรับจุดจอด แต่จะไม่มีงานที่ปิดแล้ว
อยู่ในรายการอีกต่อไป ดูการอัปเดตลำดับงานในอัปเดตงาน
- ตั้งค่าสถานะของงานเป็น
CLOSED
การดำเนินการนี้จะทำได้เฉพาะกับงานที่ไม่ได้
กำหนดให้กับยานพาหนะ ส่วนนี้จะแสดงแนวทางดังกล่าว
เมื่อปิดงานแล้ว คุณจะเปิดอีกครั้งไม่ได้
การปิดงานไม่ได้บ่งบอกถึงความสำเร็จหรือความล้มเหลวของงาน ซึ่งบ่งชี้ว่าระบบจะไม่พิจารณางานดังกล่าวว่าอยู่ระหว่างดำเนินการอีกต่อไป คุณต้องระบุผลลัพธ์ที่แท้จริงของงานเพื่อระบุ
ผลลัพธ์ที่แท้จริงของงานและแสดงผลลัพธ์ดังกล่าวเพื่อวัตถุประสงค์ในการติดตามยานพาหนะและ
การแชร์การเดินทาง ดูตั้งค่าผลลัพธ์ของงานด้านล่าง
ฟิลด์งานสำหรับการปิดงาน
ส่วนนี้จะบันทึกช่องที่ต้องตั้งค่าเมื่อปิดงาน Fleet Engine จะไม่สนใจฟิลด์อื่นๆ ทั้งหมดในเอนทิตีสำหรับการอัปเดต
ช่องที่ต้องกรอก |
ค่า |
state |
State.CLOSED |
ปิดงานโดยตรง
ตัวอย่างต่อไปนี้แสดงวิธีกำหนดสถานะของงานที่ไม่ได้กำหนดให้เป็น "ปิด"
ไม่ว่าจะใน gRPC หรือใช้การเรียกคำขอ HTTP REST ไปยัง UpdateTask
gRPC
static final String PROJECT_ID = "my-delivery-co-gcp-project";
static final String TASK_ID = "task-8241890";
DeliveryServiceBlockingStub deliveryService =
DeliveryServiceGrpc.newBlockingStub(channel);
// Task settings
String taskName = "providers/" + PROJECT_ID + "/tasks/" + TASK_ID;
Task task = Task.newBuilder()
.setName(taskName)
.setState(Task.State.CLOSED) // You can only directly CLOSE a
.build(); // task that is NOT assigned to a vehicle.
// Task request
UpdateTaskRequest updateTaskRequest =
UpdateTaskRequest.newBuilder() // No need for the header
.setTask(task)
.setUpdateMask(FieldMask.newBuilder().addPaths("state"))
.build();
try {
Task updatedTask = deliveryService.updateTask(updateTaskRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
REST
PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/tasks/<id>?updateMask=state
- <id> คือตัวระบุที่ไม่ซ้ำกันสำหรับงาน
- ส่วนหัวของคำขอต้องมีฟิลด์ Authorization ที่มีค่าเป็น
Bearer <token> โดยที่ <token> ออกโดยเซิร์ฟเวอร์ของคุณ
ตามหลักเกณฑ์ที่อธิบายไว้ในบทบาทของบัญชีบริการและ
โทเค็นเว็บ JSON
- คุณต้องรวมเอนทิตี
Task
ไว้ในเนื้อความของคำขอ
ตัวอย่างคำสั่ง curl
# Set JWT, PROJECT_ID, and TASK_ID in the local environment
curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=state,taskOutcome,taskOutcomeTime" \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${JWT}" \
--data-binary @- << EOM
{
"state": "CLOSED",
"taskOutcome": "SUCCEEDED",
"taskOutcomeTime": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOM
ตั้งค่าผลลัพธ์ของงาน
หากต้องการระบุผลลัพธ์ที่แท้จริงของงาน ให้ตั้งค่าผลลัพธ์สำหรับงานที่ปิดแล้วเป็น SUCCEEDED
หรือ FAILED
คุณต้องปิดงานก่อนจึงจะตั้งค่าผลลัพธ์ของงานได้ Fleet Engine จะเรียกเก็บเงินเฉพาะสำหรับงานนำส่งที่มีสถานะเป็น
SUCCEEDED
รายละเอียดผลลัพธ์ของงาน
นอกจากนี้ งานยังให้รายละเอียดเพิ่มเติมเกี่ยวกับผลลัพธ์ของงานด้วย คุณตั้งค่าเหล่านี้ได้
โดยตรงและ Fleet Engine จะใช้การตั้งค่าของคุณ
- สถานที่ตั้งผลลัพธ์ของงาน: Fleet Engine จะกรอกสถานที่ตั้งผลลัพธ์ของงานโดยอัตโนมัติด้วยตำแหน่งล่าสุดที่ทราบของยานพาหนะ คุณระบุ
แทนได้หากต้องการ
- เวลาผลลัพธ์ของงาน: Fleet Engine จะไม่กรอกข้อมูลในช่องนี้ แต่คุณสามารถตั้งค่าได้
คุณใช้วิธีการต่อไปนี้เพื่อตั้งค่า task_outcome_location
และ task_outcome_time
ได้
- อัปเดตในคำขอเดียวกันที่ตั้งค่าผลลัพธ์ของงาน
- อัปเดตภายหลังหลังจากตั้งค่าผลลัพธ์ของงานแล้ว
- แก้ไขอีกครั้งหลังจากตั้งค่าแล้ว
Fleet Engine จะป้องกันการอัปเดตต่อไปนี้ที่เกี่ยวข้องกับผลลัพธ์ของงาน
- คุณแก้ไขผลลัพธ์ของงานไม่ได้เมื่อตั้งค่าเป็น
SUCCEEDED
หรือ
FAILED
- คุณไม่สามารถตั้งค่าสถานที่หรือเวลาของผลลัพธ์ของงานสำหรับงานที่ไม่มีผลลัพธ์ที่ตั้งไว้
ฟิลด์งานสำหรับการตั้งค่าผลลัพธ์
ส่วนนี้จะบันทึกฟิลด์ที่จำเป็นและที่ไม่บังคับซึ่งต้องตั้งค่าเมื่อตั้งค่าผลลัพธ์ของงาน Fleet Engine จะไม่สนใจฟิลด์อื่นๆ ในเอนทิตีสำหรับการอัปเดต
ช่องที่ต้องกรอก |
ค่า |
taskOutcome |
Outcome.SUCCEEDED หรือ Outcome.FAILED |
ช่องที่ไม่บังคับ | ค่า |
taskOutcomeLocation |
สถานที่ที่งานเสร็จสมบูรณ์ หากไม่ได้ตั้งค่า Fleet Engine
จะตั้งค่านี้เป็นตำแหน่งล่าสุดของยานพาหนะโดยค่าเริ่มต้น |
taskOutcomeTime |
การประทับเวลาเมื่อทำงานเสร็จ |
ตัวอย่างผลลัพธ์ของงาน
ตัวอย่างต่อไปนี้แสดงวิธีใช้ไลบรารี gRPC ของ Java และการเรียก HTTP
REST ไปยัง UpdateTask
เพื่อตั้งค่าผลลัพธ์ของงานเป็น SUCCEEDED
และตั้งค่า
สถานที่ที่งานเสร็จสมบูรณ์
gRPC
static final String PROJECT_ID = "my-delivery-co-gcp-project";
static final String TASK_ID = "task-8241890";
DeliveryServiceBlockingStub deliveryService =
DeliveryServiceGrpc.newBlockingStub(channel);
// Task settings
String taskName = "providers/" + PROJECT_ID + "/tasks/" + TASK_ID;
Task task = Task.newBuilder()
.setName(taskName)
.setTaskOutcome(TaskOutcome.SUCCEEDED)
.setTaskOutcomeTime(now())
.setTaskOutcomeLocation( // Grand Indonesia East Mall
LocationInfo.newBuilder().setPoint(
LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))
.build();
// Task request
UpdateTaskRequest updateTaskRequest =
UpdateTaskRequest.newBuilder() // No need for the header
.setTask(task)
.setUpdateMask(FieldMask.newBuilder().addPaths("task_outcome", "task_outcome_time", "task_outcome_location"))
.build();
try {
Task updatedTask = deliveryService.updateTask(updateTaskRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
REST
PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/tasks/<id>?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation
- <id> คือตัวระบุที่ไม่ซ้ำกันสำหรับงาน
- ส่วนหัวของคำขอต้องมีฟิลด์ Authorization ที่มีค่าเป็น
Bearer <token> โดยที่ <token> ออกโดยเซิร์ฟเวอร์ของคุณ
ตามหลักเกณฑ์ที่อธิบายไว้ในบทบาทของบัญชีบริการและ
โทเค็นเว็บ JSON
- เนื้อหาของคำขอต้องมีเอนทิตี
Task
# Set JWT, PROJECT_ID, and TASK_ID in the local environment
curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation" \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${JWT}" \
--data-binary @- << EOM
{
"taskOutcome": "SUCCEEDED",
"taskOutcomeTime": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"taskOutcomeLocation": {
"point": {
"latitude": -6.195139,
"longitude": 106.820826
}
}
}
EOM
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThis document explains how to finalize shipment tasks in Fleet Engine by closing them and setting their outcome to \u003ccode\u003eSUCCEEDED\u003c/code\u003e or \u003ccode\u003eFAILED\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eClosing a task indicates it is no longer in progress, while setting the outcome reflects the delivery result for billing and journey sharing.\u003c/p\u003e\n"],["\u003cp\u003eTasks can be closed by updating the vehicle's stop status, removing them from the vehicle's stop list, or setting their state to \u003ccode\u003eCLOSED\u003c/code\u003e if unassigned.\u003c/p\u003e\n"],["\u003cp\u003eThe task outcome, location, and time can be set using the \u003ccode\u003eUpdateTask\u003c/code\u003e method with appropriate fields and values, but the outcome cannot be changed once set.\u003c/p\u003e\n"]]],["To finalize shipment tasks, you must first close them, setting the `state` to `CLOSED`, which indicates the task is no longer active. Closing can be done by updating the vehicle's stop status, removing the task from the vehicle's stop list, or directly setting the task state. Once closed, set the `taskOutcome` to `SUCCEEDED` or `FAILED`, with optional details like `taskOutcomeLocation` and `taskOutcomeTime`. The task outcome is essential for journey sharing and billing. You can use gRPC or HTTP REST calls to accomplish both.\n"],null,["This document assumes you understand how to create and use tasks. It provides\nspecific examples for how to finalize shipment tasks as follows:\n\n- **Close a task** : Closing a shipment task changes its state to `CLOSED` and\n indicates that that task is no longer active.\n\n- **Set the task outcome** : Once a task is closed, you then finalize it by\n setting its outcome to either `SUCCEEDED` or `FAILED`. This is an important\n part of finalizing a task in order to show the delivery outcome in journey\n sharing and to ensure correct billing for the Fleet Engine service.\n\nClose a task\n\nYou can close a task in the following ways:\n\n- **Update the stop status for the vehicle** . You remove the stop from the vehicle, which in turn closes all tasks associated with the stop. See [Update stop status for details](/maps/documentation/mobility/fleet-engine/journeys/tasks/update-stops).\n- **Remove the task from the list of vehicle stops** . This involves updating the list of tasks for the stop, but with the closed task no longer part of the list. See Update task order in [Update tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/update-tasks).\n- **Set the task state to `CLOSED`**. This can only be done on tasks not assigned to vehicles. This section shows this approach.\n\nOnce you close a task, you may not reopen it.\n\u003e \u003e **Closing of a task does not indicate its success or failure** . It indicates\n\u003e \u003e that the task is no longer considered in progress. In order to indicate the\n\u003e \u003e actual outcome of a task and to have that displayed for Fleet Tracking and\n\u003e \u003e journey sharing purposes, you must indicate the actual outcome of a task. See\n\u003e \u003e [Set the task outcome](#set-task-outcome) below.\n\nTask fields for closing tasks\n\nThis section documents the required fields to set when closing a\ntask. Fleet engine ignores all other fields in the entity for the update.\n\n\u003cbr /\u003e\n\n| Required field | Value |\n|----------------|----------------|\n| `state` | `State.CLOSED` |\n\n\u003cbr /\u003e\n\nClose a task directly\n\nThe following examples show how to set an unassigned task to a closed state,\neither in gRPC or using an HTTP REST request call to `UpdateTask` \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String TASK_ID = \"task-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Task settings\n String taskName = \"providers/\" + PROJECT_ID + \"/tasks/\" + TASK_ID;\n Task task = Task.newBuilder()\n .setName(taskName)\n .setState(Task.State.CLOSED) // You can only directly CLOSE a\n .build(); // task that is NOT assigned to a vehicle.\n\n // Task request\n UpdateTaskRequest updateTaskRequest =\n UpdateTaskRequest.newBuilder() // No need for the header\n .setTask(task)\n .setUpdateMask(FieldMask.newBuilder().addPaths(\"state\"))\n .build();\n\n try {\n Task updatedTask = deliveryService.updateTask(updateTaskRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\n`PATCH https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/tasks/\u003cid\u003e?updateMask=state`\n\n- *\\\u003cid\\\u003e* is a unique identifier for the task.\n- The request header must contain a field *Authorization* with the value *Bearer \\\u003ctoken\\\u003e* , where *\\\u003ctoken\\\u003e* is issued by your server according to the guidelines described in [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) and [JSON Web tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt).\n- You must include a `Task` entity in the request body\n\nExample `curl` command: \n\n # Set JWT, PROJECT_ID, and TASK_ID in the local environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=state,taskOutcome,taskOutcomeTime\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"state\": \"CLOSED\",\n \"taskOutcome\": \"SUCCEEDED\",\n \"taskOutcomeTime\": \"$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")\"\n }\n EOM\n\nSet the task outcome\n\nTo indicate the actual outcome of a task, you set the outcome for closed tasks\nto either `SUCCEEDED` or `FAILED`. A task must be closed before you set its\noutcome. Fleet Engine only charges for delivery tasks with a state of\n`SUCCEEDED`.\n\nTask outcome details\n\nTasks also provide additional details about the task outcome. You can set these\ndirectly and Fleet Engine respects your settings:\n\n- **Task outcome location**: Fleet Engine automatically fills in the task outcome location with the last known vehicle location. You can provide this instead if you prefer.\n- **Task outcome time**: Fleet Engine does not fill this field in, but is available for you to set.\n\nYou can use any of the following approaches to setting `task_outcome_location`\nand `task_outcome_time`:\n\n- **Update them in the same request** that sets the task outcome.\n- **Update them later**, after you have set task outcome.\n- **Modify them again** after they have been set.\n\nFleet Engine prevents the following updates related to task outcomes:\n\n- **You can't modify a task outcome once it is set** to either `SUCCEEDED` or `FAILED`.\n- **You can't set a task outcome location or outcome time** for tasks without a set outcome.\n\nTask fields for setting outcome\n\nThis section documents the required and optional fields to set when setting a\ntask outcome. Fleet Engine ignores other fields in the entity for the update.\n\n\u003cbr /\u003e\n\n| Required field | Value |\n|----------------|-----------------------------------------|\n| `taskOutcome` | `Outcome.SUCCEEDED` or `Outcome.FAILED` |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Optional field | Value |\n|-----------------------|-----------------------------------------------------------------------------------------------------------------|\n| `taskOutcomeLocation` | The location where the task was completed. If not set, Fleet Engine defaults this to the last vehicle location. |\n| `taskOutcomeTime` | The timestamp when the task was completed. |\n\n\u003cbr /\u003e\n\nTask outcome examples\n\nThe following example shows how to use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks) and an HTTP\nREST call to `UpdateTask` to set a task outcome to `SUCCEEDED` and set the\nlocation where the task was completed. \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String TASK_ID = \"task-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Task settings\n String taskName = \"providers/\" + PROJECT_ID + \"/tasks/\" + TASK_ID;\n Task task = Task.newBuilder()\n .setName(taskName)\n .setTaskOutcome(TaskOutcome.SUCCEEDED)\n .setTaskOutcomeTime(now())\n .setTaskOutcomeLocation( // Grand Indonesia East Mall\n LocationInfo.newBuilder().setPoint(\n LatLng.newBuilder().setLatitude(-6.195139).setLongitude(106.820826)))\n .build();\n\n // Task request\n UpdateTaskRequest updateTaskRequest =\n UpdateTaskRequest.newBuilder() // No need for the header\n .setTask(task)\n .setUpdateMask(FieldMask.newBuilder().addPaths(\"task_outcome\", \"task_outcome_time\", \"task_outcome_location\"))\n .build();\n\n try {\n Task updatedTask = deliveryService.updateTask(updateTaskRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST\n\n`PATCH https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/tasks/\u003cid\u003e?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation`\n\n- *\\\u003cid\\\u003e* is a unique identifier for the task.\n- The request header must contain a field *Authorization* with the value *Bearer \\\u003ctoken\\\u003e* , where *\\\u003ctoken\\\u003e* is issued by your server according to the guidelines described in [Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts) and [JSON Web tokens](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/jwt).\n- The request body must contain a `Task` entity.\n\n # Set JWT, PROJECT_ID, and TASK_ID in the local environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/tasks/${TASK_ID}?updateMask=taskOutcome,taskOutcomeTime,taskOutcomeLocation\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"taskOutcome\": \"SUCCEEDED\",\n \"taskOutcomeTime\": \"$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")\",\n \"taskOutcomeLocation\": {\n \"point\": {\n \"latitude\": -6.195139,\n \"longitude\": 106.820826\n }\n }\n }\n EOM\n\nWhat's next\n\n- [Find tasks](/maps/documentation/mobility/fleet-engine/journeys/tasks/find-tasks)"]]