|
|
@ -28,10 +28,13 @@ namespace BBWY.Server.Business |
|
|
|
private List<Enums.OrderState> validOrderStateList; |
|
|
|
private List<Enums.PromitionTaskStatus> preTaskStateList; |
|
|
|
private ProductBusiness productBusiness; |
|
|
|
private FreeSqlMultiDBManager freeSqlMultiDBManager; |
|
|
|
|
|
|
|
private char[] spliter; |
|
|
|
|
|
|
|
public EvaluationAssistantBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, DingDingBusiness dingDingBusiness, NLogManager nLogManager, ProductBusiness productBusiness) : base(restApiService, options, yunDingBusiness) |
|
|
|
public EvaluationAssistantBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, DingDingBusiness dingDingBusiness, NLogManager nLogManager, ProductBusiness productBusiness, FreeSqlMultiDBManager freeSqlMultiDBManager) : base(restApiService, options, yunDingBusiness) |
|
|
|
{ |
|
|
|
|
|
|
|
this.fsql = fsql; |
|
|
|
this.idGenerator = idGenerator; |
|
|
|
this.taskSchedulerManager = taskSchedulerManager; |
|
|
@ -39,6 +42,7 @@ namespace BBWY.Server.Business |
|
|
|
this.dingDingBusiness = dingDingBusiness; |
|
|
|
this.nLogManager = nLogManager; |
|
|
|
this.productBusiness = productBusiness; |
|
|
|
this.freeSqlMultiDBManager = freeSqlMultiDBManager; |
|
|
|
validOrderStateList = new List<Enums.OrderState>() |
|
|
|
{ |
|
|
|
Enums.OrderState.待出库, |
|
|
@ -303,6 +307,9 @@ namespace BBWY.Server.Business |
|
|
|
if (pt == null) |
|
|
|
throw new BusinessException($"{request.TaskId}任务不存在"); |
|
|
|
|
|
|
|
if (pt.Status != Enums.PromitionTaskStatus.等待) |
|
|
|
throw new BusinessException("任务状态必须为等待"); |
|
|
|
|
|
|
|
if (request.PreTaskId != -1) |
|
|
|
{ |
|
|
|
var prpt = fsql.Select<PromotionTask>(request.PreTaskId).ToOne(); |
|
|
@ -312,9 +319,6 @@ namespace BBWY.Server.Business |
|
|
|
if (pt.Id == prpt.Id) |
|
|
|
throw new BusinessException("前置任务不能设置为自己"); |
|
|
|
|
|
|
|
if (pt.Status != Enums.PromitionTaskStatus.等待) |
|
|
|
throw new BusinessException("任务状态必须为等待"); |
|
|
|
|
|
|
|
if (prpt.Status != Enums.PromitionTaskStatus.等待 && prpt.Status != Enums.PromitionTaskStatus.进行中) |
|
|
|
throw new BusinessException("前置任务状态必须为等待或进行中"); |
|
|
|
|
|
|
@ -563,7 +567,7 @@ namespace BBWY.Server.Business |
|
|
|
fsql.Update<PromotionTask>(id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止) |
|
|
|
.Set(pt => pt.ErrorMsg, errorMsg) |
|
|
|
.ExecuteAffrows(); |
|
|
|
Error(shop, $"评价助手-{shop.ShopName}", $"开始任务延迟任务-任务Id {request.Id}", new Exception(errorMsg)); |
|
|
|
Error(shop, $"评价助手-{shop.ShopName}", $"开始任务-延迟任务-任务Id {request.Id}", new Exception(errorMsg)); |
|
|
|
}); |
|
|
|
if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK) |
|
|
|
{ |
|
|
@ -691,6 +695,15 @@ namespace BBWY.Server.Business |
|
|
|
throw new BusinessException(response.Msg); |
|
|
|
fsql.Update<PromotionTask>(request.Id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止).ExecuteAffrows(); |
|
|
|
} |
|
|
|
|
|
|
|
public void EditPJZSSettings(PJZSShopSettingRequest request) |
|
|
|
{ |
|
|
|
var shopId = request.ShopId.ToString(); |
|
|
|
freeSqlMultiDBManager.MDSfsql.Update<Model.Db.Mds.Shops>().Set(s => s.PJZSDingDingKey, request.PJZSDingDingKey) |
|
|
|
.Set(s => s.PJZSDingDingWebHook, request.PJZSDingDingWebHook) |
|
|
|
.Where(s => s.ShopId == shopId) |
|
|
|
.ExecuteAffrows(); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 自动任务
|
|
|
@ -700,6 +713,22 @@ namespace BBWY.Server.Business |
|
|
|
//查询店铺
|
|
|
|
var shopList = venderBusiness.GetShopList(shopId, Enums.Platform.京东); |
|
|
|
|
|
|
|
//开始下一轮开始任务
|
|
|
|
var nextPromotionTaskList = fsql.Select<PromotionTask>().WhereIf(shopId != null, pt => pt.ShopId == shopId) |
|
|
|
.Where(pt => pt.Status == Enums.PromitionTaskStatus.等待 && pt.PreTaskId == -1) |
|
|
|
.ToList(pt => new { Id = pt.Id, ShopId = pt.ShopId }); |
|
|
|
if (nextPromotionTaskList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var nextTask in nextPromotionTaskList) |
|
|
|
{ |
|
|
|
var shop = shopList.FirstOrDefault(s => s.ShopId == nextTask.ShopId.ToString()); |
|
|
|
if (shop != null) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AutoStart(nextTask.Id, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//查询正在进行的任务
|
|
|
|
var runningTaskList = fsql.Select<PromotionTask>() |
|
|
|
.WhereIf(shopId != null, pt => pt.ShopId == shopId) |
|
|
@ -898,30 +927,19 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
#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) |
|
|
|
{ |
|
|
|
var childTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == shopId && |
|
|
|
pt.Status == Enums.PromitionTaskStatus.等待 && |
|
|
|
jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(pt => pt.Id); |
|
|
|
pt.Status == Enums.PromitionTaskStatus.等待 && |
|
|
|
jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(pt => pt.Id); |
|
|
|
if (childTaskList.Count() > 0) |
|
|
|
nextPromotionTaskList.AddRange(childTaskList); |
|
|
|
} |
|
|
|
|
|
|
|
if (nextPromotionTaskList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var taskId in nextPromotionTaskList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AutoStart(taskId, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); |
|
|
|
foreach (var taskId in childTaskList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AutoStart(taskId, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
@ -945,13 +963,13 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Error(ShopResponse shop, string loggerName, string message, Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.GetLogger(loggerName).Error(ex, message); |
|
|
|
|
|
|
|
//send dingding
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) |
|
|
|
dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n{shop.ShopName}\n{message}\n{ex.Message}"); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|