新增查房日志写入与查询接口
This commit is contained in:
@@ -564,6 +564,109 @@ namespace UI.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设备信息类
|
||||
/// </summary>
|
||||
public class EquipmentInfo
|
||||
{
|
||||
public string EquipmentStatus { get; set; } // 设备状态
|
||||
public string FaultDescription { get; set; } // 故障描述
|
||||
public string DevName { get; set; } // 设备名称
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入房间设备访问日志
|
||||
/// </summary>
|
||||
/// <param name="HotelID">酒店ID</param>
|
||||
/// <param name="RoomNumber">房号</param>
|
||||
/// <param name="EquipmentList">设备信息列表</param>
|
||||
/// <returns>返回操作结果</returns>
|
||||
[HttpPost]
|
||||
public ActionResult WriteRoomVisitLog(string HotelID, string RoomNumber, List<EquipmentInfo> 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<object>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询房间设备访问日志
|
||||
/// </summary>
|
||||
/// <param name="HotelID">酒店ID</param>
|
||||
/// <param name="RoomNumber">房号</param>
|
||||
/// <param name="StartTime">开始时间(格式:yyyy-MM-dd HH:mm:ss)</param>
|
||||
/// <param name="EndTime">结束时间(格式:yyyy-MM-dd HH:mm:ss)</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
[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<dynamic>(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
|
||||
|
||||
183
更新日志.md
Normal file
183
更新日志.md
Normal file
@@ -0,0 +1,183 @@
|
||||
# 系统更新日志
|
||||
|
||||
## 2025-12-24
|
||||
|
||||
### 新增接口
|
||||
|
||||
#### 1. 房间设备访问日志写入接口
|
||||
|
||||
**接口地址**:
|
||||
`/Upgrade/WriteRoomVisitLog`
|
||||
|
||||
**请求方式**:
|
||||
`POST`
|
||||
|
||||
**请求参数**:
|
||||
| 参数名 | 类型 | 必填 | 描述 |
|
||||
| --- | --- | --- | --- |
|
||||
| HotelID | string | 是 | 酒店ID |
|
||||
| RoomNumber | string | 是 | 房号 |
|
||||
| EquipmentList | List<EquipmentInfo> | 是 | 设备信息列表 |
|
||||
|
||||
**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);
|
||||
// 输出查询结果
|
||||
});
|
||||
```
|
||||
|
||||
**开发人员**:
|
||||
系统开发团队
|
||||
|
||||
**备注**:
|
||||
该接口用于查询房间设备的访问和状态信息,支持按时间范围筛选,方便进行历史记录查询和分析。
|
||||
Reference in New Issue
Block a user