You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkFlowApi.cs 13 KiB

4 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using Learun.Application.Base.AuthorizeModule;
  2. using Learun.Application.Form;
  3. using Learun.Application.Organization;
  4. using Learun.Application.WorkFlow;
  5. using Learun.Util;
  6. using Nancy;
  7. using System.Collections.Generic;
  8. namespace Learun.Application.WebApi.Modules
  9. {
  10. public class WorkFlowApi : BaseApi
  11. {
  12. /// <summary>
  13. /// 注册接口
  14. /// </summary>
  15. public WorkFlowApi()
  16. : base("/learun/adms/workflow")
  17. {
  18. Get["/bootstraper"] = GetBootstraper;
  19. Get["/taskinfo"] = Taskinfo;
  20. Get["/processinfo"] = ProcessInfo;
  21. Get["/scheme"] = GetScheme;
  22. Get["/mylist"] = GetMyProcess;// 获取数据字典详细列表
  23. Get["/mytask"] = GetMyTaskList;
  24. Get["/mytaskmaked"] = GetMyMakeTaskList;
  25. Get["/auditer"] = GetAuditer;
  26. Post["/create"] = Create;
  27. Post["/audit"] = Audit;
  28. }
  29. private UserRelationIBLL userRelationIBLL = new UserRelationBLL();
  30. private UserIBLL userIBLL = new UserBLL();
  31. private WfEngineIBLL wfEngineIBLL = new WfEngineBLL();
  32. private WfProcessInstanceIBLL wfProcessInstanceIBLL = new WfProcessInstanceBLL();
  33. private WfTaskIBLL wfTaskIBLL = new WfTaskBLL();
  34. private WfSchemeIBLL wfSchemeIBLL = new WfSchemeBLL();
  35. private FormSchemeIBLL formSchemeIBLL = new FormSchemeBLL();
  36. /// <summary>
  37. /// 获取流程模板
  38. /// </summary>
  39. /// <param name="_"></param>
  40. /// <returns></returns>
  41. private Response GetScheme(dynamic _)
  42. {
  43. QueryModel parameter = this.GetReqData<QueryModel>();
  44. IEnumerable<WfSchemeInfoEntity> list = new List<WfSchemeInfoEntity>();
  45. list = wfSchemeIBLL.GetAppSchemeInfoPageList(parameter.pagination, this.userInfo, parameter.queryJson);
  46. var jsonData = new
  47. {
  48. rows = list,
  49. total = parameter.pagination.total,
  50. page = parameter.pagination.page,
  51. records = parameter.pagination.records,
  52. };
  53. return Success(jsonData);
  54. }
  55. /// <summary>
  56. /// 获取我的流程实例信息
  57. /// </summary>
  58. /// <param name="_"></param>
  59. /// <returns></returns>
  60. private Response GetMyProcess(dynamic _)
  61. {
  62. QueryModel parameter = this.GetReqData<QueryModel>();
  63. IEnumerable<WfProcessInstanceEntity> list = new List<WfProcessInstanceEntity>();
  64. list = wfProcessInstanceIBLL.GetMyPageList(this.userInfo.userId, parameter.pagination, parameter.queryJson);
  65. var jsonData = new
  66. {
  67. rows = list,
  68. total = parameter.pagination.total,
  69. page = parameter.pagination.page,
  70. records = parameter.pagination.records,
  71. };
  72. return Success(jsonData);
  73. }
  74. /// <summary>
  75. /// 获取我的任务列表
  76. /// </summary>
  77. /// <param name="_"></param>
  78. /// <returns></returns>
  79. private Response GetMyTaskList(dynamic _)
  80. {
  81. QueryModel parameter = this.GetReqData<QueryModel>();
  82. IEnumerable<WfProcessInstanceEntity> list = new List<WfProcessInstanceEntity>();
  83. list = wfTaskIBLL.GetActiveList(this.userInfo, parameter.pagination, parameter.queryJson);
  84. var jsonData = new
  85. {
  86. rows = list,
  87. total = parameter.pagination.total,
  88. page = parameter.pagination.page,
  89. records = parameter.pagination.records,
  90. };
  91. return Success(jsonData);
  92. }
  93. /// <summary>
  94. /// 获取我已处理的任务列表
  95. /// </summary>
  96. /// <param name="_"></param>
  97. /// <returns></returns>
  98. private Response GetMyMakeTaskList(dynamic _)
  99. {
  100. QueryModel parameter = this.GetReqData<QueryModel>();
  101. IEnumerable<WfProcessInstanceEntity> list = new List<WfProcessInstanceEntity>();
  102. list = wfTaskIBLL.GetHasList(this.userInfo.userId, parameter.pagination, parameter.queryJson);
  103. var jsonData = new
  104. {
  105. rows = list,
  106. total = parameter.pagination.total,
  107. page = parameter.pagination.page,
  108. records = parameter.pagination.records,
  109. };
  110. return Success(jsonData);
  111. }
  112. /// <summary>
  113. /// 初始化流程模板->获取开始节点数据
  114. /// </summary>
  115. /// <param name="_"></param>
  116. /// <returns></returns>
  117. private Response GetBootstraper(dynamic _)
  118. {
  119. WfParameter wfParameter = this.GetReqData<WfParameter>();
  120. wfParameter.companyId = this.userInfo.companyId;
  121. wfParameter.departmentId = this.userInfo.departmentId;
  122. wfParameter.userId = this.userInfo.userId;
  123. wfParameter.userName = this.userInfo.realName;
  124. WfResult<WfContent> res = wfEngineIBLL.Bootstraper(wfParameter);
  125. return this.Success<WfResult<WfContent>>(res);
  126. }
  127. /// <summary>
  128. /// 获取流程实例信息
  129. /// </summary>
  130. /// <param name="_"></param>
  131. /// <returns></returns>
  132. private Response ProcessInfo(dynamic _)
  133. {
  134. WfParameter wfParameter = this.GetReqData<WfParameter>();
  135. wfParameter.companyId = this.userInfo.companyId;
  136. wfParameter.departmentId = this.userInfo.departmentId;
  137. wfParameter.userId = this.userInfo.userId;
  138. wfParameter.userName = this.userInfo.realName;
  139. WfResult<WfContent> res = wfEngineIBLL.GetProcessInfo(wfParameter);
  140. return this.Success<WfResult<WfContent>>(res);
  141. }
  142. /// <summary>
  143. /// 获取流程审核节点的信息
  144. /// </summary>
  145. /// <param name="_"></param>
  146. /// <returns></returns>
  147. private Response Taskinfo(dynamic _)
  148. {
  149. WfParameter wfParameter = this.GetReqData<WfParameter>();
  150. wfParameter.companyId = this.userInfo.companyId;
  151. wfParameter.departmentId = this.userInfo.departmentId;
  152. wfParameter.userId = this.userInfo.userId;
  153. wfParameter.userName = this.userInfo.realName;
  154. WfResult<WfContent> res = wfEngineIBLL.GetTaskInfo(wfParameter);
  155. return this.Success<WfResult<WfContent>>(res);
  156. }
  157. /// <summary>
  158. /// 获取下一个节点审核人员
  159. /// </summary>
  160. /// <param name="_"></param>
  161. /// <returns></returns>
  162. private Response GetAuditer(dynamic _) {
  163. WfParameter wfParameter = this.GetReqData<WfParameter>();
  164. wfParameter.companyId = this.userInfo.companyId;
  165. wfParameter.departmentId = this.userInfo.departmentId;
  166. wfParameter.userId = this.userInfo.userId;
  167. wfParameter.userName = this.userInfo.realName;
  168. WfResult<List<object>> res = wfEngineIBLL.GetAuditer(wfParameter);
  169. List<object> nodelist = new List<object>();
  170. if (res.status == 1)
  171. {
  172. var list = res.data;
  173. foreach (var item1 in list)
  174. {
  175. var item = item1.ToJson().ToJObject();
  176. if (item["auditors"].IsEmpty())
  177. {
  178. var point = new
  179. {
  180. all = true,
  181. name = item["name"],
  182. nodeId = item["nodeId"]
  183. };
  184. nodelist.Add(point);
  185. }
  186. else
  187. {
  188. List<object> userlist = new List<object>();
  189. foreach (var auditor in item["auditors"])
  190. {
  191. switch (auditor["type"].ToString())
  192. {//获取人员信息1.岗位2.角色3.用户
  193. case "1":
  194. case "2":
  195. var userRelationList = userRelationIBLL.GetUserIdList(auditor["auditorId"].ToString());
  196. string userIds = "";
  197. foreach (var userRelation in userRelationList)
  198. {
  199. if (userIds != "")
  200. {
  201. userIds += ",";
  202. }
  203. userIds += userRelation.F_UserId;
  204. }
  205. var userList = userIBLL.GetListByUserIds(userIds);
  206. if (userList != null)
  207. {
  208. foreach (var user in userList)
  209. {
  210. if (user != null)
  211. {
  212. userlist.Add(new { id = user.F_UserId, name = user.F_RealName });
  213. }
  214. }
  215. }
  216. break;
  217. case "3":
  218. userlist.Add(new { id = auditor["auditorId"], name = auditor["auditorName"] });
  219. break;
  220. }
  221. }
  222. var point = new
  223. {
  224. name = item["name"],
  225. nodeId = item["nodeId"],
  226. list = userlist
  227. };
  228. nodelist.Add(point);
  229. }
  230. }
  231. return Success(nodelist);
  232. }
  233. else
  234. {
  235. return Success(nodelist);
  236. }
  237. }
  238. #region 提交信息
  239. /// <summary>
  240. /// 创建流程实例
  241. /// </summary>
  242. /// <param name="_"></param>
  243. /// <returns></returns>
  244. private Response Create(dynamic _)
  245. {
  246. WfParameter wfParameter = this.GetReqData<WfParameter>();
  247. wfParameter.companyId = this.userInfo.companyId;
  248. wfParameter.departmentId = this.userInfo.departmentId;
  249. wfParameter.userId = this.userInfo.userId;
  250. wfParameter.userName = this.userInfo.realName;
  251. List<FormParam> req = wfParameter.formreq.ToObject<List<FormParam>>();// 获取模板请求数据
  252. foreach (var item in req)
  253. {
  254. formSchemeIBLL.SaveInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue, item.formData);
  255. }
  256. WfResult res = wfEngineIBLL.Create(wfParameter);
  257. return this.Success<WfResult>(res);
  258. }
  259. /// <summary>
  260. /// 审核流程实例
  261. /// </summary>
  262. /// <param name="_"></param>
  263. /// <returns></returns>
  264. private Response Audit(dynamic _)
  265. {
  266. WfParameter wfParameter = this.GetReqData<WfParameter>();
  267. wfParameter.companyId = this.userInfo.companyId;
  268. wfParameter.departmentId = this.userInfo.departmentId;
  269. wfParameter.userId = this.userInfo.userId;
  270. wfParameter.userName = this.userInfo.realName;
  271. List<FormParam> req = wfParameter.formreq.ToObject<List<FormParam>>();// 获取模板请求数据
  272. foreach (var item in req)
  273. {
  274. formSchemeIBLL.SaveInstanceForm(item.schemeInfoId, item.processIdName, item.keyValue, item.formData);
  275. }
  276. WfResult res = wfEngineIBLL.Audit(wfParameter);
  277. return this.Success<WfResult>(res);
  278. }
  279. #endregion
  280. /// <summary>
  281. /// 查询条件对象
  282. /// </summary>
  283. private class QueryModel
  284. {
  285. public Pagination pagination { get; set; }
  286. public string queryJson { get; set; }
  287. }
  288. /// <summary>
  289. /// 自定义表单提交参数
  290. /// </summary>
  291. private class FormParam
  292. {
  293. /// <summary>
  294. /// 流程模板id
  295. /// </summary>
  296. public string schemeInfoId { get; set; }
  297. /// <summary>
  298. /// 关联字段名称
  299. /// </summary>
  300. public string processIdName { get; set; }
  301. /// <summary>
  302. /// 数据主键值
  303. /// </summary>
  304. public string keyValue { get; set; }
  305. /// <summary>
  306. /// 表单数据
  307. /// </summary>
  308. public string formData { get; set; }
  309. }
  310. }
  311. }