WorkflowEngineController.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using wispro.sp.entity;
  9. using wispro.sp.entity.workflowInstance;
  10. using wispro.sp.share;
  11. namespace wispro.sp.api.Controllers
  12. {
  13. [Route("api/[controller]/[action]")]
  14. [ApiController]
  15. public class WorkflowEngineController : ControllerBase
  16. {
  17. spDbContext Context;
  18. public WorkflowEngineController(spDbContext context)
  19. {
  20. Context = context;
  21. }
  22. public void DoAction(int instanceId,int stepId,int ActionId,List<InputValue> inputValues)
  23. {
  24. //1、取实例对象
  25. //2、取步骤对象
  26. //3、判断Action定义对象
  27. //4、判断输入值合法性
  28. //5、保存数据
  29. }
  30. [HttpPost]
  31. public ApiSaveResponse AddNew(NewWorkflowObject workflowObject)
  32. {
  33. ApiSaveResponse ret = new ApiSaveResponse();
  34. ret.Success = true;
  35. using(var t = Context.Database.BeginTransaction())
  36. {
  37. try
  38. {
  39. if (workflowObject.InitAction != null)
  40. {
  41. Context.Actions.Add(workflowObject.InitAction);
  42. Context.SaveChanges();
  43. }
  44. else
  45. {
  46. throw new ApplicationException("没有设定初始化Action!");
  47. }
  48. workflowObject.Workflow.InitActionId = workflowObject.InitAction.Id;
  49. workflowObject.Workflow.CreateTime = DateTime.Now;
  50. workflowObject.Workflow.CreateUserId = Context.Staffs.FirstOrDefault<Staff>(s => s.Name == User.Identity.Name).Id;
  51. Context.Workflows.Add(workflowObject.Workflow);
  52. Context.SaveChanges();
  53. t.Commit();
  54. }
  55. catch(Exception ex)
  56. {
  57. t.Rollback();
  58. ret.Success = false;
  59. ret.ErrorMessage = ex.Message;
  60. }
  61. }
  62. return ret;
  63. }
  64. public List<entity.workflowDefine.Workflow> GetAllWorkflows()
  65. {
  66. return Context.Workflows.Include(d => d.CreateUser).ToList();
  67. }
  68. public entity.workflowDefine.Workflow GetWorkflow(int workflowId)
  69. {
  70. return Context.Workflows.Include(d=>d.InitAction).Include(d=>d.CreateUser).FirstOrDefault<entity.workflowDefine.Workflow>(w => w.Id == workflowId);
  71. }
  72. public List<entity.workflowDefine.Step> GetSteps(int workflowId)
  73. {
  74. return Context.Steps.Where<entity.workflowDefine.Step>(w => w.workflowId == workflowId).ToList();
  75. }
  76. public List<entity.workflowDefine.Action> GetActions(int workflowId)
  77. {
  78. var workflow = Context.Workflows.FirstOrDefault<entity.workflowDefine.Workflow>(w => w.Id == workflowId);
  79. return Context.Actions.Where<entity.workflowDefine.Action>(d => d.step.workflowId == workflowId || d.Id == workflow.InitActionId).ToList();
  80. }
  81. public List<entity.workflowDefine.TrasferCondition> GetTrasfers(int workflowId)
  82. {
  83. return Context.TrasferConditions.Where(d => d.Step.workflowId == workflowId || d.nextStep.workflowId == workflowId).ToList();
  84. }
  85. }
  86. }