|
|
@ -138,82 +138,6 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
|
|
|
|
CheckIsTimeOut(); |
|
|
|
|
|
|
|
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("任务分配成功!"); |
|
|
|
} |
|
|
|
|
|
|
@ -289,86 +213,74 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
return Error("任务不存在!"); |
|
|
|
} |
|
|
|
|
|
|
|
var users = _iuserBusiness.GetPriceTaskUserList().ToList(); |
|
|
|
|
|
|
|
Expression<Func<user, pricetasklog, PricetaskUser>> select = (a, b) => new PricetaskUser() |
|
|
|
var result = Db.RunTransaction(() => |
|
|
|
{ |
|
|
|
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); |
|
|
|
int row = Db.Update<teamitems>(c => c.Id == teamItem.Id, (item) => |
|
|
|
{ |
|
|
|
item.State = (int)TeamItemState.已发布比价; |
|
|
|
item.PriceTaskCreateDate = DateTime.Now; |
|
|
|
}); |
|
|
|
|
|
|
|
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); |
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("系统繁忙!"); |
|
|
|
|
|
|
|
//获取当日可分配的一个用户
|
|
|
|
var user = q.GroupBy(c => c.Uid).Where(c => c.Count() < c.FirstOrDefault()?.MaxTaskCount).Select(c => new { Id = c.Key, Count = c.Count() }).OrderBy(c => c.Count).FirstOrDefault(); |
|
|
|
}); |
|
|
|
|
|
|
|
if (user == null) |
|
|
|
if (result.Success) |
|
|
|
{ |
|
|
|
return Success("发布任务成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
DingHelper.DingApiHelper.Main.SendNotify("齐越慧眼比价系统任务量已达上限!"); |
|
|
|
return Error(result.ex.Message); |
|
|
|
} |
|
|
|
|
|
|
|
//钉钉推送
|
|
|
|
// return Error("当前任务量已超过任务池可用任务量!");
|
|
|
|
} |
|
|
|
public AjaxResult AcceptTask(string teamItemId) |
|
|
|
{ |
|
|
|
var teamItem = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == teamItemId); |
|
|
|
|
|
|
|
if (teamItem == null) |
|
|
|
{ |
|
|
|
return Error("任务不存在!"); |
|
|
|
} |
|
|
|
|
|
|
|
var result = Db.RunTransaction(() => |
|
|
|
{ |
|
|
|
int row = Db.Update<teamitems>(c => c.Id == teamItem.Id, (item) => |
|
|
|
var price = new pricetasklog() |
|
|
|
{ |
|
|
|
if (user != null) |
|
|
|
{ |
|
|
|
item.PriceTaskUserId = user.Id; |
|
|
|
} |
|
|
|
else { |
|
|
|
item.PriceTaskUserId = null; |
|
|
|
} |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Id = IdHelper.GetId(), |
|
|
|
CreatorId = _operator.UserId, |
|
|
|
Deleted = false, |
|
|
|
ItemId = teamItem.ItemId, |
|
|
|
UserId = _operator.UserId, |
|
|
|
State = PriceTaskState.待比价, |
|
|
|
TeamItemId = teamItem.Id |
|
|
|
}; |
|
|
|
|
|
|
|
int row = Db.Insert(price); |
|
|
|
|
|
|
|
item.State = (int)TeamItemState.已发布比价; |
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("任务已被接取!"); |
|
|
|
|
|
|
|
row = Db.Update<teamitems>(c => c.Id == teamItem.Id, (item) => |
|
|
|
{ |
|
|
|
item.PriceTaskUserId =_operator.UserId; |
|
|
|
}); |
|
|
|
|
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("系统繁忙!"); |
|
|
|
|
|
|
|
if (user != null) |
|
|
|
{ |
|
|
|
row = Db.Insert(new pricetasklog() |
|
|
|
{ |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Id = IdHelper.GetId(), |
|
|
|
CreatorId = _operator.UserId, |
|
|
|
Deleted = false, |
|
|
|
ItemId = teamItem.ItemId, |
|
|
|
UserId = user.Id, |
|
|
|
State = PriceTaskState.待比价, |
|
|
|
TeamItemId = teamItem.Id |
|
|
|
}); |
|
|
|
|
|
|
|
if (row <= 0) |
|
|
|
throw new Exception("系统任务繁忙!"); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (result.Success) |
|
|
|
{ |
|
|
|
return Success("发布任务成功!"); |
|
|
|
return Success("接取任务成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
return Error(result.ex.Message); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult SetState(string id, int state) |
|
|
|
{ |
|
|
|
|
|
|
|