WorkflowDetail.razor.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using AntDesign;
  2. using Microsoft.AspNetCore.Components;
  3. using Microsoft.Extensions.Configuration;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity.workflowDefine;
  9. using wispro.sp.web.Services;
  10. namespace wispro.sp.web.Pages.Workflow
  11. {
  12. public partial class WorkflowDetail
  13. {
  14. Components.FlowChart chart;
  15. entity.workflowDefine.Workflow workflow;
  16. List<entity.workflowDefine.Step> Steps;
  17. List<entity.workflowDefine.Action> Actions;
  18. List<entity.workflowDefine.TrasferCondition> Transfers;
  19. List<InputValueSetting> inputValueSettings;
  20. UserField userField = new UserField();
  21. [Parameter]
  22. public int WorkflowId { get; set; }
  23. [Inject] protected MessageService _msgService { get; set; }
  24. [Inject] protected WorkflowService _wfService { get; set; }
  25. [Inject] protected IConfiguration _configuration { get; set; }
  26. string DownloadUrl;
  27. async Task InitData()
  28. {
  29. //int Id = int.Parse(WorkflowId.ToString());
  30. workflow = await _wfService.GetWorkflow(WorkflowId);
  31. Steps = await _wfService.GetSteps(WorkflowId);
  32. Actions = await _wfService.GetActions(WorkflowId);
  33. Transfers = await _wfService.GetTransfers(WorkflowId);
  34. DownloadUrl = $"{_configuration.GetValue<string>("APIUrl")}WorkflowEngine/ExportToImage?workflowId={workflow.Id}";
  35. }
  36. protected async override Task OnInitializedAsync()
  37. {
  38. await base.OnInitializedAsync();
  39. #region Demo流程数据
  40. await InitData();
  41. #endregion
  42. }
  43. void OnClickStep(entity.workflowDefine.Step step)
  44. {
  45. //_msgService.Info($"您点击了:【{step.Name}】步骤");
  46. }
  47. void OnDblClickStep(entity.workflowDefine.Step step)
  48. {
  49. bool b = (workflow.EndStepId != null && workflow.EndStepId.Value == step.Id);
  50. EditStep = new share.NewStepObject() { Step = step, isLastStep = b };
  51. try
  52. {
  53. userField = System.Text.Json.JsonSerializer.Deserialize<UserField>(step.defaultResponseSetting);
  54. }
  55. catch {
  56. userField = new UserField();
  57. }
  58. EditStep.actions = GetActions(step.Id);
  59. StepModalShow = true;
  60. }
  61. void OnClickAction(entity.workflowDefine.Action action)
  62. {
  63. //_msgService.Info($"您点击了:【{action.Name}】操作");
  64. }
  65. void OnClickTransfer(entity.workflowDefine.TrasferCondition transfer)
  66. {
  67. //_msgService.Info($"您点击了:从步骤【{transfer.StepId}】到步骤【{transfer.nextStepId}】的移转条件!");
  68. }
  69. share.NewStepObject EditStep;
  70. share.ActionObject EditAction;
  71. entity.workflowDefine.TrasferCondition EditTransfer;
  72. bool StepModalShow = false;
  73. bool ActionModalShow = false;
  74. bool TransferModalShow = false;
  75. void AddNewStep()
  76. {
  77. EditStep = new share.NewStepObject();
  78. EditStep.Step = new entity.workflowDefine.Step() { Name = "新步骤", stepType = 2, workflowId = workflow.Id };
  79. EditStep.actions = new List<share.ActionObject>();
  80. EditStep.isLastStep = false;
  81. userField = new UserField();
  82. StepModalShow = true;
  83. }
  84. void AddNewAction()
  85. {
  86. EditAction = new share.ActionObject();
  87. EditAction.Action = new entity.workflowDefine.Action();
  88. EditAction.Action.Name = "新操作";
  89. EditAction.InputValueSettingObjects = new List<share.InputValueSettingObject>();
  90. if (EditStep.NewActions == null)
  91. {
  92. EditStep.NewActions = new List<share.ActionObject>();
  93. }
  94. EditStep.NewActions.Add(EditAction);
  95. ActionModalShow = true;
  96. }
  97. async Task BeginEditAction(int Id)
  98. {
  99. EditAction = EditStep.actions.FirstOrDefault(a => a.Action.Id == Id);
  100. Console.WriteLine($"BeginEditAction-Begin:{System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  101. if (EditAction != null)
  102. {
  103. if ( EditAction.Action.Id >0)
  104. {
  105. EditAction.InputValueSettingObjects = await _wfService.getInputValueSteeing(EditAction.Action.Id);
  106. }
  107. ActionModalShow = true;
  108. }
  109. Console.WriteLine($"BeginEditAction-End:{System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  110. }
  111. async void DeleteAction(int Id)
  112. {
  113. var ret = await _wfService.DeleteAction(Id);
  114. if (!ret.Success)
  115. {
  116. await _msgService.Error("删除Action出错!");
  117. }
  118. else
  119. {
  120. Actions = await _wfService.GetActions(workflow.Id);
  121. EditStep.actions = GetActions(EditStep.Step.Id);
  122. }
  123. }
  124. void AddNewTransfer()
  125. {
  126. EditTransfer = new entity.workflowDefine.TrasferCondition();
  127. TransferModalShow = true;
  128. }
  129. List<share.ActionObject> GetActions(int stepId)
  130. {
  131. var actionList = Actions.Where<entity.workflowDefine.Action>(a=>a.StepId == stepId).ToList();
  132. List<share.ActionObject> retList = new List<share.ActionObject>();
  133. foreach(var ac in actionList)
  134. {
  135. share.ActionObject acobj = new share.ActionObject();
  136. acobj.Action = ac;
  137. retList.Add(acobj);
  138. }
  139. return retList;
  140. }
  141. async Task EditStepOK()
  142. {
  143. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(userField));
  144. EditStep.Step.defaultResponseSetting = System.Text.Json.JsonSerializer.Serialize(userField);
  145. var ret = await _wfService.SaveStep(EditStep);
  146. if (ret.Success)
  147. {
  148. StepModalShow = false;
  149. await InitData();
  150. }
  151. else
  152. {
  153. await _msgService.Error("保存出现错误!");
  154. }
  155. OnRefresh();
  156. }
  157. void EditStepCancel()
  158. {
  159. StepModalShow = false;
  160. }
  161. List<share.ActionObject> newActions;
  162. async Task EditActionOK()
  163. {
  164. if (EditStep != null)
  165. {
  166. if (!EditStep.actions.Contains(EditAction))
  167. {
  168. EditStep.actions.Add(EditAction);
  169. if (EditStep.NewActions == null)
  170. {
  171. EditStep.NewActions = new List<share.ActionObject>();
  172. }
  173. if (!EditStep.NewActions.Contains(EditAction))
  174. {
  175. EditStep.NewActions.Add(EditAction);
  176. }
  177. }
  178. else
  179. {
  180. if (EditStep.ModifyActions == null)
  181. {
  182. EditStep.ModifyActions = new List<share.ActionObject>();
  183. }
  184. }
  185. if (!EditStep.ModifyActions.Contains(EditAction))
  186. {
  187. EditStep.ModifyActions.Add(EditAction);
  188. }
  189. }
  190. ActionModalShow = false;
  191. }
  192. void EditActionCancel()
  193. {
  194. ActionModalShow = false;
  195. }
  196. async Task EditTransferOK()
  197. {
  198. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(EditTransfer));
  199. if(EditTransfer.StepId!= null && EditTransfer.StepId.Value == 0)
  200. {
  201. EditTransfer.StepId = null;
  202. }
  203. var ret = await _wfService.SaveTransfer(EditTransfer);
  204. if (ret.Success)
  205. {
  206. TransferModalShow = false;
  207. await InitData();
  208. }
  209. else {
  210. await _msgService.Error("保存出现错误!");
  211. }
  212. OnRefresh();
  213. }
  214. void EditTransferCancel()
  215. {
  216. TransferModalShow = false;
  217. }
  218. void OnRefresh()
  219. {
  220. chart.Refresh();
  221. StateHasChanged();
  222. }
  223. [Inject] ModalService _modalService { get; set; }
  224. async Task DeleteObject()
  225. {
  226. string strMsg = "";
  227. if (chart.SelectedObject != null)
  228. {
  229. if(chart.SelectedObject is entity.workflowDefine.TrasferCondition)
  230. {
  231. TrasferCondition transfer = chart.SelectedObject as TrasferCondition;
  232. await _wfService.DeleteTransfer(transfer);
  233. strMsg = (transfer.StepId == null) ? "开始" : transfer.Step.Name;
  234. strMsg = $"已删除{strMsg}的转移条件!";
  235. }
  236. if(chart.SelectedObject is entity.workflowDefine.Step)
  237. {
  238. await _wfService.DeleteStep((entity.workflowDefine.Step)chart.SelectedObject);
  239. strMsg = $"已删除步骤[{((entity.workflowDefine.Step)chart.SelectedObject).Name}]";
  240. }
  241. }
  242. await InitData();
  243. await _msgService.Info(strMsg);
  244. chart.Refresh();
  245. }
  246. }
  247. }