|
@ -8,6 +8,7 @@ using Coldairarrow.Util; |
|
|
using EFCore.Sharding; |
|
|
using EFCore.Sharding; |
|
|
using LinqKit; |
|
|
using LinqKit; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
using Microsoft.Extensions.Caching.Distributed; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
@ -24,14 +25,16 @@ namespace Coldairarrow.Business.HuiYan |
|
|
IteamitemsBusiness _iteamitemsBusiness; |
|
|
IteamitemsBusiness _iteamitemsBusiness; |
|
|
readonly IOperator _operator; |
|
|
readonly IOperator _operator; |
|
|
readonly ILogger _logger; |
|
|
readonly ILogger _logger; |
|
|
|
|
|
readonly IDistributedCache _cache; |
|
|
public pricetasklogBusiness(IDbAccessor db, IuserBusiness iuserBusiness, IteamitemsBusiness iteamitemsBusiness, ILogger<pricetasklogBusiness> logger, |
|
|
public pricetasklogBusiness(IDbAccessor db, IuserBusiness iuserBusiness, IteamitemsBusiness iteamitemsBusiness, ILogger<pricetasklogBusiness> logger, |
|
|
IOperator @operator) |
|
|
IOperator @operator, IDistributedCache cache) |
|
|
: base(db) |
|
|
: base(db) |
|
|
{ |
|
|
{ |
|
|
_operator = @operator; |
|
|
_operator = @operator; |
|
|
_iuserBusiness = iuserBusiness; |
|
|
_iuserBusiness = iuserBusiness; |
|
|
_iteamitemsBusiness = iteamitemsBusiness; |
|
|
_iteamitemsBusiness = iteamitemsBusiness; |
|
|
_logger = logger; |
|
|
_logger = logger; |
|
|
|
|
|
_cache = cache; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#region 外部接口
|
|
|
#region 外部接口
|
|
@ -275,41 +278,64 @@ namespace Coldairarrow.Business.HuiYan |
|
|
|
|
|
|
|
|
bool CheckIsMaxTaskCount() |
|
|
bool CheckIsMaxTaskCount() |
|
|
{ |
|
|
{ |
|
|
Expression<Func<teamitems, items, pricetasklog, TeamitemDto>> select = (a, b, c) => new TeamitemDto |
|
|
|
|
|
{ |
|
|
|
|
|
GoodsId = b.GoodsId, |
|
|
var list = Db.GetListBySql<TaskCountDto>(@"SELECT
|
|
|
HasFilter = b.HasFilter, |
|
|
CAST( `p`.`State` AS signed ) AS State, |
|
|
Platform = b.Platform, |
|
|
COUNT(*) AS count |
|
|
GoodsUrl = b.GoodsUrl, |
|
|
FROM |
|
|
PriceTaskId = c.Id, |
|
|
`teamitems` AS `t` |
|
|
PriceTaskState = (int)c.State, |
|
|
LEFT JOIN `items` AS `i` ON `t`.`ItemId` = `i`.`Id` |
|
|
Extensions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TeamItemExtension>>(a.ExtensionJson) |
|
|
LEFT JOIN `pricetasklog` AS `p` ON `t`.`Id` = `p`.`TeamItemId` |
|
|
}; |
|
|
WHERE |
|
|
|
|
|
( `t`.`PriceTaskUserId` = @uid ) |
|
|
|
|
|
AND `p`.`State` IS NOT NULL |
|
|
|
|
|
GROUP BY |
|
|
|
|
|
State",("uid",_operator.UserId));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int? hasTaskCount = list.Select(c => new { Id = c.State, Count = c.Count }).Where(c => c.Id == 0).FirstOrDefault()?.Count; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select = select.BuildExtendSelectExpre(); |
|
|
return hasTaskCount > 10; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var q_titem = Db.GetIQueryable<teamitems>(); |
|
|
public AjaxResult AcceptTask(string teamItemId) |
|
|
var q = from a in q_titem.AsExpandable() |
|
|
{ |
|
|
join b in Db.GetIQueryable<items>() on a.ItemId equals b.Id into ab |
|
|
|
|
|
from ba in ab.DefaultIfEmpty() |
|
|
|
|
|
join c in Db.GetIQueryable<pricetasklog>() on a.Id equals c.TeamItemId into ac |
|
|
|
|
|
from bb in ac.DefaultIfEmpty() |
|
|
|
|
|
select @select.Invoke(a, ba, bb); |
|
|
|
|
|
|
|
|
|
|
|
//查询对应状态
|
|
|
string cacheKey = $"acceptTask:{_operator.UserId}"; |
|
|
var where = LinqHelper.True<TeamitemDto>().And(c => c.PriceTaskUserId == _operator.UserId); |
|
|
string keyTime = _cache.GetString(cacheKey); |
|
|
|
|
|
|
|
|
where = where.And(c => c.PriceTaskState != null); |
|
|
AcceptTime lastAccept = null; |
|
|
|
|
|
|
|
|
var list = q.Where(where).Select(c => c.PriceTaskState).ToList(); |
|
|
//判断是否没有请求过
|
|
|
|
|
|
if (!string.IsNullOrEmpty(keyTime)) |
|
|
|
|
|
{ |
|
|
|
|
|
var time=Newtonsoft.Json.JsonConvert.DeserializeObject<AcceptTime>(keyTime); |
|
|
|
|
|
|
|
|
int? hasTaskCount = list.GroupBy(c => c).Select(c => new { Id = c.Key, Count = c.Count() }).Where(c => c.Id == 0).FirstOrDefault()?.Count; |
|
|
//如果是新一轮请求
|
|
|
|
|
|
if (time.Date < DateTime.Now) |
|
|
|
|
|
{ |
|
|
|
|
|
time.Date= DateTime.Now.AddMinutes(1); |
|
|
|
|
|
time.Count = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return hasTaskCount > 10; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public AjaxResult AcceptTask(string teamItemId) |
|
|
if (time.Count >= 3) |
|
|
{ |
|
|
{ |
|
|
|
|
|
return Error("请求过于频繁!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
time.Count = time.Count + 1; |
|
|
|
|
|
lastAccept = time; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
lastAccept = new AcceptTime() { Date = DateTime.Now.AddMinutes(1), Count = 1 }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_cache.SetString(cacheKey, Newtonsoft.Json.JsonConvert.SerializeObject(lastAccept)); |
|
|
|
|
|
|
|
|
var teamItem = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == teamItemId); |
|
|
var teamItem = Db.GetIQueryable<teamitems>().FirstOrDefault(c => c.Id == teamItemId); |
|
|
|
|
|
|
|
|
if (teamItem == null) |
|
|
if (teamItem == null) |
|
@ -317,11 +343,13 @@ namespace Coldairarrow.Business.HuiYan |
|
|
return Error("任务不存在!"); |
|
|
return Error("任务不存在!"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CheckIsMaxTaskCount()) |
|
|
if (CheckIsMaxTaskCount()) |
|
|
{ |
|
|
{ |
|
|
return Error("任务接取已达上限!"); |
|
|
return Error("任务接取已达上限!"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var result = Db.RunTransaction(() => |
|
|
var result = Db.RunTransaction(() => |
|
|
{ |
|
|
{ |
|
|
string orderId = DateTime.Now.ToString("yyyyMMddHHmmssff"); |
|
|
string orderId = DateTime.Now.ToString("yyyyMMddHHmmssff"); |
|
|