修改幾個小 issue
This commit is contained in:
+27
-12
@@ -1,4 +1,4 @@
|
||||
// todo_api.dart (新增 Create 功能)
|
||||
// todo_api.dart
|
||||
|
||||
import './todo_model.dart';
|
||||
import '../services/generic_api_service.dart';
|
||||
@@ -10,16 +10,31 @@ class TodoApiService {
|
||||
|
||||
TodoApiService({this.currentUserId = 'admin'});
|
||||
|
||||
// 原始的查詢功能...
|
||||
/// 獲取指定日期的任務清單
|
||||
Future<List<Todo>> fetchTodos({DateTime? selectedDate}) async {
|
||||
Future<List<Todo>> fetchTodos({DateTime? selectedDate, String? statusFilter}) async {
|
||||
// 預設查詢今天的資料
|
||||
DateTime dateToQuery = selectedDate ?? DateTime.now();
|
||||
String formattedDate = DateFormat('yyyy-MM-dd').format(dateToQuery);
|
||||
|
||||
// 構建 queryFilter:過濾特定的 end_date 並根據 id 排序
|
||||
// 格式範例: 1^100^id^*^^end_date^2024-05-01
|
||||
String queryFilter = "1^100^id^*^^end_date^$formattedDate";
|
||||
// 1. 組合 wheresql_org (第 5 個參數)
|
||||
// 使用 LIKE 來比對 DATETIME 欄位,確保抓到該日期的所有時段
|
||||
String whereSql = "end_date LIKE '$formattedDate%'";
|
||||
|
||||
// 2. 如果有傳入狀態過濾條件,動態加上 AND 語法
|
||||
if (statusFilter != null && statusFilter != 'All') {
|
||||
String dbStatus = '';
|
||||
if (statusFilter == 'Done') dbStatus = 'DONE';
|
||||
else if (statusFilter == 'In Progress') dbStatus = 'WIP';
|
||||
else if (statusFilter == 'To do') dbStatus = 'TODO'; // 假設你的待辦狀態是 TODO
|
||||
|
||||
if (dbStatus.isNotEmpty) {
|
||||
whereSql += " AND pbi_status = '$dbStatus'";
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 嚴格依照 API 規範組裝 10 個參數 (共 9 個 ^ 分隔符)
|
||||
// 格式:pageno^pagerec^orderby^udf_fields^wheresql_org^menuid^where_fields^where_value^where_field^where_idvalue
|
||||
String queryFilter = "1^100^id^*^$whereSql^^^^^";
|
||||
|
||||
return await _apiService.fetchList<Todo>(
|
||||
tableName: "eip_todolist",
|
||||
@@ -36,14 +51,14 @@ class TodoApiService {
|
||||
"task_name": todo.taskName,
|
||||
"task_desc": todo.description,
|
||||
"issue_priority": todo.priority,
|
||||
"pbi_status": todo.status ?? 'WIP', // 預設為進行中
|
||||
"pbi_status": todo.status ?? 'WIP',
|
||||
"end_date": todo.endDate != null ? DateFormat('yyyy-MM-dd HH:mm:ss').format(todo.endDate!) : null,
|
||||
"create_user": currentUserId,
|
||||
"create_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||||
// 新增時先不寫入 update_user / update_date
|
||||
};
|
||||
|
||||
try {
|
||||
// 根據 Generic API 規範,使用 action: "C" 進行新增
|
||||
await _apiService.fetchList<dynamic>(
|
||||
tableName: "eip_todolist",
|
||||
pk: "id",
|
||||
@@ -63,13 +78,13 @@ class TodoApiService {
|
||||
Future<bool> updateTodoStatus(int id, String status) async {
|
||||
final Map<String, dynamic> data = {
|
||||
"id": id, // 必填 PK
|
||||
"pbi_status": status, // 更新狀態為 'DONE'
|
||||
"modify_user": currentUserId,
|
||||
"modify_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||||
"pbi_status": status, // 更新狀態
|
||||
// 修正為 Schema 正確的欄位名稱 update_user / update_date
|
||||
"update_user": currentUserId,
|
||||
"update_date": DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()),
|
||||
};
|
||||
|
||||
try {
|
||||
// 使用 Action "U" 代表 Update
|
||||
await _apiService.fetchList<dynamic>(
|
||||
tableName: "eip_todolist",
|
||||
pk: "id",
|
||||
|
||||
Reference in New Issue
Block a user