From 13b191d4210726d0edad35c2532b2faa226538c3 Mon Sep 17 00:00:00 2001 From: zhihao Date: Wed, 24 Dec 2025 19:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E6=88=BF=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=86=99=E5=85=A5=E4=B8=8E=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UI/Controllers/UpgradeController.cs | 103 ++++++++++++++++ 更新日志.md | 183 ++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 更新日志.md diff --git a/UI/Controllers/UpgradeController.cs b/UI/Controllers/UpgradeController.cs index 1ae1950..1457b70 100644 --- a/UI/Controllers/UpgradeController.cs +++ b/UI/Controllers/UpgradeController.cs @@ -564,6 +564,109 @@ namespace UI.Controllers } } + /// + /// 设备信息类 + /// + public class EquipmentInfo + { + public string EquipmentStatus { get; set; } // 设备状态 + public string FaultDescription { get; set; } // 故障描述 + public string DevName { get; set; } // 设备名称 + } + + /// + /// 写入房间设备访问日志 + /// + /// 酒店ID + /// 房号 + /// 设备信息列表 + /// 返回操作结果 + [HttpPost] + public ActionResult WriteRoomVisitLog(string HotelID, string RoomNumber, List EquipmentList) + { + try + { + if (string.IsNullOrWhiteSpace(HotelID) || string.IsNullOrWhiteSpace(RoomNumber)) + { + return Json(new { Status = 0, Message = "酒店ID和房号不能为空" }, JsonRequestBehavior.AllowGet); + } + + if (EquipmentList == null || EquipmentList.Count == 0) + { + return Json(new { Status = 0, Message = "设备信息列表不能为空" }, JsonRequestBehavior.AllowGet); + } + + // 创建日志列表 + var logList = new List(); + string updateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + foreach (var equipment in EquipmentList) + { + logList.Add(new { + HotelID = HotelID, + RoomNumber = RoomNumber, + EquipmentStatus = equipment.EquipmentStatus, + FaultDescription = equipment.FaultDescription, + UpdateDate = updateDate, + DevName = equipment.DevName + }); + } + + // 批量写入数据库 + SqlSugarBase.RcuDb.Ado.ExecuteCommand("INSERT INTO tbl_roomvisitlogform (HotelID, RoomNumber, EquipmentStatus, FaultDescription, UpdateDate, DevName) VALUES (@HotelID, @RoomNumber, @EquipmentStatus, @FaultDescription, @UpdateDate, @DevName)", logList); + + return Json(new { Status = 1, Message = "写入成功", Count = logList.Count }, JsonRequestBehavior.AllowGet); + } + catch (Exception ex) + { + logger.Error(ex, "WriteRoomVisitLog error"); + return Json(new { Status = -1, Message = "写入失败", Detail = ex.Message }, JsonRequestBehavior.AllowGet); + } + } + + /// + /// 查询房间设备访问日志 + /// + /// 酒店ID + /// 房号 + /// 开始时间(格式:yyyy-MM-dd HH:mm:ss) + /// 结束时间(格式:yyyy-MM-dd HH:mm:ss) + /// 返回查询结果 + [HttpPost] + public ActionResult QueryRoomVisitLog(string HotelID, string RoomNumber, string StartTime = null, string EndTime = null) + { + try + { + if (string.IsNullOrWhiteSpace(HotelID) || string.IsNullOrWhiteSpace(RoomNumber)) + { + return Json(new { Status = 0, Message = "酒店ID和房号不能为空" }, JsonRequestBehavior.AllowGet); + } + + // 构建查询条件 + string whereClause = "WHERE HotelID = @HotelID AND RoomNumber = @RoomNumber"; + var parameters = new { HotelID, RoomNumber }; + + // 如果提供了开始时间和结束时间,则添加时间范围条件 + if (!string.IsNullOrWhiteSpace(StartTime) && !string.IsNullOrWhiteSpace(EndTime)) + { + whereClause += " AND UpdateDate BETWEEN @StartTime AND @EndTime"; + parameters = new { HotelID, RoomNumber, StartTime, EndTime }; + } + + // 构建完整的SQL查询语句 + string sql = $"SELECT ID, HotelID, RoomNumber, EquipmentStatus, FaultDescription, UpdateDate, DevName FROM tbl_roomvisitlogform {whereClause} ORDER BY UpdateDate DESC"; + + // 执行查询 + var result = SqlSugarBase.RcuDb.Ado.SqlQuery(sql, parameters); + + return Json(new { Status = 1, Message = "查询成功", Data = result }, JsonRequestBehavior.AllowGet); + } + catch (Exception ex) + { + logger.Error(ex, "QueryRoomVisitLog error"); + return Json(new { Status = -1, Message = "查询失败", Detail = ex.Message }, JsonRequestBehavior.AllowGet); + } + } } public class RCUDBData diff --git a/更新日志.md b/更新日志.md new file mode 100644 index 0000000..858d690 --- /dev/null +++ b/更新日志.md @@ -0,0 +1,183 @@ +# 系统更新日志 + +## 2025-12-24 + +### 新增接口 + +#### 1. 房间设备访问日志写入接口 + +**接口地址**: +`/Upgrade/WriteRoomVisitLog` + +**请求方式**: +`POST` + +**请求参数**: +| 参数名 | 类型 | 必填 | 描述 | +| --- | --- | --- | --- | +| HotelID | string | 是 | 酒店ID | +| RoomNumber | string | 是 | 房号 | +| EquipmentList | List | 是 | 设备信息列表 | + +**EquipmentInfo 数据结构**: +| 参数名 | 类型 | 必填 | 描述 | +| --- | --- | --- | --- | +| EquipmentStatus | string | 否 | 设备状态 | +| FaultDescription | string | 否 | 故障描述 | +| DevName | string | 否 | 设备名称 | + +**返回结果**: +```json +{ + "Status": 1, // 1成功,0失败,-1异常 + "Message": "写入成功", // 操作结果描述 + "Count": 3 // 写入记录数量 +} +``` + +**功能描述**: +该接口用于向数据库表 `tbl_roomvisitlogform` 写入房间设备访问日志,支持批量写入多个设备的信息。 + +**数据库表结构**: +```sql +CREATE TABLE `tbl_roomvisitlogform` ( + `ID` int NOT NULL AUTO_INCREMENT, + `HotelID` varchar(254) DEFAULT NULL COMMENT '酒店id', + `RoomNumber` varchar(254) DEFAULT NULL COMMENT '房号', + `EquipmentStatus` varchar(254) DEFAULT NULL COMMENT '设备状态', + `FaultDescription` varchar(254) DEFAULT NULL COMMENT '故障描述', + `UpdateDate` varchar(254) DEFAULT NULL COMMENT '更新时间', + `DevName` varchar(254) DEFAULT NULL COMMENT '设备名称', + PRIMARY KEY (`ID`), + KEY `idx_hotel_room` (`HotelID`,`RoomNumber`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 +``` + +**使用示例**: +```javascript +// 请求示例 +fetch('/Upgrade/WriteRoomVisitLog', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: JSON.stringify({ + HotelID: '123', + RoomNumber: '101', + EquipmentList: [ + { + EquipmentStatus: '正常', + DevName: '灯光设备' + }, + { + EquipmentStatus: '故障', + FaultDescription: '无法正常开关', + DevName: '空调设备' + } + ] + }) +}) +.then(response => response.json()) +.then(data => { + console.log(data); + // 输出:{"Status":1,"Message":"写入成功","Count":2} +}); +``` + +**开发人员**: +系统开发团队 + +**备注**: +该接口用于记录房间设备的访问和状态信息,方便后续查询和分析。 + +#### 2. 房间设备访问日志查询接口 + +**接口地址**: +`/Upgrade/QueryRoomVisitLog` + +**请求方式**: +`POST` + +**请求参数**: +| 参数名 | 类型 | 必填 | 描述 | +| --- | --- | --- | --- | +| HotelID | string | 是 | 酒店ID | +| RoomNumber | string | 是 | 房号 | +| StartTime | string | 否 | 开始时间(格式:yyyy-MM-dd HH:mm:ss) | +| EndTime | string | 否 | 结束时间(格式:yyyy-MM-dd HH:mm:ss) | + +**返回结果**: +```json +{ + "Status": 1, // 1成功,0失败,-1异常 + "Message": "查询成功", // 操作结果描述 + "Data": [ + { + "ID": 1, + "HotelID": "123", + "RoomNumber": "101", + "EquipmentStatus": "正常", + "FaultDescription": null, + "UpdateDate": "2025-12-24 10:30:00", + "DevName": "灯光设备" + }, + { + "ID": 2, + "HotelID": "123", + "RoomNumber": "101", + "EquipmentStatus": "故障", + "FaultDescription": "无法正常开关", + "UpdateDate": "2025-12-24 10:31:00", + "DevName": "空调设备" + } + ] +} +``` + +**功能描述**: +该接口用于查询房间设备访问日志,根据酒店ID、房号和时间范围进行筛选。如果开始时间和结束时间为空,则查询该房间的所有记录。 + +**使用示例**: +```javascript +// 查询指定时间范围内的记录 +fetch('/Upgrade/QueryRoomVisitLog', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: JSON.stringify({ + HotelID: '123', + RoomNumber: '101', + StartTime: '2025-12-24 00:00:00', + EndTime: '2025-12-24 23:59:59' + }) +}) +.then(response => response.json()) +.then(data => { + console.log(data); + // 输出查询结果 +}); + +// 查询所有记录 +fetch('/Upgrade/QueryRoomVisitLog', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: JSON.stringify({ + HotelID: '123', + RoomNumber: '101' + }) +}) +.then(response => response.json()) +.then(data => { + console.log(data); + // 输出查询结果 +}); +``` + +**开发人员**: +系统开发团队 + +**备注**: +该接口用于查询房间设备的访问和状态信息,支持按时间范围筛选,方便进行历史记录查询和分析。 \ No newline at end of file