jianghaiqing 3 months ago
commit cb1a4f6040

@ -140,6 +140,21 @@ namespace DS.Module.Core.Condition
return thisScopeResult == true;
}
/// <summary>
/// 获取指定条件的条件数量
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public static int GetConditionCount(ConditionContent condition)
{
int n = condition.Conditions?.Count ?? 0;
if (condition.Groups != null && condition.Groups.Count > 0)
{
n += condition.Groups.Sum(x => GetConditionCount(x));
}
return n;
}
/// <summary>
/// 深度获取对象属性值
/// </summary>

@ -46,8 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>

@ -53,8 +53,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>

@ -47,7 +47,10 @@ namespace DS.WMS.Core.Map.Dtos
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>

@ -54,6 +54,10 @@ namespace DS.WMS.Core.Map.Dtos
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -46,7 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>

@ -49,7 +49,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>

@ -46,7 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -47,13 +47,13 @@ namespace DS.WMS.Core.Map.Dtos
/// </summary>
public string PackageName { get; set; }
/// <summary>
/// 船公司名称
/// 船司Id
/// </summary>
public string CarrierName { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司Id
/// 船司名称
/// </summary>
public long CarrierId { get; set; }
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -46,7 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -53,7 +53,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -46,7 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -53,7 +53,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -46,7 +46,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -55,7 +55,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用

@ -34,7 +34,11 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司Id
/// </summary>
public long? CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
public string Carrier { get; set; }
/// <summary>
/// 船司代码
/// </summary>

@ -45,7 +45,7 @@ namespace DS.WMS.Core.Map.Dtos
/// <summary>
/// 船司名称
/// </summary>
public string CarrierName { get; set; }
public string Carrier { get; set; }
/// <summary>
/// 港口Id
/// </summary>

@ -46,7 +46,13 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true,DefaultValue ="0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用

@ -46,8 +46,12 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true,DefaultValue ="0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -46,7 +46,12 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -47,7 +47,11 @@ namespace DS.WMS.Core.Map.Entity
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")]
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -46,8 +46,12 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -46,8 +46,12 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -48,8 +48,12 @@ namespace DS.WMS.Core.Map.Entity
/// 船司Id
/// </summary>
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true,DefaultValue ="0")]
public long CarrierId { get; set; }
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 状态 0启用 1禁用
/// </summary>

@ -39,6 +39,11 @@ namespace DS.WMS.Core.Map.Entity
[SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")]
public long? CarrierId { get; set; }
/// <summary>
/// 船司名称
/// </summary>
[SugarColumn(ColumnDescription = "船司名称", Length = 100, IsNullable = true)]
public string Carrier { get; set; }
/// <summary>
/// 船司代码
/// </summary>
[SugarColumn(ColumnDescription = "船司代码", Length = 100, IsNullable = true)]

@ -103,7 +103,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingCtnRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.CtnName = tenantDb.Queryable<CodeCtn>().Where(x => x.Id == it.LinkId).Select(n => n.CtnName).First();
}
).ToQueryPage(request.PageCondition);
@ -118,7 +117,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingCtnRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.CtnName = tenantDb.Queryable<CodeCtn>().Where(x => x.Id == it.LinkId).Select(n => n.CtnName).First();
}
)

@ -103,8 +103,7 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingFrtRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.FrtName = tenantDb.Queryable<CodeFrt>().Where(x => x.Id == it.LinkId).Select(n => n.FrtName).First();
it.FrtName = tenantDb.Queryable<CodeFrt>().Where(x => x.Id == it.LinkId).Select(n => n.FrtName).First();
}
).ToQueryPage(request.PageCondition);
return data;
@ -118,7 +117,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingFrtRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.FrtName = tenantDb.Queryable<CodeFrt>().Where(x => x.Id == it.LinkId).Select(n => n.FrtName).First();
}
)

@ -107,7 +107,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingPackageRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.PackageName = tenantDb.Queryable<CodePackage>().Where(x => x.Id == it.LinkId).Select(n => n.PackageName).First();
}
).ToQueryPage(request.PageCondition);
@ -122,7 +121,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingPackageRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.PackageName = tenantDb.Queryable<CodePackage>().Where(x => x.Id == it.LinkId).Select(n => n.PackageName).First();
}
)

@ -110,7 +110,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingPortRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.PortName = tenantDb.Queryable<CodePort>().Where(x => x.Id == it.LinkId).Select(n => n.PortName).First();
}
).ToQueryPage(request.PageCondition);
@ -125,7 +124,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingPortRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.PortName = tenantDb.Queryable<CodePort>().Where(x => x.Id == it.LinkId).Select(n => n.PortName).First();
}
)

@ -103,7 +103,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingServiceRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.ServiceName = tenantDb.Queryable<CodeService>().Where(x => x.Id == it.LinkId).Select(n => n.CnName).First();
}
).ToQueryPage(request.PageCondition);
@ -118,7 +117,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingServiceRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.ServiceName = tenantDb.Queryable<CodeService>().Where(x => x.Id == it.LinkId).Select(n => n.CnName).First();
}
)

@ -110,8 +110,7 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingYardRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
it.YardName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.LinkId).Select(n => n.ShortName).First();
it.YardName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.LinkId).Select(n => n.ShortName).First();
}
).ToQueryPage(request.PageCondition);
return data;
@ -125,7 +124,6 @@ namespace DS.WMS.Core.Map.Method
.Select<MappingYardRes>()
.Mapper(it =>
{
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n=>n.ShortName).First();
it.YardName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.LinkId).Select(n => n.ShortName).First();
}
)

@ -96,7 +96,7 @@ namespace DS.WMS.Core.Map.Method
{
it.LaneName = tenantDb.Queryable<CodeLanes>().Where(x => x.Id == it.LaneId).Select(n => n.LaneName).First();
it.PortName = tenantDb.Queryable<CodePort>().Where(x => x.Id == it.PortId).Select(n => n.CnName).First();
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
}
).ToQueryPage(request.PageCondition);
return data;
@ -112,8 +112,7 @@ namespace DS.WMS.Core.Map.Method
{
it.LaneName = tenantDb.Queryable<CodeLanes>().Where(x => x.Id == it.LaneId).Select(n => n.LaneName).First();
it.PortName = tenantDb.Queryable<CodePort>().Where(x => x.Id == it.PortId).Select(n => n.CnName).First();
it.CarrierName = tenantDb.Queryable<InfoClient>().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First();
}
}
)
.First();
return DataResult<RelationLaneAndPortRes>.Success(data, MultiLanguageConst.DataQuerySuccess);

@ -848,6 +848,121 @@ public class CommonService : ICommonService
#region 客户端通用
/// <summary>
/// 查询客户 用户拥有的菜单权限
/// </summary>
/// <returns></returns>
public async Task<DataResult<List<RouteItem>>> GetClientUserPermissions()
{
List<RouteItem> list = new List<RouteItem>();
var userId = long.Parse(user.UserId);
var userInfo = await db.Queryable<SysUser>().Where(x => x.Id == userId).FirstAsync();
var roleIds = await db.Queryable<SysRoleUser>().Where(x => x.UserId == userId).Select(x => x.RoleId).ToListAsync();
var permissions = await db.Queryable<SysRolePermission>().Where(x => roleIds.Contains(x.RoleId))
.Select(x => x.PermissionId).Distinct().ToListAsync();
var perlist = await db.Queryable<SysPermissionTenant>()
.Where(x => x.MenuType == 1 && x.IsHidden == false && permissions.Contains(x.PermissionId) &&
(x.PermissionType == 1 || x.PermissionType == 0))
.OrderBy(x => x.SortCode)
.Select(a => new RouteItem
{
Id = a.Id,
ParentId = a.PermissionId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
Redirect = a.Redirect,
SortCode = a.SortCode,
Meta = new RouteMeta()
{
Title = a.Title,
Icon = a.Icon,
}
})
.ToListAsync();
list.AddRange(perlist);
//去重
list.Distinct();
//排序
list = list.OrderBy(x => x.SortCode).ToList();
foreach (var item in list)
{
var childs = await db.Queryable<SysPermissionTenant>().Where(x =>
(x.MenuType == 1 || x.MenuType == 2) && x.ParentId == item.ParentId && x.IsHidden == false &&
permissions.Contains(x.PermissionId) &&
(x.PermissionType == 1 || x.PermissionType == 0) &&
x.PermissionId != 1744968217220222976) //排除企业用户维护
.OrderBy(x => x.SortCode)
.Select(a => new RouteItem
{
Id = a.Id,
ParentId = a.PermissionId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
IsCache = a.IsCache,
Meta = new RouteMeta()
{
Title = a.Title,
Icon = a.Icon,
}
}).ToListAsync();
//去重
childs.Distinct();
//排序
childs = childs.OrderBy(x => x.SortCode).ToList();
foreach (var child in childs)
{
var grandsons = await db.Queryable<SysPermissionTenant>().Where(x =>
x.MenuType == 2 && x.ParentId == child.ParentId && x.IsHidden == false &&
permissions.Contains(x.PermissionId)) //获取第三层路由
.OrderBy(x => x.SortCode)
.Select(a => new RouteItem
{
Id = a.Id,
ParentId = a.PermissionId,
Path = a.Url,
Name = a.PermissionName,
EnName = a.PermissionEnName,
Component = a.Component,
IsCache = a.IsCache,
Meta = new RouteMeta()
{
Title = a.Title,
Icon = a.Icon,
}
}).ToListAsync();
if (grandsons.Count > 0)
{
//去重
grandsons.Distinct();
//排序
grandsons = grandsons.OrderBy(x => x.SortCode).ToList();
child.Children = grandsons;
}
}
item.Children = childs;
}
// list = list.OrderBy(x => x.Id).ToList();
return await Task.FromResult(DataResult<List<RouteItem>>.Success("获取数据成功!", list));
}
/// <summary>
/// 获取权限树列表-客户端
/// </summary>

@ -2846,7 +2846,7 @@ namespace DS.WMS.Core.TaskPlat.Method
);
TaskFlowRuner runer = new TaskFlowRuner(tenantDb, serviceProvider);
//var result1 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, null); // 首位
var result1 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, null); // 首位
//var result2 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20001); // 正常
//var result3 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20002); // 分支判断
//var result4 = await runer.GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum.WORK_FLOW_MAIN, dataContext, 20003); // 分支结尾判断

@ -75,54 +75,42 @@ namespace DS.WMS.Core.TaskPlat
.ToListAsync();
// 判断每项流程达成的条件数量
Dictionary<long, int> configMatchCount = allConfigList.ToDictionary(x => x.Id, x => 0);
Dictionary<long, int> configMatchCount = new(allConditionList.Count);
foreach (var configItem in allConfigList)
{
var conditionItem = allConditionList.FirstOrDefault(x => x.ConfigId == configItem.Id);
if (conditionItem != null && !string.IsNullOrEmpty(conditionItem.Content))
if (conditionItem == null || string.IsNullOrEmpty(conditionItem.Content))
{
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(conditionItem.Content)!;
var oldValue = configMatchCount[configItem.Id];
if (ConditionHelper.IsPass(contitionContent, dataContext))
{
configMatchCount[configItem.Id] = oldValue + 1;
}
else
{
configMatchCount[configItem.Id] = oldValue - 1;
}
}
}
// 取出最匹配的流程
KeyValuePair<long, int>? bestMatched = null!;
foreach (var item in configMatchCount)
{
if (bestMatched == null)
{
bestMatched = new KeyValuePair<long, int>(item.Key, item.Value);
configMatchCount.Add(configItem.Id, 0);
continue;
}
if (item.Value > bestMatched.Value.Value)
else
{
bestMatched = new KeyValuePair<long, int>(item.Key, item.Value);
continue;
}
var conditionContent = JsonConvert.DeserializeObject<ConditionContent>(conditionItem.Content)!;
if (item.Value == bestMatched.Value.Value)
{
// 如果达成的条件数量相等,则取最早的流程
if (item.Key < bestMatched.Value.Key)
if (ConditionHelper.IsPass(conditionContent, dataContext))
{
bestMatched = new KeyValuePair<long, int>(item.Key, item.Value);
continue;
var conditionCount = ConditionHelper.GetConditionCount(conditionContent);
configMatchCount.Add(configItem.Id, conditionCount);
}
}
}
var targetConfig = allConfigList.First(x => x.Id == bestMatched.Value.Key);
// 取出最匹配的流程
TaskFlowConfig? targetConfig = null;
if (configMatchCount.Count == 1)
{
targetConfig = allConfigList.First(x => x.Id == configMatchCount.First().Key);
}
else if (configMatchCount.Count > 1)
{
var maxMatchNum = configMatchCount.OrderByDescending(x => x.Value).First().Value; // 取匹配条件数最多的一条
var temp = configMatchCount.Where(x => x.Value == maxMatchNum).OrderBy(x => x.Key).First().Key;
targetConfig = allConfigList.First(x => x.Id == temp);
}
if (targetConfig == null)
{
throw new Exception("targetConfig目标流程意外为null");
}
// 待执行的流程(节点列表)
var configList = await tenantDb.Queryable<TaskFlowConfig>().Where(x => x.MainConfigId == targetConfig.Id).ToListAsync();
@ -169,31 +157,32 @@ namespace DS.WMS.Core.TaskPlat
}
// 对节点列表里面的节点进行依次判断,取出要执行的节点
var matchedConfigList = new List<(TaskFlowConfig config, bool isHasCondition)>();
Dictionary<TaskFlowConfig, int> matchedConfigList = new();
foreach (var waitMatchConfigItem in waitMatchConfigList)
{
var condition = conditionList.FirstOrDefault(x => x.ConfigId == waitMatchConfigItem.Id);
if (condition == null || string.IsNullOrEmpty(condition.Content))
{
matchedConfigList.Add((waitMatchConfigItem, false));
matchedConfigList.Add(waitMatchConfigItem, 0);
continue;
}
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(contitionContent, dataContext))
var conditionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(conditionContent, dataContext))
{
matchedConfigList.Add((waitMatchConfigItem, true));
var conditionCount = ConditionHelper.GetConditionCount(conditionContent);
matchedConfigList.Add(waitMatchConfigItem, conditionCount);
continue;
}
}
if (matchedConfigList.Count == 1)
{
executeConfig = matchedConfigList[0].config;
executeConfig = matchedConfigList.First().Key;
}
else if (matchedConfigList.Count > 1)
{
var temp = matchedConfigList.OrderBy(x => x.config.Id).Where(x => x.isHasCondition).ToList();
executeConfig = temp.FirstOrDefault().config;
var maxMatchNum = matchedConfigList.OrderByDescending(x => x.Value).First().Value; // 取匹配条件数最多的一条
executeConfig = matchedConfigList.Where(x => x.Value == maxMatchNum).OrderBy(x => x.Key.Id).First().Key;
}
if (executeConfig == null)
@ -393,7 +382,7 @@ namespace DS.WMS.Core.TaskPlat
/// <param name="workFlowType">工作流流程类型</param>
/// <param name="dataContext"></param>
/// <param name="currentTaskType">当前执行的任务类型(如果为空,则返回首个任务类型)</param>
/// <returns>(下一个任务类型下一节点Id</returns>
/// <returns>(下一个任务类型</returns>
public async Task<TaskBaseTypeEnum?> GetWorkFlowNextConfigByTaskType(TaskBaseTypeEnum workFlowType, TaskFlowDataContext dataContext, TaskBaseTypeEnum? currentTaskType)
{
var allConfigList = await tenantDb.Queryable<TaskFlowConfig>()
@ -432,20 +421,21 @@ namespace DS.WMS.Core.TaskPlat
.Where(x => configIdList.Contains(x.ConfigId))
.ToListAsync();
var matchedConfigList = new List<TaskFlowConfig>();
Dictionary<TaskFlowConfig, int> matchedConfigList = new();
foreach (var item in waitMatchConfigList)
{
var condition = conditionList.FirstOrDefault(x => x.ConfigId == item.Id);
if (condition == null || string.IsNullOrEmpty(condition.Content))
{
matchedConfigList.Add(item);
matchedConfigList.Add(item, 0);
}
else
{
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(contitionContent, dataContext))
var conditionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(conditionContent, dataContext))
{
matchedConfigList.Add(item);
var conditionCount = ConditionHelper.GetConditionCount(conditionContent);
matchedConfigList.Add(item, conditionCount);
}
}
}
@ -453,11 +443,12 @@ namespace DS.WMS.Core.TaskPlat
TaskFlowConfig? executeConfig = null;
if (matchedConfigList.Count == 1)
{
executeConfig = matchedConfigList[0];
executeConfig = matchedConfigList.First().Key;
}
else if (matchedConfigList.Count > 1)
{
executeConfig = matchedConfigList.FirstOrDefault(x => x.IsMoreMatchDefault);
var maxMatchNum = matchedConfigList.OrderByDescending(x => x.Value).First().Value; // 取匹配条件数最多的一条
executeConfig = matchedConfigList.Where(x => x.Value == maxMatchNum).OrderBy(x => x.Key.Id).First().Key;
}
if (executeConfig == null)
@ -492,108 +483,6 @@ namespace DS.WMS.Core.TaskPlat
return null;
}
/// <summary>
/// 根据当前节点Id获取工作流下一个任务类型
/// </summary>
/// <param name="workFlowType">工作流流程类型</param>
/// <param name="dataContext"></param>
/// <param name="currentConfigId">当前执行的配置Id如果为空则返回首个任务类型</param>
/// <returns>下一个任务类型下一节点Id</returns>
public async Task<(TaskBaseTypeEnum taskType, long configId)?> GetWorkFlowNextConfig(TaskBaseTypeEnum workFlowType, TaskFlowDataContext dataContext, long? currentConfigId = null)
{
var allConfigList = await tenantDb.Queryable<TaskFlowConfig>()
.Where(t => t.MainConfigId == SqlFunc.Subqueryable<TaskFlowConfig>().Where(x => x.IsMain && x.TaskType == workFlowType.ToString()).Select(x => x.Id))
.OrderBy(t => t.Id)
.ToListAsync();
if (allConfigList.Count == 0) return null;
long configId;
if (currentConfigId == null)
{
configId = allConfigList.First(x => x.IsMain).Id;
}
else
{
configId = currentConfigId.Value;
}
List<TaskFlowConfig> waitMatchConfigList = new();
for (int i = 0; i < allConfigList.Count; i++)
{
var currentConfig = allConfigList.FirstOrDefault(x => x.Id == configId);
if (currentConfig == null || string.IsNullOrEmpty(currentConfig.NextConfigId))
return null;
var nextIds = currentConfig.NextConfigId.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt64(x));
waitMatchConfigList = allConfigList.Where(x => nextIds.Contains(x.Id)).ToList();
if (waitMatchConfigList.Count == 0) return null; // 如果走了这一步的return说明配置有问题配置了下一节点的id但是却查不到
var configIdList = waitMatchConfigList.Select(x => x.Id);
var conditionList = await tenantDb.Queryable<TaskFlowCondition>()
.Where(x => configIdList.Contains(x.ConfigId))
.ToListAsync();
var matchedConfigList = new List<TaskFlowConfig>();
foreach (var item in waitMatchConfigList)
{
var condition = conditionList.FirstOrDefault(x => x.ConfigId == item.Id);
if (condition == null || string.IsNullOrEmpty(condition.Content))
{
matchedConfigList.Add(item);
}
else
{
var contitionContent = JsonConvert.DeserializeObject<ConditionContent>(condition.Content)!;
if (ConditionHelper.IsPass(contitionContent, dataContext))
{
matchedConfigList.Add(item);
}
}
}
TaskFlowConfig? executeConfig = null;
if (matchedConfigList.Count == 1)
{
executeConfig = matchedConfigList[0];
}
else if (matchedConfigList.Count > 1)
{
executeConfig = matchedConfigList.FirstOrDefault(x => x.IsMoreMatchDefault);
}
if (executeConfig == null)
{
executeConfig = waitMatchConfigList.FirstOrDefault(x => x.IsUnMatchDefault);
}
if (executeConfig == null)
{
// 如果最终还是没有匹配到,则需要判断情况
// 如果待匹配的分支只有1个则继续循环判断下一节点否则如果待匹配的分支有多个则无法判断下一节点
if (waitMatchConfigList.Count == 1)
{
configId = waitMatchConfigList[0].Id;
continue;
}
else
{
return null;
}
}
else
{
var taskType = await tenantDb.Queryable<TaskFlowModule>().Where(x => x.Id == executeConfig.ExecuteModuleId && x.ModuleType == 2).Select(x => x.TaskType).FirstAsync();
if (taskType != null && Enum.TryParse(typeof(TaskBaseTypeEnum), taskType, out object? temp))
{
return ((TaskBaseTypeEnum)temp, executeConfig.Id);
}
}
}
return null;
}
static string WriteLog(string throwMsg, Exception ex)
{
return string.Format("【自定义错误】:{0} \r\n【异常类型】{1} \r\n【异常信息】{2} \r\n【堆栈调用】{3}", new object[]

@ -5,6 +5,7 @@ using DS.Module.SqlSugar;
using DS.WMS.Core.Check.Entity;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Map.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.BookingSlot;
using DS.WMS.Core.Sys.Entity;
@ -54,15 +55,15 @@ public class SaasDBUpdateTest
{
var tenantList = db.Queryable<DS.Module.SqlSugar.SysTenantLink>().ToList();
var ass = Assembly.Load("DS.WMS.Core");
//var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.TaskPlat.Entity") == true).ToArray();
var types = ass.GetTypes().Where(it => it.FullName?.Contains("DS.WMS.Core.Map.Entity") == true).ToArray();
foreach (var item in tenantList)
{
var tenantDb = saasService.GetBizDbScopeById(item.TenantId).CopyNew();
StaticConfig.CodeFirst_MySqlCollate = "utf8mb4_0900_ai_ci"; //较高版本支持
//tenantDb.CodeFirst.InitTables(types); //指定表空间下的实体
tenantDb.CodeFirst.InitTables(typeof(InfoClient));//指定更新特定实体
tenantDb.CodeFirst.InitTables(typeof(MappingFrt));//指定更新特定实体
}
Assert.True(true);
}

Loading…
Cancel
Save