using Learun.Application.Base.AuthorizeModule; using Learun.Application.Form; using Learun.Application.Organization; using Learun.Application.WorkFlow; using Learun.Util; using Nancy; using System.Collections.Generic; namespace Learun.Application.WebApi.Modules { public class WorkFlowApi : BaseApi { /// /// 注册接口 /// public WorkFlowApi() : base("/learun/adms/workflow") { Get["/bootstraper"] = GetBootstraper; Get["/taskinfo"] = Taskinfo; Get["/processinfo"] = ProcessInfo; Get["/scheme"] = GetScheme; Get["/mylist"] = GetMyProcess;// 获取数据字典详细列表 Get["/mytask"] = GetMyTaskList; Get["/mytaskmaked"] = GetMyMakeTaskList; Get["/auditer"] = GetAuditer; Post["/create"] = Create; Post["/audit"] = Audit; } private UserRelationIBLL userRelationIBLL = new UserRelationBLL(); private UserIBLL userIBLL = new UserBLL(); private WfEngineIBLL wfEngineIBLL = new WfEngineBLL(); private WfProcessInstanceIBLL wfProcessInstanceIBLL = new WfProcessInstanceBLL(); private WfTaskIBLL wfTaskIBLL = new WfTaskBLL(); private WfSchemeIBLL wfSchemeIBLL = new WfSchemeBLL(); private FormSchemeIBLL formSchemeIBLL = new FormSchemeBLL(); /// /// 获取流程模板 /// /// /// private Response GetScheme(dynamic _) { QueryModel parameter = this.GetReqData(); IEnumerable list = new List(); list = wfSchemeIBLL.GetAppSchemeInfoPageList(parameter.pagination, this.userInfo, parameter.queryJson); var jsonData = new { rows = list, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records, }; return Success(jsonData); } /// /// 获取我的流程实例信息 /// /// /// private Response GetMyProcess(dynamic _) { QueryModel parameter = this.GetReqData(); IEnumerable list = new List(); list = wfProcessInstanceIBLL.GetMyPageList(this.userInfo.userId, parameter.pagination, parameter.queryJson); var jsonData = new { rows = list, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records, }; return Success(jsonData); } /// /// 获取我的任务列表 /// /// /// private Response GetMyTaskList(dynamic _) { QueryModel parameter = this.GetReqData(); IEnumerable list = new List(); list = wfTaskIBLL.GetActiveList(this.userInfo, parameter.pagination, parameter.queryJson); var jsonData = new { rows = list, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records, }; return Success(jsonData); } /// /// 获取我已处理的任务列表 /// /// /// private Response GetMyMakeTaskList(dynamic _) { QueryModel parameter = this.GetReqData(); IEnumerable list = new List(); list = wfTaskIBLL.GetHasList(this.userInfo.userId, parameter.pagination, parameter.queryJson); var jsonData = new { rows = list, total = parameter.pagination.total, page = parameter.pagination.page, records = parameter.pagination.records, }; return Success(jsonData); } /// /// 初始化流程模板->获取开始节点数据 /// /// /// private Response GetBootstraper(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; WfResult res = wfEngineIBLL.Bootstraper(wfParameter); return this.Success>(res); } /// /// 获取流程实例信息 /// /// /// private Response ProcessInfo(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; WfResult res = wfEngineIBLL.GetProcessInfo(wfParameter); return this.Success>(res); } /// /// 获取流程审核节点的信息 /// /// /// private Response Taskinfo(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; WfResult res = wfEngineIBLL.GetTaskInfo(wfParameter); return this.Success>(res); } /// /// 获取下一个节点审核人员 /// /// /// private Response GetAuditer(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; WfResult> res = wfEngineIBLL.GetAuditer(wfParameter); List nodelist = new List(); if (res.status == 1) { var list = res.data; foreach (var item1 in list) { var item = item1.ToJson().ToJObject(); if (item["auditors"].IsEmpty()) { var point = new { all = true, name = item["name"], nodeId = item["nodeId"] }; nodelist.Add(point); } else { List userlist = new List(); foreach (var auditor in item["auditors"]) { switch (auditor["type"].ToString()) {//获取人员信息1.岗位2.角色3.用户 case "1": case "2": var userRelationList = userRelationIBLL.GetUserIdList(auditor["auditorId"].ToString()); string userIds = ""; foreach (var userRelation in userRelationList) { if (userIds != "") { userIds += ","; } userIds += userRelation.F_UserId; } var userList = userIBLL.GetListByUserIds(userIds); if (userList != null) { foreach (var user in userList) { if (user != null) { userlist.Add(new { id = user.F_UserId, name = user.F_RealName }); } } } break; case "3": userlist.Add(new { id = auditor["auditorId"], name = auditor["auditorName"] }); break; } } var point = new { name = item["name"], nodeId = item["nodeId"], list = userlist }; nodelist.Add(point); } } return Success(nodelist); } else { return Success(nodelist); } } #region 提交信息 /// /// 创建流程实例 /// /// /// private Response Create(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; List req = wfParameter.formreq.ToObject>();// 获取模板请求数据 foreach (var item in req) { formSchemeIBLL.SaveInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue, item.formData); } WfResult res = wfEngineIBLL.Create(wfParameter); return this.Success(res); } /// /// 审核流程实例 /// /// /// private Response Audit(dynamic _) { WfParameter wfParameter = this.GetReqData(); wfParameter.companyId = this.userInfo.companyId; wfParameter.departmentId = this.userInfo.departmentId; wfParameter.userId = this.userInfo.userId; wfParameter.userName = this.userInfo.realName; List req = wfParameter.formreq.ToObject>();// 获取模板请求数据 foreach (var item in req) { formSchemeIBLL.SaveInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue, item.formData); } WfResult res = wfEngineIBLL.Audit(wfParameter); return this.Success(res); } #endregion /// /// 查询条件对象 /// private class QueryModel { public Pagination pagination { get; set; } public string queryJson { get; set; } } /// /// 自定义表单提交参数 /// private class FormParam { /// /// 流程模板id /// public string schemeInfoId { get; set; } /// /// 关联字段名称 /// public string processIdName { get; set; } /// /// 数据主键值 /// public string keyValue { get; set; } /// /// 表单数据 /// public string formData { get; set; } } } }