using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using wispro.sp.entity; using wispro.sp.entity.workflowInstance; using wispro.sp.share; namespace wispro.sp.api.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class WorkflowEngineController : ControllerBase { spDbContext Context; public WorkflowEngineController(spDbContext context) { Context = context; } public void DoAction(int instanceId,int stepId,int ActionId,List inputValues) { //1、取实例对象 //2、取步骤对象 //3、判断Action定义对象 //4、判断输入值合法性 //5、保存数据 } [HttpPost] public ApiSaveResponse AddNew(NewWorkflowObject workflowObject) { ApiSaveResponse ret = new ApiSaveResponse(); ret.Success = true; using(var t = Context.Database.BeginTransaction()) { try { if (workflowObject.InitAction != null) { Context.Actions.Add(workflowObject.InitAction); Context.SaveChanges(); } else { throw new ApplicationException("没有设定初始化Action!"); } workflowObject.Workflow.InitActionId = workflowObject.InitAction.Id; workflowObject.Workflow.CreateTime = DateTime.Now; workflowObject.Workflow.CreateUserId = Context.Staffs.FirstOrDefault(s => s.Name == User.Identity.Name).Id; Context.Workflows.Add(workflowObject.Workflow); Context.SaveChanges(); t.Commit(); } catch(Exception ex) { t.Rollback(); ret.Success = false; ret.ErrorMessage = ex.Message; } } return ret; } public List GetAllWorkflows() { return Context.Workflows.Include(d => d.CreateUser).ToList(); } public entity.workflowDefine.Workflow GetWorkflow(int workflowId) { return Context.Workflows.Include(d=>d.InitAction).Include(d=>d.CreateUser).FirstOrDefault(w => w.Id == workflowId); } public List GetSteps(int workflowId) { return Context.Steps.Where(w => w.workflowId == workflowId).ToList(); } public List GetActions(int workflowId) { var workflow = Context.Workflows.FirstOrDefault(w => w.Id == workflowId); return Context.Actions.Where(d => d.step.workflowId == workflowId || d.Id == workflow.InitActionId).ToList(); } public List GetTrasfers(int workflowId) { return Context.TrasferConditions.Where(d => d.Step.workflowId == workflowId || d.nextStep.workflowId == workflowId).ToList(); } } }