/// <summary> /// 添加用户 /// </summary> /// <param name="dbHelper">数据库连接</param> /// <param name="userInfo">用户信息</param> /// <param name="userEntity">用户实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string AddUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage) { // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif string returnValue = string.Empty; BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 若是系统需要用加密的密码,这里需要加密密码。 if (BaseSystemInfo.ServerEncryptPassword) { userEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword); // 安全通讯密码、交易密码也生成好 userEntity.CommunicationPassword = userManager.EncryptUserPassword(userEntity.CommunicationPassword); } returnValue = userManager.Add(userEntity, out statusCode); statusMessage = userManager.GetStateMessage(statusCode); // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了 if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString())) { // 不是系统管理员添加 if (!userInfo.IsAdministrator) { // 给超级管理员群组发信息 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); string[] roleIds = roleManager.GetIds(new KeyValuePair<string, object>(BaseRoleEntity.FieldCode, "Administrators")); string[] userIds = userManager.GetIds(new KeyValuePair<string, object>(BaseUserEntity.FieldCode, "Administrator")); // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.FunctionCode = MessageFunction.WaitForAudit.ToString(); // Pcsky 2012.05.04 显示申请的用户名 messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.UserName + AppMessage.UserService_Check; //messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.BatchSend(userIds, null, roleIds, messageEntity, false); } } return returnValue; }
/// <summary> /// 批量发送站内信息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="receiverIds">接受者主键数组</param> /// <param name="organizeIds">组织机构主键数组</param> /// <param name="roleIds">角色主键数组</param> /// <param name="messageEntity">消息内容</param> /// <returns>影响行数</returns> public int BatchSend(BaseUserInfo userInfo, string[] receiverIds, string[] organizeIds, string[] roleIds, BaseMessageEntity messageEntity) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.BatchSend(receiverIds, organizeIds, roleIds, messageEntity, true); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_BatchSend, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 发送即时通讯提醒 /// </summary> /// <param name="id">主键</param> /// <param name="auditStatus">审核状态</param> /// <param name="auditIdea">审核意见</param> /// <param name="userId">发送给用户主键</param> /// <param name="roleId">发送给角色主键</param> /// <returns>影响行数</returns> public int SendRemindMessage(string id, AuditStatus auditStatus, string auditIdea, string[] userIds, string[] organizeIds, string[] roleIds) { int returnValue = 0; // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); // 这里是回调的类,用反射要回调的 messageEntity.FunctionCode = this.GetType().ToString(); messageEntity.ObjectId = id; // 这里是网页上的显示地址 // messageEntity.Title = this.GetUrl(id); // messageEntity.Content = BaseBusinessLogic.GetAuditStatus(auditStatus) + ":" + this.GetEntity(id).Title + " 请查收" // + Environment.NewLine // + this.GetUrl(id) // + auditIdea; messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; BaseMessageManager messageManager = new BaseMessageManager(this.UserInfo); returnValue = messageManager.BatchSend(userIds, organizeIds, roleIds, messageEntity, false); return returnValue; }
/// <summary> /// 获取特定用户的新信息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="receiverId">当前交互的用户</param> /// <returns>数据表</returns> public DataTable ReadFromReceiver(BaseUserInfo userInfo, string receiverId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseMessageEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); dataTable = messageManager.ReadFromReceiver(receiverId); dataTable.TableName = BaseMessageEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_ReadFromReceiver, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return dataTable; }
/// <summary> /// 发送消息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="receiverId">接收者主键</param> /// <param name="contents">内容</param> /// <returns>主键</returns> public string Send(BaseUserInfo userInfo, string receiverId, string contents) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.ReceiverId = receiverId; messageEntity.Contents = contents; messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.ReadCount = 0; messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 1; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.Send(messageEntity, true); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_Send, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 获取消息状态 /// </summary> /// <param name="userInfo">用户</param> /// <param name="onLineState">用户在线状态</param> /// <param name="lastChekDate">最后检查日期</param> /// <returns>消息状态数组</returns> public string[] MessageChek(BaseUserInfo userInfo, int onLineState, string lastChekDate) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string[] returnValue = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); // 设置为在线状态 BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); userManager.OnLine(userInfo.Id, onLineState); // 读取信息状态 BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.MessageChek(); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_MessageChek, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 获取用户的新信息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="openId">单点登录标识</param> /// <returns>数据表</returns> public DataTable GetDataTableNew(BaseUserInfo userInfo, out string openId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif openId = userInfo.OpenId; DataTable dataTable = new DataTable(BaseMessageEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); if (!BaseSystemInfo.CheckOnLine) { BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); openId = userManager.GetProperty(userInfo.Id, BaseUserEntity.FieldOpenId); } if (userInfo.OpenId.Equals(openId)) { BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); dataTable = messageManager.GetDataTableNew(); dataTable.TableName = BaseMessageEntity.TableName; } // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, "获取用户的新信息", MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return dataTable; }
/// <summary> /// 广播消息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="message">消息内容</param> /// <returns>主键</returns> public int Broadcast(BaseUserInfo userInfo, string message) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string[] receiverIds = null; BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); receiverIds = userManager.GetIds(new KeyValuePair<string, object>(BaseUserEntity.FieldEnabled, 1), new KeyValuePair<string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); messageEntity.FunctionCode = MessageFunction.Remind.ToString(); messageEntity.Contents = message; messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; returnValue = messageManager.BatchSend(receiverIds, string.Empty, string.Empty, messageEntity, false); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_BatchSend, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 发送即时通讯提醒 /// </summary> /// <param name="workFlowCurrentEntity">当前审核流实体信息</param> /// <param name="auditStatus">审核状态</param> /// <param name="auditIdea">审核意见</param> /// <param name="userIds">发送给用户主键</param> /// <param name="roleIds">发送给角色主键</param> /// <returns>影响行数</returns> public virtual int SendRemindMessage(BaseWorkFlowCurrentEntity workFlowCurrentEntity, AuditStatus auditStatus, string[] userIds, string organizeId, string roleId) { // string currentId, string objectId, string objectFullName int returnValue = 0; // 不用给自己发消息了,消息多了也烦恼 userIds = StringUtil.Remove(userIds, this.UserInfo.Id); // BaseUserEntity userEntity = userManager.GetEntity(userId); // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); // 这里是回调的类,用反射要回调的 messageEntity.FunctionCode = MessageFunction.Remind.ToString(); // messageEntity.FunctionCode = this.GetType().ToString(); messageEntity.ObjectId = workFlowCurrentEntity.ObjectId; // 这里是网页上的显示地址 // messageEntity.Title = this.GetUrl(id); string auditIdea = string.Empty; if (!string.IsNullOrEmpty(workFlowCurrentEntity.AuditIdea)) { auditIdea = " 批示: " + workFlowCurrentEntity.AuditIdea; } // messageEntity.Contents = userEntity.DepartmentName + " " + userEntity.RealName messageEntity.Contents = workFlowCurrentEntity.CreateBy + " 发出审批申请: " + "<a title='点击这里,直接查看单据' target='_blank' href='" + this.GetUrl(workFlowCurrentEntity.Id) + "'>" + workFlowCurrentEntity.ObjectFullName + "</a> " + Environment.NewLine + this.UserInfo.RealName + " " + BaseBusinessLogic.GetAuditStatus(auditStatus) + " " + Environment.NewLine + auditIdea; messageEntity.Contents = "有单据" + BaseBusinessLogic.GetAuditStatus(auditStatus); messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; BaseMessageManager messageManager = new BaseMessageManager(this.UserInfo); returnValue = messageManager.BatchSend(userIds, organizeId, roleId, messageEntity, false); return returnValue; }
/// <summary> /// 发送文件 /// </summary> /// <param name="userInfo">用户</param> /// <param name="fileName">文件名</param> /// <param name="file">文件内容</param> /// <param name="toUserId">发送给谁主键</param> /// <returns>文件主键</returns> public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseFolderEntity folderEntity = new BaseFolderEntity(); BaseFolderManager folderManager = new BaseFolderManager(dbHelper, userInfo); // 检查相应的系统必备文件夹 folderManager.FolderCheck(); BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetEntity(toUserId); if (!string.IsNullOrEmpty(userEntity.Id)) { // 04:判断发送者的空间是否存在? // 05:判断已收文件夹是否存在? if (!folderManager.Exists(userEntity.Id.ToString())) { folderEntity.FolderName = userEntity.RealName + AppMessage.FileService_File; folderEntity.ParentId = "UserSpace"; folderEntity.Id = userEntity.Id.ToString(); folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } // 06:判断来自谁的文件夹是否存在? // 07:判断发给谁的文件夹是否存在? if (!folderManager.Exists(toUserId + "_Receive")) { folderEntity.FolderName = AppMessage.FileService_ReceiveFile; folderEntity.ParentId = toUserId; folderEntity.Id = toUserId + "_Receive"; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId)) { folderEntity.FolderName = userEntity.RealName + "(" + userEntity.UserName + ")"; folderEntity.ParentId = userInfo.Id + "_Send"; folderEntity.Id = userInfo.Id + "_Send_" + toUserId; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id)) { folderEntity.FolderName = userInfo.RealName + "(" + userInfo.UserName + ")"; folderEntity.ParentId = toUserId + "_Receive"; folderEntity.Id = toUserId + "_Receive_" + userInfo.Id; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } // 08:已发送文件夹多一个文件。 // 09:已接收文件夹多一个文件。 BaseFileEntity fileEntity = new BaseFileEntity(); fileEntity.FileName = fileName; fileEntity.Contents = file; fileEntity.Enabled = 1; fileEntity.ReadCount = 0; fileEntity.FolderId = userInfo.Id + "_Send_" + toUserId; // 把修改人显示出来 fileEntity.ModifiedBy = userInfo.RealName; fileEntity.ModifiedUserId = userInfo.Id; fileEntity.ModifiedOn = DateTime.Now; BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo); fileManager.AddEntity(fileEntity); fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id; returnValue = fileManager.AddEntity(fileEntity); // string webHostUrl = BaseSystemInfo.WebHostUrl; // if (string.IsNullOrEmpty(webHostUrl)) // { // webHostUrl = "WebHostUrl"; // } // 10:应该还发一个短信提醒一下才对。 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.ObjectId = returnValue; messageEntity.ReceiverId = toUserId; // target=\"_blank\" messageEntity.Contents = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + returnValue + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile; messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.ReadCount = 0; messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 1; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.Add(messageEntity); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }