WorkflowDetail.razor.cs 11 KB

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