WorkflowDetail.razor.cs 11 KB

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