public ActionResult AddOffice(Models.Office.OfficeEditModel vm) { using (var db = new XkSystem.Models.DbContext()) { if (string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && !string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.OfficeFileName"); } else if (!string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.FileContent"); } else if (string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.FileContent"); } var error = new List <string>(); if (error.Count == decimal.Zero) { //保存附件,rar,word(doc),pdf string FileName = string.Empty; if (!string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName)) { var file = Request.Files[nameof(vm.OfficeEditDto) + "." + nameof(vm.OfficeEditDto.OfficeFileName)]; var suffix = file.FileName.Substring(file.FileName.LastIndexOf(".")); FileName = System.IO.Path.GetRandomFileName().Replace(".", string.Empty) + suffix; vm.OfficeEditDto.OfficeFileName = file.FileName; file.SaveAs(Server.MapPath("~/Files/OfficeFile/") + FileName); } //审批内容表记录 var tb = new Wechat.Entity.tbWeOAOffice(); tb.OfficeFileFrom = vm.OfficeEditDto.OfficeFileFrom; tb.OfficeFileName = vm.OfficeEditDto.OfficeFileName; tb.OfficeFileNameSeq = FileName; tb.ReceiveFileTime = vm.OfficeEditDto.ReceiveFileTime; tb.Title = vm.OfficeEditDto.Title; tb.FileContent = vm.OfficeEditDto.FileContent; tb.LimitDateTo = vm.OfficeEditDto.LimitDateTo; db.Set <Wechat.Entity.tbWeOAOffice>().Add(tb); db.SaveChanges(); //执行流程引擎 OAWeWorkFlow.ExecuteWorkFlowEngine(db, flowTypeCode, tb.Id, "", "发起流程", false, vm.OfficeEditDto.NextApproveUserId); } else { vm.ErrorMsg = string.Join("\r\n", error); return(View(vm));//包含文件表单的方式 } return(Content("<script type='text/javascript'> window.parent.location.href = '" + Url.Action("OfficeIndex", "Office", new { area = "wechat" }) + "';</script>")); } }
/// <summary> /// 审批流程 /// </summary> /// <param name="flowTypeCode">流程类型</param> /// <param name="approveBodyId">流程审批内容ID</param> /// <param name="conditionalFormula">匹配公式</param> /// <param name="approveOpinion">审批意见</param> /// <param name="reject">是否驳回</param> /// <param name="nextApproveUserId">下一个节点指定的审批人</param> public static void ExecuteWorkFlowEngine(XkSystem.Models.DbContext db, string flowTypeCode, int approveBodyId, string conditionalFormula, string approveOpinion, bool reject = false, int nextApproveUserId = 0) { //流程类型 var flowType = db.Table <Wechat.Entity.tbWeOAFlowType>().Where(m => m.Code == flowTypeCode).FirstOrDefault(); //当前审批人或流程发起人,如果登录角色非发起人角色则没有提交审批申请单的功能 var approveUser = db.Set <Sys.Entity.tbSysUser>().Find(XkSystem.Code.Common.UserId); //获取该审批项目的流程列表,排除驳回的流程 var approveDetailList = db.Table <Wechat.Entity.tbWeOAFlowDetail>() .Where(m => m.tbWeOAFlowType.Code == flowTypeCode && m.ApproveBodyId == approveBodyId && m.NodeApproveStatus != Code.EnumHelper.OAFlowNodeStatus.WithoutApproval) .Include(m => m.tbWeOAFlowNextNode) .Include(m => m.tbWeOAFlowPreviousNode); //上次申请或审批的节点,可能有可能多个分支,e.g.:2个FlowStep=2 var approveDetailNode = approveDetailList.OrderByDescending(m => m.tbWeOAFlowNextNode.FlowStep).FirstOrDefault(); //查询当前审批流程是否有并列分支,判断走哪条分支,过滤流程节点,保留一个节点 if (approveDetailNode != null) { var mulStepNo = (from m in approveDetailList group m by m.tbWeOAFlowNextNode.FlowStep into g where g.Count() > 1 select g.Key).FirstOrDefault();//??? if (mulStepNo != 0) { int step = Convert.ToInt32(mulStepNo); //查询当前审批角色对应的是哪个节点 var flowApprovalNode = db.Table <Wechat.Entity.tbWeOAFlowApprover>().Where(m => m.tbWeOAFlowNode.tbSysOAFlowType.Code == flowTypeCode && m.tbSysUser.Id == approveUser.Id && m.tbWeOAFlowNode.FlowStep == step).Select(m => m.tbWeOAFlowNode.FlowApprovalNode).FirstOrDefault(); approveDetailNode = approveDetailList.Where(m => m.tbWeOAFlowNextNode.FlowStep == step && m.tbWeOAFlowNextNode.FlowApprovalNode == flowApprovalNode).FirstOrDefault(); } } //1.发起流程 if (approveDetailNode == null) { //发起流程可能有多个分支,则产生多个detail流程实例,该分支是或者关系 var thisNextNodeList = db.Table <Wechat.Entity.tbWeOAFlowNode>().Where(m => m.tbSysOAFlowType.Code == flowTypeCode); if (!string.IsNullOrEmpty(conditionalFormula)) { thisNextNodeList = thisNextNodeList.Where(m => m.ConditionalFormula == conditionalFormula).OrderBy(m => m.FlowStep); } else { thisNextNodeList = thisNextNodeList.Where(m => m.FlowStep == 2).OrderBy(m => m.FlowStep);//正常顺序流下一个流程是2 } Wechat.Entity.tbWeOAFlowDetail tbWeOAFlowDetail = null; Sys.Entity.tbSysUser nextApproveUser = null; if (nextApproveUserId != 0) { nextApproveUser = db.Set <Sys.Entity.tbSysUser>().Find(nextApproveUserId); } var step = 0; foreach (var thisNextNode in thisNextNodeList) { if (step == thisNextNode.FlowStep || step == 0) { tbWeOAFlowDetail = new Wechat.Entity.tbWeOAFlowDetail(); tbWeOAFlowDetail.tbSysUser = approveUser; tbWeOAFlowDetail.NodeApproveStatus = Code.EnumHelper.OAFlowNodeStatus.Approved; tbWeOAFlowDetail.tbWeOAFlowType = flowType; tbWeOAFlowDetail.ApproveBodyId = approveBodyId; tbWeOAFlowDetail.ApproveDate = System.DateTime.Now; tbWeOAFlowDetail.ApproveOpinion = approveOpinion; tbWeOAFlowDetail.tbWeOAFlowPreviousNode = null;//我的申请则查询该字段为null的数据 tbWeOAFlowDetail.tbWeOAFlowNextNode = thisNextNode; tbWeOAFlowDetail.AssignNextApproveUser = nextApproveUser; db.Set <Wechat.Entity.tbWeOAFlowDetail>().Add(tbWeOAFlowDetail); } step = thisNextNode.FlowStep; } db.SaveChanges(); } //2.审批流程,流程节点链条:P1-N1-P2(N1)-N2-P3(N2)-N3 else { //执行下一个流程,**不考虑审批分支** if (approveDetailNode.tbWeOAFlowNextNode != null) { //本次审批的上一个节点 var thisPreNode = db.Table <Wechat.Entity.tbWeOAFlowNode>().Where(m => m.tbSysOAFlowType.Code == flowTypeCode && m.FlowStep == approveDetailNode.tbWeOAFlowNextNode.FlowStep).FirstOrDefault(); //检查当前审批后是否还有下一个流程,比如用车申请司机关闭流程 Wechat.Entity.tbWeOAFlowNode thisNextNode = null;//为null则流程结束 int nextNodeNo = approveDetailNode.tbWeOAFlowNextNode.FlowStep; if (approveDetailNode.tbWeOAFlowNextNode.FlowComplete == false) { nextNodeNo += 1; //本次审批的下一个节点,如果驳回则为null if (reject == false) { thisNextNode = db.Table <Wechat.Entity.tbWeOAFlowNode>().Where(m => m.tbSysOAFlowType.Code == flowTypeCode && m.FlowStep == nextNodeNo).FirstOrDefault(); } } var tbWeOAFlowDetail = new Wechat.Entity.tbWeOAFlowDetail(); tbWeOAFlowDetail.tbSysUser = approveUser; tbWeOAFlowDetail.NodeApproveStatus = reject ? Code.EnumHelper.OAFlowNodeStatus.WithoutApproval : Code.EnumHelper.OAFlowNodeStatus.Approved; tbWeOAFlowDetail.tbWeOAFlowType = flowType; tbWeOAFlowDetail.ApproveBodyId = approveBodyId; tbWeOAFlowDetail.ApproveDate = System.DateTime.Now; tbWeOAFlowDetail.ApproveOpinion = approveOpinion; tbWeOAFlowDetail.tbWeOAFlowPreviousNode = thisPreNode; tbWeOAFlowDetail.tbWeOAFlowNextNode = thisNextNode; if (nextApproveUserId != 0) { tbWeOAFlowDetail.AssignNextApproveUser = db.Set <Sys.Entity.tbSysUser>().Find(nextApproveUserId); } db.Set <Wechat.Entity.tbWeOAFlowDetail>().Add(tbWeOAFlowDetail); db.SaveChanges(); } } }
public static IQueryable <TEntity> TableRoot <TEntity>(this XkSystem.Models.DbContext db) where TEntity : XkSystem.Code.EntityHelper.EntityRoot { return(db.Set <TEntity>().Where(d => d.IsDeleted == false)); }
public static IQueryable <TEntity> Table <TEntity>(this XkSystem.Models.DbContext db, int TenantId) where TEntity : XkSystem.Code.EntityHelper.EntityBase { return(db.Set <TEntity>().Where(d => d.IsDeleted == false && d.tbTenant.Id == TenantId)); }