|
|
@ -120,6 +120,89 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
return Success(new { MaxCount = user.MaxPriceTaskCount, Count = user.MaxPriceTaskCount - nowCount }); |
|
|
|
} |
|
|
|
|
|
|
|
public AjaxResult DayTaskSet() |
|
|
|
{ |
|
|
|
var users = _iuserBusiness.GetPriceTaskUserList().ToList(); |
|
|
|
|
|
|
|
Expression<Func<user, pricetasklog, PricetaskUser>> select = (a, b) => new PricetaskUser() |
|
|
|
{ |
|
|
|
UserName = a.UserName, |
|
|
|
MaxTaskCount = a.MaxPriceTaskCount, |
|
|
|
Uid = a.Id |
|
|
|
}; |
|
|
|
|
|
|
|
select = select.BuildExtendSelectExpre(); |
|
|
|
|
|
|
|
var q_User = Db.GetIQueryable<pricetasklog>().Where(c => c.CreateTime.Date == DateTime.Now.Date || c.CreateTime == DateTime.MinValue); |
|
|
|
|
|
|
|
var q = from a in users |
|
|
|
join b in q_User on a.Id equals b.UserId into ab |
|
|
|
from b in ab.DefaultIfEmpty() |
|
|
|
select @select.Invoke(a, b); |
|
|
|
|
|
|
|
|
|
|
|
var userList = q.GroupBy(c => c.Uid).Where(c => c.Count() < c.FirstOrDefault()?.MaxTaskCount).Select(c => new PriceUserCount(c.Key, c.Count(), c.Max(c => c.MaxTaskCount) ?? 30)).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var teamItemList = Db.GetIQueryable<teamitems>().Where(c => c.State == (int)TeamItemState.已发布比价 && string.IsNullOrEmpty(c.PriceTaskUserId)).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Db.RunTransaction(() => |
|
|
|
{ |
|
|
|
|
|
|
|
List<pricetasklog> pricetasklogs = new List<pricetasklog>(); |
|
|
|
|
|
|
|
teamItemList.ForEach(teamItem => |
|
|
|
{ |
|
|
|
|
|
|
|
var user = userList.Where(c => c.Count < c.MaxCount).OrderBy(c => c.Count).FirstOrDefault(); |
|
|
|
|
|
|
|
if (user == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
teamItem.PriceTaskUserId = user.UserId; |
|
|
|
|
|
|
|
user.Count += 1; |
|
|
|
|
|
|
|
|
|
|
|
pricetasklogs.Add(new pricetasklog() |
|
|
|
{ |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Id = IdHelper.GetId(), |
|
|
|
CreatorId = _operator.UserId, |
|
|
|
Deleted = false, |
|
|
|
ItemId = teamItem.ItemId, |
|
|
|
UserId = user.UserId, |
|
|
|
State = PriceTaskState.待比价, |
|
|
|
TeamItemId = teamItem.Id |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
int row = Db.Insert(pricetasklogs); |
|
|
|
if (row <= 0) |
|
|
|
{ |
|
|
|
throw new Exception("执行定时任务分配错误!"); |
|
|
|
} |
|
|
|
row = Db.Update(teamItemList, new List<string>() { "PriceTaskUserId" }); |
|
|
|
if (row <= 0) |
|
|
|
{ |
|
|
|
throw new Exception("执行定时任务分配更新任务信息错误!"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
DingHelper.DingApiHelper.Main.SendNotify("齐越慧眼比价系统任务分配异常!"); |
|
|
|
} |
|
|
|
|
|
|
|
return Success("任务分配成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
public AjaxResult CanelTask(string teamItemId) |
|
|
|
{ |
|
|
|
var teamItem = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == teamItemId && c.UserId == _operator.UserId); |
|
|
@ -199,21 +282,30 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
DingHelper.DingApiHelper.Main.SendNotify("齐越慧眼比价系统任务量已达上限!"); |
|
|
|
|
|
|
|
//钉钉推送
|
|
|
|
return Error("当前任务量已超过任务池可用任务量!"); |
|
|
|
// return Error("当前任务量已超过任务池可用任务量!");
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var result = Db.RunTransaction(() => |
|
|
|
{ |
|
|
|
int row = Db.Update<teamitems>(c => c.Id == teamItem.Id, (item) => |
|
|
|
{ |
|
|
|
if (user != null) |
|
|
|
{ |
|
|
|
item.PriceTaskUserId = user.Id; |
|
|
|
} |
|
|
|
else { |
|
|
|
item.PriceTaskUserId = null; |
|
|
|
} |
|
|
|
|
|
|
|
item.State = (int)TeamItemState.已发布比价; |
|
|
|
}); |
|
|
|
|
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("系统繁忙!"); |
|
|
|
|
|
|
|
if (user != null) |
|
|
|
{ |
|
|
|
row = Db.Insert(new pricetasklog() |
|
|
|
{ |
|
|
|
CreateTime = DateTime.Now, |
|
|
@ -228,6 +320,7 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
|
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("系统任务繁忙!"); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|