Browse Source

上架失败恢复完整标题

qianyi
shanji 2 years ago
parent
commit
3a7bfafc7e
  1. 83
      BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs
  2. 4
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs

83
BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs

@ -446,7 +446,9 @@ namespace BBWY.Server.Business
/// 开始任务 /// 开始任务
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
public void StartPromotionTask(StartPromotionTaskRequest request) /// <param name="shop"></param>
/// <exception cref="BusinessException"></exception>
public void StartPromotionTask(StartPromotionTaskRequest request, ShopResponse shop = null)
{ {
var dbPromotionTask = fsql.Select<PromotionTask>(request.Id).ToOne(); var dbPromotionTask = fsql.Select<PromotionTask>(request.Id).ToOne();
@ -454,7 +456,10 @@ namespace BBWY.Server.Business
throw new BusinessException("任务不存在"); throw new BusinessException("任务不存在");
if (dbPromotionTask.Status != Enums.PromitionTaskStatus.) if (dbPromotionTask.Status != Enums.PromitionTaskStatus.)
throw new BusinessException("只能在任务处于等待状态时才能开始"); throw new BusinessException("只能在任务处于等待状态时才能开始");
if (shop == null)
shop = venderBusiness.GetShopList(dbPromotionTask.ShopId, Enums.Platform.)?.FirstOrDefault();
if (shop == null)
throw new BusinessException("未查询到店铺");
IList<GiftTemplateSkuRequest> giftTemplateSkuList = null; //赠品模板sku IList<GiftTemplateSkuRequest> giftTemplateSkuList = null; //赠品模板sku
var motherTemplateSku = string.Empty; //奶妈模板的sku var motherTemplateSku = string.Empty; //奶妈模板的sku
@ -469,7 +474,9 @@ namespace BBWY.Server.Business
Title = gs.Title Title = gs.Title
}); });
if (giftTemplateSkuList == null || giftTemplateSkuList.Count() == 0) if (giftTemplateSkuList == null || giftTemplateSkuList.Count() == 0)
{
throw new BusinessException("赠品模板不存在"); throw new BusinessException("赠品模板不存在");
}
} }
var runingTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == dbPromotionTask.ShopId && pt.Status == Enums.PromitionTaskStatus.).ToList(); var runingTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == dbPromotionTask.ShopId && pt.Status == Enums.PromitionTaskStatus.).ToList();
@ -522,7 +529,6 @@ namespace BBWY.Server.Business
startResponse.DeleteGiftSkuList.Count() != 0) startResponse.DeleteGiftSkuList.Count() != 0)
dbPromotionTask.GiftTemplatePutNewSku = string.Join(",", startResponse.DeleteGiftSkuList); dbPromotionTask.GiftTemplatePutNewSku = string.Join(",", startResponse.DeleteGiftSkuList);
fsql.Update<PromotionTask>(request.Id).Set(pt => pt.PromotionId, startResponse.JDPromotionId) fsql.Update<PromotionTask>(request.Id).Set(pt => pt.PromotionId, startResponse.JDPromotionId)
.SetIf(!string.IsNullOrEmpty(dbPromotionTask.GiftTemplatePutNewSku), pt => pt.GiftTemplatePutNewSku, dbPromotionTask.GiftTemplatePutNewSku) .SetIf(!string.IsNullOrEmpty(dbPromotionTask.GiftTemplatePutNewSku), pt => pt.GiftTemplatePutNewSku, dbPromotionTask.GiftTemplatePutNewSku)
.Set(pt => pt.StartTime, DateTime.Now) .Set(pt => pt.StartTime, DateTime.Now)
@ -531,10 +537,10 @@ namespace BBWY.Server.Business
.ExecuteAffrows(); .ExecuteAffrows();
//开启延迟任务 //开启延迟任务
Task.Factory.StartNew(() => StartPromotionDelayTask(request, startResponse, dbPromotionTask), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler); Task.Factory.StartNew(() => StartPromotionDelayTask(request, startResponse, dbPromotionTask, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler);
} }
private void StartPromotionDelayTask(StartPromotionTaskRequest request, StartPromotionTaskResponse startResponse, PromotionTask promotionTask) private void StartPromotionDelayTask(StartPromotionTaskRequest request, StartPromotionTaskResponse startResponse, PromotionTask promotionTask, ShopResponse shop)
{ {
var host = GetPlatformRelayAPIHost(Enums.Platform.); var host = GetPlatformRelayAPIHost(Enums.Platform.);
@ -557,6 +563,7 @@ namespace BBWY.Server.Business
fsql.Update<PromotionTask>(id).Set(pt => pt.Status, Enums.PromitionTaskStatus.) fsql.Update<PromotionTask>(id).Set(pt => pt.Status, Enums.PromitionTaskStatus.)
.Set(pt => pt.ErrorMsg, errorMsg) .Set(pt => pt.ErrorMsg, errorMsg)
.ExecuteAffrows(); .ExecuteAffrows();
Error(shop, $"评价助手-{shop.ShopName}", $"开始任务延迟任务-任务Id {request.Id}", new Exception(errorMsg));
}); });
if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK) if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK)
{ {
@ -767,7 +774,7 @@ namespace BBWY.Server.Business
IList<OrderSku> orderSkuList, IList<OrderSku> orderSkuList,
IList<PromotionTaskSkuRecord> promotionTaskSkuRecordList) IList<PromotionTaskSkuRecord> promotionTaskSkuRecordList)
{ {
var loggerName = $"评价助手任务监控-{shop.ShopName}"; var loggerName = $"评价助手-{shop.ShopName}";
List<IUpdate<PromotionTask>> updatePromotionTaskList = new List<IUpdate<PromotionTask>>(); List<IUpdate<PromotionTask>> updatePromotionTaskList = new List<IUpdate<PromotionTask>>();
List<PromotionTaskSkuRecord> insertPromotionTaskSkuRecordList = new List<PromotionTaskSkuRecord>(); List<PromotionTaskSkuRecord> insertPromotionTaskSkuRecordList = new List<PromotionTaskSkuRecord>();
IList<long> jobDoneTaskIdList = new List<long>(); IList<long> jobDoneTaskIdList = new List<long>();
@ -789,7 +796,7 @@ namespace BBWY.Server.Business
}); });
if (productResponseSkuList == null || productResponseSkuList.Count() == 0) if (productResponseSkuList == null || productResponseSkuList.Count() == 0)
{ {
LogMonitorError(shop, loggerName, $"{promotionTask.Id}-监控任务-查询主商品sku", "未查询到主商品sku信息"); Error(shop, loggerName, $"监控任务-查询主商品sku-任务Id {promotionTask.Id}", new Exception("未查询到主商品sku信息"));
continue; continue;
} }
productSkuList.AddRange(productResponseSkuList.Select(p => p.Id)); productSkuList.AddRange(productResponseSkuList.Select(p => p.Id));
@ -861,18 +868,14 @@ namespace BBWY.Server.Business
if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) if (httpResult.StatusCode != System.Net.HttpStatusCode.OK)
{ {
LogMonitorError(shop, loggerName, $"{promotionTask.Id}-监控任务-暂停京东活动", httpResult.Content); Error(shop, loggerName, $"监控任务-暂停京东活动-任务Id {promotionTask.Id}", new Exception(httpResult.Content));
} }
else else
{ {
var response = JsonConvert.DeserializeObject<ApiResponse>(httpResult.Content); var response = JsonConvert.DeserializeObject<ApiResponse>(httpResult.Content);
if (!response.Success) if (!response.Success)
{ {
LogMonitorError(shop, loggerName, $"{promotionTask.Id}-监控任务-暂停京东活动", response.Msg); Error(shop, loggerName, $"监控任务-暂停京东活动-任务Id {promotionTask.Id}", new Exception(response.Msg));
}
else
{
} }
} }
} }
@ -894,32 +897,58 @@ namespace BBWY.Server.Business
}); });
#region 开始后续任务 #region 开始后续任务
//下一轮开始任务
var nextPromotionTaskList = new List<long>();
var noPrePromotionTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == shopId &&
pt.Status == Enums.PromitionTaskStatus. &&
pt.PreTaskId == -1).ToList(pt => pt.Id);
if (noPrePromotionTaskList.Count() > 0)
nextPromotionTaskList.AddRange(noPrePromotionTaskList);
if (jobDoneTaskIdList.Count() > 0) if (jobDoneTaskIdList.Count() > 0)
{ {
//var nextPromotionTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == shopId && var childTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == shopId &&
// pt.Status == Enums.PromitionTaskStatus.等待 && pt.Status == Enums.PromitionTaskStatus. &&
// jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(); jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(pt => pt.Id);
if (childTaskList.Count() > 0)
//if (nextPromotionTaskList.Count() > 0) nextPromotionTaskList.AddRange(childTaskList);
//{ }
// foreach (var task in nextPromotionTaskList)
// {
// } if (nextPromotionTaskList.Count() > 0)
//} {
foreach (var taskId in nextPromotionTaskList)
{
Task.Factory.StartNew(() => AutoStart(taskId, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler);
}
} }
#endregion #endregion
} }
private void AutoStart(long taskId, string appKey, string appSecret, string appToken) private void AutoStart(long taskId, ShopResponse shop)
{ {
var loggerName = $"评价助手-{shop.ShopName}";
try
{
StartPromotionTask(new StartPromotionTaskRequest()
{
Id = taskId,
AppKey = shop.AppKey2,
AppSecret = shop.AppSecret2,
AppToken = shop.AppToken2,
Platform = Enums.Platform.
}, shop);
}
catch (Exception ex)
{
Error(shop, loggerName, $"AutoStart 任务Id {taskId}", ex);
}
} }
private void LogMonitorError(ShopResponse shop, string loggerName, string step, string error) private void Error(ShopResponse shop, string loggerName, string message, Exception ex)
{ {
nLogManager.GetLogger(loggerName).Error($"{step},{error}"); nLogManager.GetLogger(loggerName).Error(ex, message);
//send dingding //send dingding

4
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -1018,11 +1018,13 @@ namespace BBWY.Server.Business
res.Json = JObject.Parse(res.Body); res.Json = JObject.Parse(res.Body);
if (res.IsError) if (res.IsError)
{ {
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, null, request.MainProductSpu, request.FullTitle, brandName, false);
throw new BusinessException($"上架sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); throw new BusinessException($"上架sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
/*{"error_response":{"code":"501","en_desc":"com.jd.bk.saf.exception.SafJosException:京东价超出该类目允许范围:12.15-39437元!#821c1c3b382f476abeb21f1f515274c7(Solution reference: https://jos.jd.com/commondoc?listId=171)","zh_desc":"调用参数错误(解决方案参考: https://jos.jd.com/commondoc?listId=171)"}}*/ /*{"error_response":{"code":"501","en_desc":"com.jd.bk.saf.exception.SafJosException:京东价超出该类目允许范围:12.15-39437元!#821c1c3b382f476abeb21f1f515274c7(Solution reference: https://jos.jd.com/commondoc?listId=171)","zh_desc":"调用参数错误(解决方案参考: https://jos.jd.com/commondoc?listId=171)"}}*/
} }
var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList().Select(x => x.Value<string>("skuId")).ToList(); var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList().Select(x => x.Value<string>("skuId")).ToList();
giftSkuIdList.AddRange(newSkuList); giftSkuIdList.AddRange(newSkuList);
} }

Loading…
Cancel
Save