public JsonResult ValidateLoginForDingTalkPC(string state, string code)
        {
            this.Engine.LogWriter.Write("DingTalkPC:进入登录方法-------------------------");
            OThinker.Organization.User currentUser = null;
            UserValidator userValidator            = null;
            string        userImage = string.Empty;
            // 钉钉登录
            IEngine engine = AppUtility.Engine;

            userValidator = UserValidatorFactory.LoginAsDingTalkPCAndReturnUserValidator(state, code);
            object result = null;

            if (userValidator == null)
            {
                result = new
                {
                    Success = false
                };
            }
            else
            {
                currentUser = userValidator.User;
                userImage   = userValidator.ImagePath;
                MobileAccess            mobile     = new MobileAccess();
                MobileAccess.MobileUser mobileUser = mobile.GetMobileUser(userValidator, currentUser, userImage, string.Empty, string.Empty);
                FormsAuthentication.SetAuthCookie(currentUser.Code, false);
                // 当前用户登录
                Session[Sessions.GetUserValidator()] = userValidator;
                result = getCurrentUser();
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 获取移动办公单点登录编码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="mobileType"></param>
        /// <param name="uuid"></param>
        /// <param name="jpushId"></param>
        /// <returns></returns>
        private string GetMobileToken(OThinker.Organization.User user, string mobileType, string uuid, string jpushId)
        {
            user.SID = uuid;
            if (!string.IsNullOrEmpty(jpushId))
            {
                //保证用户JPushID的唯一性
                List <string>            usersId = Engine.PortalQuery.GetUsersIdByjpushId(jpushId);
                List <Organization.Unit> units   = Engine.Organization.GetUnits(usersId.ToArray());
                foreach (var unit in units)
                {
                    if (unit.ObjectID != user.ObjectID)
                    {
                        Organization.User Updateuser = unit as Organization.User;
                        Updateuser.JPushID = null;
                        this.Engine.LogWriter.Write("删除" + Updateuser.Name + "[" + Updateuser.Code + "] jpushId");
                        this.Engine.Organization.UpdateUnit(user.ObjectID, Updateuser);
                    }
                }
                // JPushId 只会在第一次登录的时候取值
                user.JPushID = jpushId;
            }

            // 生成一个Token值
            string mobileToken = Guid.NewGuid().ToString().Replace("-", string.Empty);

            user.MobileToken = mobileToken;// OThinker.Security.MD5Encryptor.GetMD5(mobileToken);
            user.MobileType  = mobileType.ToLower().IndexOf("android") > -1 ? OThinker.Organization.MobileSystem.Android : OThinker.Organization.MobileSystem.iOS;
            // 更新用户的信息
            if (user.DirtyProperties.Length > 0)
            {
                this.Engine.LogWriter.Write("更新" + user.Name + "[" + user.Code + "] jpushId:" + jpushId);
                this.Engine.Organization.UpdateUnit(user.ObjectID, user);
            }
            return(mobileToken);
        }
Ejemplo n.º 3
0
        public JsonResult GetUserByObjectID(string userCode, string mobileToken, string targetUserId)
        {
            UserValidator sourceUser = this.UserValidator;

            if (sourceUser == null)
            {
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }

            OThinker.Organization.User user = this.Engine.Organization.GetUnit(targetUserId) as OThinker.Organization.User;
            if (user == null)
            {
                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }

            UserValidator userValidator = UserValidatorFactory.GetUserValidator(this.Engine, user.Code);
            MobileAccess  mobile        = new MobileAccess();

            MobileAccess.MobileUser mobileUser = mobile.GetMobileUser(sourceUser, user, user.ImageUrl, userValidator.DepartmentName, string.Empty);
            var result = new
            {
                MobileUser = mobileUser
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取当前已登录的用户信息
        /// </summary>
        /// <returns></returns>
        private object getCurrentUser()
        {
            OThinker.Organization.User user      = null;
            List <FunctionViewModel>   functions = null;

            if (this.UserValidator != null)
            {
                user          = this.UserValidator.User;
                user.Password = string.Empty;
                functions     = this.getFunctionApps();
                user.ImageUrl = GetUserImageUrl(user);
            }
            var result = new
            {
                Success          = user != null,
                Functions        = functions,
                User             = user,
                PortalRoot       = this.PortalRoot,
                ManagerName      = GetUserManagerName(user),
                OUDepartName     = GetUserParentName(user),
                chkEmail         = user == null ? false : user.CheckNotifyType(OThinker.Organization.NotifyType.Email),
                chkMobileMessage = user == null ? false : user.CheckNotifyType(OThinker.Organization.NotifyType.MobileMessage),
                chkWeChat        = user == null ? false : user.CheckNotifyType(OThinker.Organization.NotifyType.WeChat),
                chkApp           = user == null ? false : user.CheckNotifyType(OThinker.Organization.NotifyType.App),
                chkDingTalk      = user == null ? false : user.CheckNotifyType(OThinker.Organization.NotifyType.DingTalk),
                DirectoryUnits   = user == null ? null : GetDirectoryUnits(user.ObjectID),
                UserRole         = user == null ? "" : GetUserRole(user.ObjectID)
            };

            return(result);
        }
        public JsonResult LoadFunctions()
        {
            OThinker.Organization.User user = null;

            var result = new
            {
                Success = true,
                User    = user
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public JsonResult GetParticipants(string ActivityCode, string InstanceID)
        {
            return(ExecuteFunctionRun(() =>
            {
                if (!string.IsNullOrEmpty(ActivityCode) && !string.IsNullOrEmpty(InstanceID))
                {
                    //流程
                    Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(InstanceID);
                    if (InstanceContext != null)
                    {
                        //流程模板
                        WorkflowTemplate.PublishedWorkflowTemplate Template = this.Engine.WorkflowManager.GetPublishedTemplate(
                            InstanceContext.WorkflowCode,
                            InstanceContext.WorkflowVersion);
                        if (Template != null)
                        {
                            //活动信息
                            ClientActivityBase Activity = Template.GetActivityByCode(ActivityCode) as ClientActivityBase;

                            OThinker.H3.Instance.InstanceData InstanceData = new Instance.InstanceData(this.Engine, InstanceID, null);

                            string[] ParticipantIDs = Activity.ParseParticipants(InstanceData, this.Engine.Organization);
                            OThinker.Organization.Unit[] ParticipantUsers = this.Engine.Organization.GetUnits(ParticipantIDs).ToArray();

                            if (ParticipantUsers != null)
                            {
                                List <object> ParticipantUserNames = new List <object>();
                                foreach (OThinker.Organization.Unit u in ParticipantUsers)
                                {
                                    if (u != null && u.UnitType == OThinker.Organization.UnitType.User)
                                    {
                                        OThinker.Organization.User user = (OThinker.Organization.User)u;
                                        ParticipantUserNames.Add(new
                                        {
                                            Name = user.Name,
                                            Code = user.Code,
                                            ObjectID = user.ObjectID
                                        });
                                        //ParticipantUserNames.Add(u.Name + "[" + u.Code + "]");
                                    }
                                }
                                return Json(ParticipantUserNames, JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                }

                return Json(new string[] { }, JsonRequestBehavior.AllowGet);
            }));
        }
Ejemplo n.º 7
0
 public static OThinker.Organization.User getUserByName(string name)
 {
     System.Data.DataTable dt = OThinker.H3.Controllers.AppUtility.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(
         " SELECT * " +
         " FROM OT_User " +
         " where Name = '" + name + "'");
     OThinker.Organization.User u = new OThinker.Organization.User();
     if (dt.Rows.Count > 0)
     {
         u.ObjectID = dt.Rows[0]["ObjectID"].ToString();
         u.Name     = dt.Rows[0]["Name"].ToString();
     }
     return(u);
 }
        public System.Web.Mvc.ActionResult SubmitWorkItem(string appId, string pwd, string userCode, string workItemId, string paramValues)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (item == null) throw new Exception("工作任务不存在");
            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user == null) throw new Exception("用户不存在");
            List<DataItemParam> listParamValues = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            // 保存数据项
            SaveBizObject(item, user, OThinker.Data.BoolMatchValue.True, listParamValues);

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                user.UnitID,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                null,
                OThinker.Data.BoolMatchValue.True,
                string.Empty,
                null,
                OThinker.H3.WorkItem.ActionEventType.Forward,
                11);

            // 需要通知实例事件管理器结束事件
            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                    MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.True,
                    false,
                    OThinker.Data.BoolMatchValue.True,
                    true,
                    null);
            this.Engine.InstanceManager.SendMessage(endMessage);
            return Json(new
            {
                Result = true,
                Message = string.Empty
            });
        }
 /// <summary>
 /// 钉钉集成登录
 /// </summary>
 /// <param name="state">引擎编码</param>
 /// <param name="code">临时授权码</param>
 public JsonResult ValidateLoginForDingTalk(string state, string code)
 {
     return(ExecutionActionWithLog("DingTalkController.ValidateLoginForDingTalk", () =>
     {
         OThinker.Organization.User currentUser = null;
         UserValidator userValidator = null;
         string userImage = string.Empty;
         // 钉钉登录
         IEngine engine = AppUtility.Engine;
         userValidator = UserValidatorFactory.LoginAsDingTalkReturnUserValidator(state, code);
         object result = null;
         if (userValidator == null)
         {
             result = new
             {
                 Success = false
             };
         }
         else
         {
             currentUser = userValidator.User;
             userImage = userValidator.ImagePath;
             MobileAccess mobile = new MobileAccess();
             MobileAccess.MobileUser mobileUser = mobile.GetMobileUser(userValidator, currentUser, userImage, string.Empty, string.Empty);
             result = new
             {
                 Success = true,
                 PortalRoot = this.PortalRoot,
                 MobileUser = mobileUser,
                 DirectoryUnits = GetDirectoryUnits(mobileUser.ObjectID, userValidator)
             };
             FormsAuthentication.SetAuthCookie(currentUser.Code, false);
             // 当前用户登录
             Session[Sessions.GetUserValidator()] = userValidator;
             Session[Sessions.GetDingTalkLogin()] = true;
         }
         return Json(result, JsonRequestBehavior.AllowGet);
     }));
 }
        /// <summary>
        /// 保存表单数据
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="user"></param>
        /// <param name="boolMatchValue"></param>
        /// <param name="paramValues"></param>
        private void SaveBizObject(OThinker.H3.WorkItem.WorkItem workItem, OThinker.Organization.User user, OThinker.Data.BoolMatchValue boolMatchValue, List<DataItemParam> paramValues)
        {
            Instance.InstanceContext InstanceContext = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId);
            string bizObjectId = InstanceContext == null ? string.Empty : InstanceContext.BizObjectId;
            OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(InstanceContext.BizObjectSchemaCode);
            OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(this.Engine, schema, workItem.Participant);
            bo.ObjectID = bizObjectId;
            bo.Load();

            // 设置数据项的值
            foreach (DataItemParam param in paramValues)
            {
                OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                if (property.LogicType == DataLogicType.Comment)
                {// 审核意见
                    CommentParam comment = JSSerializer.Deserialize<CommentParam>(param.ItemValue + string.Empty);
                    this.Engine.BizObjectManager.AddComment(new Comment()
                    {
                        BizObjectId = bo.ObjectID,
                        BizObjectSchemaCode = schema.SchemaCode,
                        InstanceId = workItem.InstanceId,
                        TokenId = workItem.TokenId,
                        Approval = boolMatchValue,
                        Activity = workItem.ActivityCode,
                        DataField = property.Name,
                        UserID = user.ObjectID,
                        SignatureId = comment.SignatureId,
                        Text = comment.Text
                    });
                }
                else
                {
                    this.SetItemValue(bo, property, param.ItemValue);
                }
            }

            bo.Update();
        }
Ejemplo n.º 11
0
        public RestfulResult StartWorkflow_Base(string USER_CODE, string WORKFLOW_CODE, bool FINISH_START, string INSTANCE_ID, string PARAM_VALUES)
        {
            Engine.LogWriter.Write("Restful 服务,方法:StartWorkflow,参数:USER_CODE-->" + USER_CODE + ",WORKFLOW_CODE-->" + WORKFLOW_CODE + ",FINISH_START-->" + FINISH_START + ",INSTANCE_ID-->" + INSTANCE_ID + ",PARAM_VALUES-->" + JsonConvert.SerializeObject(PARAM_VALUES));
            RestfulResult result = new RestfulResult();
            Dictionary <string, object> listParams = JsonConvert.DeserializeObject <Dictionary <string, object> >(PARAM_VALUES);
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;
            try
            {
                #region 参数校验
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(WORKFLOW_CODE);
                if (workflowTemplate == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "流程模板不存在,模板编码:" + WORKFLOW_CODE + "。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(USER_CODE);
                if (user == null)
                {
                    result.INSTANCE_ID   = "";
                    result.MESSAGE       = "用户{" + USER_CODE + "}不存在。";
                    result.STATUS        = "0";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                    return(result);
                }
                #endregion

                #region 流程实例ID为空:发起新流程
                if (string.IsNullOrEmpty(INSTANCE_ID))
                {
                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Create();

                    // 创建流程实例
                    string InstanceId = this.Engine.InstanceManager.CreateInstance(
                        bo.ObjectID,
                        workflowTemplate.WorkflowCode,
                        workflowTemplate.WorkflowVersion,
                        null,
                        null,
                        user.UnitID,
                        null,
                        false,
                        InstanceContext.UnspecifiedID,
                        null,
                        Token.UnspecifiedID);

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            if (property.LogicType == DataLogicType.Comment)
                            {// 审核意见
                                CommentParam comment = JsonConvert.DeserializeObject <CommentParam>(JsonConvert.SerializeObject(param.Value));
                                this.Engine.BizObjectManager.AddComment(new Comment()
                                {
                                    BizObjectId         = bo.ObjectID,
                                    BizObjectSchemaCode = schema.SchemaCode,
                                    InstanceId          = InstanceId,
                                    Activity            = workflowTemplate.StartActivityCode,
                                    TokenId             = 1,
                                    Approval            = OThinker.Data.BoolMatchValue.True,
                                    DataField           = property.Name,
                                    UserID      = user.ObjectID,
                                    UserName    = user.Name,
                                    SignatureId = comment.SignatureId,
                                    Text        = comment.Text
                                });
                            }
                        }
                    }

                    // 启动流程的消息
                    OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                        = new OThinker.H3.Messages.StartInstanceMessage(
                              MessageEmergencyType.Normal,
                              InstanceId,
                              workItemID,
                              null,
                              PriorityType.Normal,
                              FINISH_START,
                              null,
                              false,
                              OThinker.H3.Instance.Token.UnspecifiedID,
                              null);
                    Engine.InstanceManager.SendMessage(startInstanceMessage);

                    result.INSTANCE_ID   = InstanceId;
                    result.MESSAGE       = "流程实例启动成功!";
                    result.BIZOBJECTID   = bo.ObjectID;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion

                #region 流程实例ID不为空:更新流程数据;
                else
                {
                    InstanceContext ic = this.Engine.InstanceManager.GetInstanceContext(INSTANCE_ID);
                    if (ic == null)
                    {
                        result.INSTANCE_ID   = INSTANCE_ID;
                        result.MESSAGE       = "InstanceID错误,此ID在H3系统中不存在,请检查";
                        result.STATUS        = "0";
                        result.WORKFLOW_CODE = WORKFLOW_CODE;
                        result.USER_CODE     = USER_CODE;
                        return(result);
                    }

                    OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                    OThinker.H3.DataModel.BizObject       bo     = new OThinker.H3.DataModel.BizObject(
                        this.Engine.Organization,
                        this.Engine.MetadataRepository,
                        this.Engine.BizObjectManager,
                        null,
                        schema,
                        user.ObjectID,
                        user.ParentID);

                    bo.ObjectID = ic.BizObjectId;
                    bo.Load();//装载流程数据;

                    if (listParams != null)
                    {
                        // 这里可以在创建流程的时候赋值
                        foreach (KeyValuePair <string, object> param in listParams)
                        {
                            OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.Key);
                            if (property == null)
                            {
                                continue;
                            }
                            SetItemValue(bo, property, param.Value);
                        }
                    }

                    bo.Update();
                    #region 提交当前任务,往下流转
                    if (FINISH_START)
                    {
                        string sql = "SELECT ObjectID FROM OT_WorkItem WHERE InstanceId='{0}' ORDER BY TokenId desc";
                        sql = string.Format(sql, INSTANCE_ID);
                        string workItemId = this.Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteScalar(sql) + string.Empty;
                        if (workItemId != "")
                        {
                            // 获取工作项
                            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);

                            // 结束工作项
                            this.Engine.WorkItemManager.FinishWorkItem(
                                item.ObjectID,
                                user.UnitID,
                                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,
                                null,
                                OThinker.Data.BoolMatchValue.True,
                                string.Empty,
                                null,
                                OThinker.H3.WorkItem.ActionEventType.Forward,
                                11);

                            // 需要通知实例事件管理器结束事件
                            AsyncEndMessage endMessage = new OThinker.H3.Messages.AsyncEndMessage(
                                MessageEmergencyType.Normal,
                                item.InstanceId,
                                item.ActivityCode,
                                item.TokenId,
                                OThinker.Data.BoolMatchValue.True,
                                false,
                                OThinker.Data.BoolMatchValue.True,
                                true,
                                null);
                            this.Engine.InstanceManager.SendMessage(endMessage);
                        }
                    }
                    #endregion

                    result.INSTANCE_ID   = INSTANCE_ID;
                    result.MESSAGE       = "流程实例启动成功!(更新数据项的值)";
                    result.BIZOBJECTID   = ic.BizObjectId;
                    result.STATUS        = "2";
                    result.WORKFLOW_CODE = WORKFLOW_CODE;
                    result.USER_CODE     = USER_CODE;
                }
                #endregion
            }
            catch (Exception ex)
            {
                result               = new RestfulResult();
                result.INSTANCE_ID   = "";
                result.BIZOBJECTID   = "";
                result.MESSAGE       = "接口异常:" + ex.ToString();
                result.STATUS        = "0";
                result.WORKFLOW_CODE = WORKFLOW_CODE;
                result.USER_CODE     = USER_CODE;
            }
            return(result);
        }
        public System.Web.Mvc.ActionResult RejectWorkItem(string appId, string pwd, string userCode, string workItemId, string rejectToActivity, string paramValues)
        {
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem item = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (item == null) throw new Exception("工作任务不存在");
            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user == null) throw new Exception("用户不存在");
            List<DataItemParam> listParamValues = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            // 保存数据项
            SaveBizObject(item, user, OThinker.Data.BoolMatchValue.True, listParamValues);

            // 获取驳回节点
            if (string.IsNullOrEmpty(rejectToActivity))
            {// 目标节点为空,则判断当前节点允许驳回的环节 
                PublishedWorkflowTemplate template = this.Engine.WorkflowManager.GetPublishedTemplate(item.WorkflowCode, item.WorkflowVersion);
                ParticipativeActivity activity = template.GetActivityByCode(item.ActivityCode) as ParticipativeActivity;
                if (activity == null) throw new Exception("当前环节不允许驳回");
                if (activity.PermittedActions.RejectToStart) rejectToActivity = template.StartActivityCode; // 驳回到开始
                else if (activity.PermittedActions.RejectToFixed || activity.PermittedActions.RejectToAny)
                {
                    if (activity.PermittedActions.RejectToActivityCodes != null && activity.PermittedActions.RejectToActivityCodes.Length > 0)
                    {
                        rejectToActivity = activity.PermittedActions.RejectToActivityCodes[0];
                    }
                }
                else if (activity.PermittedActions.Reject)
                {// 驳回上一步 
                    InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
                    int[] tokens = context.GetToken(item.TokenId).PreTokens;
                    if (tokens != null && tokens.Length > 0)
                    {
                        rejectToActivity = context.GetToken(tokens[0]).Activity;
                    }
                }

                if (string.IsNullOrEmpty(rejectToActivity))
                {
                    rejectToActivity = template.StartActivityCode;
                }
            }

            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                  item.ObjectID,
                  user.ObjectID,
                  H3.WorkItem.AccessPoint.ExternalSystem,
                  null,
                  OThinker.Data.BoolMatchValue.False,
                  string.Empty,
                  null,
                  H3.WorkItem.ActionEventType.Backward,
                  10);
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                OThinker.H3.Messages.MessageEmergencyType.Normal,
                item.InstanceId,
                rejectToActivity,
                OThinker.H3.Instance.Token.UnspecifiedID,
                null,
                new int[] { item.TokenId },
                false,
                H3.WorkItem.ActionEventType.Backward);

            // 通知该Activity已经完成
            OThinker.H3.Messages.AsyncEndMessage endMessage =
                new OThinker.H3.Messages.AsyncEndMessage(
                    OThinker.H3.Messages.MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.False,
                    true,
                    OThinker.Data.BoolMatchValue.False,
                    false,
                    activateMessage);
            this.Engine.InstanceManager.SendMessage(endMessage);
            return Json(new
            {
                Result = true,
                Message = string.Empty
            });
        }
        public System.Web.Mvc.ActionResult GetInstanceInfo(string appId, string pwd, string userCode, string workItemId)
        {
            OThinker.H3.WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            if (workItem == null) throw new Exception("工作任务不存在");
            OThinker.H3.Instance.InstanceContext instance = this.Engine.InstanceManager.GetInstanceContext(workItem.InstanceId);

            OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate template = this.Engine.WorkflowManager.GetPublishedTemplate(instance.WorkflowCode, instance.WorkflowVersion);
            OThinker.H3.WorkflowTemplate.Activity activity = template.GetActivityByCode(workItem.ActivityCode);

            InstanceInfo result = new InstanceInfo()
            {
                ActivityCode = activity.ActivityCode,
                ActivityName = activity.DisplayName,
                DataPermissions = (activity is OThinker.H3.WorkflowTemplate.ParticipativeActivity) ? ((OThinker.H3.WorkflowTemplate.ParticipativeActivity)activity).DataPermissions : null,
                InstanceId = instance.InstanceId,
                InstanceState = instance.State,
                Originator = instance.Originator,
                TokenId = workItem.TokenId,
                WorkflowCode = template.WorkflowCode,
                WorkflowName = template.WorkflowFullName,
                SequenceNo = instance.SequenceNo,
                WorkItemState = workItem.State
            };

            OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
            if (user != null)
            {
                OThinker.Organization.Signature[] signatures = this.Engine.Organization.GetSignaturesByUnit(user.ObjectID);
                result.MySignatures = new List<SignatureParam>();
                if (signatures != null)
                {
                    foreach (OThinker.Organization.Signature signature in signatures)
                    {
                        result.MySignatures.Add(new SignatureParam()
                        {
                            IsDefault = signature.IsDefault,
                            SignatureName = signature.Name,
                            SignautreId = signature.ObjectID,
                            SortKey = signature.SortKey
                        });
                    }
                }

                result.FrequentlyComment = this.Engine.Organization.GetFrequentlyUsedCommentTextsByUser(user.ObjectID);

                if (activity is OThinker.H3.WorkflowTemplate.ParticipativeActivity)
                {
                    // PermittedActions actions = new PermittedActions();
                    OThinker.H3.WorkflowTemplate.ParticipativeActivity participative = activity as OThinker.H3.WorkflowTemplate.ParticipativeActivity;
                    //actions.AdjustParticipant = participative.PermittedActions.AdjustParticipant;
                    //actions.Assist = participative.PermittedActions.Assist;
                    //actions.CancelIfUnfinished = participative.PermittedActions.CancelIfUnfinished;
                    //actions.Choose = participative.PermittedActions.Choose;
                    //actions.Circulate = participative.PermittedActions.Circulate;
                    //actions.Consult = participative.PermittedActions.Consult;
                    //actions.Forward = participative.PermittedActions.Forward;
                    //actions.Reject = participative.PermittedActions.Reject || participative.PermittedActions.RejectToAny || participative.PermittedActions.RejectToFixed;

                    if (participative.PermittedActions.RejectToAny)
                    {// 获取允许驳回的节点
                        List<ActivityParam> rejectActivies = new List<ActivityParam>();
                        foreach (OThinker.H3.Instance.Token token in instance.Tokens)
                        {
                            if (token.Activity == activity.ActivityCode) continue;
                            ParticipativeActivity act = template.GetActivityByCode(token.Activity) as ParticipativeActivity;
                            if (act == null) continue;
                            rejectActivies.Add(new ActivityParam()
                            {
                                ActivityCode = act.ActivityCode,
                                DisplayName = act.DisplayName
                            });
                        }
                        result.RejectActivies = rejectActivies;
                    }

                    result.PermittedActions = participative.PermittedActions;
                }
            }

            return Json(result);
        }
        public bool startWorkflow(
            string workflowCode,
            string userCode,
            bool finishStart,
            List <DataItemParam> paramValues)
        {
            //ValidateSoapHeader();
            string workItemID, keyItem, errorMessage;

            workItemID = keyItem = errorMessage = string.Empty;


            try
            {
                // 获取模板
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplateHeader workflowTemplate = GetWorkflowTemplate(workflowCode);
                if (workflowTemplate == null)
                {
                    return(false);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as Organization.User;
                if (user == null)
                {
                    return(false);
                }

                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject       bo     = new DataModel.BizObject(
                    this.Engine.Organization,
                    this.Engine.MetadataRepository,
                    this.Engine.BizObjectManager,
                    this.Engine.BizBus,
                    schema,
                    OThinker.Organization.User.AdministratorID,
                    OThinker.Organization.OrganizationUnit.DefaultRootID);

                if (paramValues != null)
                {
                    // 这里可以在创建流程的时候赋值
                    //foreach (DataItemParam param in paramValues)
                    //{

                    //    if (bo.Schema.ContainsField(param.ItemName))
                    //    {
                    //        bo[param.ItemName] = param.ItemValue;
                    //    }
                    //}
                    List <OThinker.H3.DataModel.BizObject> details = null;
                    foreach (DataItemParam param in paramValues)
                    {
                        if (!(details != null && details.Count > 0 && details[0].Schema.SchemaCode == param.ItemName))
                        {
                            details = new List <OThinker.H3.DataModel.BizObject>();
                        }
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null)
                        {
                            continue;
                        }
                        SetItemValue(bo, property, param.ItemValue, details, param.ItemName);
                    }
                }

                bo.Create();

                // 创建流程实例
                string InstanceId = this.Engine.InstanceManager.CreateInstance(
                    bo.ObjectID,
                    workflowTemplate.WorkflowCode,
                    workflowTemplate.WorkflowVersion,
                    null,
                    null,
                    user.UnitID,
                    null,
                    false,
                    Instance.InstanceContext.UnspecifiedID,
                    null,
                    Instance.Token.UnspecifiedID);

                // 设置紧急程度为普通
                OThinker.H3.Messages.MessageEmergencyType emergency = Messages.MessageEmergencyType.Normal;
                // 这里也可以在启动流程的时候赋值
                Dictionary <string, object> paramTables = new Dictionary <string, object>();

                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                    = new OThinker.H3.Messages.StartInstanceMessage(
                          emergency,
                          InstanceId,
                          null,
                          paramTables,
                          Instance.PriorityType.Normal,
                          true,
                          null,
                          false,
                          OThinker.H3.Instance.Token.UnspecifiedID,
                          null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
        public System.Web.Mvc.ActionResult StartWorkflow(string appId, string pwd, string userCode, string workflowCode,
            bool finishStart, string paramValues)
        {
            BPMServiceResult result = new BPMServiceResult();

            List<DataItemParam> listParams = JSSerializer.Deserialize<List<DataItemParam>>(paramValues);
            string workItemID, keyItem, errorMessage;
            workItemID = keyItem = errorMessage = string.Empty;

            try
            {
                OThinker.H3.WorkflowTemplate.PublishedWorkflowTemplate workflowTemplate = this.Engine.WorkflowManager.GetDefaultWorkflow(workflowCode);
                if (workflowTemplate == null)
                {
                    result = new BPMServiceResult(false, "流程模板不存在,模板编码:" + workflowCode + "。");
                    return Json(result);
                }
                // 查找流程发起人
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(userCode) as OThinker.Organization.User;
                if (user == null)
                {
                    result = new BPMServiceResult(false, "用户{" + userCode + "}不存在。");
                    return Json(result);
                }

                OThinker.H3.DataModel.BizObjectSchema schema = this.Engine.BizObjectManager.GetPublishedSchema(workflowTemplate.BizObjectSchemaCode);
                OThinker.H3.DataModel.BizObject bo = new OThinker.H3.DataModel.BizObject(
                    this.Engine.Organization,
                    this.Engine.MetadataRepository,
                    this.Engine.BizObjectManager,
                    null,
                    schema,
                    user.ObjectID,
                    user.ParentID);

                if (listParams != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in listParams)
                    {
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null) continue;
                        SetItemValue(bo, property, param.ItemValue);
                    }
                }


                bo.Create();

                // 创建流程实例
                string InstanceId = this.Engine.InstanceManager.CreateInstance(
                     bo.ObjectID,
                     workflowTemplate.WorkflowCode,
                     workflowTemplate.WorkflowVersion,
                     null,
                     null,
                     user.UnitID,
                     null,
                     false,
                     InstanceContext.UnspecifiedID,
                     null,
                     Token.UnspecifiedID);

                if (listParams != null)
                {
                    // 这里可以在创建流程的时候赋值
                    foreach (DataItemParam param in listParams)
                    {
                        OThinker.H3.DataModel.PropertySchema property = schema.GetProperty(param.ItemName);
                        if (property == null) continue;
                        if (property.LogicType == DataLogicType.Comment)
                        {// 审核意见
                            CommentParam comment = JSSerializer.Deserialize<CommentParam>(param.ItemValue + string.Empty);
                            this.Engine.BizObjectManager.AddComment(new Comment()
                            {
                                BizObjectId = bo.ObjectID,
                                BizObjectSchemaCode = schema.SchemaCode,
                                InstanceId = InstanceId,
                                Activity = workflowTemplate.StartActivityCode,
                                TokenId = 1,
                                Approval = OThinker.Data.BoolMatchValue.True,
                                DataField = property.Name,
                                UserID = user.ObjectID,
                                SignatureId = comment.SignatureId,
                                Text = comment.Text
                            });
                        }
                    }
                }

                // 启动流程的消息
                OThinker.H3.Messages.StartInstanceMessage startInstanceMessage
                    = new OThinker.H3.Messages.StartInstanceMessage(
                        MessageEmergencyType.Normal,
                        InstanceId,
                        workItemID,
                        null,
                        PriorityType.Normal,
                        true,
                        null,
                        false,
                        OThinker.H3.Instance.Token.UnspecifiedID,
                        null);
                Engine.InstanceManager.SendMessage(startInstanceMessage);
                result = new BPMServiceResult(true, InstanceId, workItemID, "流程实例启动成功!", string.Empty);
            }
            catch (Exception ex)
            {
                result = new BPMServiceResult(false, ex.ToString());
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 16
0
        public JsonResult WorkItemSheets(string paramString)
        {
            ActionResult result = new ActionResult(false, "");

            Dictionary <string, string> dicParams = JsonConvert.DeserializeObject <Dictionary <string, string> >(paramString);

            bool   isMobile      = false;
            string LoginName     = string.Empty;
            string LoginPassword = string.Empty;
            string MobileToken   = string.Empty;
            string WechatCode    = string.Empty;
            string EngineCode    = string.Empty;

            foreach (string key in dicParams.Keys)
            {
                if (key == Param_WorkItemID)
                {
                    WorkItemID = dicParams[key]; continue;
                }
                if (key == Param_Mode)
                {
                    SheetMode = (SheetMode)Enum.Parse(typeof(SheetMode), dicParams[key]); continue;
                }
                if (key == Param_IsMobile)
                {
                    bool.TryParse(dicParams[key], out isMobile);
                    IsMobile = isMobile;
                    continue;
                }
                if (key.ToLower() == "loginname")
                {
                    LoginName = dicParams[key];
                }
                if (key.ToLower() == "loginpassword")
                {
                    LoginPassword = dicParams[key];
                }
                if (key.ToLower() == "mobiletoken")
                {
                    MobileToken = dicParams[key];
                }
                if (key.ToLower() == "code")
                {
                    WechatCode = dicParams[key];
                }
                if (key.ToLower() == "state")
                {
                    EngineCode = dicParams[key];
                }
            }
            //TODO:微信不需要做单点登录
            ////实现微信单点登录
            //if (!string.IsNullOrEmpty(WechatCode) && !string.IsNullOrEmpty(EngineCode)
            //    && System.Web.HttpContext.Current.Session[Sessions.GetUserValidator()] != null)
            //{
            //    IsMobile = true;
            //    UserValidatorFactory.LoginAsWeChat(EngineCode, WechatCode);
            //}

            //APP打开表单验证
            if (!string.IsNullOrEmpty(LoginName) && !string.IsNullOrEmpty(MobileToken) && this.UserValidator == null)
            {
                if (!SSOopenSheet(LoginName, MobileToken))
                {
                    result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            if (this.UserValidator == null && !string.IsNullOrEmpty(LoginName) && !string.IsNullOrEmpty(LoginPassword))
            {            // 实现登录验证
                OThinker.Organization.User user = this.Engine.Organization.GetUserByCode(LoginName);
                if (user.ValidatePassword(LoginPassword))
                {
                    Session[Sessions.GetUserValidator()] = UserValidatorFactory.GetUserValidator(this.Engine, user.Code);
                }
            }

            if (this.UserValidator == null)
            {
                result = new ActionResult(false, "登录超时!", null, ExceptionCode.NoAuthorize);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            // 解析Url地址
            if (SheetMode == SheetMode.Work)
            {
                if (CurrentWorkItem != null)
                {
                    url = this.GetWorkSheetUrl(
                        CurrentWorkItem,
                        WorkItemSheet,
                        IsMobile);
                }
                else
                {
                    url = this.GetViewCirculateItemSheetUrl(
                        CurrentCirculateItem,
                        WorkItemSheet,
                        SheetMode,
                        IsMobile);
                }
            }
            else
            {
                if (CurrentWorkItem != null)
                {
                    url = this.GetViewSheetUrl(
                        CurrentWorkItem,
                        WorkItemSheet,
                        SheetMode,
                        IsMobile);
                }
                else
                {
                    url = this.GetViewCirculateItemSheetUrl(
                        CurrentCirculateItem,
                        WorkItemSheet,
                        SheetMode,
                        IsMobile);
                }
            }
            // 将其中的数据参数做转换
            if (url.Contains(OThinker.H3.Math.Variant.VariablePrefix.ToString()))
            {
                url = InstanceData.ParseText(url);
            }
            // 处理缓存
            DateTime t = DateTime.Now;

            url += "&T=" + t.ToString("HHmmss") + WorkItemID.Substring(0, 8);
            if (SheetMode == SheetMode.Print)
            {
                url += "Print";
            }
            result.Success = true;
            result.Message = url;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 驳回工作任务
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="workItemId"></param>
        /// <param name="commentText"></param>
        /// <returns></returns>
        public bool ReturnItem(string userId, string workItemId, string commentText)
        {
            //Console.Write("不回");
            OThinker.Organization.User user = this.Engine.Organization.GetUnit(userId) as OThinker.Organization.User;
            if (user == null)
            {
                return(false);
            }
            // 获取工作项
            OThinker.H3.WorkItem.WorkItem        item    = this.Engine.WorkItemManager.GetWorkItem(workItemId);
            OThinker.H3.Instance.InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(item.InstanceId);
            // ToKen
            OThinker.H3.Instance.IToken Token = context.GetToken(item.TokenId);
            if (Token.PreTokens == null)
            {
                return(false);
            }
            int PreToken = int.Parse(Token.PreTokens[0].ToString());

            OThinker.H3.Instance.IToken PreToken1 = context.GetToken(PreToken);
            string activityName = PreToken1.Activity;

            // 添加意见
            this.AppendComment(context, item, OThinker.Data.BoolMatchValue.False, commentText);
            // 结束工作项
            this.Engine.WorkItemManager.FinishWorkItem(
                item.ObjectID,
                user.ObjectID,
                OThinker.H3.WorkItem.AccessPoint.ExternalSystem,

                null,
                OThinker.Data.BoolMatchValue.False,
                commentText,
                null,
                OThinker.H3.WorkItem.ActionEventType.Backward,
                (int)OThinker.H3.Controllers.SheetButtonType.Return);
            // 准备触发后面Activity的消息
            OThinker.H3.Messages.ActivateActivityMessage activateMessage
                = new OThinker.H3.Messages.ActivateActivityMessage(
                      OThinker.H3.Messages.MessageEmergencyType.Normal,
                      item.InstanceId,
                      activityName,
                      OThinker.H3.Instance.Token.UnspecifiedID,
                      null,
                      new int[] { item.TokenId },
                      false,
                      OThinker.H3.WorkItem.ActionEventType.Backward);

            // 通知该Activity已经完成
            OThinker.H3.Messages.AsyncEndMessage endMessage =
                new OThinker.H3.Messages.AsyncEndMessage(
                    OThinker.H3.Messages.MessageEmergencyType.Normal,
                    item.InstanceId,
                    item.ActivityCode,
                    item.TokenId,
                    OThinker.Data.BoolMatchValue.False,
                    true,
                    OThinker.Data.BoolMatchValue.False,
                    false,
                    activateMessage);
            this.Engine.InstanceManager.SendMessage(endMessage);
            return(true);
        }
        /// <summary>
        /// 角色用户关系列表
        /// </summary>
        /// <returns></returns>
        public List <RoleUserViewModel> GetRoleUserList(string roleId)
        {
            //return ExecuteFunctionRun(() =>
            //{
            string userCode = "";
            string userName = "";

            OThinker.Organization.OrgPost post = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetUnit(roleId) as OThinker.Organization.OrgPost;

            List <RoleUserViewModel> lstRoleUsers = new List <RoleUserViewModel>();

            if (post != null && post.ChildList != null && post.ChildList.Length > 0)
            {
                foreach (OThinker.Organization.OrgStaff staff in post.ChildList)
                {
                    string userid = staff.UserID;
                    OThinker.Organization.User _user = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetUnit(userid) as OThinker.Organization.User;
                    if (_user == null)
                    {
                        continue;
                    }
                    string _userCode = _user.Code;
                    string _userName = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetUnit(userid).Name;
                    string OrgName   = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetName(_user.ParentID);
                    _userName = _userName + "(" + OrgName + ")";

                    //范围组织名称
                    string[] scopeids = staff.OUScope;
                    Dictionary <string, string> dicNames = OThinker.H3.Controllers.AppUtility.Engine.Organization.GetNames(scopeids);
                    string scopeNames = "";
                    foreach (string key in dicNames.Keys)
                    {
                        scopeNames += dicNames[key] + ";";
                    }

                    lstRoleUsers.Add(new RoleUserViewModel
                    {
                        ObjectID        = staff.ObjectID,
                        RoleID          = roleId,
                        UserID          = staff.UserID,
                        UserCode        = _userCode,
                        UserName        = _userName,
                        Sortkey         = staff.ParentIndex,//staff 没有对应属性
                        ManagerScope    = scopeNames,
                        ManagerScopeIds = string.Join(";", staff.OUScope),
                        Description     = staff.Description
                    });
                }
            }

            //筛选
            if (userCode != null)
            {
                lstRoleUsers = lstRoleUsers.Where(r => r.UserCode.ToLower().Contains(userCode.ToLower())).ToList();
            }

            if (userCode != null && lstRoleUsers != null)
            {
                lstRoleUsers = lstRoleUsers.Where(r => r.UserName.Contains(userName)).ToList();
            }
            if (lstRoleUsers.Count > 0)
            {
                lstRoleUsers = lstRoleUsers.OrderBy(r => r.Sortkey).ToList();
            }

            return(lstRoleUsers);
            //});
        }
        /// <summary>
        /// 角色用户关系列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetRoleUserList(string roleId, string userCode, string userName)
        {
            return(ExecuteFunctionRun(() =>
            {
                OThinker.Organization.OrgPost post = this.Engine.Organization.GetUnit(roleId) as OThinker.Organization.OrgPost;

                List <RoleUserViewModel> lstRoleUsers = new List <RoleUserViewModel>();

                if (post != null && post.ChildList != null && post.ChildList.Length > 0)
                {
                    foreach (OThinker.Organization.OrgStaff staff in post.ChildList)
                    {
                        string userid = staff.UserID;
                        OThinker.Organization.User _user = this.Engine.Organization.GetUnit(userid) as OThinker.Organization.User;
                        if (_user == null)
                        {
                            continue;
                        }
                        string _userCode = _user.Code;
                        string _userName = this.Engine.Organization.GetUnit(userid).Name;
                        string OrgName = this.Engine.Organization.GetName(_user.ParentID);
                        _userName = _userName + "(" + OrgName + ")";

                        //范围组织名称
                        string[] scopeids = staff.OUScope;
                        Dictionary <string, string> dicNames = this.Engine.Organization.GetNames(scopeids);
                        string scopeNames = "";
                        foreach (string key in dicNames.Keys)
                        {
                            scopeNames += dicNames[key] + ";";
                        }

                        lstRoleUsers.Add(new RoleUserViewModel
                        {
                            ObjectID = staff.ObjectID,
                            RoleID = roleId,
                            UserID = staff.UserID,
                            UserCode = _userCode,
                            UserName = _userName,
                            Sortkey = staff.ParentIndex,//staff 没有对应属性
                            ManagerScope = scopeNames,
                            ManagerScopeIds = string.Join(";", staff.OUScope),
                            Description = staff.Description
                        });
                    }
                }

                //筛选
                if (userCode != null)
                {
                    lstRoleUsers = lstRoleUsers.Where(r => r.UserCode.ToLower().Contains(userCode.ToLower())).ToList();
                }

                if (userCode != null && lstRoleUsers != null)
                {
                    lstRoleUsers = lstRoleUsers.Where(r => r.UserName.Contains(userName)).ToList();
                }
                if (lstRoleUsers.Count > 0)
                {
                    lstRoleUsers = lstRoleUsers.OrderBy(r => r.Sortkey).ToList();
                }

                var gridData = CreateLigerUIGridData(lstRoleUsers.ToArray());
                return Json(gridData, JsonRequestBehavior.AllowGet);
            }));
        }
        public object LoginInMobile(string userCode,
                                    string password,
                                    string uuid,
                                    string jpushId,
                                    string mobileToken,
                                    string mobileType,
                                    bool isAppLogin)
        {
            OThinker.Organization.User currentUser = null;
            string userImage = string.Empty;

            OThinker.H3.Controllers.UserValidator userValidator = OThinker.H3.Controllers.UserValidatorFactory.GetUserValidator(Engine, userCode);
            password = HttpUtility.UrlDecode(password).Replace("_38;_", "&");

            if (userValidator != null)
            {
                /*
                 * 移动端登录:1.比较账号密码匹配;2.比较uuid和Token是否匹配
                 */

                OThinker.Organization.User user = Engine.Organization.GetUserByCode(userCode);
                if (user == null || user.State == OThinker.Organization.State.Inactive ||
                    user.ServiceState == OThinker.Organization.UserServiceState.Dismissed || user.IsVirtualUser)
                {// 虚拟用户、离职、禁用用户不允许登录
                    return(new { Success = false });
                }

                if (
                    (!string.IsNullOrEmpty(uuid) &&
                     userValidator.User.SID == uuid &&
                     userValidator.User.ValidateMobileToken(mobileToken)) ||
                    userValidator.User.ValidatePassword(password)
                    )
                {
                    currentUser = userValidator.User;
                    userImage   = userValidator.ImagePath;
                }
            }

            if (currentUser == null)
            {// 登录失败
                return(new { Success = false });
            }
            FormsAuthentication.SetAuthCookie(currentUser.Code, false);
            // App 登录则更新 MobileToken 等信息
            if (isAppLogin)
            {
                mobileToken = this.GetMobileToken(currentUser, mobileType, uuid, jpushId);
            }

            OThinker.H3.Controllers.MobileAccess mobile = new OThinker.H3.Controllers.MobileAccess();
            MobileAccess.MobileUser mobileUser          = mobile.GetMobileUser(userValidator, currentUser, userImage, userValidator.DepartmentName, mobileToken);

            var result = new
            {
                Success    = true,
                PortalRoot = this.PortalRoot,
                MobileUser = mobileUser,
                User       = mobileUser
            };

            System.Web.HttpContext.Current.Session[Sessions.GetUserValidator()] = userValidator;

            // 记录登录日志
            this.Engine.UserLogWriter.Write(new Tracking.UserLog()
            {
                LogType        = Tracking.UserLogType.Login,
                SiteType       = Site.PortalType.Mobile,
                ClientPlatform = mobileType,
                ClientAddress  = jpushId,
                DeviceToken    = mobileToken,
                UserCode       = mobileUser.Code,
                MobileSID      = uuid,
                UserID         = mobileUser.ObjectID
            });
            return(result);
        }
Ejemplo n.º 21
0
        public JsonResult ImportSimulation(string SquenceNo, string WorkflowCode)
        {
            return(ExecuteFunctionRun(() => {
                ActionResult result = new ActionResult(false, "");

                DataModel.BizObjectSchema Schema = null;
                OThinker.H3.WorkflowTemplate.WorkflowClause Clause = null;

                EditSimulationViewModel model = new EditSimulationViewModel();
                model.WorkflowCode = WorkflowCode;
                if (!string.IsNullOrEmpty(WorkflowCode))
                {
                    Clause = this.Engine.WorkflowManager.GetClause(WorkflowCode);
                }
                if (Clause != null)
                {
                    Schema = this.Engine.BizObjectManager.GetPublishedSchema(Clause.BizSchemaCode);
                }

                string[] conditions = null;
                string seqCondition = OThinker.H3.Instance.InstanceContext.TableName + "." + OThinker.H3.Instance.InstanceContext.PropertyName_SequenceNo + " ='" + SquenceNo + "'";
                conditions = OThinker.Data.ArrayConvertor <string> .AddToArray(conditions, seqCondition);
                DataTable dt = this.Engine.Query.QueryInstance(conditions, 0, 1);
                if (dt != null && dt.Rows.Count > 0)
                {
                    string InstanceId = dt.Rows[0][1] + string.Empty;
                    InstanceContext context = this.Engine.InstanceManager.GetInstanceContext(InstanceId);
                    if (context != null)
                    {
                        if (context.WorkflowCode == WorkflowCode)
                        {
                            InstanceData dataitems = new InstanceData(this.Engine, InstanceId, this.UserValidator.UserID);
                            Dictionary <string, object> valuetable = dataitems.BizObject.ValueTable;

                            OThinker.Organization.User Originator = this.Engine.Organization.GetUnit(context.Originator) as OThinker.Organization.User;
                            if (Originator != null)
                            {
                                model.Originator = new { ObjectID = Originator.ObjectID, Name = Originator.Name };
                            }


                            string[] workitemIds = this.Engine.Query.QueryWorkItems(InstanceId, -1, WorkItem.WorkItemType.Unspecified, WorkItem.WorkItemState.Unspecified, OThinker.Data.BoolMatchValue.Unspecified);
                            if (workitemIds != null || workitemIds.Length > 0)
                            {
                                foreach (string workitemId in workitemIds)
                                {
                                    WorkItem.WorkItem workItem = this.Engine.WorkItemManager.GetWorkItem(workitemId);
                                    if (!valuetable.ContainsKey(workItem.ActivityCode))
                                    {
                                        valuetable.Add(workItem.ActivityCode, workItem.Participant);
                                    }
                                }
                            }

                            model.WorkflowName = context.InstanceName;
                            ShowDataItems(WorkflowCode, Schema, null, valuetable, model);
                        }
                        else
                        {
                            result.Message = "Simulation.EditSimulation_Mssg1";
                            return Json(result, JsonRequestBehavior.AllowGet);
                        }
                    }
                }
                else
                {
                    result.Message = "Simulation.EditSimulation_Mssg2";
                    return Json(result, JsonRequestBehavior.AllowGet);
                }

                result.Success = true;
                result.Extend = model;
                result.Message = "msgGlobalString.ImportSucceed";
                return Json(result, JsonRequestBehavior.AllowGet);
            }));
        }
Ejemplo n.º 22
0
 /// <summary>
 /// 验证用户身份
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="mobileToken"></param>
 /// <returns></returns>
 private bool ValidateMobileToken(string userId, string mobileToken)
 {
     OThinker.Organization.User user = this.Engine.Organization.GetUnit(userId) as OThinker.Organization.User;
     return(user == null ? false : user.ValidateMobileToken(mobileToken));
 }