feat: 开放品牌文案读写,短名全称走对象存储配置
All checks were successful
Build and Deploy / deploy (push) Successful in 1m19s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m19s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
b8b18c4f59
commit
adb1dc322f
49
src/Oms.Application/Dtos/System/BrandCopyDtos.cs
Normal file
49
src/Oms.Application/Dtos/System/BrandCopyDtos.cs
Normal file
@ -0,0 +1,49 @@
|
||||
namespace Oms.Application.Dtos.System;
|
||||
|
||||
/// <summary>
|
||||
/// 品牌文案(存对象存储 JSON,非数据库;前端可本地缓存秒开)。
|
||||
/// </summary>
|
||||
public class BrandCopyOutput
|
||||
{
|
||||
/// <summary>顶栏 / 官网短名,如 BCD。</summary>
|
||||
public string NavName { get; set; } = "BCD";
|
||||
|
||||
/// <summary>顶栏 / 官网全称,如 Business & Customer & Delivery。</summary>
|
||||
public string NavFullName { get; set; } = "Business & Customer & Delivery";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎主标题(中文)。</summary>
|
||||
public string AiWelcomeTitleZh { get; set; } = "BCD · 一站式跨境物流顾问";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎短标题(中文,窄屏备用)。</summary>
|
||||
public string AiWelcomeTitleShortZh { get; set; } = "BCD · 跨境物流顾问";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎主标题(英文)。</summary>
|
||||
public string AiWelcomeTitleEn { get; set; } = "BCD · One-stop cross-border logistics advisor";
|
||||
|
||||
/// <summary>官网 AI 顾问欢迎短标题(英文)。</summary>
|
||||
public string AiWelcomeTitleShortEn { get; set; } = "BCD · Logistics advisor";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存品牌文案。
|
||||
/// </summary>
|
||||
public class BrandCopySaveInput
|
||||
{
|
||||
/// <summary>顶栏 / 官网短名。</summary>
|
||||
public string NavName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>顶栏 / 官网全称。</summary>
|
||||
public string NavFullName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎主标题(中文)。</summary>
|
||||
public string AiWelcomeTitleZh { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎短标题(中文)。</summary>
|
||||
public string AiWelcomeTitleShortZh { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎主标题(英文)。</summary>
|
||||
public string AiWelcomeTitleEn { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>AI 欢迎短标题(英文)。</summary>
|
||||
public string AiWelcomeTitleShortEn { get; set; } = string.Empty;
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using Fake.Application;
|
||||
using Fake.ObjectStorage;
|
||||
@ -28,6 +30,16 @@ public class SystemOtherConfigService : ApplicationService
|
||||
private const string BrandLogoChannelFavicon = "favicon";
|
||||
private const string BrandLogoChannelMascot = "mascot";
|
||||
|
||||
/// <summary>品牌文案固定对象键(JSON,不落业务库表)。</summary>
|
||||
private const string BrandCopyObjectKey = "uploads/brand-logo/brand-copy.json";
|
||||
|
||||
private static readonly JsonSerializerOptions BrandCopyJsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
private ISystemOtherConfigRepository SystemOtherConfigRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ISystemOtherConfigRepository>();
|
||||
|
||||
@ -292,6 +304,33 @@ public class SystemOtherConfigService : ApplicationService
|
||||
return await StreamManagedImageAsync(objectKey, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取品牌文案(顶栏/官网一套 + AI 欢迎语一套)。匿名可读;文件存对象存储,非数据库。
|
||||
/// </summary>
|
||||
[AllowAnonymous]
|
||||
[HttpGet("/system/other-config/brand-copy")]
|
||||
public async Task<BrandCopyOutput> GetBrandCopyAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ReadBrandCopyAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存品牌文案到对象存储 JSON(uploads/brand-logo/brand-copy.json)。
|
||||
/// </summary>
|
||||
/// <param name="input">入参:顶栏文案与 AI 欢迎语文案。</param>
|
||||
/// <param name="cancellationToken">取消令牌。</param>
|
||||
[HttpPost("/system/other-config/brand-copy/save")]
|
||||
public async Task<BrandCopyOutput> SaveBrandCopyAsync(
|
||||
BrandCopySaveInput input,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var output = NormalizeBrandCopy(input);
|
||||
var json = JsonSerializer.Serialize(output, BrandCopyJsonOptions);
|
||||
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
|
||||
await FileStorage.SaveObjectAsync(stream, BrandCopyObjectKey, "application/json", cancellationToken);
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传并替换品牌 Logo。Channel=portal|site|favicon|mascot;返回最新可访问 URL。
|
||||
/// </summary>
|
||||
@ -383,6 +422,92 @@ public class SystemOtherConfigService : ApplicationService
|
||||
MascotUrl = BuildSameOriginImageUrl("/system/other-config/brand-logo/file", BrandLogoChannelMascot, entity?.AppSecret)
|
||||
};
|
||||
|
||||
private static BrandCopyOutput DefaultBrandCopy() => new();
|
||||
|
||||
private static BrandCopyOutput NormalizeBrandCopy(BrandCopySaveInput? input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
return DefaultBrandCopy();
|
||||
}
|
||||
|
||||
return new BrandCopyOutput
|
||||
{
|
||||
NavName = RequireBrandText(input.NavName, "顶栏短名"),
|
||||
NavFullName = RequireBrandText(input.NavFullName, "顶栏全称"),
|
||||
AiWelcomeTitleZh = RequireBrandText(input.AiWelcomeTitleZh, "AI 欢迎标题(中文)"),
|
||||
AiWelcomeTitleShortZh = RequireBrandText(input.AiWelcomeTitleShortZh, "AI 欢迎短标题(中文)"),
|
||||
AiWelcomeTitleEn = RequireBrandText(input.AiWelcomeTitleEn, "AI 欢迎标题(英文)"),
|
||||
AiWelcomeTitleShortEn = RequireBrandText(input.AiWelcomeTitleShortEn, "AI 欢迎短标题(英文)")
|
||||
};
|
||||
}
|
||||
|
||||
private static string RequireBrandText(string? value, string label)
|
||||
{
|
||||
var text = (value ?? string.Empty).Trim();
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
throw new BusinessException($"{label}不能为空");
|
||||
}
|
||||
|
||||
if (text.Length > 200)
|
||||
{
|
||||
throw new BusinessException($"{label}不能超过 200 字");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private async Task<BrandCopyOutput> ReadBrandCopyAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var defaults = DefaultBrandCopy();
|
||||
try
|
||||
{
|
||||
if (!await FileStorage.ExistsAsync(BrandCopyObjectKey, cancellationToken))
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
await using var stream = await FileStorage.GetAsync(BrandCopyObjectKey, cancellationToken);
|
||||
using var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms, cancellationToken);
|
||||
if (ms.Length <= 0)
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
var parsed = JsonSerializer.Deserialize<BrandCopyOutput>(ms.ToArray(), BrandCopyJsonOptions);
|
||||
if (parsed == null)
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
|
||||
return new BrandCopyOutput
|
||||
{
|
||||
NavName = string.IsNullOrWhiteSpace(parsed.NavName) ? defaults.NavName : parsed.NavName.Trim(),
|
||||
NavFullName = string.IsNullOrWhiteSpace(parsed.NavFullName)
|
||||
? defaults.NavFullName
|
||||
: parsed.NavFullName.Trim(),
|
||||
AiWelcomeTitleZh = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleZh)
|
||||
? defaults.AiWelcomeTitleZh
|
||||
: parsed.AiWelcomeTitleZh.Trim(),
|
||||
AiWelcomeTitleShortZh = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleShortZh)
|
||||
? defaults.AiWelcomeTitleShortZh
|
||||
: parsed.AiWelcomeTitleShortZh.Trim(),
|
||||
AiWelcomeTitleEn = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleEn)
|
||||
? defaults.AiWelcomeTitleEn
|
||||
: parsed.AiWelcomeTitleEn.Trim(),
|
||||
AiWelcomeTitleShortEn = string.IsNullOrWhiteSpace(parsed.AiWelcomeTitleShortEn)
|
||||
? defaults.AiWelcomeTitleShortEn
|
||||
: parsed.AiWelcomeTitleShortEn.Trim()
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaults;
|
||||
}
|
||||
}
|
||||
|
||||
private PaymentReceiveQrOutput MapPaymentReceiveQrOutput(SystemOtherConfig? entity) =>
|
||||
new()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user