新增:管理后台前端页面,以及openspec内容。
This commit is contained in:
243
WxCheckMvc/Controllers/AdminController.cs
Normal file
243
WxCheckMvc/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WxCheckMvc.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AdminController : ControllerBase
|
||||
{
|
||||
private readonly MySqlConnection _connection;
|
||||
|
||||
public AdminController(MySqlConnection connection)
|
||||
{
|
||||
_connection = connection;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> QueryConversations([FromBody] ConversationQueryRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_connection.State != ConnectionState.Open)
|
||||
{
|
||||
await _connection.OpenAsync();
|
||||
}
|
||||
|
||||
List<ConversationQueryResponse> conversations = [];
|
||||
|
||||
string query = @"SELECT c.Id, c.Guid, c.UserKey, c.ConversationContent, c.SendMethod,
|
||||
c.UserLocation, c.Latitude, c.Longitude, c.RecordTime,
|
||||
c.RecordTimeUTCStamp, c.IsDeleted, c.CreateTime, c.MessageType, c.SpeakingTime,
|
||||
u.UserName, u.WeChatName, u.PhoneNumber, u.AvatarUrl, u.Department
|
||||
FROM xcx_conversation c
|
||||
LEFT JOIN xcx_users u ON c.UserKey = u.UserKey
|
||||
WHERE c.IsDeleted = 0";
|
||||
|
||||
var parameters = new List<MySqlParameter>();
|
||||
|
||||
if (!string.IsNullOrEmpty(request.UserKey))
|
||||
{
|
||||
query += " AND c.UserKey = @UserKey";
|
||||
parameters.Add(new MySqlParameter("@UserKey", request.UserKey));
|
||||
}
|
||||
|
||||
if (request.MessageType.HasValue)
|
||||
{
|
||||
query += " AND c.MessageType = @MessageType";
|
||||
parameters.Add(new MySqlParameter("@MessageType", request.MessageType.Value));
|
||||
}
|
||||
|
||||
if (request.StartTime.HasValue)
|
||||
{
|
||||
long startUtcStamp = new DateTimeOffset(request.StartTime.Value).ToUnixTimeMilliseconds();
|
||||
query += " AND c.RecordTimeUTCStamp >= @StartTime";
|
||||
parameters.Add(new MySqlParameter("@StartTime", startUtcStamp));
|
||||
}
|
||||
|
||||
if (request.EndTime.HasValue)
|
||||
{
|
||||
long endUtcStamp = new DateTimeOffset(request.EndTime.Value).ToUnixTimeMilliseconds();
|
||||
query += " AND c.RecordTimeUTCStamp <= @EndTime";
|
||||
parameters.Add(new MySqlParameter("@EndTime", endUtcStamp));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Department))
|
||||
{
|
||||
query += " AND u.Department = @Department";
|
||||
parameters.Add(new MySqlParameter("@Department", request.Department));
|
||||
}
|
||||
|
||||
query += " ORDER BY c.RecordTimeUTCStamp DESC";
|
||||
|
||||
int offset = (request.Page - 1) * request.PageSize;
|
||||
query += " LIMIT @Limit OFFSET @Offset";
|
||||
parameters.Add(new MySqlParameter("@Limit", request.PageSize));
|
||||
parameters.Add(new MySqlParameter("@Offset", offset));
|
||||
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
cmd.Parameters.AddRange(parameters.ToArray());
|
||||
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
conversations.Add(new ConversationQueryResponse
|
||||
{
|
||||
Id = reader.GetInt64(0),
|
||||
Guid = reader.IsDBNull(1) ? "" : reader.GetString(1),
|
||||
UserKey = reader.GetString(2),
|
||||
ConversationContent = reader.GetString(3),
|
||||
SendMethod = reader.GetString(4),
|
||||
UserLocation = reader.IsDBNull(5) ? "" : reader.GetString(5),
|
||||
Latitude = reader.IsDBNull(6) ? "" : reader.GetString(6),
|
||||
Longitude = reader.IsDBNull(7) ? "" : reader.GetString(7),
|
||||
RecordTime = reader.GetDateTime(8),
|
||||
RecordTimeUTCStamp = reader.GetInt64(9),
|
||||
IsDeleted = reader.GetBoolean(10),
|
||||
CreateTime = reader.GetDateTime(11),
|
||||
MessageType = reader.GetInt32(12),
|
||||
SpeakingTime = reader.IsDBNull(13) ? null : reader.GetInt32(13),
|
||||
UserName = reader.IsDBNull(14) ? "" : reader.GetString(14),
|
||||
WeChatName = reader.IsDBNull(15) ? "" : reader.GetString(15),
|
||||
PhoneNumber = reader.IsDBNull(16) ? "" : reader.GetString(16),
|
||||
AvatarUrl = reader.IsDBNull(17) ? "" : reader.GetString(17),
|
||||
Department = reader.IsDBNull(18) ? "" : reader.GetString(18)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new { success = true, data = conversations });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new { success = false, message = "查询失败", error = ex.Message });
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_connection.State == ConnectionState.Open)
|
||||
{
|
||||
await _connection.CloseAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> QueryUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_connection.State != ConnectionState.Open)
|
||||
{
|
||||
await _connection.OpenAsync();
|
||||
}
|
||||
|
||||
List<UserQueryResponse> users = [];
|
||||
|
||||
string query = @"SELECT Id, UserName, UserKey, WeChatName, PhoneNumber,
|
||||
FirstLoginTime, IsDisabled, CreateTime, UpdateTime, AvatarUrl, Department
|
||||
FROM xcx_users
|
||||
WHERE PhoneNumber IS NOT NULL
|
||||
AND PhoneNumber != ''
|
||||
AND UserName IS NOT NULL
|
||||
AND UserName != ''
|
||||
AND UserKey IS NOT NULL
|
||||
AND UserKey != ''
|
||||
AND IsDisabled = 0
|
||||
ORDER BY FirstLoginTime DESC";
|
||||
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
users.Add(new UserQueryResponse
|
||||
{
|
||||
Id = reader.GetInt64(0),
|
||||
UserName = reader.IsDBNull(1) ? "" : reader.GetString(1),
|
||||
UserKey = reader.GetString(2),
|
||||
WeChatName = reader.IsDBNull(3) ? "" : reader.GetString(3),
|
||||
PhoneNumber = reader.IsDBNull(4) ? "" : reader.GetString(4),
|
||||
FirstLoginTime = reader.GetDateTime(5),
|
||||
IsDisabled = reader.GetBoolean(6),
|
||||
CreateTime = reader.GetDateTime(7),
|
||||
UpdateTime = reader.GetDateTime(8),
|
||||
AvatarUrl = reader.IsDBNull(9) ? "" : reader.GetString(9),
|
||||
Department = reader.IsDBNull(10) ? "" : reader.GetString(10)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new { success = true, data = users });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new { success = false, message = "查询失败", error = ex.Message });
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_connection.State == ConnectionState.Open)
|
||||
{
|
||||
await _connection.CloseAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConversationQueryRequest
|
||||
{
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
public string UserKey { get; set; }
|
||||
public int? MessageType { get; set; }
|
||||
public string Department { get; set; }
|
||||
public int Page { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 20;
|
||||
}
|
||||
|
||||
public class ConversationQueryResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Guid { get; set; }
|
||||
public string UserKey { get; set; }
|
||||
public string ConversationContent { get; set; }
|
||||
public string SendMethod { get; set; }
|
||||
public string UserLocation { get; set; }
|
||||
public string Latitude { get; set; }
|
||||
public string Longitude { get; set; }
|
||||
public DateTime RecordTime { get; set; }
|
||||
public long RecordTimeUTCStamp { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public int MessageType { get; set; }
|
||||
public int? SpeakingTime { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string WeChatName { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public string AvatarUrl { get; set; }
|
||||
public string Department { get; set; }
|
||||
}
|
||||
|
||||
public class UserQueryResponse
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string UserKey { get; set; }
|
||||
public string WeChatName { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public DateTime FirstLoginTime { get; set; }
|
||||
public bool IsDisabled { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public DateTime UpdateTime { get; set; }
|
||||
public string AvatarUrl { get; set; }
|
||||
public string Department { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,17 @@ builder.Services.AddControllersWithViews();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>HttpClientFactory
|
||||
builder.Services.AddHttpClient();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(name: "KuaYu",
|
||||
policy =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
builder.Services.AddScoped<MySqlConnection>(sp => {
|
||||
var connectionString = builder.Configuration.GetConnectionString("MySQLConnection");
|
||||
@@ -68,7 +78,7 @@ if (!app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseCors("KuaYu");
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<_PublishTargetUrl>E:\Project_Class\WX_XCX\Wx_WxCheck_Prod\WxCheckMvc\bin\Release\net8.0\publish\</_PublishTargetUrl>
|
||||
<History>True|2025-12-12T03:09:28.8147447Z||;True|2025-12-11T17:04:53.2856075+08:00||;True|2025-12-11T17:04:22.0809574+08:00||;True|2025-12-05T18:56:51.7439135+08:00||;True|2025-12-05T17:44:11.4130698+08:00||;</History>
|
||||
<History>True|2025-12-24T12:05:02.2999541Z||;True|2025-12-24T16:33:44.2108439+08:00||;True|2025-12-24T15:32:13.8037439+08:00||;True|2025-12-12T11:09:28.8147447+08:00||;True|2025-12-11T17:04:53.2856075+08:00||;True|2025-12-11T17:04:22.0809574+08:00||;True|2025-12-05T18:56:51.7439135+08:00||;True|2025-12-05T17:44:11.4130698+08:00||;</History>
|
||||
<LastFailureDetails />
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 120002 (12.0.2-MariaDB)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 05/12/2025 18:09:30
|
||||
Date: 24/12/2025 10:33:17
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -43,7 +43,7 @@ CREATE TABLE `xcx_conversation` (
|
||||
INDEX `idx_recordtime`(`RecordTime` ASC) USING BTREE,
|
||||
INDEX `idx_messagetype`(`MessageType` ASC) USING BTREE,
|
||||
INDEX `idx_guid`(`Guid` ASC) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 434 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会话记录表' ROW_FORMAT = Dynamic;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 499 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '会话记录表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for xcx_log
|
||||
@@ -77,10 +77,11 @@ CREATE TABLE `xcx_users` (
|
||||
`CreateTime` datetime NULL DEFAULT current_timestamp() COMMENT '创建时间',
|
||||
`UpdateTime` datetime NULL DEFAULT current_timestamp() ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`AvatarUrl` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像地址',
|
||||
`Department` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户部门',
|
||||
PRIMARY KEY (`Id`) USING BTREE,
|
||||
UNIQUE INDEX `idx_userkey`(`UserKey` ASC) USING BTREE,
|
||||
INDEX `idx_disabled`(`IsDisabled` ASC) USING BTREE,
|
||||
INDEX `idx_logintime`(`FirstLoginTime` ASC) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 22 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '小程序用户表' ROW_FORMAT = Dynamic;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 42 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '小程序用户表' ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
Reference in New Issue
Block a user