Import OT
นำเข้าเอกสาร OT แบบกลุ่ม (Batch Import)
ใช้ API นี้เพื่อนำเข้าข้อมูล OT จำนวนมากพร้อมกัน รองรับทั้งการเพิ่ม/แก้ไข (UPSERT) และการลบ (DEL) ข้อมูลจะถูกส่งเข้า Queue เพื่อประมวลผลแบบ Asynchronous
Endpoint
POST /api/v1/open-apis/overtime/importRequest Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
import_data | array | Yes | รายการข้อมูล OT ที่ต้องการนำเข้า | (ดูตัวอย่างด้านล่าง) |
import_data[].status | string | Yes | การดำเนินการ: UPSERT หรือ DEL | UPSERT |
import_data[].employee_code | string | Yes | รหัสพนักงาน | EMP001 |
import_data[].type | string | Yes | รหัสประเภท OT | OT_1_5 |
import_data[].start_dt | string | Yes | วันเวลาเริ่มต้น (YYYY-MM-DD HH:MM:SS) | 2025-11-15 18:00:00 |
import_data[].end_dt | string | Yes | วันเวลาสิ้นสุด (YYYY-MM-DD HH:MM:SS) | 2025-11-15 22:00:00 |
import_data[].description | string | No | รายละเอียดงาน OT | ทำงานโปรเจกต์พิเศษ |
OT Type Codes
| Type Code | Rate | Description |
|---|---|---|
OT_1_0 | 1.0x | OT อัตราปกติ |
OT_1_5 | 1.5x | OT วันทำงานปกติ |
OT_2_0 | 2.0x | OT วันหยุด |
OT_3_0 | 3.0x | OT วันหยุดนักขัตฤกษ์ |
OT_4_0 - OT_7_0 | 4.0x - 7.0x | OT พิเศษ |
Request Body Example
{
"import_data": [
{
"status": "UPSERT",
"employee_code": "EMP001",
"type": "OT_1_5",
"start_dt": "2025-11-15 18:00:00",
"end_dt": "2025-11-15 22:00:00",
"description": "ทำงานโปรเจกต์พิเศษ"
},
{
"status": "UPSERT",
"employee_code": "EMP002",
"type": "OT_2_0",
"start_dt": "2025-11-16 09:00:00",
"end_dt": "2025-11-16 17:00:00",
"description": "ทำงานวันหยุด"
}
]
}Response Format
Success Response (HTTP 200)
เมื่อมีข้อมูลที่ถูกต้องอย่างน้อย 1 รายการ ระบบจะส่งข้อมูลที่ถูกต้องเข้า Queue และตอบกลับรายการที่ไม่ผ่าน validation
{
"code": 200,
"message": "successfully en-queued",
"payload": {
"invalid_items": [
{
"index": 1,
"data": {
"status": "UPSERT",
"employee_code": "EMP999",
"type": "OT_1_5",
"start_dt": "2025-11-16 18:00:00",
"end_dt": "2025-11-16 21:00:00"
},
"errors": ["employee_code 'EMP999' not found"]
}
]
}
}Error Response - Validation Failed (HTTP 400)
เมื่อโครงสร้างข้อมูลไม่ถูกต้อง (ไม่มี import_data, ไม่ใช่ array, หรือว่างเปล่า)
{
"code": 400,
"message": "Validation failed",
"errors": ["Missing 'import_data' field"]
}Error Response - No Valid Data (HTTP 400)
เมื่อไม่มีข้อมูลที่ผ่าน validation เลย
{
"code": 400,
"message": "No valid data to import",
"payload": {
"invalid_items": [
{
"index": 0,
"data": {
"status": "UPSERT",
"employee_code": "EMP999",
"type": "OT_1_5",
"start_dt": "2025-11-15 18:00:00",
"end_dt": "2025-11-15 22:00:00"
},
"errors": ["employee_code 'EMP999' not found"]
}
]
}
}Response Fields
| Field | Type | Description |
|---|---|---|
code | number | รหัสสถานะ (200 = สำเร็จ, 400 = ไม่สำเร็จ) |
message | string | ข้อความตอบกลับ |
payload.invalid_items | array | รายการข้อมูลที่ไม่ผ่าน validation |
errors | array | รายการข้อผิดพลาดของโครงสร้างข้อมูล (กรณี validation ไม่ผ่าน) |
Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/overtime/import" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"import_data": [
{
"status": "UPSERT",
"employee_code": "EMP001",
"type": "OT_1_5",
"start_dt": "2025-11-15 18:00:00",
"end_dt": "2025-11-15 22:00:00",
"description": "ทำงานโปรเจกต์พิเศษ"
}
]
}'Validation Rules
| Parameter | Validation | Error Message |
|---|---|---|
status | ต้องเป็น UPSERT หรือ DEL | status must be 'UPSERT' or 'DEL' |
employee_code | ต้องมีอยู่ในระบบ | employee_code 'XXX' not found |
type | ต้องเป็นหนึ่งใน OT Type Codes | type must be one of: OT_1_0, OT_1_5, ... |
start_dt | ต้องอยู่ในรูปแบบ YYYY-MM-DD HH:MM:SS | start_dt must be in format YYYY-MM-DD HH:MM:SS |
end_dt | ต้อง >= start_dt | end_dt must be greater than or equal to start_dt |
Business Rules
Partial Success:
- ระบบจะประมวลผลเฉพาะรายการที่ถูกต้อง และแจ้งรายการที่ไม่ถูกต้องกลับมาใน response
- รายการที่ผ่าน validation จะถูกส่งเข้า Queue ทันที
- รายการที่ไม่ผ่าน validation จะถูกส่งกลับมาพร้อม error message
Asynchronous Processing
- ข้อมูลจะถูกส่งเข้าระบบคิว (Queue) เพื่อประมวลผล
- API จะตอบกลับทันทีหลังจาก validate และส่งข้อมูลเข้า Queue สำเร็จ
- เหมาะสำหรับการนำเข้าข้อมูลจำนวนมาก
Notes
Status Values
| Status | Description |
|---|---|
UPSERT | เพิ่มหรือแก้ไขข้อมูล OT |
DEL | ลบข้อมูล OT ที่มีอยู่ |
Use Cases
- Migration - ย้ายข้อมูล OT จากระบบเดิม
- Bulk Update - อัปเดตข้อมูล OT จำนวนมาก
- Integration - รับข้อมูลจากระบบภายนอก
Related APIs
- Get OT Types - ดึงรายการประเภท OT
- Get OT List - ดึงรายการคำขอ OT
- Submit OT - ยื่นคำขอ OT ทีละรายการ
- Delete OT - ลบคำขอ OT
Last updated on