WorkflowDetail.razor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. async void OnDblClickAction(entity.workflowDefine.Action action)
  81. {
  82. if (action.Id == workflow.InitAction.Id)
  83. {
  84. EditAction = new share.ActionObject();
  85. EditAction.Action = action;
  86. }
  87. else
  88. {
  89. Console.WriteLine($"BeginEditAction-Begin:{System.Text.Json.JsonSerializer.Serialize(action)}");
  90. if (EditStep.actions != null)
  91. {
  92. EditAction = EditStep.actions.FirstOrDefault(a => a.Action.Id == action.Id);
  93. }
  94. }
  95. if (EditAction != null)
  96. {
  97. if (EditAction.Action.Id > 0)
  98. {
  99. EditAction.InputValueSettingObjects = await _wfService.getInputValueSteeing(EditAction.Action.Id);
  100. }
  101. ActionModalShow = true;
  102. }
  103. Console.WriteLine($"BeginEditAction-End:{System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  104. StateHasChanged();
  105. }
  106. void OnDblClickTransfer(entity.workflowDefine.TrasferCondition transfer)
  107. {
  108. EditTransfer = transfer;
  109. TransferModalShow = true;
  110. }
  111. share.NewStepObject EditStep;
  112. share.ActionObject EditAction;
  113. entity.workflowDefine.TrasferCondition EditTransfer;
  114. bool StepModalShow = false;
  115. bool ActionModalShow = false;
  116. bool TransferModalShow = false;
  117. void AddNewStep()
  118. {
  119. EditStep = new share.NewStepObject();
  120. EditStep.Step = new entity.workflowDefine.Step() { Name = "新步骤", stepType = 2, workflowId = workflow.Id };
  121. EditStep.actions = new List<share.ActionObject>();
  122. EditStep.isLastStep = false;
  123. userField = new UserField();
  124. StepModalShow = true;
  125. }
  126. void AddNewAction()
  127. {
  128. EditAction = new share.ActionObject();
  129. EditAction.Action = new entity.workflowDefine.Action();
  130. EditAction.Action.Name = "新操作";
  131. EditAction.InputValueSettingObjects = new List<share.InputValueSettingObject>();
  132. if (EditStep.NewActions == null)
  133. {
  134. EditStep.NewActions = new List<share.ActionObject>();
  135. }
  136. EditStep.NewActions.Add(EditAction);
  137. ActionModalShow = true;
  138. }
  139. async Task BeginEditAction(int Id)
  140. {
  141. EditAction = EditStep.actions.FirstOrDefault(a => a.Action.Id == Id);
  142. Console.WriteLine($"BeginEditAction-Begin:{System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  143. if (EditAction != null)
  144. {
  145. if ( EditAction.Action.Id >0)
  146. {
  147. EditAction.InputValueSettingObjects = await _wfService.getInputValueSteeing(EditAction.Action.Id);
  148. }
  149. ActionModalShow = true;
  150. }
  151. Console.WriteLine($"BeginEditAction-End:{System.Text.Json.JsonSerializer.Serialize(EditAction)}");
  152. }
  153. async void DeleteAction(int Id)
  154. {
  155. var ret = await _wfService.DeleteAction(Id);
  156. if (!ret.Success)
  157. {
  158. await _msgService.Error("删除Action出错!");
  159. }
  160. else
  161. {
  162. Actions = await _wfService.GetActions(workflow.Id);
  163. EditStep.actions = GetActions(EditStep.Step.Id);
  164. }
  165. }
  166. void AddNewTransfer()
  167. {
  168. EditTransfer = new entity.workflowDefine.TrasferCondition();
  169. TransferModalShow = true;
  170. }
  171. List<share.ActionObject> GetActions(int stepId)
  172. {
  173. var actionList = Actions.Where<entity.workflowDefine.Action>(a=>a.StepId == stepId).ToList();
  174. List<share.ActionObject> retList = new List<share.ActionObject>();
  175. foreach(var ac in actionList)
  176. {
  177. share.ActionObject acobj = new share.ActionObject();
  178. acobj.Action = ac;
  179. retList.Add(acobj);
  180. }
  181. return retList;
  182. }
  183. async Task EditStepOK()
  184. {
  185. JsonSerializerOptions options = new() { IgnoreNullValues = true };
  186. EditStep.Step.defaultResponseSetting = System.Text.Json.JsonSerializer.Serialize(userField,options);
  187. Console.WriteLine($"UsrValue={userField.UserValue},UserConditionType={userField.UserConditionType},UserType={userField.UserType}");
  188. Console.WriteLine(EditStep.Step.defaultResponseSetting);
  189. var ret = await _wfService.SaveStep(EditStep);
  190. if (ret.Success)
  191. {
  192. StepModalShow = false;
  193. await InitData();
  194. }
  195. else
  196. {
  197. await _msgService.Error("保存出现错误!");
  198. }
  199. OnRefresh();
  200. }
  201. void EditStepCancel()
  202. {
  203. StepModalShow = false;
  204. }
  205. List<share.ActionObject> newActions;
  206. async Task EditActionOK()
  207. {
  208. if (EditStep != null)
  209. {
  210. if (!EditStep.actions.Contains(EditAction))
  211. {
  212. EditStep.actions.Add(EditAction);
  213. if (EditStep.NewActions == null)
  214. {
  215. EditStep.NewActions = new List<share.ActionObject>();
  216. }
  217. if (!EditStep.NewActions.Contains(EditAction))
  218. {
  219. EditStep.NewActions.Add(EditAction);
  220. }
  221. }
  222. else
  223. {
  224. if (EditStep.ModifyActions == null)
  225. {
  226. EditStep.ModifyActions = new List<share.ActionObject>();
  227. }
  228. }
  229. if (!EditStep.ModifyActions.Contains(EditAction))
  230. {
  231. EditStep.ModifyActions.Add(EditAction);
  232. }
  233. }
  234. ActionModalShow = false;
  235. }
  236. void EditActionCancel()
  237. {
  238. ActionModalShow = false;
  239. }
  240. async Task EditTransferOK()
  241. {
  242. //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(EditTransfer));
  243. if(EditTransfer.StepId!= null && EditTransfer.StepId.Value == 0)
  244. {
  245. EditTransfer.StepId = null;
  246. }
  247. var ret = await _wfService.SaveTransfer(EditTransfer);
  248. if (ret.Success)
  249. {
  250. TransferModalShow = false;
  251. await InitData();
  252. }
  253. else {
  254. await _msgService.Error("保存出现错误!");
  255. }
  256. OnRefresh();
  257. }
  258. void EditTransferCancel()
  259. {
  260. TransferModalShow = false;
  261. }
  262. void OnRefresh()
  263. {
  264. chart.Refresh();
  265. StateHasChanged();
  266. }
  267. [Inject] ModalService _modalService { get; set; }
  268. async Task DeleteObject()
  269. {
  270. string strMsg = "";
  271. if (chart.SelectedObject != null)
  272. {
  273. if(chart.SelectedObject is entity.workflowDefine.TrasferCondition)
  274. {
  275. TrasferCondition transfer = chart.SelectedObject as TrasferCondition;
  276. await _wfService.DeleteTransfer(transfer);
  277. strMsg = (transfer.StepId == null) ? "开始" : transfer.Step.Name;
  278. strMsg = $"已删除{strMsg}的转移条件!";
  279. }
  280. if(chart.SelectedObject is entity.workflowDefine.Step)
  281. {
  282. await _wfService.DeleteStep((entity.workflowDefine.Step)chart.SelectedObject);
  283. strMsg = $"已删除步骤[{((entity.workflowDefine.Step)chart.SelectedObject).Name}]";
  284. }
  285. }
  286. await InitData();
  287. await _msgService.Info(strMsg);
  288. chart.Refresh();
  289. }
  290. }
  291. }