public UpdateOAToDoList() { loginService = new loginService(); log = LogManager.GetCurrentClassLogger(); dataOp = new DataOperation(); helper = new FlowInstanceHelper(dataOp); }
/// <summary> /// 修改计划状态为进行中 /// </summary> /// <param name="UserId"></param> /// <param name="instance"></param> /// <param name="stepTran"></param> public void ExecuteTran(int UserId, BsonDocument instance, BsonDocument stepTran) { var DataOp = new DataOperation(); if (instance != null) { FlowInstanceHelper helper = new FlowInstanceHelper(); SendFinishMsg msg = new SendFinishMsg(); var currentInstrance = DataOp.FindOneByKeyVal("BusFlowInstance", "flowInstanceId", instance.String("flowInstanceId")); var userIdListInt = helper.GetFlowInstanceAssociateUser(instance.Int("flowId"), instance.Int("flowInstanceId")); userIdListInt.Add(instance.Int("approvalUserId")); List <string> userIdList = (from t in userIdListInt select t.ToString()).Distinct().ToList(); var userList = DataOp.FindAllByKeyValList("SysUser", "userId", userIdList); //获取流程涉及的所有人员 string smsTemple = "您{0}的流程已被审批通过: {1}项目 {2}任务"; BsonDocument task = DataOp.FindOneByKeyVal("XH_DesignManage_Task", "taskId", instance.Text("referFieldValue")); BsonDocument project = DataOp.FindOneByKeyVal("XH_DesignManage_Project", "projId", task.Text("projId")); BsonDocument user = DataOp.FindOneByKeyVal("SysUser", "userId", UserId.ToString()); BsonDocument trace = DataOp.FindAllByKeyVal("BusFlowTrace", "flowInstanceId", instance.Text("flowInstanceId")).OrderByDescending(t => t.Date("createDate")).FirstOrDefault(); List <SmsClass> smsSendList = new List <SmsClass>(); foreach (var item in userList) { SmsClass smsc = new SmsClass(); if (!string.IsNullOrEmpty(item.Text("mobileNumber"))) { smsc.mobileNumber = item.Text("mobileNumber"); if (item.Int("userId") == instance.Int("approvalUserId")) { smsc.content = string.Format(smsTemple, "发起", project.Text("name"), task.Text("name")); } else { smsc.content = string.Format(smsTemple, "参与", project.Text("name"), task.Text("name"));; } smsSendList.Add(smsc); } } msg.Send1(smsSendList); } }
/// <summary> /// 事务金额自动跳转步骤 /// </summary> /// <param name="UserId"></param> /// <param name="instance"></param> /// <param name="stepTran"></param> public void ExecuteTran(int UserId, BsonDocument instance, BsonDocument stepTran) { var dataOp = new DataOperation(); if (instance != null) { var tranStore = stepTran.SourceBson("transactionId"); ///设计变更属性 //var checkPropertyArray = new string[] { "isBuilding", "isAffectArea", "isConstruct", "isMaterial", "changeKindId", "isHandOver", "isReviewTime", "isAffectCheck", "isAffectHandRoom", "isNeedNoticeOwer" }; var approvedAmount = GetApprovedAmount(instance); //获取对应审批金额 if (tranStore != null) { var flowPosId = tranStore.Int("flowPosId"); if (flowPosId == 0) { return; } FlowInstanceHelper helper = new FlowInstanceHelper(dataOp); if (canJumpStep(approvedAmount, tranStore) && CheckProperty(checkPropertyArray, instance, tranStore)) { if (flowPosId == -1) // 默认直接结束流程 { helper.ExecStepTranSysAction(instance, 0); } else { var hitStepObj = dataOp.FindAllByKeyVal("BusFlowStep", "flowId", instance.Text("flowId")).Where(c => c.Int("flowPosId") == flowPosId).FirstOrDefault(); if (hitStepObj != null) { //流程跳转 helper.ExecStepTranSysAction(instance, hitStepObj.Int("stepId")); } } } } } }
public ActionResult saveProgEval(FormCollection saveForm) { InvokeResult result = new InvokeResult(); #region 构建数据 string tbName = PageReq.GetForm("tbName"); string queryStr = PageReq.GetForm("queryStr"); string dataStr = PageReq.GetForm("dataStr"); int saveStatus = PageReq.GetFormInt("saveStatus");//0:保存 1:提交 List <string> filterStrList = new List <string>() { "tbName", "queryStr", "actionUserStr", "flowId", "stepIds", "fileTypeId", "fileObjId", "tableName", "keyName", "keyValue", "delFileRelIds", "uploadFileList", "fileSaveType", "skipStepIds" }; BsonDocument dataBson = new BsonDocument(); var allKeys = saveForm.AllKeys.Where(i => !filterStrList.Contains(i)); if (dataStr.Trim() == "") { foreach (var tempKey in allKeys) { if (tempKey == "tbName" || tempKey == "queryStr" || tempKey.Contains("fileList[") || tempKey.Contains("param.")) { continue; } dataBson.Add(tempKey, PageReq.GetForm(tempKey)); } } else { dataBson = TypeConvert.ParamStrToBsonDocument(dataStr); } #endregion #region 验证参数 string flowId = PageReq.GetForm("flowId"); BsonDocument flowObj = dataOp.FindOneByQuery("BusFlow", Query.EQ("flowId", flowId)); if (flowObj.IsNullOrEmpty()) { result.Message = "无效的流程模板"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } var stepList = dataOp.FindAllByKeyVal("BusFlowStep", "flowId", flowId).OrderBy(c => c.Int("stepOrder")).ToList(); BsonDocument bootStep = stepList.Where(c => c.Int("actTypeId") == (int)FlowActionType.Launch).FirstOrDefault(); if (saveStatus == 1 && bootStep.IsNullOrEmpty())//提交时才判断 { result.Message = "该流程缺少发起步骤"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } var activeStepIdList = PageReq.GetFormIntList("stepIds"); List <int> hitEnslavedStepOrder = dataOp.FindAllByKeyVal("BusFlowStep", "enslavedStepId", bootStep.Text("stepId")).OrderBy(c => c.Int("stepOrder")).Select(c => c.Int("stepOrder")).Distinct().ToList(); List <int> hitStepIds = stepList.Where(c => hitEnslavedStepOrder.Contains(c.Int("stepOrder"))).Select(c => c.Int("stepId")).ToList(); if (saveStatus == 1 && activeStepIdList.Count() <= 0 && hitEnslavedStepOrder.Count() > 0)//提交时才判断 { result.Status = Status.Failed; result.Message = "请先选定会签部门"; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion TableRule rule = new TableRule(tbName); ColumnRule columnRule = rule.ColumnRules.Where(t => t.IsPrimary == true).FirstOrDefault(); string keyName = columnRule != null ? columnRule.Name : ""; #region 验证重名 string newName = PageReq.GetForm("name").Trim(); BsonDocument curChange = dataOp.FindOneByQuery(tbName, TypeConvert.NativeQueryToQuery(queryStr)); BsonDocument oldChange = dataOp.FindOneByQuery(tbName, Query.EQ("name", newName)); if (!oldChange.IsNullOrEmpty() && oldChange.Int(keyName) != curChange.Int(keyName)) { result.Message = "已经存在该名称的方案评审"; result.Status = Status.Failed; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion #region 保存数据 result = dataOp.Save(tbName, queryStr != "" ? TypeConvert.NativeQueryToQuery(queryStr) : Query.Null, dataBson); if (result.Status == Status.Failed) { result.Message = "保存方案评审失败"; return(Json(TypeConvert.InvokeResultToPageJson(result))); } #endregion #region 文件上传 int primaryKey = 0; if (!string.IsNullOrEmpty(queryStr)) { var query = TypeConvert.NativeQueryToQuery(queryStr); var recordDoc = dataOp.FindOneByQuery(tbName, query); saveForm["keyValue"] = result.BsonInfo.Text(keyName); if (recordDoc != null) { primaryKey = recordDoc.Int(keyName); } } if (primaryKey == 0)//新建 { if (saveForm["tableName"] != null) { saveForm["keyValue"] = result.BsonInfo.Text(keyName); } } else//编辑 { #region 除文件 string delFileRelIds = saveForm["delFileRelIds"] != null ? saveForm["delFileRelIds"] : ""; if (!string.IsNullOrEmpty(delFileRelIds)) { FileOperationHelper opHelper = new FileOperationHelper(); try { string[] fileArray; if (delFileRelIds.Length > 0) { fileArray = delFileRelIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (fileArray.Length > 0) { foreach (var item in fileArray) { var result1 = opHelper.DeleteFileByRelId(int.Parse(item)); if (result1.Status == Status.Failed) { break; } } } } } catch (Exception ex) { result.Status = Status.Failed; result.Message = ex.Message; return(Json(TypeConvert.InvokeResultToPageJson(result))); } } #endregion saveForm["keyValue"] = primaryKey.ToString(); } result.FileInfo = SaveMultipleUploadFiles(saveForm); #endregion #region 保存审批人员 InvokeResult tempResult = new InvokeResult(); int proEvalId = result.BsonInfo.Int(keyName); BsonDocument proEvalObj = result.BsonInfo; PageJson json = new PageJson(); json.AddInfo("proEvalId", proEvalId.ToString()); var actionUserStr = PageReq.GetForm("actionUserStr"); #region 查找方案评审流程模板关联,没有则添加 BsonDocument proEvalFlowRel = dataOp.FindOneByQuery("ProgrammeEvaluationBusFlow", Query.EQ("proEvalId", proEvalId.ToString())); if (proEvalFlowRel.IsNullOrEmpty()) { tempResult = dataOp.Insert("ProgrammeEvaluationBusFlow", "proEvalId=" + proEvalId.ToString() + "&flowId=" + flowId); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "插入流程关联失败"; return(Json(json)); } else { proEvalFlowRel = tempResult.BsonInfo; } } #endregion #region 初始化流程实例 var helper = new Yinhe.ProcessingCenter.BusinessFlow.FlowInstanceHelper(dataOp); var flowUserHelper = new Yinhe.ProcessingCenter.BusinessFlow.FlowUserHelper(dataOp); //当前步骤 BsonDocument curStep = null; var hasOperateRight = false; //是否可以跳转步骤 var hasEditRight = false; //是否可以编辑表单 var canForceComplete = false; //是否可以强制结束当前步骤 string curAvaiableUserName = string.Empty; //当前可执行人 BsonDocument curFlowInstance = dataOp.FindAllByQuery("BusFlowInstance", Query.And( Query.EQ("tableName", "ProgrammeEvaluation"), Query.EQ("referFieldName", "proEvalId"), Query.EQ("referFieldValue", proEvalId.ToString()) ) ).OrderByDescending(i => i.Date("createDate")).FirstOrDefault(); if (curFlowInstance.IsNullOrEmpty() == false) { //初始化流程状态 curStep = helper.InitialExecuteCondition(flowObj.Text("flowId"), curFlowInstance.Text("flowInstanceId"), dataOp.GetCurrentUserId(), ref hasOperateRight, ref hasEditRight, ref canForceComplete, ref curAvaiableUserName); if (curStep == null) { curStep = curFlowInstance.SourceBson("stepId"); } } else { curStep = bootStep; //初始化流程实例 if (flowObj != null && curStep != null) { curFlowInstance = new BsonDocument(); curFlowInstance.Add("flowId", flowObj.Text("flowId")); curFlowInstance.Add("stepId", curStep.Text("stepId")); curFlowInstance.Add("tableName", "ProgrammeEvaluation"); curFlowInstance.Add("referFieldName", "proEvalId"); curFlowInstance.Add("referFieldValue", proEvalId); curFlowInstance.Add("instanceStatus", "0"); curFlowInstance.Add("instanceName", proEvalObj.Text("name")); tempResult = helper.CreateInstance(curFlowInstance); if (tempResult.Status == Status.Successful) { curFlowInstance = tempResult.BsonInfo; } else { json.Success = false; json.Message = "创建流程实例失败:" + tempResult.Message; return(Json(json)); } helper.InitialExecuteCondition(flowObj.Text("flowId"), curFlowInstance.Text("flowInstanceId"), dataOp.GetCurrentUserId(), ref hasOperateRight, ref hasEditRight, ref canForceComplete, ref curAvaiableUserName); } if (curStep == null) { curStep = stepList.FirstOrDefault(); } } #endregion #region 保存流程实例步骤人员 List <BsonDocument> allStepList = dataOp.FindAllByKeyVal("BusFlowStep", "flowId", flowId).ToList(); //所有步骤 //获取可控制的会签步骤 string curStepId = curStep.Text("stepId"); var oldRelList = dataOp.FindAllByKeyVal("InstanceActionUser", "flowInstanceId", curFlowInstance.Text("flowInstanceId")).ToList(); //所有的审批人 //stepId + "|Y|" + uid +"|N|"+ status + "|H|"; var arrActionUserStrUserStr = actionUserStr.Split(new string[] { "|H|" }, StringSplitOptions.RemoveEmptyEntries); var storageList = new List <StorageData>(); //不需要审批的所有步骤的id--袁辉 var skipStepIds = PageReq.GetForm("skipStepIds"); var flowHelper = new FlowInstanceHelper(); foreach (var userStr in arrActionUserStrUserStr) { var arrUserStatusStr = userStr.Split(new string[] { "|N|" }, StringSplitOptions.None); if (arrUserStatusStr.Length <= 1) { continue; } string status = arrUserStatusStr[1];//该流程步骤人员是否有效 0:有效 1:无效 var arrUserStr = arrUserStatusStr[0].Split(new string[] { "|Y|" }, StringSplitOptions.RemoveEmptyEntries); var stepId = int.Parse(arrUserStr[0]); var curStepObj = allStepList.Where(c => c.Int("stepId") == stepId).FirstOrDefault(); if (curStepObj == null) { continue; } if (arrUserStr.Length <= 1) { //如果被跳过的审批没有选择人员,则在这里进行保存 var oldRels = oldRelList.Where(t => t.Int("stepId") == stepId).ToList(); if (oldRels.Count > 0) { var skipStr = "1"; if (skipStepIds.Contains(stepId.ToString())) { oldRels = oldRels.Where(t => t.Int("isSkip") == 0).ToList(); } else { oldRels = oldRels.Where(t => t.Int("isSkip") == 1).ToList(); skipStr = "0"; } if (oldRels.Count > 0) { foreach (var oldRel in oldRels) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Update; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); tempData.Document = new BsonDocument().Add("isSkip", skipStr); storageList.Add(tempData); } } } else if (skipStepIds.Contains(stepId.ToString())) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Insert; BsonDocument actionUser = new BsonDocument(); actionUser.Add("flowInstanceId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("actionConditionId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("userId", ""); actionUser.Add("stepId", stepId); actionUser.Add("isSkip", "1"); //新增模板属性对象 flowHelper.CopyFlowStepProperty(actionUser, curStepObj); tempData.Document = actionUser; storageList.Add(tempData); } continue; } var userArrayIds = arrUserStr[1]; var userIds = userArrayIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var userId in userIds) { var oldRel = oldRelList.FirstOrDefault(i => i.Int("stepId") == stepId && i.Text("userId") == userId); if (oldRel.IsNullOrEmpty()) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Insert; BsonDocument actionUser = new BsonDocument(); actionUser.Add("flowInstanceId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("actionConditionId", curFlowInstance.Text("flowInstanceId")); actionUser.Add("userId", userId); actionUser.Add("stepId", stepId); //新增模板属性对象 flowHelper.CopyFlowStepProperty(actionUser, curStepObj); if (curStepObj.Int("actTypeId") == 2)//如果是会签步骤 { actionUser.Set("status", status); } //判断步骤是否跳过审批--袁辉 if (skipStepIds.Contains(stepId.ToString())) { actionUser.Add("isSkip", "1"); } else { actionUser.Add("isSkip", "0"); } tempData.Document = actionUser; storageList.Add(tempData); } else { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Update; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); BsonDocument actionUser = new BsonDocument(); if (hitStepIds.Contains(stepId)) { actionUser.Add("status", status); } actionUser.Add("converseRefuseStepId", ""); actionUser.Add("actionAvaiable", ""); flowHelper.CopyFlowStepProperty(actionUser, curStepObj); //判断步骤是否跳过审批--袁辉 if (skipStepIds.Contains(stepId.ToString())) { actionUser.Add("isSkip", "1"); } else { actionUser.Add("isSkip", "0"); } tempData.Document = actionUser; storageList.Add(tempData); oldRelList.Remove(oldRel); } } } foreach (var oldRel in oldRelList) { var tempData = new StorageData(); tempData.Name = "InstanceActionUser"; tempData.Type = StorageType.Delete; tempData.Query = Query.EQ("inActId", oldRel.Text("inActId")); storageList.Add(tempData); } tempResult = dataOp.BatchSaveStorageData(storageList); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存审批人员失败"; return(Json(json)); } #endregion #endregion #region 提交时保存提交信息并跳转 if (saveStatus == 1)//提交时直接发起 { //保存发起人 BsonDocument tempData = new BsonDocument().Add("approvalUserId", dataOp.GetCurrentUserId().ToString()).Add("instanceStatus", "0"); tempResult = dataOp.Save("BusFlowInstance", Query.EQ("flowInstanceId", curFlowInstance.Text("flowInstanceId")), tempData); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存发起人失败"; return(Json(json)); } //保存发起时间 var timeFormat = "yyyy-MM-dd HH:mm:ss"; tempData = new BsonDocument() { { "startTime", DateTime.Now.ToString(timeFormat) } }; tempResult = dataOp.Save("ProgrammeEvaluation", Query.EQ("proEvalId", proEvalId.ToString()), tempData); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "保存发起时间失败"; return(Json(json)); } //跳转步骤 BsonDocument act = dataOp.FindAllByKeyVal("BusFlowAction", "type", "0").FirstOrDefault(); tempResult = helper.ExecAction(curFlowInstance, act.Int("actId"), null, bootStep.Int("stepId")); if (tempResult.Status == Status.Failed) { json.Success = false; json.Message = "流程跳转失败:" + tempResult.Message; return(Json(json)); } } #endregion return(Json(TypeConvert.InvokeResultToPageJson(result))); }
/// <summary> /// 对所有流程人员发送消息 /// </summary> /// <param name="UserId"></param> /// <param name="instance"></param> /// <param name="stepTran"></param> public void ExecuteTran(int UserId, BsonDocument instance, BsonDocument stepTran) { var DataOp = new DataOperation(); if (instance != null) { FlowInstanceHelper helper = new FlowInstanceHelper(); var currentInstrance = DataOp.FindOneByKeyVal("BusFlowInstance", "flowInstanceId", instance.String("flowInstanceId")); var stepObj = currentInstrance.SourceBson("stepId"); var userIdListInt = new List <int>(); if (stepObj != null && stepObj.Int("actTypeId") == (int)FlowActionType.Launch) { userIdListInt.Add(currentInstrance.Int("approvalUserId")); } else { userIdListInt = helper.GetFlowInstanceAvaiableStepUser(instance.Int("flowId"), instance.Int("flowInstanceId"), currentInstrance.Int("stepId")); } List <string> userIdList = new List <string>(); userIdList = (from t in userIdListInt select t.ToString()).Distinct().ToList(); //userIdList.Add(instance.Text("approvalUserId")); var userList = DataOp.FindAllByKeyValList("SysUser", "userId", userIdList); //获取流程涉及的所有人员 //string strPre = "参与的"; bool isSend = true; string smsTemple = "请审批{0}提交的流程:{1}项目 {2}任务";//"您{4}流程{3}已被{0}审批通过: {1}项目 {2}任务"; BsonDocument task = DataOp.FindOneByKeyVal("XH_DesignManage_Task", "taskId", instance.Text("referFieldValue")); BsonDocument project = DataOp.FindOneByKeyVal("XH_DesignManage_Project", "projId", task.Text("projId")); BsonDocument user = DataOp.FindOneByKeyVal("SysUser", "userId", UserId.ToString()); string content = string.Format(smsTemple, user.Text("name"), project.Text("name"), task.Text("name"), instance.Text("instanceName")); BsonDocument trace = DataOp.FindAllByKeyVal("BusFlowTrace", "flowInstanceId", instance.Text("flowInstanceId")).OrderByDescending(t => t.Date("createDate")).FirstOrDefault(); string actId = trace != null?trace.Text("actId") : "0"; List <string> numList = new List <string>(); List <SmsClass> smsSendList = new List <SmsClass>(); if (trace.Int("traceType") == 0 || trace.Int("traceType") == -1) // 发起审批 { smsTemple = "请审批{0}提交的流程:{1}项目 {2}任务"; content = string.Format(smsTemple, user.Text("name"), project.Text("name"), task.Text("name"), instance.Text("instanceName")); isSend = false; //不对发起人发送发起短信 } else { if (actId != "0") { BsonDocument action = DataOp.FindOneByKeyVal("BusFlowAction", "actId", actId); //驳回审批 if (action.Int("type") == 3) { smsTemple = "您正在处理的流程已被{0}驳回: {1}项目 {2}任务";// "您{4}流程{3}已被{0}审批驳回: {1}项目 {2}任务"; content = string.Format(smsTemple, user.Text("name"), project.Text("name"), task.Text("name"), instance.Text("instanceName")); } } } foreach (var item in userList) { SmsClass smsc = new SmsClass(); if (!string.IsNullOrEmpty(item.Text("mobileNumber"))) { numList.Add(item.Text("mobileNumber")); smsc.mobileNumber = item.Text("mobileNumber"); smsc.content = content; smsSendList.Add(smsc); } } //if (isSend) //{ // strPre = "发起的"; // string apprvoeContent = string.Format(smsTemple, user.Text("name"), project.Text("name"), task.Text("name"), instance.Text("instanceName"), strPre); // var apprUser = userList.Where(t => t.Int("userId") == instance.Int("approvalUserId")).FirstOrDefault(); // if (!string.IsNullOrEmpty(apprUser.Text("mobileNumber"))) // { // SmsClass smsc = new SmsClass(); // smsc.mobileNumber = apprUser.Text("mobileNumber"); // smsc.content = apprvoeContent; // smsSendList.Add(smsc); // } //} Send1(smsSendList); } }
static void Main(string[] args) { bool testCreateOrgStru = false; bool testQueryOrgStru = false; bool testCreateSystemManager = false; bool testImportFlowDefinitionJSON = false; bool testCreateFlowTemplate = false; // Actions bool testCreateFlowActionStart = false; bool testCreateFlowActionMoveTo_1 = false; bool testCreateFlowActionMoveTo_2 = false; bool testCreateFlowActionMoveTo_3 = false; bool testCreateFlowActionMoveTo_4 = false; bool testCreateFlowActionRejectToStart = false; bool testCreateFlowActionJumpTo_1 = false; //bool testCreateFlowActionTake = false; //bool testCreateFlowActionInviteOther = false; //bool testCreateFlowActionFeedBackOfInvite = false; // Engine bool testRunEngine = false; // OPAS2Model bool testBizDocumentSerialNoGenerator = false; bool testCreatePR = false; bool testGenerateBizDataPayloadJson = false; // FlowDynamicUser bool testFlowDynamicUser = false; #region Test OrgMgmtLib #region Creation if (testCreateOrgStru) { using (var db = new EnouFlowOrgMgmtContext()) { // var DBHelper = DBHelper; var orgHelper = new OrgHelper(db); var _org = orgHelper.createObject(); _org.name = "CQAC集团"; orgHelper.saveCreatedObject(_org); var orgSchemaHelper = new OrgSchemaHelper(db); var _orgSchema = orgSchemaHelper.createObject(); _orgSchema.name = "默认组织结构方案"; _orgSchema.Org = _org; orgSchemaHelper.saveCreatedObject(_orgSchema); var bizEntityHelper = new BizEntityHelper(db); var _bizEntity = bizEntityHelper.createObject(); _bizEntity.name = "Qoros汽车有限公司"; bizEntityHelper.saveCreatedObject(_orgSchema, _bizEntity, null); //var _bizEntityChild = OrgMgmtDBHelper.createBizEntity(db); //_bizEntityChild.name = "上海总部"; //OrgMgmtDBHelper.saveCreatedBizEntity(_orgSchema, _bizEntityChild, _bizEntity, db); //var _bizEntityChild2 = OrgMgmtDBHelper.createBizEntity(db); //_bizEntityChild2.name = "常熟生产基地"; //OrgMgmtDBHelper.saveCreatedBizEntity(_orgSchema, _bizEntityChild2, _bizEntity, db); BizEntitySchemaHelper bizEntitySchemaHelper = new BizEntitySchemaHelper(db); var _bizEntitySchema = bizEntitySchemaHelper.createObject(); _bizEntitySchema.name = "Qoros默认公司架构"; _bizEntitySchema.BizEntity = _bizEntity; bizEntitySchemaHelper.saveCreatedObject(_bizEntitySchema); DepartmentHelper departmentHelper = new DepartmentHelper(db); var _department0 = departmentHelper.createObject(); _department0.name = "董事会"; departmentHelper.saveCreatedObject(_bizEntitySchema, _department0, null); //var _department = departmentHelper.createObject() ; //_department.name = "后台部门"; //OrgMgmtDBHelper.saveCreatedDepartment(_bizEntitySchema, _department, null, db); var _department1 = departmentHelper.createObject(); _department1.name = "产品部"; departmentHelper.saveCreatedObject(_bizEntitySchema, _department1, null); var _departmentChild = departmentHelper.createObject(); _departmentChild.name = "财务部"; departmentHelper.saveCreatedObject(_bizEntitySchema, _departmentChild, null); UserHelper userHelper = new UserHelper(db); var _user = userHelper.createObject(); _user.name = "张三"; userHelper.saveCreatedObject(_user); var _user2 = userHelper.createObject(); _user2.name = "李四"; userHelper.saveCreatedObject(_user2); var _user3 = userHelper.createObject(); _user3.name = "王五"; userHelper.saveCreatedObject(_user3); userHelper.createDepartmentUserRelation(_departmentChild, _user); userHelper.createDepartmentUserRelation(_departmentChild, _user2); userHelper.createDepartmentUserRelation(_department1, _user3); RoleHelper roleHelper = new RoleHelper(db); var _role = roleHelper.createObject(); _role.name = "系统管理员"; roleHelper.saveCreatedObject(_role); var _role1 = roleHelper.createObject(); _role1.name = "CXOs"; roleHelper.saveCreatedObject(_role1); userHelper.setUserRole(_user.userId, _role); userHelper.setUserRole(_user.userId, _role1); userHelper.setUserRole(_user2.userId, _role1); RoleTypeHelper roleTypeHelper = new RoleTypeHelper(db); RoleType _roleType = roleTypeHelper.createObject(); _roleType.name = "系统"; roleTypeHelper.saveCreatedObject(_roleType); roleHelper.createRole_RoleTypeRelation(_role, _roleType); } } #endregion #region Query if (testQueryOrgStru) { using (var db = new EnouFlowOrgMgmtContext()) { //找到一个OrgSchema下的顶级业务实体集 var defaultOrg = db.orgs.ToList().FirstOrDefault(); if (defaultOrg == null) { Console.WriteLine("No defaultOrg Exists."); Console.Read(); return; } var defaultOrgSchema = defaultOrg.orgSchema; if (defaultOrgSchema == null) { Console.WriteLine("No defaultOrgSchema Exists."); Console.Read(); return; } var rootBizEntities = defaultOrg.orgSchema.rootBizEntities; var rootBizEntity = rootBizEntities[0]; if (rootBizEntity == null) { Console.WriteLine("No rootBizEntity Exists."); Console.Read(); return; } //找到一个业务实体指定OrgSchema的下级业务实体集 var bizEntityChildren = rootBizEntity.getBizEntitiesChildren( db, db.orgs.ToList().FirstOrDefault().orgSchema); var bizEntityChild = bizEntityChildren[0]; //找到一个业务实体指定OrgSchema的上级业务实体 var bizEntityParent = bizEntityChild.getBizEntitiyParent( db, db.orgs.ToList().FirstOrDefault().orgSchema); //找到一个业务实体指定BizEntitySchema下的顶级部门集 var depts = bizEntityChild.bizEntitySchemas[0].getRootDepartments(db); //找到一个部门的所有下级部门 var dps = depts.LastOrDefault().getDepartmentChildren(db); //找到一个部门的上级部门 var dp1 = depts.LastOrDefault().getDepartmentChildren(db)[1]; var dpParent = dp1.getParentDepartment(db); dpParent = dpParent.getParentDepartment(db); //找到一个部门的所有用户 var usrs = dp1.getUserChildren(db); //找到一个用户的所有部门 var u = usrs[0]; var depts1 = u.getDepartmentsBelongTo(db); //找到一个用户的所有角色 var roles = u.getRolesBelongTo(db); //找到一个角色的所有用户 var cxos = db.roles.ToList()[1].getUsersBelongTo(db); Console.WriteLine("查询完成."); //return; } } #endregion #endregion #region Test OrgMgmtLib.SystemManager if (testCreateSystemManager) { using (var db = new EnouFlowOrgMgmtContext()) { //if (db.systemManagers.Count() <= 0) //{ // var _sysmgr = db.systemManagers.Create(); // _sysmgr.name = "系统管理员"; // _sysmgr.logonName = "sys"; // _sysmgr.logonSalt = "f6152039-1745-4f4c-8f8e-3ed37770fa0d"; // _sysmgr.logonPasswordHash = Convert.ToBase64String( // new System.Security.Cryptography.SHA256Managed().ComputeHash( // Encoding.UTF8.GetBytes( // "111111" + //测试密码 // "f6152039-1745-4f4c-8f8e-3ed37770fa0d"))); // db.systemManagers.Add(_sysmgr); // db.SaveChanges(); // Console.WriteLine("成功创建系统管理员"); //} } } #endregion var PRFlowTemplateFilePath = @"C:\data\MyProjs\99Flow\EnouFlow\internal\test_flow.json"; var POFlowTemplateFilePath = @"C:\data\MyProjs\99Flow\EnouFlow\EnouFlowEngine\PO.json"; var GRFlowTemplateFilePath = @"C:\data\MyProjs\99Flow\EnouFlow\EnouFlowEngine\GR.json"; var PMFlowTemplateFilePath = @"C:\data\MyProjs\99Flow\EnouFlow\EnouFlowEngine\PM.json"; #region Test import Flow Definition JSON if (testImportFlowDefinitionJSON) { StreamReader oJsonFile = new StreamReader( POFlowTemplateFilePath); //StreamReader oJsonFile = new System.IO.StreamReader( //@"C:\data\MyProjs\99Flow\EnouFlow\EnouFlowEngine\test_flow.json"); var flowTemplateDefTest = JsonHelper.DeserializeJsonToObject <FlowTemplateDef>( oJsonFile.ReadToEnd()); dynamic temp = parseJsonToDynamicObject("{'AmountTotal': 49999}"); Console.WriteLine("成功导入流程定义文件"); } #endregion #region Test Create Flow Template in DB if (testCreateFlowTemplate) { StreamReader oJsonFile = new StreamReader(PMFlowTemplateFilePath); var tplJson = oJsonFile.ReadToEnd(); var flowTemplateDefTest = JsonHelper.DeserializeJsonToObject <FlowTemplateDef>( tplJson); Tuple <bool, FlowTemplate, List <string> > result = FlowTemplateDBHelper.createFlowTemplate( flowTemplateDefTest.basicInfo.guid, flowTemplateDefTest.basicInfo.name, flowTemplateDefTest.basicInfo.displayName, flowTemplateDefTest.basicInfo.version, "PM", tplJson ); var tpl = result.Item2; //tpl.guid = flowTemplateDefTest.basicInfo.guid; //tpl.name = flowTemplateDefTest.basicInfo.name; //tpl.displayName = flowTemplateDefTest.basicInfo.displayName; //tpl.version = flowTemplateDefTest.basicInfo.version; //tpl.code = "PM"; //tpl.flowTemplateJson = tplJson; FlowTemplateDBHelper.saveCreatedFlowTemplate(tpl); Console.WriteLine("成功创建流程定义模板"); } #endregion #region Test Create FlowActions #region Test Create FlowActionStart if (testCreateFlowActionStart) { var actionStart = FlowActionHelper.PostFlowActionStart( "aaaaaaa-1745-4f4c-8f8e-3ed37770fa0d", "bizDocumentGuid", "PR", "用户输入的备注内容aaa", null, null, 1, "abc", 1, "def", null, "TestFlow-001", "f6152039-1745-4f4c-8f8e-3ed37770fa0d" ); } #endregion #region Test Create FlowActionMoveTo if (testCreateFlowActionMoveTo_1) { var action1 = FlowActionHelper.PostFlowActionMoveTo( "bbbbbbb-1745-4f4c-8f8e-3ed37770fa0d", "bizDocumentGuid", "PR", DateTime.Now.AddSeconds(1), "用户输入的备注内容bbb", "{'AmountTotal': 50001}", "{'AmountTotalUpdated': 49999}", 1, "user-guid", 0, null, "TestFlow-001", "f6152039-1745-4f4c-8f8e-3ed37770fa0d", "9d985ac5-a1da-4c63-8aea-83e9974ffccc", "9d4a6006-1099-46ad-b037-24e84476ab50", new List <Paticipant>() { new Paticipant("user", new PaticipantDigest( "李四", "27bcd361-12c7-4376-8dd8-ce68ad964431", 2, null, null) ) }, null, null ); } if (testCreateFlowActionMoveTo_2) { var action2 = FlowActionHelper.PostFlowActionMoveTo( "cccccc-1745-4f4c-8f8e-3ed37770fa0d", "bizDocumentGuid", "PR", DateTime.Now.AddSeconds(2), "用户输入的备注内容ccc", null, null, 1, "user-guid", 1, "flow-inst-guid", "TestFlow-001", "2dde0ed2-c10b-4c98-b263-1016dcfa951d", "55d72a3e-051a-46a0-9aae-0be1c62b2e24", "ab0f92f6-35cd-44b9-a7bd-5a17e544aa9c", new List <Paticipant>() { new Paticipant("user", new PaticipantDigest( "王五", "f17004ea-1246-40df-9f48-2adf0cfa8517", 3, null, null) ) }, null, null ); } if (testCreateFlowActionMoveTo_3) { var action3 = FlowActionHelper.PostFlowActionMoveTo( "dddddd-1745-4f4c-8f8e-3ed37770fa0d", "bizDocumentGuid", "PR", DateTime.Now.AddSeconds(3), "用户输入的备注内容ddd", null, null, 1, "user-guid", 1, "flow-inst-guid", "TestFlow-001", "ab0f92f6-35cd-44b9-a7bd-5a17e544aa9c", "ceeae036-7b21-438f-bc46-33bfad0cc546", "5ee19a5b-df8b-4c11-a0d4-082848b5f216", new List <Paticipant>() { new Paticipant("user", new PaticipantDigest( "张三", "85a14f4d-e68e-4684-88b2-3bf9dea386e6", 1, null, null) ) }, null, null ); } if (testCreateFlowActionMoveTo_4) { var action4 = FlowActionHelper.PostFlowActionMoveTo( "eeeeee-1745-4f4c-8f8e-3ed37770fa0d", "bizDocumentGuid", "PR", DateTime.Now.AddSeconds(4), "用户输入的备注内容eee", null, null, 1, "user-guid", 1, "flow-inst-guid", "TestFlow-001", "5ee19a5b-df8b-4c11-a0d4-082848b5f216", "0dade9b8-acc9-4223-8dab-9d55480722a8", "c09fcfbe-92a9-48cd-bd14-975996e063a7", new List <Paticipant>(), null, null //{ // new Paticipant("user", // new PaticipantDigest( // "川普", // "c4961686-41a6-469a-afa9-df05e42ba9f8", // 16,null) // ) //} ); } #endregion #region TODO: Test Create FlowActionTake #endregion #region TODO: Test Create FlowActionInviteOther #endregion #region TODO: Test Create FlowActionFeedBackOfInvite #endregion #endregion #region Test Engine if (testRunEngine) { var dispatcher = new FlowActionRequestDispatcher(); //EnumFlowActionRequestType[] types = new EnumFlowActionRequestType[] { EnumFlowActionRequestType.moveToAutoGenerated }; //dispatcher.processNextActionOfSpecifiedInstance(1, types); var result = dispatcher.processNextAction(); } #endregion #region Test BizDocumentSerialNoGenerator if (testBizDocumentSerialNoGenerator) { var prNumberNew = new OPAS2ModelDBHelper(). generateDocumentSerialNo(EnumBizDocumentType.PR, "QOROS", "SH", "2017", "IT"); Console.WriteLine(prNumberNew); } #endregion #region Test CreatePR if (testCreatePR) { var prNumberNew = new OPAS2ModelDBHelper(). generateDocumentSerialNo(EnumBizDocumentType.PR, "QOROS", "SH", "2017", "IT"); Console.WriteLine(prNumberNew); using (var db = new OPAS2DbContext()) { var pr = db.purchaseReqs.Create(); pr.guid = "test-pr-guid:" + Guid.NewGuid().ToString(); pr.documentNo = new OPAS2ModelDBHelper().generateDocumentSerialNo( EnumBizDocumentType.PR, "QOROS", "SH", "2017", "IT"); pr.WBSNo = "test-WBS"; pr.contactOfficePhone = "contactOfficePhone"; pr.contactMobile = "contactMobile"; pr.contactOtherMedia = "contactOtherMedia"; pr.departmentId = 1; pr.departmentIdBelongTo = 1; pr.costCenterId = 1; pr.expectReceiveBeginTime = DateTime.Now; pr.expectReceiveEndTime = DateTime.Now; pr.isBidingRequired = true; pr.noBiddingReason = "noBiddingReason"; pr.reason = "reason"; pr.description = "description"; pr.estimatedCost = (decimal)123456.789; pr.currencyTypeId = 1; pr.mainCurrencyRate = (decimal)1.0; pr.estimatedCostInRMB = (decimal)123456.789; pr.averageBenchmark = (decimal)787654.78; pr.benchmarkDescription = "benchmarkDescription"; pr.isFirstBuy = false; pr.firstBuyDate = DateTime.Now; pr.firstCostAmount = (decimal)73663387.87; pr.firstBuyDescription = "firstBuyDescription"; pr.remarkOfAprrovers = "remarkOfAprrovers"; pr.otherVendorsNotInList = "otherVendorsNotInList"; pr.submitTime = DateTime.Now; pr.submitor = "ChaoQin"; pr.submitorUserId = 1; pr.creator = "ChaoQin"; pr.creatorUserId = 1; var prDtl1 = db.purchaseReqDetails.Create(); prDtl1.PurchaseReq = pr; prDtl1.estimatedCost = (decimal)123.45; prDtl1.lineNo = 5; prDtl1.itemName = "name1"; prDtl1.itemType = (EnumPRItemType)1; prDtl1.description = "description1"; prDtl1.creator = "ChaoQin"; prDtl1.creatorUserId = 1; //pr.details.Add(prDtl1); db.purchaseReqs.Add(pr); db.purchaseReqDetails.Add(prDtl1); db.SaveChanges(); Console.WriteLine("PR: " + pr.purchaseReqId.ToString()); } } #endregion #region Test GenerateBizDataPayloadJson if (testGenerateBizDataPayloadJson) { using (var db = new OPAS2DbContext()) { var pr = db.purchaseReqs.Find(8); dynamic bizDataPayload = new ExpandoObject(); bizDataPayload.document = pr; //bizDataPayload.subDocuments = pr.details; bizDataPayload.AmountTotal = pr.details.Aggregate <PurchaseReqDetail, decimal>( 0, (total, detail) => { return(total + detail.estimatedCost.Value); }); var s = JsonConvert.SerializeObject(bizDataPayload, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, } ); Console.WriteLine(s); } } #endregion #region testFlowDynamicUser Console.Out.WriteLine("Enter into script:"); var _session = new DictionaryContext(); var flowInstDb = new EnouFlowInstanceContext(); var flowInstance = FlowInstanceHelper.GetFlowInstance(42, flowInstDb); _session.globals.Add("flowInstance", flowInstance); var _references = new Assembly[] { typeof(DictionaryContext).Assembly, typeof(System.Runtime.CompilerServices.DynamicAttribute).Assembly, typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly, typeof(ExpandoObject).Assembly, typeof(JsonConvert).Assembly, typeof(ExpandoObjectConverter).Assembly, typeof(Paticipant).Assembly, typeof(UserDTO).Assembly, typeof(FlowInstance).Assembly, typeof(List <>).Assembly }; var _imports = new string[] { typeof(DictionaryContext).Namespace, typeof(System.Runtime.CompilerServices.DynamicAttribute).Namespace, typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Namespace, typeof(ExpandoObject).Namespace, typeof(JsonConvert).Namespace, typeof(ExpandoObjectConverter).Namespace, typeof(Paticipant).Namespace, typeof(UserDTO).Namespace, typeof(FlowInstance).Namespace, typeof(List <>).Namespace }; var _options = ScriptOptions.Default .AddReferences(_references) .AddImports(_imports); //var code = @"var result = new List<UserDTO>(); // result.Add(OrgMgmtDBHelper.getUserDTO(((FlowInstance)globals[""flowInstance""]).creatorId)); // return result;"; using (var db = new EnouFlowOrgMgmtContext()) { var retShouldBe = new DepartmentHelper(db).getUserDTOsOfPositionInDepartment( new UserHelper(db).getUserDefaultDepartment(flowInstance.creatorId).departmentId, UserPositionToDepartment.manager); } var code = @" FlowInstance flowInstance = (FlowInstance)globals[""flowInstance""]; Department department = OrgMgmtDBHelper.getUserDefaultDepartment(flowInstance.creatorId); if(department!=null){ return OrgMgmtDBHelper.getUserDTOsOfPositionInDepartment( department.departmentId, UserPositionToDepartment.manager); }else{ return null; }"; var result1 = CSharpScript.RunAsync(code, globals: _session, options: _options).Result.ReturnValue; var retList = (List <UserDTO>)result1; #endregion Console.WriteLine("All done!"); Console.Read(); }
public void ZHHYSendTurnNotice(int flowInstanceId, List <int> userIds) { DataOperation dataOp = new DataOperation(); Logger log = LogManager.GetCurrentClassLogger(); var userIdListInt = new List <int>(); var helper = new FlowInstanceHelper(); int noticeType = 0;//0:普通下一步审批提醒 1:驳回提醒 2:通过提醒 var curFlowInstance = dataOp.FindOneByKeyVal("BusFlowInstance", "flowInstanceId", flowInstanceId.ToString()); //获取当前步骤 var curStepObj = dataOp.FindOneByKeyVal("BusFlowStep", "stepId", curFlowInstance.Text("stepId")); //当前流程动作类型 var curActTypeObj = dataOp.FindOneByKeyVal("BusFlowActionType", "actTypeId", curStepObj.Text("actTypeId")); List <string> userIdList = new List <string>(); userIdList = (from t in userIds select t.ToString()).Distinct().ToList(); var userList = dataOp.FindAllByKeyValList("SysUser", "userId", userIdList); //获取流程涉及的所有人员 //获取当前流程模板 var busflow = dataOp.FindOneByQuery("BusFlow", Query.EQ("flowId", curFlowInstance.Text("flowId"))); var curTaskObj = dataOp.FindOneByKeyVal(curFlowInstance.Text("tableName"), curFlowInstance.Text("referFieldName"), curFlowInstance.Text("referFieldValue")); //设置链接跳转地址 string taskLinkStr = string.Empty; switch (curFlowInstance.Text("tableName")) { case "XH_DesignManage_Task": taskLinkStr = string.Format("{0}{1}{2}", SysAppConfig.MailHostDomain, "/DesignManage/NewTaskWorkFlowInfo/", curFlowInstance.Text("referFieldValue")); break; case "FreeFlow_FreeApproval": taskLinkStr = string.Format("{0}{1}{2}", SysAppConfig.MailHostDomain, "/WorkFlowInfoCenter/FreeTaskWorkFlowInfo/", curFlowInstance.Text("referFieldValue")); break; case "DesignChange": taskLinkStr = SysAppConfig.MailHostDomain + "/DesignManage/DesignChangeWorkFlowInfo?dngChangeId=" + curFlowInstance.Text("referFieldValue") + "&typeStr=1"; break; default: break; } var body = new StringBuilder(); body.Append("此邮件来自于宏洋设计ERP系统,请勿回复,谢谢!<br />"); body.Append("您有一条待审批流程需要进入系统处理 <br />"); body.AppendFormat("流程名称:{0} <br />", busflow.Text("name")); //设置邮件内容是否为html格式 bool isBodyHtml = true; log.Info("开始给 {0} 发送流程审批 转办 邮件提醒", string.Join(",", userList.Select(i => i.Text("name")))); string logInfo = string.Format("流程名称:{0} 流程ID:{1} 动作:{2} 动作ID:{3} 动作顺序:{4}", curFlowInstance.Text("instanceName"), curFlowInstance.Int("flowInstanceId"), curActTypeObj.Text("name"), curStepObj.Int("stepId"), curStepObj.Int("stepOrder") ); log.Info(logInfo); //异步发送邮件 foreach (var user in userList) { //邮件主题 var subject = string.Format("尊敬的{0},您好,从设计ERP系统推送过来一条待审批流程,请处理", user.Text("name")); //通过用户名直接登录 var loginCheckUrl = SysAppConfig.MailHostDomain + "/Account/Mail_Login?name="; //发送成功后的log var successInfo = string.Format("给 {0} 发送邮件提醒成功 流程名称:{1}", user.Text("name"), curFlowInstance.Text("instanceName")); var nameByte = Encoding.Unicode.GetBytes(user.Text("name")); loginCheckUrl += Convert.ToBase64String(nameByte); loginCheckUrl += "&ReturnUrl=" + HttpUtility.UrlEncode(taskLinkStr); string emailAddr = user.Text("emailAddr");//收件人邮箱 StringBuilder tempBody = new StringBuilder(body.ToString()); tempBody.AppendFormat("当前轮到您审批,请<a href='{0}'>点击</a>此链接进入", loginCheckUrl); MailSender sender = new MailSender( emailAddr, subject, tempBody.ToString(), string.Empty, isBodyHtml, successInfo); sender.SendAsync(); } }
public void ZHHYSendNextAppNotice(int flowInstanceId) { DataOperation dataOp = new DataOperation(); Logger log = LogManager.GetCurrentClassLogger(); var userIdListInt = new List <int>(); var helper = new FlowInstanceHelper(); int noticeType = 0;//0:普通下一步审批提醒 1:驳回提醒 2:通过提醒 var curFlowInstance = dataOp.FindOneByKeyVal("BusFlowInstance", "flowInstanceId", flowInstanceId.ToString()); if (curFlowInstance.Int("instanceStatus") == 1) { noticeType = 2; } else { BsonDocument trace = dataOp.FindAllByKeyVal("BusFlowTrace", "flowInstanceId", curFlowInstance.Text("flowInstanceId")).OrderByDescending(t => t.Date("createDate")).FirstOrDefault(); string actId = trace != null?trace.Text("actId") : "0"; if (actId != "0") { BsonDocument action = dataOp.FindOneByKeyVal("BusFlowAction", "actId", actId); //驳回审批 if (action.Int("type") == 3) { noticeType = 1; } } } //获取当前步骤 var curStepObj = dataOp.FindOneByKeyVal("BusFlowStep", "stepId", curFlowInstance.Text("stepId")); //当前流程动作类型 var curActTypeObj = dataOp.FindOneByKeyVal("BusFlowActionType", "actTypeId", curStepObj.Text("actTypeId")); if (curFlowInstance.Int("instanceStatus") == 1) { userIdListInt.Add(curFlowInstance.Int("approvalUserId")); } else { if (curStepObj.Int("actTypeId") == (int)FlowActionType.Launch) { userIdListInt = helper.GetCanLaunchUserIds(flowInstanceId); } else { userIdListInt = helper.GetFlowInstanceAvaiableStepUser(curFlowInstance.Int("flowId"), curFlowInstance.Int("flowInstanceId"), curFlowInstance.Int("stepId")); } } List <string> userIdList = new List <string>(); userIdList = (from t in userIdListInt select t.ToString()).Distinct().ToList(); var userList = dataOp.FindAllByKeyValList("SysUser", "userId", userIdList); //获取流程涉及的所有人员 //获取当前流程模板 var busflow = dataOp.FindOneByQuery("BusFlow", Query.EQ("flowId", curFlowInstance.Text("flowId"))); var curTaskObj = dataOp.FindOneByKeyVal(curFlowInstance.Text("tableName"), curFlowInstance.Text("referFieldName"), curFlowInstance.Text("referFieldValue")); //设置链接跳转地址 string taskLinkStr = string.Empty; switch (curFlowInstance.Text("tableName")) { case "XH_DesignManage_Task": taskLinkStr = string.Format("{0}{1}{2}", SysAppConfig.MailHostDomain, "/DesignManage/NewTaskWorkFlowInfo/", curFlowInstance.Text("referFieldValue")); break; case "FreeFlow_FreeApproval": taskLinkStr = string.Format("{0}{1}{2}", SysAppConfig.MailHostDomain, "/WorkFlowInfoCenter/FreeTaskWorkFlowInfo/", curFlowInstance.Text("referFieldValue")); break; case "DesignChange": taskLinkStr = SysAppConfig.MailHostDomain + "/DesignManage/DesignChangeWorkFlowInfo?dngChangeId=" + curFlowInstance.Text("referFieldValue") + "&typeStr=1"; break; default: break; } //设置邮件内容 //此邮件来自于宏洋设计ERP系统,请勿回复,谢谢! //您有一条待审批流程需要进入系统处理。 //流程名称:XXXX。(取自我们系统的流程名称) //当前轮到您审批,请点击此链接进入。(“链接"加上我们系统对应页面的链接,用户可以点击跳转到对应的页面) //顺祝商祺! var body = new StringBuilder(); body.Append("此邮件来自于宏洋设计ERP系统,请勿回复,谢谢!<br />"); if (noticeType == 0) { body.Append("您有一条待审批流程需要进入系统处理 <br />"); } else if (noticeType == 1) { body.Append("您有一条审批流程被驳回需要进入系统处理 <br />"); } else if (noticeType == 2) { body.Append("您有一条审批流程通过审批请进入系统查看 <br />"); } body.AppendFormat("流程名称:{0} <br />", busflow.Text("name")); //设置邮件内容是否为html格式 bool isBodyHtml = true; log.Info("开始给 {0} 发送流程审批邮件提醒", string.Join(",", userList.Select(i => i.Text("name")))); string logInfo = string.Format("流程名称:{0} 流程ID:{1} 动作:{2} 动作ID:{3} 动作顺序:{4}", curFlowInstance.Text("instanceName"), curFlowInstance.Int("flowInstanceId"), curActTypeObj.Text("name"), curStepObj.Int("stepId"), curStepObj.Int("stepOrder") ); log.Info(logInfo); //异步发送邮件 foreach (var user in userList) { //邮件主题 var subject = string.Format("尊敬的{0},您好,从设计ERP系统推送过来一条待审批流程,请处理", user.Text("name")); //通过用户名直接登录 var loginCheckUrl = SysAppConfig.MailHostDomain + "/Account/Mail_Login?name="; //发送成功后的log var successInfo = string.Format("给 {0} 发送邮件提醒成功 流程名称:{1}", user.Text("name"), curFlowInstance.Text("instanceName")); var nameByte = Encoding.Unicode.GetBytes(user.Text("name")); loginCheckUrl += Convert.ToBase64String(nameByte); loginCheckUrl += "&ReturnUrl=" + HttpUtility.UrlEncode(taskLinkStr); string emailAddr = user.Text("emailAddr");//收件人邮箱 StringBuilder tempBody = new StringBuilder(body.ToString()); tempBody.AppendFormat("当前轮到您审批,请<a href='{0}'>点击</a>此链接进入", loginCheckUrl); MailSender sender = new MailSender( emailAddr, subject, tempBody.ToString(), string.Empty, isBodyHtml, successInfo); sender.SendAsync(); } }