|
|
@@ -7,6 +7,10 @@ using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using Learun.Application.TwoDevelopment.LR_LGManager; |
|
|
|
using Dapper; |
|
|
|
using Learun.Application.Organization; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
namespace Learun.Application.WorkFlow |
|
|
|
{ |
|
|
@@ -2081,6 +2085,171 @@ namespace Learun.Application.WorkFlow |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 流程监控统计耗时最长信息 |
|
|
|
/// </summary> |
|
|
|
public void StatisticsData() |
|
|
|
{ |
|
|
|
var db = this.BaseRepository(); |
|
|
|
try |
|
|
|
{ |
|
|
|
db.BeginTrans(); |
|
|
|
var processList = db.FindList<NWFProcessEntity>(t => t.F_EnabledMark != 2 && t.F_IsChild == 0).ToList(); |
|
|
|
|
|
|
|
//删除今天统计的数据,每天只记录一份数据 |
|
|
|
db.ExecuteBySql("delete from LR_NWF_ProcessStatistics where DateDiff(dd,F_CreateDate,getdate())=0"); |
|
|
|
|
|
|
|
var NTRList = db.FindList<NWFTaskRelationEntity>($"SELECT * FROM LR_NWF_TaskRelation").ToList(); |
|
|
|
var userList = db.FindList<UserEntity>(x => x.F_DeleteMark == 0).ToList(); |
|
|
|
var deptList = db.FindList<DepartmentEntity>().ToList(); |
|
|
|
//Action<IRepository, NWFProcessEntity, List<NWFTaskRelationEntity>, List<UserEntity>, List<DepartmentEntity>> action = new Action<IRepository, NWFProcessEntity, List<NWFTaskRelationEntity>, List<UserEntity>, List<DepartmentEntity>>(AddProcessStatistics); |
|
|
|
|
|
|
|
//RunTask<NWFProcessEntity>(processList, action); |
|
|
|
|
|
|
|
ConcurrentQueue<NWFProcessEntity> queue = new ConcurrentQueue<NWFProcessEntity>(processList); |
|
|
|
int threadCount = 10; //开启10个线程 |
|
|
|
for (int i = 0; i < threadCount; i++) |
|
|
|
{ |
|
|
|
string fileName = $"task{i}.txt"; |
|
|
|
//开启新线程 |
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
var sb = new StringBuilder(); |
|
|
|
int j = 0; |
|
|
|
//数据循环出队 |
|
|
|
while (queue.TryDequeue(out NWFProcessEntity model)) |
|
|
|
{ |
|
|
|
//处理数据 |
|
|
|
if (model != null) |
|
|
|
AddProcessStatistics(db, model, NTRList, userList, deptList); |
|
|
|
|
|
|
|
if (j % 100 == 0 || (queue.Count.Equals(0) && j < 100)) |
|
|
|
{ |
|
|
|
Thread.Sleep(100); |
|
|
|
} |
|
|
|
j++; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
db.Commit(); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
db.Rollback(); |
|
|
|
if (ex is ExceptionEx) |
|
|
|
{ |
|
|
|
throw; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw ExceptionEx.ThrowServiceException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 流程监控统计表添加数据 |
|
|
|
/// </summary> |
|
|
|
/// <param name="db"></param> |
|
|
|
/// <param name="model"></param> |
|
|
|
/// <param name="NTRList"></param> |
|
|
|
/// <param name="userList"></param> |
|
|
|
/// <param name="deptList"></param> |
|
|
|
private void AddProcessStatistics(IRepository db, NWFProcessEntity model, List<NWFTaskRelationEntity> NTRList, List<UserEntity> userList, List<DepartmentEntity> deptList) |
|
|
|
{ |
|
|
|
var userNames = ""; |
|
|
|
var tasklist = db.FindList<NWFTaskEntity>(t => t.F_ProcessId == model.F_Id && t.F_IsFinished == 0).FirstOrDefault(); |
|
|
|
if (tasklist != null && !string.IsNullOrEmpty(tasklist.F_Id)) |
|
|
|
{ |
|
|
|
List<string> usernamelist = new List<string>(); |
|
|
|
List<string> nextlist = NTRList.Where(x => x.F_TaskId == tasklist.F_Id).Select(m => m.F_UserId).ToList(); |
|
|
|
|
|
|
|
foreach (var uid in nextlist) |
|
|
|
{ |
|
|
|
var userentity = userList.Find(x => x.F_UserId == uid); |
|
|
|
string deptname = deptList.Find(x => x.F_DepartmentId == userentity?.F_DepartmentId)?.F_FullName; |
|
|
|
usernamelist.Add("[" + deptname + "]" + userentity?.F_RealName); |
|
|
|
} |
|
|
|
userNames = string.Join(",", usernamelist); |
|
|
|
} |
|
|
|
|
|
|
|
var addSql = $@"INSERT INTO [dbo].[LR_NWF_ProcessStatistics] |
|
|
|
([Id] |
|
|
|
,[F_ProcessId] |
|
|
|
,[F_SchemeId] |
|
|
|
,[F_SchemeCode] |
|
|
|
,[F_SchemeName] |
|
|
|
,[F_Title] |
|
|
|
,[F_Level] |
|
|
|
,[F_EnabledMark] |
|
|
|
,[F_IsAgain] |
|
|
|
,[F_IsFinished] |
|
|
|
,[F_IsChild] |
|
|
|
,[F_IsAsyn] |
|
|
|
,[F_ParentNodeId] |
|
|
|
,[F_ParentTaskId] |
|
|
|
,[F_ParentProcessId] |
|
|
|
,[F_IsStart] |
|
|
|
,[F_CurrentHandler] |
|
|
|
,[F_LongestTimeProcessor] |
|
|
|
,[F_LongestTime] |
|
|
|
,[F_CreateDate] |
|
|
|
,[F_CreateUserId]) |
|
|
|
VALUES |
|
|
|
(newid() |
|
|
|
,'{model.F_Id}' |
|
|
|
,'{model.F_SchemeId}' |
|
|
|
,'{model.F_SchemeCode}' |
|
|
|
,'{model.F_SchemeName}' |
|
|
|
,'{model.F_Title}' |
|
|
|
,'{model.F_Level}' |
|
|
|
,'{model.F_EnabledMark}' |
|
|
|
,'{model.F_IsAgain}' |
|
|
|
,'{model.F_IsFinished}' |
|
|
|
,'{model.F_IsChild}' |
|
|
|
,'{model.F_IsAsyn}' |
|
|
|
,'{model.F_ParentNodeId}' |
|
|
|
,'{model.F_ParentTaskId}' |
|
|
|
,'{model.F_ParentProcessId}' |
|
|
|
,'{model.F_IsStart}' |
|
|
|
,'{userNames}' |
|
|
|
,''--最长耗时处理人 |
|
|
|
,null--最长耗时处理时间 |
|
|
|
,GETDATE() |
|
|
|
,'{LoginUserInfo.Get().userId}')"; |
|
|
|
|
|
|
|
db.ExecuteBySql(addSql); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 多线程处理数据(无返回值) |
|
|
|
/// </summary> |
|
|
|
/// <typeparam name="T">数据类型</typeparam> |
|
|
|
/// <param name="list">待处理数据</param> |
|
|
|
/// <param name="action">数据处理方法(有参数无返回值)</param> |
|
|
|
/// <param name="count">处理线程数量</param> |
|
|
|
/// <param name="waitFlag">是否等待执行结束</param> |
|
|
|
public static void RunTask<T>(List<T> list, Action<T, T, T, T, T> action, IRepository db, int threadCount = 5, bool waitFlag = true) |
|
|
|
{ |
|
|
|
ConcurrentQueue<T> queue = new ConcurrentQueue<T>(list); |
|
|
|
Task[] tasks = new Task[threadCount]; |
|
|
|
for (int i = 0; i < threadCount; i++) |
|
|
|
{ |
|
|
|
tasks[i] = Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
while (queue.TryDequeue(out T t)) |
|
|
|
{ |
|
|
|
//action(db,t); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
if (waitFlag) |
|
|
|
{ |
|
|
|
Task.WaitAll(tasks); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |