新增 user.WecomKfUrl 存取与迁移脚本,顾问接口同步返回该字段。 Co-authored-by: Cursor <cursoragent@cursor.com>
92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using Fake.DependencyInjection;
|
|
using Fake.Rbac.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Oms.Application.Dtos.Customers;
|
|
|
|
namespace Oms.Application.Rbac;
|
|
|
|
public class CustomerServiceAdvisorResolver(FakeRbacDbContext dbContext) : IScopedDependency
|
|
{
|
|
public async Task<CustomerServiceAdvisorOutput> ResolveAsync(
|
|
string? customerServiceKey,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var key = customerServiceKey?.Trim();
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
{
|
|
return new CustomerServiceAdvisorOutput();
|
|
}
|
|
|
|
var row = await FindByUserIdAsync(key, cancellationToken)
|
|
?? await FindByNameOrAccountAsync(key, cancellationToken);
|
|
|
|
if (row == null)
|
|
{
|
|
return new CustomerServiceAdvisorOutput { Name = key };
|
|
}
|
|
|
|
return new CustomerServiceAdvisorOutput
|
|
{
|
|
Name = row.Name,
|
|
WechatId = row.WechatId,
|
|
WechatQrCode = row.WechatQrCode,
|
|
WecomKfUrl = row.WecomKfUrl,
|
|
};
|
|
}
|
|
|
|
private async Task<AdvisorRow?> FindByUserIdAsync(string key, CancellationToken cancellationToken)
|
|
{
|
|
if (!int.TryParse(key, out var userId) || userId <= 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
const string sql = """
|
|
SELECT
|
|
u.`Name` AS `Name`,
|
|
u.`WechatId` AS `WechatId`,
|
|
u.`WechatQrCode` AS `WechatQrCode`,
|
|
u.`WecomKfUrl` AS `WecomKfUrl`
|
|
FROM `user` u
|
|
WHERE u.`IsDeleted` = 0
|
|
AND u.`userid` = {0}
|
|
LIMIT 1
|
|
""";
|
|
|
|
return await dbContext.Database
|
|
.SqlQueryRaw<AdvisorRow>(sql, userId)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
|
|
private async Task<AdvisorRow?> FindByNameOrAccountAsync(string key, CancellationToken cancellationToken)
|
|
{
|
|
const string sql = """
|
|
SELECT
|
|
u.`Name` AS `Name`,
|
|
u.`WechatId` AS `WechatId`,
|
|
u.`WechatQrCode` AS `WechatQrCode`,
|
|
u.`WecomKfUrl` AS `WecomKfUrl`
|
|
FROM `user` u
|
|
WHERE u.`IsDeleted` = 0
|
|
AND (u.`Name` = {0} OR u.`Account` = {0})
|
|
ORDER BY u.`CreateTime` ASC
|
|
LIMIT 1
|
|
""";
|
|
|
|
return await dbContext.Database
|
|
.SqlQueryRaw<AdvisorRow>(sql, key)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
}
|
|
|
|
private sealed class AdvisorRow
|
|
{
|
|
public string? Name { get; set; }
|
|
|
|
public string? WechatId { get; set; }
|
|
|
|
public string? WechatQrCode { get; set; }
|
|
|
|
public string? WecomKfUrl { get; set; }
|
|
}
|
|
}
|