guoziyun před 9 měsíci
rodič
revize
be88ddea4c

+ 36 - 3
oms/dist/src/controllers/messageRecordController.js

@@ -41,14 +41,47 @@ class MessageRecordController {
             filters.activityId = activityId;
         }
         if (status) {
-            const statusNum = parseInt(status, 30);
+            const statusNum = parseInt(status, 10);
             if (!isNaN(statusNum)) {
                 filters.status = statusNum;
             }
         }
-        // 处理日期范围筛选,默认为 createdAt
+        // 定义所有可查询的日期字段
+        const dateQueryKeys = ["plannedSendAt", "actualSendAt", "deliveredAt", "openedAt", "createdAt", "updatedAt"];
+        // 遍历所有日期字段,处理单个日期或日期范围
+        dateQueryKeys.forEach((key) => {
+            const queryValue = req.query[key];
+            if (queryValue) {
+                const dates = queryValue.split(",");
+                if (dates.length === 2) {
+                    const startDate = new Date(dates[0]);
+                    const endDate = new Date(dates[1]);
+                    // 确保日期有效
+                    if (!isNaN(startDate.getTime()) && !isNaN(endDate.getTime())) {
+                        filters[key] = {
+                            $gte: startDate,
+                            $lte: endDate,
+                        };
+                    }
+                    else {
+                        console.warn(`[API] Invalid date range format for ${key}: ${queryValue}. Skipping.`);
+                    }
+                }
+                else {
+                    // 如果不是范围,则按单个日期精确匹配
+                    const singleDate = new Date(queryValue);
+                    if (!isNaN(singleDate.getTime())) {
+                        filters[key] = singleDate;
+                    }
+                }
+            }
+        });
+        // 保留对原有startDate/endDate参数的兼容性,并将其应用于createdAt
         if (startDate || endDate) {
-            filters.createdAt = {};
+            // 确保 createdAt 过滤器不存在冲突,如果已通过范围查询设置,则跳过
+            if (!filters.createdAt) {
+                filters.createdAt = {};
+            }
             if (startDate) {
                 filters.createdAt.$gte = new Date(startDate);
             }

+ 26 - 15
oms/dist/src/controllers/userController.js

@@ -132,14 +132,36 @@ class UserController {
     async getPaginatedUsers(req, res) {
         try {
             const page = parseInt(req.query.page) || 1;
-            const limit = parseInt(req.query.limit) || 30; // 从 req.query 中筛选出只与 IUser 相关的属性,作为 MongoDB 的查询条件
+            const limit = parseInt(req.query.limit) || 30;
+            // 从 req.query 中筛选出只与 IUser 相关的属性,作为 MongoDB 的查询条件
             const mongooseQuery = {};
             for (const key in req.query) {
                 if (Object.prototype.hasOwnProperty.call(req.query, key)) {
                     // 检查 key 是否在 USER_MODEL_KEYS 中 (即是否是 IUser 的有效属性)
                     // 并且不是分页参数 'page' 或 'limit'
                     if (USER_MODEL_KEYS.includes(key)) {
-                        const queryValue = req.query[key]; // 根据需要进行类型转换
+                        const queryValue = req.query[key];
+                        // --- 新增:处理日期范围查询 ---
+                        if (key === "firstLoginAt" || key === "lastActiveAt") {
+                            // 检查是否为日期范围格式 (e.g., "2023-01-01,2023-01-31")
+                            const dates = queryValue.split(",");
+                            if (dates.length === 2) {
+                                const startDate = new Date(dates[0]);
+                                const endDate = new Date(dates[1]);
+                                // 确保日期有效
+                                if (!isNaN(startDate.getTime()) && !isNaN(endDate.getTime())) {
+                                    mongooseQuery[key] = {
+                                        $gte: startDate,
+                                        $lte: endDate,
+                                    };
+                                    continue; // 继续下一个查询参数
+                                }
+                                else {
+                                    console.warn(`[API] Invalid date range format for ${key}: ${queryValue}. Skipping.`);
+                                }
+                            }
+                        }
+                        // --- 其他属性处理,保持不变 ---
                         if (key === "project" || key === "apiLevel" || key === "versionCode") {
                             const numValue = parseInt(queryValue);
                             if (!isNaN(numValue)) {
@@ -156,25 +178,14 @@ class UserController {
                             // 如果 tags 是以逗号分隔的字符串,可以将其转换为数组
                             mongooseQuery[key] = queryValue.split(",").map((s) => s.trim());
                         }
-                        else if (key === "firstLoginAt" || key === "lastActiveAt") {
-                            // 尝试将字符串转换为 Date 对象
-                            try {
-                                const dateValue = new Date(queryValue);
-                                if (!isNaN(dateValue.getTime())) {
-                                    // 检查日期是否有效
-                                    mongooseQuery[key] = dateValue;
-                                }
-                            }
-                            catch (e) {
-                                console.warn(`Invalid date format for ${key}: ${queryValue}. Skipping.`); // 可以选择在这里返回错误或忽略该查询参数
-                            }
-                        } // 对于其他字符串类型,直接赋值
                         else {
+                            // 对于其他字符串类型,直接赋值
                             mongooseQuery[key] = queryValue;
                         }
                     }
                 }
             }
+            // 为了确保类型兼容性,我们暂时使用any来处理mongooseQuery
             const { users, total } = await userService_1.default.getPaginatedUsers(page, limit, mongooseQuery // 传入处理后的查询对象
             );
             res.status(200).json({

+ 1 - 1
oms/public/app/index.html

@@ -9,5 +9,5 @@
   <style>body,html{width:100%;height:100%}*,:after,:before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:transparent}@-ms-viewport{width:device-width}body{margin:0;color:#000000d9;font-size:14px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-variant:tabular-nums;line-height:1.5715;background-color:#fff;font-feature-settings:"tnum"}html{--antd-wave-shadow-color:#1890ff;--scroll-bar:0}</style><link rel="stylesheet" href="styles-LXBSU6DF.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles-LXBSU6DF.css"></noscript></head>
   <body>
     <app-root></app-root>
-  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-TV4M6D7M.js" type="module"></script></body>
+  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-67SRJ75K.js" type="module"></script></body>
 </html>

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
oms/public/app/main-67SRJ75K.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
oms/public/app/main-TV4M6D7M.js


+ 38 - 4
oms/src/controllers/messageRecordController.ts

@@ -1,5 +1,5 @@
 import { Request, Response } from "express";
-import { MessageRecord } from "../models/messageRecordModel";
+import { MessageRecord, IMessageRecord } from "../models/messageRecordModel";
 import { isObjectIdOrHexString } from "mongoose";
 
 class MessageRecordController {
@@ -43,15 +43,49 @@ class MessageRecordController {
       filters.activityId = activityId;
     }
     if (status) {
-      const statusNum = parseInt(status as string, 30);
+      const statusNum = parseInt(status as string, 10);
       if (!isNaN(statusNum)) {
         filters.status = statusNum;
       }
     }
 
-    // 处理日期范围筛选,默认为 createdAt
+    // 定义所有可查询的日期字段
+    const dateQueryKeys: (keyof IMessageRecord)[] = ["plannedSendAt", "actualSendAt", "deliveredAt", "openedAt", "createdAt", "updatedAt"];
+
+    // 遍历所有日期字段,处理单个日期或日期范围
+    dateQueryKeys.forEach((key) => {
+      const queryValue = req.query[key as string] as string;
+      if (queryValue) {
+        const dates = queryValue.split(",");
+        if (dates.length === 2) {
+          const startDate = new Date(dates[0]);
+          const endDate = new Date(dates[1]);
+
+          // 确保日期有效
+          if (!isNaN(startDate.getTime()) && !isNaN(endDate.getTime())) {
+            filters[key] = {
+              $gte: startDate,
+              $lte: endDate,
+            };
+          } else {
+            console.warn(`[API] Invalid date range format for ${key}: ${queryValue}. Skipping.`);
+          }
+        } else {
+          // 如果不是范围,则按单个日期精确匹配
+          const singleDate = new Date(queryValue);
+          if (!isNaN(singleDate.getTime())) {
+            filters[key] = singleDate;
+          }
+        }
+      }
+    });
+
+    // 保留对原有startDate/endDate参数的兼容性,并将其应用于createdAt
     if (startDate || endDate) {
-      filters.createdAt = {};
+      // 确保 createdAt 过滤器不存在冲突,如果已通过范围查询设置,则跳过
+      if (!filters.createdAt) {
+        filters.createdAt = {};
+      }
       if (startDate) {
         filters.createdAt.$gte = new Date(startDate as string);
       }

+ 35 - 22
oms/src/controllers/userController.ts

@@ -147,48 +147,61 @@ class UserController {
   public async getPaginatedUsers(req: Request, res: Response): Promise<void> {
     try {
       const page = parseInt(req.query.page as string) || 1;
-      const limit = parseInt(req.query.limit as string) || 30; // 从 req.query 中筛选出只与 IUser 相关的属性,作为 MongoDB 的查询条件
+      const limit = parseInt(req.query.limit as string) || 30;
 
-      const mongooseQuery: Partial<IUser> = {};
+      // 从 req.query 中筛选出只与 IUser 相关的属性,作为 MongoDB 的查询条件
+      const mongooseQuery: any = {};
       for (const key in req.query) {
         if (Object.prototype.hasOwnProperty.call(req.query, key)) {
           // 检查 key 是否在 USER_MODEL_KEYS 中 (即是否是 IUser 的有效属性)
           // 并且不是分页参数 'page' 或 'limit'
           if (USER_MODEL_KEYS.includes(key as keyof IUser)) {
-            const queryValue = req.query[key]; // 根据需要进行类型转换
+            const queryValue = req.query[key] as string;
+
+            // --- 新增:处理日期范围查询 ---
+            if (key === "firstLoginAt" || key === "lastActiveAt") {
+              // 检查是否为日期范围格式 (e.g., "2023-01-01,2023-01-31")
+              const dates = queryValue.split(",");
+              if (dates.length === 2) {
+                const startDate = new Date(dates[0]);
+                const endDate = new Date(dates[1]);
+
+                // 确保日期有效
+                if (!isNaN(startDate.getTime()) && !isNaN(endDate.getTime())) {
+                  mongooseQuery[key] = {
+                    $gte: startDate,
+                    $lte: endDate,
+                  };
+                  continue; // 继续下一个查询参数
+                } else {
+                  console.warn(`[API] Invalid date range format for ${key}: ${queryValue}. Skipping.`);
+                }
+              }
+            }
 
+            // --- 其他属性处理,保持不变 ---
             if (key === "project" || key === "apiLevel" || key === "versionCode") {
-              const numValue = parseInt(queryValue as string);
+              const numValue = parseInt(queryValue);
               if (!isNaN(numValue)) {
-                mongooseQuery[key as keyof IUser] = numValue as any;
+                mongooseQuery[key] = numValue;
               }
             } else if (key === "deviceMem") {
-              const numValue = parseFloat(queryValue as string);
+              const numValue = parseFloat(queryValue);
               if (!isNaN(numValue)) {
-                mongooseQuery[key as keyof IUser] = numValue as any;
+                mongooseQuery[key] = numValue;
               }
             } else if (key === "tags") {
               // 如果 tags 是以逗号分隔的字符串,可以将其转换为数组
-              mongooseQuery[key as keyof IUser] = (queryValue as string).split(",").map((s) => s.trim()) as any;
-            } else if (key === "firstLoginAt" || key === "lastActiveAt") {
-              // 尝试将字符串转换为 Date 对象
-              try {
-                const dateValue = new Date(queryValue as string);
-                if (!isNaN(dateValue.getTime())) {
-                  // 检查日期是否有效
-                  mongooseQuery[key as keyof IUser] = dateValue as any;
-                }
-              } catch (e) {
-                console.warn(`Invalid date format for ${key}: ${queryValue}. Skipping.`); // 可以选择在这里返回错误或忽略该查询参数
-              }
-            } // 对于其他字符串类型,直接赋值
-            else {
-              mongooseQuery[key as keyof IUser] = queryValue as any;
+              mongooseQuery[key] = queryValue.split(",").map((s) => s.trim());
+            } else {
+              // 对于其他字符串类型,直接赋值
+              mongooseQuery[key] = queryValue;
             }
           }
         }
       }
 
+      // 为了确保类型兼容性,我们暂时使用any来处理mongooseQuery
       const { users, total } = await userService.getPaginatedUsers(
         page,
         limit,

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů