WorkflowServices.cs 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. using Autofac;
  7. using EMIS.DataLogic.SystemDAL;
  8. using EMIS.Entities;
  9. using Bowin.Common.Utility;
  10. using EMIS.CommonLogic.PlugworkflowServices;
  11. using System.Reflection;
  12. using EMIS.ViewModel.SystemView;
  13. using Bowin.Common.Linq.Entity;
  14. using System.Linq.Expressions;
  15. using EMIS.ViewModel.WorkflowManage;
  16. using EMIS.Utility.FormValidate;
  17. using EMIS.Utility;
  18. using Bowin.Common.Mobile;
  19. using System.Transactions;
  20. namespace EMIS.CommonLogic.SystemServices
  21. {
  22. public class WorkflowServices : BaseServices, IWorkflowServices
  23. {
  24. public ProcessWorkfloconfigDAL ProcessWorkfloconfigDAL { get; set; }
  25. public RoleDAL RoleDAL { get; set; }
  26. public Lazy<IProcessRelationServices> ProcessRelationServices { get; set; }
  27. public Lazy<IUserServices> UserServices { get; set; }
  28. private PlugworkflowServices.entreeSoapClient client = new PlugworkflowServices.entreeSoapClient();
  29. private PlugworkflowServices.VerificationModel vm = new PlugworkflowServices.VerificationModel();
  30. public Func<Guid, MessageBody> MessageFunc = null;
  31. /// <summary>
  32. /// 接入系统ID
  33. /// </summary>
  34. private static string sysID = ConfigurationSettings.AppSettings["sys_InsertingID"].ToString();
  35. /// <summary>
  36. /// 接入系统密码
  37. /// </summary>
  38. private static string sysPwd = ConfigurationSettings.AppSettings["sys_InsertingPwd"].ToString();
  39. /// <summary>
  40. /// 查询对应tableName的EntityType
  41. /// </summary>
  42. /// <param name="tableName"></param>
  43. /// <returns></returns>
  44. private Type GetEntityType(string tableName)
  45. {
  46. var assembly = typeof(EMISNewContext).Assembly;
  47. return assembly.GetType("EMIS.Entities." + tableName, false, true);
  48. }
  49. /// <summary>
  50. /// 工作流验证
  51. /// </summary>
  52. private void InitVerificationModel()
  53. {
  54. vm.AppUID = sysID; // 接入系统ID
  55. vm.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  56. vm.AppUPwd = (sysPwd + vm.time).MD5(); //验证密码
  57. }
  58. /// <summary>
  59. /// 查询对应的接入流程表中AppID(接入流程表ID)
  60. /// </summary>
  61. /// <param name="tableName"></param>
  62. /// <returns></returns>
  63. private string GetAppIDByTableName(string tableName)
  64. {
  65. string AppID = string.Empty; //流程ID
  66. Sys_Workfloconfig workfloconfig = ProcessWorkfloconfigDAL.GetWorkfloconfigQueryable()
  67. .Where(x => x.TableName == tableName).FirstOrDefault();
  68. if (workfloconfig != null)
  69. {
  70. AppID = workfloconfig.ProcessID.ToString();
  71. }
  72. return AppID;
  73. }
  74. /// <summary>
  75. /// 查询对应的接入流程表信息List
  76. /// </summary>
  77. /// <param name="tableName"></param>
  78. /// <returns></returns>
  79. private List<NextDetailModel> GetStatusList(string tableName)
  80. {
  81. //接入流程表ID
  82. string AppID = this.GetAppIDByTableName(tableName);
  83. this.InitVerificationModel();
  84. PlugworkflowServices.ProcessItemAndActionResultModel piarm = client.FlowProcessAndActionSetting(AppID, vm);
  85. if (piarm.doNum == 1)
  86. {
  87. return piarm.resultDataList.ToList();
  88. }
  89. else
  90. {
  91. return new List<NextDetailModel>();
  92. }
  93. }
  94. /// <summary>
  95. /// 查询对应的接入流程表开始流程环节的信息List
  96. /// </summary>
  97. /// <param name="tableName"></param>
  98. /// <returns></returns>
  99. private List<NextDetailModel> GetStartStatusList(string tableName)
  100. {
  101. //接入流程表ID
  102. string AppID = this.GetAppIDByTableName(tableName);
  103. this.InitVerificationModel();
  104. PlugworkflowServices.ProcessItemAndActionResultModel piarm = client.FlowProcessAndActionSetting(AppID, vm);
  105. if (piarm.doNum == 1)
  106. {
  107. return piarm.resultDataList.Where(x => x.Tp == "start").ToList();
  108. }
  109. else
  110. {
  111. return new List<NextDetailModel>();
  112. }
  113. }
  114. /// <summary>
  115. /// 查询对应的接入流程表开始流程环节的Pid(对应的流程环节Pid)
  116. /// </summary>
  117. /// <param name="tableName"></param>
  118. /// <returns></returns>
  119. public int? GetStartStatus(string tableName)
  120. {
  121. var statusList = this.GetStatusList(tableName);
  122. return statusList.Where(x => x.Tp == "start").Select(x => x.Pid).FirstOrDefault();
  123. }
  124. /// <summary>
  125. /// 查询对应的接入流程表已退回流程环节Pid(注:不包含开始环节、结束环节且为[BP]标识)
  126. /// </summary>
  127. /// <param name="tableName"></param>
  128. /// <returns></returns>
  129. public int? GetSendBackStatus(string tableName)
  130. {
  131. var statusList = this.GetStatusList(tableName);
  132. return statusList.Where(x => x.Tp == "auto" && (x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).FirstOrDefault();
  133. }
  134. /// <summary>
  135. /// 查询对应的接入流程表已通过流程环节Pid(注:不包含开始环节、结束环节且为[PASS]标识)
  136. /// </summary>
  137. /// <param name="tableName"></param>
  138. /// <returns></returns>
  139. public int? GetPassNoEndStatus(string tableName)
  140. {
  141. var statusList = this.GetStatusList(tableName);
  142. return statusList.Where(x => x.Tp == "auto" && (x.Description ?? "").Contains("[PASS]")).Select(x => x.Pid).FirstOrDefault();
  143. }
  144. /// <summary>
  145. /// 查询对应的结束流程环节Pid
  146. /// </summary>
  147. /// <param name="tableName"></param>
  148. /// <returns></returns>
  149. public List<int?> GetEndStatus(string tableName)
  150. {
  151. var statusList = this.GetStatusList(tableName);
  152. return statusList.Where(x => x.Tp == "end").Select(x => x.Pid).ToList();
  153. }
  154. /// <summary>
  155. /// 查询对应的结束流程环节且正常结束的流程环节Pid(注:结束环节且不为[BP]标识的)
  156. /// </summary>
  157. /// <param name="tableName"></param>
  158. /// <returns></returns>
  159. public int? GetCorrectEndStatus(string tableName)
  160. {
  161. var statusList = this.GetStatusList(tableName);
  162. return statusList.Where(x => x.Tp == "end" && !(x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).FirstOrDefault();
  163. }
  164. /// <summary>
  165. /// 查询重录待审,重新录入环节Pid(用于期末设定学生名单背景颜色)
  166. /// </summary>
  167. /// <param name="tableName"></param>
  168. /// <returns></returns>
  169. public List<int?> GetRebutStatus(string tableName)
  170. {
  171. var statusList = this.GetStatusList(tableName);
  172. return statusList.Where(x => (x.Description ?? "").Contains("[Rebut]")).Select(x => x.Pid).ToList();
  173. }
  174. /// <summary>
  175. /// 查询对应的接入流程表非正常结束的流程环节Pid(注:通常为结束环节且为[BP]标识的)
  176. /// </summary>
  177. /// <param name="tableName"></param>
  178. /// <returns></returns>
  179. public List<int?> GetBackpointStatus(string tableName)
  180. {
  181. var statusList = this.GetStatusList(tableName);
  182. return statusList.Where(x => (x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).ToList();
  183. }
  184. /// <summary>
  185. /// 查询对应的接入流程表中开始环节、审核流程环节Pid(注:不包含结束、非正常[BP]结束环节)
  186. /// </summary>
  187. /// <param name="tableName"></param>
  188. /// <returns></returns>
  189. public List<int?> GetStartApproveStatusList(string tableName)
  190. {
  191. try
  192. {
  193. return this.GetStatusList(tableName).Where(x => x.Tp != "end" && !(x.Description ?? "").Contains("[BP]"))
  194. .Select(x => x.Pid).ToList();
  195. }
  196. catch (Exception ex)
  197. {
  198. throw new Exception(ex.Message);
  199. }
  200. }
  201. /// <summary>
  202. /// 查询对应的接入流程表中全部流程环节信息(WorkflowStatusView)
  203. /// </summary>
  204. /// <param name="tableName"></param>
  205. /// <returns></returns>
  206. public List<WorkflowStatusView> GetStatusViewList(string tableName)
  207. {
  208. return this.GetStatusList(tableName).Select(x => new WorkflowStatusView
  209. {
  210. ID = x.Pid,
  211. Name = x.PName,
  212. Description = x.Description ?? ""
  213. }).OrderBy(x => x.ID).ToList();
  214. }
  215. /// <summary>
  216. /// 查询对应的接入流程表中审核流程环节信息(WorkflowStatusView,不包含开始、结束、非正常[BP]结束环节)
  217. /// </summary>
  218. /// <param name="tableName"></param>
  219. /// <returns></returns>
  220. public List<WorkflowStatusView> GetApproveStatusViewList(string tableName)
  221. {
  222. try
  223. {
  224. return this.GetStatusList(tableName).Where(x => x.Tp != "start" && x.Tp != "end" && !(x.Description ?? "").Contains("[BP]"))
  225. .Select(x => new WorkflowStatusView
  226. {
  227. ID = x.Pid,
  228. Name = x.PName,
  229. Description = x.Description ?? ""
  230. }).OrderBy(x => x.ID).ToList();
  231. }
  232. catch (Exception ex)
  233. {
  234. throw new Exception(ex.Message);
  235. }
  236. }
  237. /// <summary>
  238. /// 查询对应的接入流程表中全部非开始流程环节信息(WorkflowStatusView,不包含开始环节)
  239. /// </summary>
  240. /// <param name="tableName"></param>
  241. /// <returns></returns>
  242. public List<WorkflowStatusView> GetNoStartStatusViewList(string tableName)
  243. {
  244. try
  245. {
  246. return this.GetStatusList(tableName).Where(x => x.Tp != "start")
  247. .Select(x => new WorkflowStatusView
  248. {
  249. ID = x.Pid,
  250. Name = x.PName,
  251. Description = x.Description ?? ""
  252. })
  253. .OrderBy(x => x.ID).ToList();
  254. }
  255. catch (Exception ex)
  256. {
  257. throw new Exception(ex.Message);
  258. }
  259. }
  260. /// <summary>
  261. /// 查询对应的接入流程表中全部结束流程环节信息
  262. /// </summary>
  263. /// <param name="tableName"></param>
  264. /// <returns></returns>
  265. public List<WorkflowStatusView> GetEndStatusViewList(string tableName)
  266. {
  267. try
  268. {
  269. return this.GetStatusList(tableName).Where(x => x.Tp == "end")
  270. .Select(x => new WorkflowStatusView
  271. {
  272. ID = x.Pid,
  273. Name = x.PName,
  274. Description = x.Description ?? ""
  275. }).OrderBy(x => x.ID).ToList();
  276. }
  277. catch (Exception ex)
  278. {
  279. throw new Exception(ex.Message);
  280. }
  281. }
  282. /// <summary>
  283. /// 查询工作流程中是否有对应的权限(根据对应的信息-处理人、处理人标识)
  284. /// </summary>
  285. /// <param name="tableName"></param>
  286. /// <param name="userID"></param>
  287. /// <param name="formIDs"></param>
  288. /// <param name="dataRangeUserFunc"></param>
  289. /// <returns></returns>
  290. private bool IsCanSubmit(string tableName, Guid userID, List<Guid> formIDs,
  291. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  292. {
  293. bool isMatched = false;
  294. //获取当前用户
  295. var user = UserServices.Value.GetUserByID(userID);
  296. this.InitVerificationModel();
  297. List<PlugworkflowServices.NextDetailModel> listNetxtDetail = this.GetStatusList(tableName)
  298. .Where(x => x.Tp == "start").ToList();
  299. var userAndRoleList = listNetxtDetail.SelectMany(x => x.PendingUserType.Split(',')).Distinct().ToList();
  300. var posibleUserList = UserServices.Value.GetUserListByLoginID(userAndRoleList);
  301. IList<Sys_Role> listrole = UserServices.Value.GetUserRoles(user.UserID);
  302. foreach (var listDetail in listNetxtDetail)
  303. {
  304. var pandingUserList = listDetail.PendingUserType.Split(',');
  305. for (int i = 0; i < pandingUserList.Length; i++)
  306. {
  307. string userAndrole = pandingUserList[i]; //获取工作流配置处理人的ID
  308. var userlist = posibleUserList.FirstOrDefault(x => x.LoginID == userAndrole);
  309. //判断工作流配置处理是否是用户操作还是角色操作处理
  310. if (userlist != null)
  311. {
  312. if (userlist.UserID == userID)
  313. {
  314. isMatched = true;
  315. }
  316. }
  317. else
  318. {
  319. //如果配置角色和当前登录人角色对应
  320. foreach (var role in listrole)
  321. {
  322. if (userAndrole == role.RoleName)
  323. {
  324. isMatched = true;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. if (!isMatched)
  331. {
  332. return false;
  333. }
  334. if (dataRangeUserFunc != null)
  335. {
  336. return dataRangeUserFunc(formIDs, userID);
  337. }
  338. return true;
  339. }
  340. /// <summary>
  341. /// 查询工作流程中是否有对应的操作权限——动作(根据对应的信息-处理人、处理人标识)
  342. /// </summary>
  343. /// <param name="tableName">主表表名</param>
  344. /// <param name="userID">用户ID</param>
  345. /// <param name="actionID">审核动作ID(路由ID)</param>
  346. /// <param name="formIDs">表单ID列表</param>
  347. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  348. /// <returns></returns>
  349. public bool IsCanApprove(string tableName, Guid userID, Guid actionID, List<Guid> formIDs,
  350. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  351. {
  352. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  353. List<string> instanceIDList = new List<string>();
  354. List<string> list = new List<string>();
  355. //获取当前用户
  356. var user = UserServices.Value.GetUserByID(userID);
  357. var role = UserServices.Value.GetUserRoles(userID);
  358. this.InitVerificationModel();
  359. //流程关联表
  360. List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  361. .Where(x => x.TableName == tableName && formIDs.Contains((Guid)x.formID)).ToList();
  362. if (processRelationList.Count > 0)
  363. instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
  364. PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm); //读取待办
  365. if (pwrm.doNum == 1)
  366. {
  367. var userPendingWorkList = pwrm.resultDataList.GroupBy(x => x.InstanceID)
  368. .Where(x => !x.Any(n => role.Any(w => w.RoleName == n.PendingUsers) || n.PendingUsers == user.LoginID)).ToList();
  369. if (userPendingWorkList.Count > 0)
  370. {
  371. return false;
  372. }
  373. }
  374. if (dataRangeUserFunc != null)
  375. {
  376. return dataRangeUserFunc.Invoke(formIDs, userID);
  377. }
  378. return true;
  379. }
  380. /// <summary>
  381. ///
  382. /// </summary>
  383. /// <param name="tableName"></param>
  384. /// <param name="userID"></param>
  385. /// <param name="formIDs"></param>
  386. /// <returns></returns>
  387. public List<WorkflowPermissionView> IsCanApprove(string tableName, Guid userID, List<Guid> formIDs)
  388. {
  389. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  390. List<string> instanceIDList = new List<string>();
  391. List<string> list = new List<string>();
  392. //获取当前用户
  393. var user = UserServices.Value.GetUserByID(userID);
  394. var role = UserServices.Value.GetUserRoles(userID);
  395. this.InitVerificationModel();
  396. //流程关联表
  397. List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  398. .Where(x => x.TableName == tableName && formIDs.Contains((Guid)x.formID)).ToList();
  399. if (processRelationList.Count > 0)
  400. instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
  401. PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm); //读取待办
  402. if (pwrm.doNum == 1)
  403. {
  404. var userPendingWorkList = pwrm.resultDataList.GroupBy(x => x.InstanceID)
  405. .Where(x => x.Any(n => role.Any(w => w.RoleName == n.PendingUsers) || n.PendingUsers == user.LoginID)).ToList();
  406. var permissionResult = (from fid in formIDs
  407. join pr in processRelationList on fid equals pr.formID into dpr
  408. from pr in dpr.DefaultIfEmpty()
  409. join upw in userPendingWorkList on pr.InstanceID equals upw.Key into dupw
  410. from upw in dupw.DefaultIfEmpty()
  411. select new { FormID = fid, IsCanApprove = (pr != null && upw != null) } into result
  412. group result by new { result.FormID, result.IsCanApprove } into g
  413. select new WorkflowPermissionView { FormID = g.Key.FormID, IsCanApprove = g.Key.IsCanApprove }).ToList();
  414. return permissionResult;
  415. }
  416. else
  417. {
  418. throw new Exception(pwrm.doMessage);
  419. }
  420. }
  421. /// <summary>
  422. /// 重载方法,启动对应的流程并执行指定的动作至下一环节(提交),适用于开始节点有两个以上动作时
  423. /// </summary>
  424. /// <param name="tableName">主表表名</param>
  425. /// <param name="formID">需要提交的记录主键ID</param>
  426. /// <param name="userID">提交人ID</param>
  427. /// <param name="userID">动作ID</param>
  428. /// <param name="comment">提交意见</param>
  429. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  430. public void StartUp(string tableName, Guid formID, Guid userID, Guid actionID, string comment,
  431. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  432. {
  433. try
  434. {
  435. //查询接入流程表ID
  436. string AppID = this.GetAppIDByTableName(tableName);
  437. string instanceID = string.Empty;
  438. bool isCanSubmit = this.IsCanSubmit(tableName, userID, new List<Guid> { formID }, dataRangeUserFunc);
  439. if (!isCanSubmit)
  440. {
  441. throw new Exception("对不起,您没权限进行操作。");
  442. }
  443. //获取当前用户
  444. var user = UserServices.Value.GetUserByID(userID);
  445. this.InitVerificationModel();
  446. PlugworkflowServices.NextDetailModel listNetxtDetail = this.GetStatusList(tableName)
  447. .Where(x => x.Tp == "start").FirstOrDefault();
  448. var pendingUserList = listNetxtDetail.PendingUserType.Split(',');
  449. //流程关联表
  450. Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  451. .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
  452. if (processRelation != null)
  453. instanceID = processRelation.InstanceID;
  454. if (string.IsNullOrEmpty(instanceID)) //判断是否已经存在流程如果存在就直接提交审核
  455. {
  456. var result = client.InstanceProcessStart(AppID, "", user.LoginID, vm); //启动流程
  457. if (result.doNum == 1)
  458. {
  459. PendingWorkItem pwi = result.resultDataList.FirstOrDefault(); //转换
  460. ProcessRelationServices.Value.ProcessRelationAdd(formID, pwi.InstanceID, tableName); //保存流程关联表
  461. }
  462. else
  463. {
  464. throw new Exception(result.doMessage);
  465. }
  466. }
  467. try
  468. {
  469. //判断是否卡在开始环节,否则不能随便审核
  470. var result = client.PendingWorkList("", "", AppID, instanceID, "", "", "A", "1", "100", vm);
  471. if (result.doNum == 1)
  472. {
  473. if (result.resultDataList.Length == 0)
  474. {
  475. throw new Exception("该环节并无后续动作,无法提交。");
  476. }
  477. var instanceProcessModel = result.resultDataList.FirstOrDefault();
  478. if (instanceProcessModel.PID == this.GetStartStatus(tableName))
  479. {
  480. Approve(tableName, formID, userID, actionID, comment, dataRangeUserFunc);
  481. }
  482. else
  483. {
  484. throw new Exception("该流程已经提交,不能重复提交。");
  485. }
  486. }
  487. else
  488. {
  489. throw new Exception(result.doMessage);
  490. }
  491. }
  492. catch (Exception ex)
  493. {
  494. throw new Exception(ex.Message);
  495. }
  496. }
  497. catch (Exception ex)
  498. {
  499. throw new Exception(ex.Message);
  500. }
  501. }
  502. /// <summary>
  503. /// 启动对应的流程并执行指定的动作至下一环节(提交)
  504. /// </summary>
  505. /// <param name="tableName">主表表名</param>
  506. /// <param name="formID">需要提交的记录主键ID</param>
  507. /// <param name="userID">提交人ID</param>
  508. /// <param name="comment">提交意见</param>
  509. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  510. public void StartUp(string tableName, Guid formID, Guid userID, string comment = "",
  511. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  512. {
  513. this.StartUp(tableName, formID, userID, Guid.Empty, comment, dataRangeUserFunc);
  514. }
  515. /// <summary>
  516. /// 启动对应的流程并执行指定的动作至下一环节(提交)
  517. /// </summary>
  518. /// <param name="tableName">主表表名</param>
  519. /// <param name="formIDList">需要提交的记录主键ID</param>
  520. /// <param name="userID">提交人ID</param>
  521. /// <param name="actionID">动作ID</param>
  522. /// <param name="comment">提交意见</param>
  523. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  524. public void BatchStartUp(string tableName, List<Guid> formIDList, Guid userID, string comment,
  525. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  526. {
  527. try
  528. {
  529. //查询接入流程表ID
  530. if (formIDList.Count == 0)
  531. {
  532. return;
  533. }
  534. string AppID = this.GetAppIDByTableName(tableName);
  535. List<string> instanceIDList = new List<string>();
  536. bool isCanSubmit = this.IsCanSubmit(tableName, userID, formIDList, dataRangeUserFunc);
  537. if (!isCanSubmit)
  538. {
  539. throw new Exception("对不起,您没权限进行操作。");
  540. }
  541. var newProcessRelationList = new List<BaseProcessRelationView>();
  542. //获取当前用户
  543. var user = UserServices.Value.GetUserByID(userID);
  544. this.InitVerificationModel();
  545. PlugworkflowServices.NextDetailModel listNetxtDetail = this.GetStatusList(tableName)
  546. .Where(x => x.Tp == "start").FirstOrDefault();
  547. var pendingUserList = listNetxtDetail.PendingUserType.Split(',');
  548. //流程关联表
  549. List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  550. .Where(x => x.TableName == tableName && formIDList.Contains((Guid)x.formID)).ToList();
  551. if (processRelationList.Count > 0)
  552. instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
  553. var newProcessList = (from fid in formIDList
  554. join pr in processRelationList on fid equals pr.formID into dpr
  555. from pr in dpr.DefaultIfEmpty()
  556. where pr == null
  557. select fid).ToList();
  558. if (newProcessList.Count > 0) //判断是否已经存在流程如果存在就直接提交审核
  559. {
  560. var result = client.InstanceProcessBatchStart(newProcessList.Count, AppID, "", user.LoginID, vm); //启动流程
  561. if (result.doNum == 1)
  562. {
  563. List<PendingWorkItem> pwi = result.resultDataList.ToList(); //转换
  564. for (var i = 0; i < newProcessList.Count; i ++ )
  565. {
  566. newProcessRelationList.Add(new BaseProcessRelationView { FormID = newProcessList[i], InstanceID = pwi[i].InstanceID });
  567. instanceIDList.Add(pwi[i].InstanceID);
  568. }
  569. ProcessRelationServices.Value.ProcessRelationAdd(newProcessRelationList, tableName); //保存流程关联表
  570. }
  571. else
  572. {
  573. throw new Exception(result.doMessage);
  574. }
  575. }
  576. try
  577. {
  578. //判断是否卡在开始环节,否则不能随便审核
  579. var result = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm);
  580. if (result.doNum == 1)
  581. {
  582. var noNextList = instanceIDList.Where(x => !result.resultDataList.Select(w => w.InstanceID).Contains(x)).ToList();
  583. if (noNextList.Count > 0)
  584. {
  585. throw new Exception("部分数据在该环节并无后续动作,无法提交,可能由于没有配置相应权限,请联系系统管理员检查。");
  586. }
  587. var instanceProcessModel = result.resultDataList.FirstOrDefault();
  588. if (instanceProcessModel.PID == this.GetStartStatus(tableName))
  589. {
  590. BatchApprove(tableName, formIDList, userID, Guid.Empty, comment, dataRangeUserFunc);
  591. }
  592. else
  593. {
  594. throw new Exception("该流程已经提交,不能重复提交。");
  595. }
  596. }
  597. else
  598. {
  599. throw new Exception(result.doMessage);
  600. }
  601. }
  602. catch (Exception ex)
  603. {
  604. throw new Exception(ex.Message);
  605. }
  606. }
  607. catch (Exception ex)
  608. {
  609. throw new Exception(ex.Message);
  610. }
  611. }
  612. /// <summary>
  613. /// 审核流程(不包括提交——不包含流程启动)
  614. /// </summary>
  615. /// <param name="tableName">主表表名</param>
  616. /// <param name="formID">需要审核的记录主键ID</param>
  617. /// <param name="userID">审核人ID</param>
  618. /// <param name="actionID">审核动作ID</param>
  619. /// <param name="comment">提交意见</param>
  620. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  621. public void Approve(string tableName, Guid formID, Guid userID, Guid actionID, string comment = "",
  622. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  623. {
  624. try
  625. {
  626. //接入流程表ID
  627. string AppID = this.GetAppIDByTableName(tableName);
  628. string instanceID = string.Empty;
  629. List<string> nextWorkby = new List<string>();
  630. IList<Sys_User> dataRangeUserList = new List<Sys_User>();
  631. bool isCanApprove = this.IsCanApprove(tableName, userID, actionID, new List<Guid> { formID }, dataRangeUserFunc);
  632. //获取有权限审核的用户
  633. if (!isCanApprove)
  634. {
  635. throw new Exception("对不起,您没权限进行操作。");
  636. }
  637. //获取当前用户
  638. var user = UserServices.Value.GetUserByID(userID);
  639. var roleList = UserServices.Value.GetUserRoles(userID);
  640. this.InitVerificationModel();
  641. var startStepList = this.GetStatusList(tableName).Where(x => x.Tp == "start").ToList();
  642. var endStepList = this.GetStatusList(tableName).Where(x => x.Tp == "end").ToList();
  643. //流程关联表
  644. Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  645. .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
  646. if (processRelation != null)
  647. instanceID = processRelation.InstanceID;
  648. PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, instanceID, "",
  649. "", "A", "1", "100", vm); //读取待办
  650. if (pwrm.doNum == 1)
  651. {
  652. var userPendingWorkList = pwrm.resultDataList.Where(x => roleList.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
  653. if (userPendingWorkList.Count == 0)
  654. {
  655. throw new Exception("对不起,您没权限进行操作。");
  656. }
  657. foreach (var itempwi in userPendingWorkList)
  658. {
  659. if (itempwi.WorkTime == null)
  660. {
  661. List<NextStepModel> nextStepList = null;
  662. var processItemResultModel = client.ProcessLoadNextDetail(itempwi.InstanceProcessID, vm); //获取流程明细
  663. if (processItemResultModel.resultDataItem.Tp == "start")
  664. {
  665. throw new Exception("当前流程并未提交,请先提交再进行审核。");
  666. }
  667. if (processItemResultModel.resultDataItem.Tp == "end")
  668. {
  669. throw new Exception("当前流程已经结束,无法审核。");
  670. }
  671. //判断是否有指定下一步动作
  672. if (actionID != null && actionID != Guid.Empty)
  673. nextStepList = processItemResultModel.resultDataItem.NextSteps
  674. .Where(x => x.ActionID == actionID.ToString()).ToList(); //获取下一步用户
  675. else
  676. nextStepList = processItemResultModel.resultDataItem.NextSteps.ToList(); //获取下一步用户
  677. //根据角色ID 获取用户ID
  678. foreach (var itemnext in nextStepList)
  679. {
  680. string nextActionID = itemnext.ActionID.ToString();
  681. string methodName = itemnext.ActionFunc;
  682. int pid = itemnext.Pid;
  683. //if (startStepList.Any(x => x.Pid == itemnext.Pid)) //如果是提交到起始环节
  684. //{
  685. // ProcessDetailResultModel pdrm = client.LoadProcessDetails(AppID, instanceID, vm); //获取处理记录
  686. // if (pdrm.doNum == 1)
  687. // {
  688. // //获取开始环节信息
  689. // InstanceProcessModel ipm = pdrm.resultDataList.Where(x => x.tp == "start").FirstOrDefault();
  690. // if (ipm != null)
  691. // {
  692. // //获取下一步的待办名单
  693. // nextWorkby.Add(ipm.WorkBy);
  694. // }
  695. // }
  696. //}
  697. //else
  698. if (endStepList.Any(x => x.Pid == pid))
  699. {
  700. nextWorkby = new List<string>();
  701. }
  702. else
  703. {
  704. //获取下一步的待办名单
  705. nextWorkby = itemnext.PendingUserType.Split(',').ToList();
  706. }
  707. if (nextWorkby.Count == 0 && !endStepList.Any(x => x.Pid == pid))
  708. {
  709. throw new Exception("后续的流程环节并没有适合的审批人,无法提交。");
  710. }
  711. if (!string.IsNullOrEmpty(methodName))
  712. {
  713. ReflectorHelper.RunMethod(methodName, new List<Guid>() { formID }, userID);
  714. }
  715. //推送下一步流程
  716. ResultModel rm = client.ProcessMoveNext(itempwi.InstanceProcessID, nextActionID
  717. , new ActionFunc[] { }, nextWorkby.Distinct().ToArray(), comment, user.LoginID, new string[] { }, vm);
  718. if (rm.doNum != 1)
  719. throw new Exception(rm.doMessage);
  720. else
  721. {
  722. var entity = UnitOfWork.Set(this.GetEntityType(tableName)).Find(formID);
  723. dynamic dyEntity = entity;
  724. var entityType = entity.GetType();
  725. if (entityType.GetProperty("ApprovalStatus") != null)
  726. {
  727. dyEntity.ApprovalStatus = pid;
  728. }
  729. else if (entityType.GetProperty("RecordStatus") != null)
  730. {
  731. dyEntity.RecordStatus = pid;
  732. }
  733. UnitOfWork.Update(dyEntity);
  734. UnitOfWork.Commit();
  735. this.SendMobileMQ(formID, nextWorkby.ToArray());
  736. return;
  737. }
  738. }
  739. }
  740. }
  741. }
  742. else
  743. {
  744. throw new Exception(pwrm.doMessage);
  745. }
  746. }
  747. catch (Exception ex)
  748. {
  749. throw new Exception(ex.Message);
  750. }
  751. }
  752. /// <summary>
  753. /// 审核流程(不包括提交——不包含流程启动)
  754. /// </summary>
  755. /// <param name="tableName">主表表名</param>
  756. /// <param name="formID">需要审核的记录主键ID</param>
  757. /// <param name="userID">审核人ID</param>
  758. /// <param name="actionID">审核动作ID</param>
  759. /// <param name="comment">提交意见</param>
  760. /// <param name="dataRangeUserFunc">获取数据范围用户的方法</param>
  761. public void BatchApprove(string tableName, List<Guid> formIDList, Guid userID, Guid actionID, string comment = "",
  762. Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
  763. {
  764. try
  765. {
  766. if (formIDList.Count == 0)
  767. {
  768. return;
  769. }
  770. //接入流程表ID
  771. string AppID = this.GetAppIDByTableName(tableName);
  772. List<string> instanceIDList = new List<string>();
  773. List<string> nextWorkby = new List<string>();
  774. IList<Sys_User> dataRangeUserList = new List<Sys_User>();
  775. string approveMethodName = null;
  776. string nextActionID = null;
  777. int? pid = null;
  778. bool isCanApprove = this.IsCanApprove(tableName, userID, actionID, formIDList, dataRangeUserFunc);
  779. //获取有权限审核的用户
  780. if (!isCanApprove)
  781. {
  782. throw new Exception("对不起,您没权限进行操作。");
  783. }
  784. //获取当前用户
  785. var user = UserServices.Value.GetUserByID(userID);
  786. var roleList = UserServices.Value.GetUserRoles(userID);
  787. this.InitVerificationModel();
  788. var startStepList = this.GetStatusList(tableName).Where(x => x.Tp == "start").ToList();
  789. var endStepList = this.GetStatusList(tableName).Where(x => x.Tp == "end").ToList();
  790. //流程关联表
  791. List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  792. .Where(x => x.TableName == tableName && formIDList.Contains((Guid)x.formID)).ToList();
  793. if (processRelationList.Count == formIDList.Count)
  794. instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
  795. else
  796. throw new Exception("部分记录并未提交,无法直接审核。");
  797. PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm); //读取待办
  798. if (pwrm.doNum == 1)
  799. {
  800. var userPendingWorkList = pwrm.resultDataList.Where(x => roleList.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
  801. if (userPendingWorkList.Select(x => x.InstanceID).Distinct().Count() != formIDList.Count)
  802. {
  803. throw new Exception("对不起,对于部分数据,您没权限进行操作,请重新选择数据提交。");
  804. }
  805. if (userPendingWorkList.GroupBy(x => new { x.AppID, x.PID }).Count() > 1)
  806. {
  807. throw new Exception("需要审批的数据状态不一致,不能批量审核,请重新选择数据提交。");
  808. }
  809. var processItemResultModelList = client.ProcessBatchLoadNextDetail(userPendingWorkList.Select(x => x.InstanceProcessID).ToArray(), vm);
  810. if (processItemResultModelList.doNum != 1)
  811. {
  812. throw new Exception("流程信息读取失败。", new Exception(processItemResultModelList.doMessage));
  813. }
  814. foreach (var itempwi in userPendingWorkList)
  815. {
  816. if (itempwi.WorkTime == null)
  817. {
  818. List<NextStepModel> nextStepList = null;
  819. var processItemResultModel = processItemResultModelList.resultDataItemList.FirstOrDefault(x => x.ID == itempwi.InstanceProcessID); //获取流程明细
  820. if (processItemResultModel == null)
  821. {
  822. throw new Exception("流程信息读取失败。");
  823. }
  824. if (processItemResultModel.Tp == "start")
  825. {
  826. throw new Exception("当前流程并未提交,请先提交再进行审核。");
  827. }
  828. if (processItemResultModel.Tp == "end")
  829. {
  830. throw new Exception("当前流程已经结束,无法审核。");
  831. }
  832. //判断是否有指定下一步动作
  833. if (actionID != null && actionID != Guid.Empty)
  834. nextStepList = processItemResultModel.NextSteps
  835. .Where(x => x.ActionID == actionID.ToString()).ToList(); //获取下一步用户
  836. else
  837. nextStepList = processItemResultModel.NextSteps.ToList(); //获取下一步用户
  838. //根据角色ID 获取用户ID
  839. foreach (var itemnext in nextStepList)
  840. {
  841. nextActionID = itemnext.ActionID.ToString();
  842. approveMethodName = itemnext.ActionFunc;
  843. pid = itemnext.Pid;
  844. if (endStepList.Any(x => x.Pid == pid))
  845. {
  846. nextWorkby = new List<string>();
  847. }
  848. else
  849. {
  850. //获取下一步的待办名单
  851. nextWorkby = itemnext.PendingUserType.Split(',').ToList();
  852. }
  853. if (nextWorkby.Count == 0 && !endStepList.Any(x => x.Pid == pid))
  854. {
  855. throw new Exception("后续的流程环节并没有适合的审批人,无法提交。");
  856. }
  857. }
  858. }
  859. }
  860. using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(1, 0, 0)))
  861. {
  862. if (!string.IsNullOrEmpty(approveMethodName))
  863. {
  864. ReflectorHelper.RunMethod(approveMethodName, formIDList, userID);
  865. }
  866. //推送下一步流程
  867. ResultModel rm = client.ProcessBatchMoveNext(userPendingWorkList.Select(x => x.InstanceProcessID).ToArray(), nextActionID
  868. , new ActionFunc[] { }, nextWorkby.Distinct().ToArray(), comment, user.LoginID, new string[] { }, vm);
  869. if (rm.doNum != 1)
  870. throw new Exception(rm.doMessage);
  871. else
  872. {
  873. IDictionary<string, object> updateKeyValueList = new Dictionary<string, object>();
  874. var entityType = this.GetEntityType(tableName);
  875. if (entityType.GetProperty("ApprovalStatus") != null)
  876. {
  877. updateKeyValueList.Add("ApprovalStatus", pid.Value);
  878. }
  879. else if (entityType.GetProperty("RecordStatus") != null)
  880. {
  881. updateKeyValueList.Add("RecordStatus", pid);
  882. }
  883. foreach (var formID in formIDList)
  884. {
  885. this.SendMobileMQ(formID, nextWorkby.ToArray());
  886. }
  887. UnitOfWork.BatchUpdate(tableName, updateKeyValueList, formIDList);
  888. scope.Complete();
  889. return;
  890. }
  891. }
  892. }
  893. else
  894. {
  895. throw new Exception(pwrm.doMessage);
  896. }
  897. }
  898. catch (Exception ex)
  899. {
  900. throw new Exception(ex.Message);
  901. }
  902. }
  903. /// <summary>
  904. /// 工作流流程状态修改(通常用于取消申请、撤销等环节)
  905. /// </summary>
  906. /// <param name="tableName">主表表名</param>
  907. /// <param name="formID">表单ID</param>
  908. /// <param name="status">状态:A为活动,D为结束、其他的自己定义</param>
  909. /// <param name="description">描述改变内容</param>
  910. public void ModifyProcessState(string tableName, Guid formID, string status, string description)
  911. {
  912. try
  913. {
  914. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  915. string instanceID = string.Empty;
  916. List<string> list = new List<string>();
  917. //流程关联表
  918. Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  919. .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
  920. if (processRelation != null)
  921. instanceID = processRelation.InstanceID;
  922. this.InitVerificationModel();
  923. ResultModel rm = client.InstanceProcessChange(instanceID, status, description, vm);
  924. if (rm.doNum != 1)
  925. {
  926. throw new Exception(rm.doMessage);
  927. }
  928. }
  929. catch (Exception ex)
  930. {
  931. throw new Exception(ex.Message);
  932. }
  933. }
  934. /// <summary>
  935. /// 根据当前流程环节ID获取下一步审批动作
  936. /// </summary>
  937. /// <param name="tableName">主表表名</param>
  938. /// <param name="formID">表单ID</param>
  939. /// <param name="userID">当前用户ID</param>
  940. /// <returns></returns>
  941. public List<ActionView> GetActionView(string tableName, Guid formID, Guid userID)
  942. {
  943. try
  944. {
  945. List<ActionView> listAction = new List<ActionView>();
  946. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  947. string instanceID = string.Empty;
  948. Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  949. .Where(x => x.formID == formID && x.TableName == tableName).FirstOrDefault();
  950. if (processRelation != null)
  951. instanceID = processRelation.InstanceID;
  952. this.InitVerificationModel();
  953. var user = UserServices.Value.GetUserByID(userID);
  954. var role = UserServices.Value.GetUserRoles(userID);
  955. PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, instanceID, "", "", "A", "1", "100", vm); //读取待办
  956. if (pwrm != null)
  957. {
  958. var userPendingWorkList = pwrm.resultDataList.Where(x => role.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
  959. if (userPendingWorkList.Count == 0)
  960. {
  961. throw new Exception("对不起,您没权限进行操作。");
  962. }
  963. List<PendingWorkItem> listpwi = userPendingWorkList.Take(1).ToList();
  964. foreach (var itempwi in listpwi)
  965. {
  966. if (itempwi.WorkTime == null)
  967. {
  968. var processItemResultModel = client.ProcessLoadNextDetail(itempwi.InstanceProcessID, vm); //获取动作
  969. List<NextStepModel> listnext = processItemResultModel.resultDataItem.NextSteps.OrderBy(x => x.sort).ToList(); //获取下一步用户
  970. foreach (var item in listnext)
  971. {
  972. ActionView action = new ActionView();
  973. action.ActionID = new Guid(item.ActionID);
  974. action.ActionName = item.AName;
  975. action.PendingUser = item.PendingUserType;
  976. action.PendingUserName = item.PendingUser;
  977. action.StepName = item.PName;
  978. action.Sort = item.sort;
  979. action.Description = item.ADescription;
  980. listAction.Add(action);
  981. }
  982. }
  983. }
  984. }
  985. return listAction;
  986. }
  987. catch (Exception ex)
  988. {
  989. throw (new Exception(ex.Message));
  990. }
  991. }
  992. /// <summary>
  993. /// 重载方法,根据当前流程环节ID获取全部审批动作
  994. /// </summary>
  995. /// <param name="tableName">主表表名</param>
  996. /// <returns></returns>
  997. public List<ActionView> GetActionView(string tableName)
  998. {
  999. try
  1000. {
  1001. List<NextDetailModel> statusLists = GetStatusList(tableName);
  1002. List<ActionView> listAction = new List<ActionView>();
  1003. foreach (var statusList in statusLists)
  1004. {
  1005. foreach (var item in statusList.NextSteps)
  1006. {
  1007. ActionView action = new ActionView();
  1008. action.ActionID = new Guid(item.ActionID);
  1009. action.ActionName = item.AName;
  1010. action.PendingUser = item.PendingUserType;
  1011. action.PendingUserName = item.PendingUser;
  1012. action.StepName = item.PName;
  1013. action.Pid = statusList.Pid;
  1014. action.ToPid = item.Pid;
  1015. action.Sort = item.sort;
  1016. listAction.Add(action);
  1017. }
  1018. }
  1019. return listAction;
  1020. }
  1021. catch (Exception ex)
  1022. {
  1023. throw (new Exception(ex.Message));
  1024. }
  1025. }
  1026. /// <summary>
  1027. /// 查询开始流程环节的动作列表List
  1028. /// </summary>
  1029. /// <param name="tableName">主表表名</param>
  1030. /// <returns></returns>
  1031. public List<ActionView> GetStartActionView(string tableName)
  1032. {
  1033. return this.GetStartStatusList(tableName).FirstOrDefault().NextSteps.Select(x => new ActionView
  1034. {
  1035. ActionID = new Guid(x.ActionID),
  1036. ActionName = x.AName,
  1037. StepName = x.AName,
  1038. Sort = x.sort,
  1039. Description = x.ADescription
  1040. }).ToList();
  1041. }
  1042. /// <summary>
  1043. /// 查询对应的审核历史信息列表List(WorkflowApproveHistoryView)
  1044. /// </summary>
  1045. /// <param name="tableName">主表表名</param>
  1046. /// <param name="formID">需要获取的记录主键ID</param>
  1047. /// <returns></returns>
  1048. public IList<ViewModel.SystemView.WorkflowApproveHistoryView> GetApproveHistoryViewList(string tableName, Guid formID)
  1049. {
  1050. try
  1051. {
  1052. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  1053. string InstanceID = string.Empty;
  1054. List<WorkflowApproveHistoryView> list = new List<WorkflowApproveHistoryView>();
  1055. this.InitVerificationModel();
  1056. Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
  1057. .Where(x => x.formID == formID && x.TableName == tableName).FirstOrDefault();
  1058. if (processRelation != null)
  1059. InstanceID = processRelation.InstanceID;
  1060. if (!string.IsNullOrEmpty(InstanceID))
  1061. {
  1062. ProcessDetailResultModel processDetailResultModel = client.LoadProcessDetails(AppID, InstanceID, vm);
  1063. List<InstanceProcessModel> listipm = processDetailResultModel.resultDataList
  1064. .Where(x => !string.IsNullOrEmpty(x.WorkBy))
  1065. .OrderBy(x => x.CreateTime).ToList();
  1066. foreach (var lt in listipm)
  1067. {
  1068. string userNo = string.Empty;
  1069. string username = string.Empty;
  1070. if (lt.WorkBy != null)
  1071. {
  1072. var userlist = UserServices.Value.GetUserByLoginID(lt.WorkBy);
  1073. if (userlist != null)
  1074. {
  1075. userNo = userlist.LoginID;
  1076. username = userlist.Name;
  1077. }
  1078. }
  1079. if (!list.Any(x => x.PID == lt.PID && x.ApproveUserName == username
  1080. && x.PName == lt.PName && x.ActionName == lt.ActionName
  1081. && x.ApproveTime == lt.WorkTime.ParseStrTo<DateTime>() && x.Comment == lt.Comment))
  1082. {
  1083. WorkflowApproveHistoryView wahv = new WorkflowApproveHistoryView();
  1084. wahv.ApproveHistoryID = lt.ID.ParseStrTo<Guid>();
  1085. wahv.PID = lt.PID;
  1086. wahv.ApproveUserNo = userNo;
  1087. wahv.ApproveUserName = username;
  1088. wahv.PName = lt.PName;
  1089. wahv.ActionName = lt.ActionName;
  1090. wahv.ApproveTime = lt.WorkTime.ParseStrTo<DateTime>();
  1091. wahv.Comment = lt.Comment;
  1092. list.Add(wahv);
  1093. }
  1094. }
  1095. }
  1096. return list;
  1097. }
  1098. catch (Exception ex)
  1099. {
  1100. throw new Exception(ex.Message);
  1101. }
  1102. }
  1103. /// <summary>
  1104. /// 获取待办列表
  1105. /// </summary>
  1106. /// <typeparam name="T"></typeparam>
  1107. /// <param name="tableName">主表表名</param>
  1108. /// <param name="query">查询视图,指定一个IQueryable决定如何获取表单记录</param>
  1109. /// <param name="userID">待办用户ID</param>
  1110. /// <param name="pkSelector">指定主键列</param>
  1111. /// <param name="pageIndex">页码</param>
  1112. /// <param name="pageSize">每页行数</param>
  1113. /// <returns></returns>
  1114. public IGridResultSet<T> QueryByPendingJob<T, TOrder>(string tableName, IQueryable<T> query, Guid userID,
  1115. Expression<Func<T, Guid>> pkSelector, Expression<Func<T, TOrder>> orderby, bool isDescending = false,
  1116. int? pageIndex = null, int? pageSize = null)
  1117. {
  1118. try
  1119. {
  1120. string AppID = this.GetAppIDByTableName(tableName); //流程ID
  1121. string InstanceID = string.Empty;
  1122. var user = UserServices.Value.GetUserByID(userID); //获取提交人
  1123. var role = UserServices.Value.GetUserRoles(userID);
  1124. this.InitVerificationModel();
  1125. var queryProessRelation = ProcessWorkfloconfigDAL.processRelationRepository.GetList(x => x.TableName == tableName);
  1126. PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, "", "", "", "A",
  1127. ((pageIndex ?? 0) + 1).ToString(), "9999", vm);
  1128. //访问接口成功
  1129. if (pwrm.doNum == 1)
  1130. {
  1131. var instanceIDList = pwrm.resultDataList.Where(x => role.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID)
  1132. .Select(x => x.InstanceID).ToList();
  1133. var queryprrm = queryProessRelation.Where(x => instanceIDList.Contains(x.InstanceID));
  1134. var result = query.Join(queryprrm, pkSelector, (x => (x.formID ?? Guid.Empty)), ((x, y) => x));
  1135. if (isDescending)
  1136. {
  1137. result = result.OrderByDescending(orderby);
  1138. }
  1139. else
  1140. {
  1141. result = result.OrderBy(orderby);
  1142. }
  1143. return result.ToGridResultSet(pageIndex, pageSize);
  1144. }
  1145. else
  1146. {
  1147. return new GridResultSet<T> { rows = new List<T>(), total = 0 };
  1148. }
  1149. }
  1150. catch (Exception ex)
  1151. {
  1152. throw new Exception(ex.Message);
  1153. }
  1154. }
  1155. /// <summary>
  1156. /// 推送下一个处理人标识
  1157. /// </summary>
  1158. /// <param name="formID"></param>
  1159. /// <param name="nextWorkbyArray"></param>
  1160. private void SendMobileMQ(Guid formID, string[] nextWorkbyArray)
  1161. {
  1162. if (this.MessageFunc == null)
  1163. {
  1164. return;
  1165. }
  1166. var userIDList = RoleDAL.RoleRepository.GetList(x => nextWorkbyArray.Contains(x.RoleName))
  1167. .SelectMany(x => x.Sys_User).Where(x => x.CF_Student.UserID != null).Distinct()
  1168. .Union(
  1169. RoleDAL.UserRepository.GetList(x => nextWorkbyArray.Contains(x.LoginID))
  1170. .Where(x => x.CF_Student.UserID != null))
  1171. .Select(x => x.UserID).ToList();
  1172. var message = this.MessageFunc.Invoke(formID);
  1173. MobileMQ.SendMessage(userIDList.Select(x => x.ToString()).ToArray(), message);
  1174. }
  1175. }
  1176. }