优化:给注册用户新增用户名不为空的判断逻辑
This commit is contained in:
@@ -91,7 +91,7 @@ namespace WxCheckMvc.Controllers
|
||||
}
|
||||
|
||||
string updateSql = "UPDATE xcx_users SET AvatarUrl = @AvatarUrl, UpdateTime = NOW() WHERE UserKey = @UserKey";
|
||||
using (MySqlCommand cmd = new MySqlCommand(updateSql, _connection))
|
||||
using (MySqlCommand cmd = new(updateSql, _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@AvatarUrl", fullUrl);
|
||||
cmd.Parameters.AddWithValue("@UserKey", userKey);
|
||||
@@ -212,13 +212,13 @@ namespace WxCheckMvc.Controllers
|
||||
{
|
||||
var part = addressParts[i];
|
||||
// 如果部分包含"路"、"街"、"巷"等关键词,可能是街道信息
|
||||
if (part.Contains("路") || part.Contains("街") || part.Contains("巷") || part.Contains("道"))
|
||||
if (part.Contains('路') || part.Contains('街') || part.Contains('巷') || part.Contains('道'))
|
||||
{
|
||||
street = part;
|
||||
// 如果下一个部分存在且不是区县名称,可能是门牌号
|
||||
if (i + 1 < addressParts.Length &&
|
||||
!addressParts[i + 1].Contains("区") &&
|
||||
!addressParts[i + 1].Contains("县"))
|
||||
!addressParts[i + 1].Contains('区') &&
|
||||
!addressParts[i + 1].Contains('县'))
|
||||
{
|
||||
streetNumber = addressParts[i + 1];
|
||||
}
|
||||
@@ -299,7 +299,7 @@ namespace WxCheckMvc.Controllers
|
||||
string latitude = "";
|
||||
string longitude = "";
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand("SELECT Latitude, Longitude FROM xcx_conversation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
|
||||
using (MySqlCommand cmd = new("SELECT Latitude, Longitude FROM xcx_conversation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", request.Guid);
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace WxCheckMvc.Controllers
|
||||
var address = await ConvertCoordinatesToAddress(longitude, latitude);
|
||||
|
||||
// 更新数据库中的UserLocation字段
|
||||
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET UserLocation = @UserLocation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
|
||||
using (MySqlCommand cmd = new("UPDATE xcx_conversation SET UserLocation = @UserLocation WHERE Guid = @Guid AND IsDeleted = 0", _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", request.Guid);
|
||||
cmd.Parameters.AddWithValue("@UserLocation", address);
|
||||
@@ -334,7 +334,7 @@ namespace WxCheckMvc.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new { success = true, message = "地址更新成功", address = address });
|
||||
return Ok(new { success = true, message = "地址更新成功", address });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -383,7 +383,7 @@ namespace WxCheckMvc.Controllers
|
||||
// 生成GUID
|
||||
string conversationGuid = string.IsNullOrEmpty(request.Guid) ? Guid.NewGuid().ToString("N") : request.Guid;
|
||||
long conversationId = 0;
|
||||
using (MySqlCommand cmd = new MySqlCommand("INSERT INTO xcx_conversation (UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, Guid, SpeakingTime) VALUES (@UserKey, @ConversationContent, @SendMethod, @UserLocation, @Latitude, @Longitude, @RecordTime, @RecordTimeUTCStamp, @IsDeleted, @CreateTime, @MessageType, @Guid, @SpeakingTime); SELECT LAST_INSERT_ID();", _connection))
|
||||
using (MySqlCommand cmd = new("INSERT INTO xcx_conversation (UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, Guid, SpeakingTime) VALUES (@UserKey, @ConversationContent, @SendMethod, @UserLocation, @Latitude, @Longitude, @RecordTime, @RecordTimeUTCStamp, @IsDeleted, @CreateTime, @MessageType, @Guid, @SpeakingTime); SELECT LAST_INSERT_ID();", _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
cmd.Parameters.AddWithValue("@MessageType", request.MessageType);
|
||||
@@ -414,7 +414,7 @@ namespace WxCheckMvc.Controllers
|
||||
LEFT JOIN xcx_users AS users ON convs.UserKey = users.UserKey
|
||||
WHERE convs.Guid = @Guid";
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", conversationGuid);
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
@@ -495,7 +495,7 @@ namespace WxCheckMvc.Controllers
|
||||
await _connection.OpenAsync();
|
||||
}
|
||||
|
||||
List<ConversationResponse> conversations = new List<ConversationResponse>();
|
||||
List<ConversationResponse> conversations = [];
|
||||
|
||||
// 构建查询SQL,根据MessageType参数决定是否添加过滤条件
|
||||
string query = "SELECT Id, Guid, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, SpeakingTime FROM xcx_conversation WHERE UserKey = @UserKey AND IsDeleted = 0";
|
||||
@@ -505,7 +505,7 @@ namespace WxCheckMvc.Controllers
|
||||
}
|
||||
query += " ORDER BY RecordTimeUTCStamp DESC";
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
|
||||
@@ -561,13 +561,13 @@ namespace WxCheckMvc.Controllers
|
||||
}
|
||||
|
||||
DateTime nowtime = DateTime.Now;
|
||||
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET ConversationContent = @ConversationContent, SendMethod = @SendMethod, UserLocation = @UserLocation, MessageType = @MessageType, RecordTime = @RecordTime WHERE Guid = @Guid AND UserKey = @UserKey", _connection))
|
||||
using (MySqlCommand cmd = new("UPDATE xcx_conversation SET ConversationContent = @ConversationContent, SendMethod = @SendMethod, UserLocation = @UserLocation, MessageType = @MessageType, RecordTime = @RecordTime WHERE Guid = @Guid AND UserKey = @UserKey", _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", request.Guid);
|
||||
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
cmd.Parameters.AddWithValue("@ConversationContent", request.ConversationContent);
|
||||
cmd.Parameters.AddWithValue("@SendMethod", request.SendMethod);
|
||||
cmd.Parameters.AddWithValue("@UserLocation", request.UserLocation ?? "");
|
||||
cmd.Parameters.AddWithValue("@UserLocation", "");//request.UserLocation ?? "");
|
||||
cmd.Parameters.AddWithValue("@MessageType", request.MessageType);
|
||||
cmd.Parameters.AddWithValue("@RecordTime", nowtime);
|
||||
|
||||
@@ -605,7 +605,7 @@ namespace WxCheckMvc.Controllers
|
||||
await _connection.OpenAsync();
|
||||
}
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand("UPDATE xcx_conversation SET IsDeleted = 1 WHERE Guid = @Guid AND UserKey = @UserKey AND IsDeleted = 0", _connection))
|
||||
using (MySqlCommand cmd = new("UPDATE xcx_conversation SET IsDeleted = 1 WHERE Guid = @Guid AND UserKey = @UserKey AND IsDeleted = 0", _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", request.Guid);
|
||||
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
@@ -649,7 +649,7 @@ namespace WxCheckMvc.Controllers
|
||||
FROM xcx_conversation
|
||||
WHERE Guid = @Guid";
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Guid", request.Guid);
|
||||
|
||||
@@ -714,7 +714,7 @@ namespace WxCheckMvc.Controllers
|
||||
|
||||
int offset = (request.Page - 1) * request.PageSize;
|
||||
|
||||
List<ConversationResponse> conversations = new List<ConversationResponse>();
|
||||
List<ConversationResponse> conversations = [];
|
||||
|
||||
// 构建分页查询SQL,根据MessageType参数决定是否添加过滤条件
|
||||
string query = @"SELECT Id, Guid, UserKey, ConversationContent, SendMethod, UserLocation, Latitude, Longitude, RecordTime, RecordTimeUTCStamp, IsDeleted, CreateTime, MessageType, SpeakingTime
|
||||
@@ -726,7 +726,7 @@ namespace WxCheckMvc.Controllers
|
||||
}
|
||||
query += " ORDER BY RecordTimeUTCStamp DESC LIMIT @Offset, @Limit";
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand(query, _connection))
|
||||
using (MySqlCommand cmd = new(query, _connection))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
if (request.MessageType == 1)
|
||||
@@ -769,7 +769,7 @@ namespace WxCheckMvc.Controllers
|
||||
countQuery += " AND MessageType = @MessageType";
|
||||
}
|
||||
|
||||
using (MySqlCommand countCmd = new MySqlCommand(countQuery, _connection))
|
||||
using (MySqlCommand countCmd = new(countQuery, _connection))
|
||||
{
|
||||
countCmd.Parameters.AddWithValue("@UserKey", request.UserKey);
|
||||
if (request.MessageType == 1)
|
||||
|
||||
Reference in New Issue
Block a user