云收藏 增加AI检测图片
This commit is contained in:
1 parent
b28940c02d
commit
b54a5f5310
36 files changed
+1978
-523
No files matched your search
@@ -0,0 +1,70 @@
|
||||
using AllBase;
|
||||
using AllBase.Helper;
|
||||
using CsharpHttpHelper;
|
||||
using NaiBa.Util.Helper;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.Store.Api;
|
||||
|
||||
public sealed class GoodsComplianceApi
|
||||
{
|
||||
private readonly ApiTransport transport;
|
||||
internal GoodsComplianceApi(ApiTransport transport) => this.transport = transport;
|
||||
|
||||
///// <summary>上报平台商品的安全检测记录。</summary>
|
||||
//public Task SaveProductSafety(SaveProductSafetyRequest request)
|
||||
//{
|
||||
// request.UserName = BaseClass.UserName;
|
||||
// return transport.SendAsync<object>("ProductInspection/SaveProductSafety", MethodType.Post,
|
||||
// request ?? throw new ArgumentNullException(nameof(request)));
|
||||
//}
|
||||
|
||||
/// <summary>按平台和商品 ID 批量查询安全记录。</summary>
|
||||
public Task<List<ProductSafetyDto>> QueryProductSafety(QueryProductSafetyRequest request)
|
||||
{
|
||||
request.UserName = BaseClass.UserName;
|
||||
return transport.GetRequiredAsync<List<ProductSafetyDto>>("ProductInspection/QueryProductSafety", MethodType.Post,
|
||||
request ?? throw new ArgumentNullException(nameof(request)));
|
||||
}
|
||||
|
||||
/// <summary>识别上传图片中的文字和品牌 Logo。</summary>
|
||||
public async Task<List<string>> RecognizeAsync(string urlMd5, byte[] jpeg)
|
||||
{
|
||||
int sleep = 0;
|
||||
if (EnvironmentHelper.IsProduction)
|
||||
{
|
||||
sleep = RandomHelper.GetRandom(600, 1200);
|
||||
}
|
||||
var minimumDuration = Task.Delay(TimeSpan.FromMilliseconds(sleep));
|
||||
var request = new { UserName = BaseClass.UserName, Md5 = urlMd5, Image = Convert.ToBase64String(jpeg) };
|
||||
var recognitionTask = transport.GetRequiredAsync<List<string>>("ProductInspection/InspectImage", MethodType.Post, request);
|
||||
await Task.WhenAll(minimumDuration, recognitionTask).ConfigureAwait(false);
|
||||
return await recognitionTask.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SaveProductSafetyRequest
|
||||
{
|
||||
[Required] public string UserName { get; set; } = "";
|
||||
[Required] public string ProductId { get; set; } = "";
|
||||
[Required] public bool? IsSafe { get; set; }
|
||||
}
|
||||
|
||||
public sealed class QueryProductSafetyRequest
|
||||
{
|
||||
[Required] public string UserName { get; set; } = "";
|
||||
[Required] public string PlatformId { get; set; } = "";
|
||||
[Required] public string[] ProductIds { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed record ProductSafetyDto(string ProductId, bool IsSafe)
|
||||
{
|
||||
[Required] public string UserName { get; set; } = "";
|
||||
public string ProductId { get; } = ProductId;
|
||||
public bool IsSafe { get; } = IsSafe;
|
||||
}
|
||||
Reference in new issue
Block a user