Browse Source

流程监控统计(未完成)

新疆影视学院高职
zhangli 2 years ago
parent
commit
f23c0f0060
5 changed files with 204 additions and 0 deletions
  1. +10
    -0
      Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_NewWorkFlow/Controllers/NWFProcessController.cs
  2. +12
    -0
      Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_NewWorkFlow/Views/NWFProcess/MonitorIndexStatistics.js
  3. +8
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessBLL.cs
  4. +5
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessIBLL.cs
  5. +169
    -0
      Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessSerivce.cs

+ 10
- 0
Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_NewWorkFlow/Controllers/NWFProcessController.cs View File

@@ -1060,5 +1060,15 @@ namespace Learun.Application.Web.Areas.LR_NewWorkFlow.Controllers
return SuccessString("");
}
}
/// <summary>
/// 流程监控统计
/// </summary>
/// <returns></returns>
[HttpPost]
public ActionResult StatisticsData()
{
nWFProcessIBLL.StatisticsData();
return Success("操作成功");
}
}
}

+ 12
- 0
Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LR_NewWorkFlow/Views/NWFProcess/MonitorIndexStatistics.js View File

@@ -116,6 +116,18 @@ var bootstrap = function ($, learun) {
});
}
});


// 统计
$('#lr_statistics').on('click', function () {
learun.layerConfirm('是否确认统计!', function (res) {
if (res) {
learun.postForm(top.$.rootUrl + '/LR_NewWorkFlow/NWFProcess/StatisticsData', function () {
refreshGirdData();
});
}
});
});
},
initleft: function () {
$('#lr_left_list li').on('click', function () {


+ 8
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessBLL.cs View File

@@ -3916,6 +3916,14 @@ namespace Learun.Application.WorkFlow
nWFProcessSerive.SaveTask(taskList);
}

/// <summary>
/// 流程监控统计耗时最长信息
/// </summary>
public void StatisticsData()
{
nWFProcessSerive.StatisticsData();
}

#endregion




+ 5
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessIBLL.cs View File

@@ -323,6 +323,11 @@ namespace Learun.Application.WorkFlow
/// <param name="bNodeId">开始节点</param>
/// <param name="eNodeId">结束节点(审核任务的节点)</param>
void AddTask(string processId, string bNodeId, string eNodeId, UserInfo userInfo);

/// <summary>
/// 流程监控统计耗时最长信息
/// </summary>
void StatisticsData();
#endregion

#region 获取sql语句


+ 169
- 0
Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.WorkFlow/Process/NWFProcessSerivce.cs View File

@@ -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
}
}

Loading…
Cancel
Save