72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using AllBase;
|
|
using AllBase.Extension;
|
|
using NaiBa.Util.Extension;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.Config;
|
|
using AllBase.Model.DBModel;
|
|
using AllBase.Model.Param.WXParam;
|
|
using AllBase.Model.Result;
|
|
using AllBase.Model.Result.PDDResult;
|
|
using AllBase.Model.Result.WXResult;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Store.Product.Models.PublishParameters.Wx;
|
|
using Store.Product.Publish;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Work;
|
|
|
|
namespace Store.Product.Publish.Steps.Wx;
|
|
/// <summary>
|
|
/// 由 WXDBProdUploadForm.UploadProduct 的“生成AI短标题”区段迁移。
|
|
/// TODO(迁移): 原区段中的 TEMUKJD/WXUpload/窗体服务引用需按 Store.Product 运行时适配逐项核对。
|
|
/// </summary>
|
|
public sealed class GenerateAiShortTitleStep : WxProductPublishStepBase
|
|
{
|
|
public override string Description => "生成AI短标题";
|
|
|
|
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
|
{
|
|
if (context.Parameters.IsAiShortTitle || context.Parameters.IsAiImage)
|
|
{
|
|
if (context.Progress != null)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
context.Progress.Report("正在生成短标题");
|
|
}));
|
|
}
|
|
|
|
WXGetShortTitleParam titleParam = new WXGetShortTitleParam()
|
|
{
|
|
categories = new List<categorieParam>(),
|
|
headImgUrls = context.Parameters.ProductParameter.product.info.headImg,
|
|
productTitle = context.Parameters.ProductParameter.product.info.title,
|
|
};
|
|
foreach (var cate in context.Parameters.ProductParameter.product.info.category)
|
|
{
|
|
titleParam.categories.Add(new categorieParam() { catId = cate.catId, catName = cate.name });
|
|
}
|
|
var shortTitleRst = WXUpload.genProductShortTitle(context.Parameters.Shop, titleParam);
|
|
if (!shortTitleRst.Contains("\"code\":0") && !shortTitleRst.Contains("\"success\":true"))
|
|
{
|
|
var error = BaseRegex.GetStringJson(ref shortTitleRst, "msg");
|
|
if (string.IsNullOrEmpty(error))
|
|
error = shortTitleRst;
|
|
throw new Exception("短标题获取失败 " + error);
|
|
}
|
|
context.Parameters.ProductParameter.product.info.shortTitle = BaseRegex.GetStringJson(ref shortTitleRst, "shortTitle");
|
|
context.Parameters.ProductParameter.product.info.aiGenShortTitle = context.Parameters.ProductParameter.product.info.shortTitle;
|
|
context.Parameters.ProductParameter.product.info.title = context.Parameters.ProductParameter.product.info.shortTitle + context.Parameters.ProductParameter.product.info.title;
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|