Exemplo n.º 1
0
        public async Task <ActionResult> SubmitForm(FlowschemeEntity entity, string keyValue)
        {
            if (string.IsNullOrEmpty(keyValue))
            {
                entity.F_DeleteMark      = false;
                entity.F_OrganizeId      = (await _formService.GetForm(entity.F_FrmId)).F_OrganizeId;
                entity.F_CreatorUserName = _service.currentuser.UserName;
            }
            try
            {
                await _service.SubmitForm(entity, keyValue);

                return(await Success("操作成功。", "", keyValue));
            }
            catch (Exception ex)
            {
                return(await Error(ex.Message, "", keyValue));
            }
        }
        public async Task UpdateInstance(FlowinstanceEntity entity)
        {
            FlowschemeEntity scheme = null;

            if (!string.IsNullOrEmpty(entity.F_SchemeId))
            {
                scheme = await uniwork.FindEntity <FlowschemeEntity>(entity.F_SchemeId);
            }
            if (scheme == null)
            {
                throw new Exception("该流程模板已不存在,请重新设计流程");
            }
            entity.F_SchemeContent = scheme.F_SchemeContent;
            var form = await uniwork.FindEntity <FormEntity>(scheme.F_FrmId);

            if (form == null)
            {
                throw new Exception("该流程模板对应的表单已不存在,请重新设计流程");
            }
            var wfruntime = new FlowRuntime(await repository.FindEntity(entity.F_Id));

            entity.F_FrmContentData   = form.F_ContentData;
            entity.F_FrmContentParse  = form.F_ContentParse;
            entity.F_FrmType          = form.F_FrmType;
            entity.F_FrmId            = form.F_Id;
            entity.F_InstanceSchemeId = "";
            entity.F_DbName           = form.F_WebId;
            entity.F_FlowLevel        = 0;
            //创建运行实例
            wfruntime = new FlowRuntime(entity);

            var user = currentuser;

            #region 根据运行实例改变当前节点状态
            entity.F_ActivityId      = wfruntime.nextNodeId;
            entity.F_ActivityType    = wfruntime.GetNextNodeType();
            entity.F_ActivityName    = wfruntime.nextNode.name;
            entity.F_PreviousId      = wfruntime.currentNodeId;
            entity.F_CreatorUserName = user.UserName;
            entity.F_MakerList       = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            entity.F_IsFinish        = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);
            uniwork.BeginTrans();
            await uniwork.Update(entity);

            wfruntime.flowInstanceId = entity.F_Id;
            //复杂表单提交
            if (entity.F_FrmType == 1)
            {
                var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
                var referencedAssemblies = Directory.GetFiles(path, "*.dll").Select(Assembly.LoadFrom).ToArray();
                var t = referencedAssemblies
                        .SelectMany(a => a.GetTypes().Where(t => t.FullName.Contains("WaterCloud.Service.") && t.FullName.Contains("." + entity.F_DbName + "Service"))).FirstOrDefault();
                ICustomerForm icf = (ICustomerForm)GlobalContext.ServiceProvider.GetService(t);
                await icf.Edit(entity.F_Id, entity.F_FrmData);
            }
            #endregion

            #region 流程操作记录
            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                F_Id              = Utils.GuId(),
                F_InstanceId      = entity.F_Id,
                F_CreatorUserId   = user.UserId,
                F_CreatorUserName = entity.F_CreatorUserName,
                F_CreatorTime     = DateTime.Now,
                F_Content         = "【修改】"
                                    + entity.F_CreatorUserName
                                    + "修改了一个流程【"
                                    + entity.F_Code + "/"
                                    + entity.F_CustomName + "】"
            };
            await uniwork.Insert(processOperationHistoryEntity);

            #endregion

            await AddTransHistory(wfruntime);

            MessageEntity msg = new MessageEntity();
            msg.F_CreatorUserName = currentuser.UserName;
            msg.F_EnabledMark     = true;
            if (entity.F_IsFinish == 1)
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程已完成";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                msg.F_ClickRead  = true;
                msg.F_KeyValue   = entity.F_Id;
            }
            else if (entity.F_IsFinish == 3)
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程已终止";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                var makerList = uniwork.IQueryable <FlowInstanceOperationHistory>(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList();
                msg.F_ToUserId  = entity.F_CreatorUserId;
                msg.F_ClickRead = true;
                msg.F_KeyValue  = entity.F_Id;
            }
            else
            {
                msg.F_MessageInfo = entity.F_CustomName + "--流程待处理";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow";
                msg.F_HrefTarget = module.F_Target;
                msg.F_ClickRead  = false;
                msg.F_KeyValue   = entity.F_Id;
            }
            msg.F_MessageType = 2;
            msg.F_ToUserId    = entity.F_MakerList == "1" ? "" : entity.F_MakerList;
            var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault();
            if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0)
            {
                await messageApp.ReadMsgForm(lastmsg.F_Id);
            }
            await messageApp.SubmitForm(msg);

            uniwork.Commit();
            await CacheHelper.Remove(cacheKey + entity.F_Id);

            await CacheHelper.Remove(cacheKey + "list");

            msg.F_ClickRead = false;
            msg.F_KeyValue  = entity.F_Id;
        }