/// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="baseMessageEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseMessageEntity baseMessageEntity)
 {
     SetEntityExpand(sqlBuilder, baseMessageEntity);
     sqlBuilder.SetValue(BaseMessageEntity.FieldParentId, baseMessageEntity.ParentId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentId, baseMessageEntity.ReceiverDepartmentId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentName, baseMessageEntity.ReceiverDepartmentName);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverId, baseMessageEntity.ReceiverId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverRealName, baseMessageEntity.ReceiverRealName);
     sqlBuilder.SetValue(BaseMessageEntity.FieldFunctionCode, baseMessageEntity.FunctionCode);
     sqlBuilder.SetValue(BaseMessageEntity.FieldCategoryCode, baseMessageEntity.CategoryCode);
     sqlBuilder.SetValue(BaseMessageEntity.FieldObjectId, baseMessageEntity.ObjectId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldTitle, baseMessageEntity.Title);
     sqlBuilder.SetValue(BaseMessageEntity.FieldContents, baseMessageEntity.Contents);
     sqlBuilder.SetValue(BaseMessageEntity.FieldIsNew, baseMessageEntity.IsNew);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReadCount, baseMessageEntity.ReadCount);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReadDate, baseMessageEntity.ReadDate);
     sqlBuilder.SetValue(BaseMessageEntity.FieldTargetURL, baseMessageEntity.TargetURL);
     sqlBuilder.SetValue(BaseMessageEntity.FieldIPAddress, baseMessageEntity.IPAddress);
     sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentId, baseMessageEntity.CreateDepartmentId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentName, baseMessageEntity.CreateDepartmentName);
     sqlBuilder.SetValue(BaseMessageEntity.FieldDeletionStateCode, baseMessageEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseMessageEntity.FieldEnabled, baseMessageEntity.Enabled);
     sqlBuilder.SetValue(BaseMessageEntity.FieldDescription, baseMessageEntity.Description);
     sqlBuilder.SetValue(BaseMessageEntity.FieldSortCode, baseMessageEntity.SortCode);
 }
Ejemplo n.º 2
0
        public int SendGroupMessage(BaseUserInfo userInfo, string organizeId, string roleId, string contents)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessMessageDb(userInfo, parameter, (dbHelper) =>
            {
                // 发给角色里所有的
                BaseMessageEntity entity = new BaseMessageEntity();
                //messageEntity.Id = Guid.NewGuid().ToString("N");
                entity.CategoryCode = MessageCategory.Send.ToString();
                if (!string.IsNullOrEmpty(organizeId))
                {
                    entity.FunctionCode = MessageFunction.OrganizeMessage.ToString();
                    entity.ObjectId     = organizeId;
                }
                if (!string.IsNullOrEmpty(roleId))
                {
                    entity.FunctionCode = MessageFunction.RoleMessage.ToString();
                    entity.ObjectId     = roleId;
                }
                entity.Contents          = contents;
                entity.IsNew             = (int)MessageStateCode.New;
                entity.ReadCount         = 0;
                entity.DeletionStateCode = 0;
                var manager      = new BaseMessageManager(dbHelper, userInfo);
                manager.Identity = true;
                result           = manager.BatchSend(string.Empty, organizeId, roleId, entity, false);
            });

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// </summary>
        /// <returns>影响行数</returns>
        public static int CachePreheating()
        {
            int result = 0;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseMessageEntity.FieldCategoryCode, MessageCategory.Receiver.ToString()));
            parameters.Add(new KeyValuePair <string, object>(BaseMessageEntity.FieldIsNew, (int)MessageStateCode.New));
            parameters.Add(new KeyValuePair <string, object>(BaseMessageEntity.FieldDeletionStateCode, 0));

            // 2015-09-27 吉日嘎拉 把所有的未阅读的消息都缓存起来的代码。
            BaseMessageManager manager = new BaseMessageManager();

            using (IDataReader dataReader = manager.ExecuteReader(parameters, BaseMessageEntity.FieldCreateOn))
            {
                while (dataReader.Read())
                {
                    BaseMessageEntity entity = BaseEntity.Create <BaseMessageEntity>(dataReader, false);
                    // 2015-09-30 吉日嘎拉 两个月以上的信息,意义不大了,可以考虑不缓存了
                    if (entity != null)
                    {
                        manager.CacheProcessing(entity);
                        result++;
                        // System.Console.WriteLine(result.ToString() + " : " + entity.Contents);
                    }
                }
                dataReader.Close();
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 把未阅读的消息,进行缓存处理
 /// 2015-09-27 吉日嘎拉 优化代码
 /// </summary>
 /// <param name="entity">消息</param>
 public void CacheProcessing(BaseMessageEntity entity, DateTime?expireAt = null)
 {
     using (var redisClient = PooledRedisHelper.GetMessageClient())
     {
         CacheProcessing(redisClient, entity, expireAt);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 阅读短信
        /// </summary>
        /// <param name="id">短信ID</param>
        /// <returns>数据权限</returns>
        public DataTable Read(string id)
        {
            // 这里需要改进一下,运行一个高性能的sql语句就可以了,效率会高一些
            DataTable         dataTable     = this.GetDataTableById(id);
            BaseMessageEntity messageEntity = new BaseMessageEntity(dataTable);

            this.OnRead(messageEntity, id);
            dataTable = this.GetDataTableById(id);
            return(dataTable);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加短信,可以发给多个人
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="receiverIds">接收者主键组</param>
        /// <param name="saveSend">保存每个发送记录</param>
        /// <returns>影响行数</returns>
        public int Send(IRedisClient redisClient, BaseMessageEntity entity, string[] receiverIds, bool saveSend = true, DateTime?expireAt = null)
        {
            // 每发一条短信,数据库中需要记录两条记录,他们的CreateUserId都为创建者ID。
            // 接收者多人的话,不要重复设置创建人的记录了,即对发送者来说,只要记录一条记录就够了
            int result = 0;

            entity.CategoryCode = MessageCategory.Receiver.ToString();
            entity.IsNew        = (int)MessageStateCode.New;

            BaseUserEntity userEntity = null;

            for (int i = 0; i < receiverIds.Length; i++)
            {
                entity.ReceiverId = receiverIds[i];
                // 没必要给自己发了, 其实给自己也需要发,否则不知道是否发送成功了没
                //if (entity.ReceiverId.Equals(UserInfo.Id))
                //{
                //    entity.IsNew = (int)MessageStateCode.Old;
                //    continue;
                //}
                // messageEntity.ParentId = null;
                entity.Id           = Guid.NewGuid().ToString("N");
                entity.CategoryCode = MessageCategory.Receiver.ToString();
                userEntity          = BaseUserManager.GetObjectByCache(receiverIds[i]);
                if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
                {
                    entity.ReceiverRealName = userEntity.RealName;
                    // 发给了哪个部门的人,意义不大,是来自哪个部门的人,意义更大一些
                    entity.ReceiverDepartmentId   = userEntity.DepartmentId;
                    entity.ReceiverDepartmentName = userEntity.DepartmentName;
                }
                entity.IsNew = 1;
                // 接收信息
                //string parentId = this.Add(entity, this.Identity, false);
                string parentId = this.AddObject(entity);

# if Redis
                // 20151018 吉日嘎拉 进行缓存处理, 让程序兼容不用缓存也可以用
                CacheProcessing(redisClient, entity, expireAt);
#endif

                if (saveSend)
                {
                    // 已发送信息
                    entity.Id                = Guid.NewGuid().ToString("N");
                    entity.ParentId          = parentId;
                    entity.IsNew             = (int)MessageStateCode.Old;
                    entity.CategoryCode      = MessageCategory.Send.ToString();
                    entity.DeletionStateCode = 0;
                    //this.Add(entity, this.Identity, false);
                    this.AddObject(entity);
                }
                result++;
            }
Ejemplo n.º 8
0
 private static void SetCache(BaseMessageEntity entity)
 {
     if (entity != null && !string.IsNullOrWhiteSpace(entity.Id))
     {
         string key = string.Empty;
         using (var redisClient = PooledRedisHelper.GetMessageClient())
         {
             SetCache(redisClient, entity);
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 添加短信,可以发给多个人
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="receiverIds">接收者主键组</param>
        /// <param name="saveSend">保存每个发送记录</param>
        /// <returns>影响行数</returns>
        public int Send(BaseMessageEntity entity, string[] receiverIds, bool saveSend = true)
        {
            int result = 0;

            using (var redisClient = PooledRedisHelper.GetMessageClient())
            {
                result = Send(redisClient, entity, receiverIds, saveSend);
            }

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取最新一条信息
        /// </summary>
        /// <returns>记录个数</returns>
        public BaseMessageEntity GetNewOne()
        {
            BaseMessageEntity messageEntity = new BaseMessageEntity();
            string            sqlQuery      = " SELECT * "
                                              + "   FROM (SELECT * FROM " + BaseMessageEntity.TableName + " WHERE (" + BaseMessageEntity.FieldIsNew + " = " + ((int)MessageStateCode.New).ToString() + " ) "
                                              + "         AND (" + BaseMessageEntity.FieldReceiverId + " = '" + UserInfo.Id + "') "
                                              + " ORDER BY " + BaseMessageEntity.FieldCreateOn + " DESC) "
                                              + " WHERE ROWNUM = 1 ";
            DataTable dataTable = DbHelper.Fill(sqlQuery);

            return(messageEntity.GetSingle(dataTable));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 添加短信,可以发给多个人
        /// </summary>
        /// <param name="messageEntity">实体</param>
        /// <param name="receiverIds">接收者ID组</param>
        /// <returns>影响行数</returns>
        public int Send(BaseMessageEntity messageEntity, string[] receiverIds, bool saveSend = true)
        {
            BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo);
            // 每发一条短信,数据库中需要记录两条记录,他们的CreateUserId都为创建者ID。
            // 接收者多人的话,不要重复设置创建人的记录了,即对发送者来说,只要记录一条记录就够了
            int returnValue = 0;

            messageEntity.CategoryCode      = MessageCategory.Receiver.ToString();
            messageEntity.IsNew             = (int)MessageStateCode.New;
            messageEntity.IPAddress         = UserInfo.IPAddress;
            messageEntity.ParentId          = null;
            messageEntity.DeletionStateCode = 0;
            messageEntity.Enabled           = 1;
            returnValue++;

            BaseUserEntity userEntity = null;

            for (int i = 0; i < receiverIds.Length; i++)
            {
                messageEntity.ParentId     = null;
                messageEntity.Id           = Guid.NewGuid().ToString();
                messageEntity.CategoryCode = MessageCategory.Receiver.ToString();
                messageEntity.ReceiverId   = receiverIds[i];
                userEntity = userManager.GetEntity(receiverIds[i]);
                if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id))
                {
                    messageEntity.ReceiverRealName = userEntity.RealName;
                    // 发给了哪个部门的人,意义不大,是来自哪个部门的人,意义更大一些
                    // messageEntity.DepartmentId = userEntity.DepartmentId;
                    // messageEntity.DepartmentName = userEntity.DepartmentName;
                }
                messageEntity.Enabled = 1;
                messageEntity.IsNew   = 1;
                if (messageEntity.ReceiverId.Equals(UserInfo.Id))
                {
                    messageEntity.IsNew = (int)MessageStateCode.Old;
                }
                // 接收信息
                string parentId = this.Add(messageEntity, false, false);
                if (saveSend)
                {
                    // 已发送信息
                    messageEntity.Id                = Guid.NewGuid().ToString();
                    messageEntity.ParentId          = parentId;
                    messageEntity.CategoryCode      = MessageCategory.Send.ToString();
                    messageEntity.DeletionStateCode = 0;
                    messageEntity.Enabled           = 0;
                    this.Add(messageEntity, false, false);
                }
                returnValue++;
            }
            return(returnValue);
        }
Ejemplo n.º 12
0
 private static void SetCache(IRedisClient redisClient, BaseMessageEntity entity)
 {
     if (entity != null && !string.IsNullOrWhiteSpace(entity.Id))
     {
         // string key = string.Empty;
         string key = "m";
         // 默认缓存三个月,三个月不看的消息,意义也不大了,也浪费内存空间了。
         // key = "Message" + entity.Id;
         // 2015-09-27 吉日嘎拉 用简短的Key,这样效率高一些,节约内存
         key = key + entity.Id;
         redisClient.Set <BaseMessageEntity>(key, entity, DateTime.Now.AddDays(15));
     }
 }
Ejemplo n.º 13
0
        /// <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);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateObject(BaseMessageEntity entity)
        {
            int result = 0;

            var sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetObject(sqlBuilder, entity);

            sqlBuilder.SetWhere(BaseMessageEntity.FieldId, entity.Id);
            result = sqlBuilder.EndUpdate();

            return(result);
        }
Ejemplo n.º 15
0
 public int BatchSend(string[] receiverIds, string organizeId, string roleId, BaseMessageEntity messageEntity, bool saveSend = true)
 {
     string[] organizeIds = null;
     string[] roleIds     = null;
     if (!string.IsNullOrEmpty(organizeId))
     {
         organizeIds = new string[] { organizeId };
     }
     if (!string.IsNullOrEmpty(roleId))
     {
         roleIds = new string[] { roleId };
     }
     return(BatchSend(receiverIds, organizeIds, roleIds, messageEntity, saveSend));
 }
Ejemplo n.º 16
0
        public static BaseMessageEntity GetCacheByKey(string key)
        {
            BaseMessageEntity result = null;

            if (!string.IsNullOrWhiteSpace(key))
            {
                using (var redisClient = PooledRedisHelper.GetMessageReadOnlyClient())
                {
                    result = redisClient.Get <BaseMessageEntity>(key);
                }
            }

            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 发送系统提示消息
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="receiverId">接收者主键</param>
        /// <param name="contents">内容</param>
        /// <returns>主键</returns>
        public string Remind(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 entity = new BaseMessageEntity();
                    entity.Id                = Guid.NewGuid().ToString();
                    entity.CategoryCode      = MessageCategory.Receiver.ToString();
                    entity.FunctionCode      = MessageFunction.Remind.ToString();
                    entity.ReceiverId        = receiverId;
                    entity.Contents          = contents;
                    entity.IsNew             = (int)MessageStateCode.New;
                    entity.ReadCount         = 0;
                    entity.DeletionStateCode = 0;
                    entity.Enabled           = 1;
                    BaseMessageManager manager = new BaseMessageManager(dbHelper, userInfo);
                    returnValue = manager.Add(entity);
                    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);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="entity">用户实体</param>
        /// <param name="userContactEntity">用户联系方式</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string CreateUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity entity, BaseUserContactEntity userContactEntity, out string statusCode, out string statusMessage)
        {
            string result = string.Empty;

            // 加强安全验证防止未授权匿名调用
#if (!DEBUG)
            BaseSystemInfo.IsAuthorized(userInfo);
#endif

            var userManager = new BaseUserManager(dbHelper, userInfo);
            result        = userManager.Add(entity);
            statusCode    = userManager.StatusCode;
            statusMessage = userManager.GetStateMessage();

            // 20140219 JiRiGaLa 添加成功的用户才增加联系方式
            if (!string.IsNullOrEmpty(result) && statusCode.Equals(Status.OKAdd.ToString()) && userContactEntity != null)
            {
                // 添加联系方式
                userContactEntity.Id = result;
                var userContactManager = new BaseUserContactManager(dbHelper, userInfo);
                userContactEntity.CompanyId = entity.CompanyId;
                userContactManager.Add(userContactEntity);
            }

            // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了
            if (entity.Enabled == 0 && statusCode.Equals(Status.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 + entity.UserName + AppMessage.UserService_Check;
                    //messageEntity.Contents = result.RealName + "(" + result.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check;

                    var messageManager = new BaseMessageManager(dbHelper, userInfo);
                    messageManager.BatchSend(userIds, null, roleIds, messageEntity, false);
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 按部门群发短信
        /// </summary>
        /// <param name="messageEntity">实体</param>
        /// <param name="organizeId">部门主键</param>
        /// <returns>影响行数</returns>
        public int Send(BaseMessageEntity messageEntity, string organizeId, bool saveSend = true)
        {
            int             returnValue = 0;
            int             i           = 0;
            BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo);
            DataTable       dataTable   = userManager.GetChildrenUsers(organizeId);

            string[] receiverIds = new string[dataTable.Rows.Count];
            foreach (DataRow dataRow in dataTable.Rows)
            {
                receiverIds[i++] = dataRow[BaseMessageEntity.FieldId].ToString();
            }
            returnValue = this.Send(messageEntity, receiverIds, saveSend);
            return(returnValue);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="receiverId">接收者主键</param>
        /// <param name="contents">内容</param>
        /// <param name="functionCode">内容</param>
        /// <returns>主键</returns>
        public string Send(BaseUserInfo userInfo, string receiverId, string contents, string functionCode)
        {
            string result = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessMessageDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseMessageManager(dbHelper, userInfo);
                BaseMessageEntity entity = manager.Send(receiverId, contents, functionCode);
                result = entity.Id;
            });

            return(result);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="baseMessageEntity">实体</param>
        public int UpdateEntity(BaseMessageEntity baseMessageEntity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetEntity(sqlBuilder, baseMessageEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseMessageEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseMessageEntity.FieldId, baseMessageEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
Ejemplo n.º 22
0
        /// <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);
        }
Ejemplo n.º 23
0
        /// <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);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 把未阅读的消息,进行缓存处理
        /// 2015-10-08 吉日嘎拉 优化代码
        /// </summary>
        /// <param name="entity">消息</param>
        public void CacheProcessing(IRedisClient redisClient, BaseMessageEntity entity, DateTime?expireAt = null)
        {
            // 需要把消息本身放一份在缓存服务器里
            if (entity != null)
            {
                SetCache(redisClient, entity);

                if (!string.IsNullOrEmpty(entity.ReceiverId))
                {
                    // 把消息的主键放在有序集合里, 尽量存放小数字,不要太长了
                    redisClient.AddItemToSortedSet(entity.ReceiverId, entity.Id, entity.CreateOn.Value.Ticks - (new DateTime(2015, 10, 1)).Ticks);
                }
                if (!string.IsNullOrEmpty(entity.CreateUserId))
                {
                    if (!expireAt.HasValue)
                    {
                        expireAt = DateTime.Now.AddDays(15);
                    }
                    // 设置一个需要阅读的标志(过期时间)
                    redisClient.ExpireEntryAt(entity.CreateUserId, expireAt.Value);
                }

                if (!string.IsNullOrEmpty(entity.CreateUserId))
                {
                    // 设置一个最近联络人标注,把最近联系人放在有序集合里(过期时间)
                    // 设置过期时间,防止长时间不能释放
                    redisClient.AddItemToSortedSet("r" + entity.CreateUserId, entity.ReceiverId, entity.CreateOn.Value.Ticks - (new DateTime(2015, 10, 1)).Ticks);
                    redisClient.ExpireEntryAt("r" + entity.CreateUserId, DateTime.Now.AddDays(15));
                }

                if (!string.IsNullOrEmpty(entity.ReceiverId))
                {
                    redisClient.AddItemToSortedSet("r" + entity.ReceiverId, entity.CreateUserId, entity.CreateOn.Value.Ticks - (new DateTime(2015, 10, 1)).Ticks);
                    redisClient.ExpireEntryAt("r" + entity.ReceiverId, DateTime.Now.AddDays(15));
                }

                // 把多余的数据删除掉,没必要放太多的历史数据,最近联系人列表里
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 添加实体
        /// 20151008 吉日嘎拉 把排序码去掉,排序码没有意义
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddObject(BaseMessageEntity entity)
        {
            string result = string.Empty;

            // 20151008 吉日嘎拉 消息的主键没必要自增,为了安全性高一些,直接用GUID就可以了,代码页简洁了,思路也简单了
            if (string.IsNullOrEmpty(entity.Id))
            {
                entity.Id = Guid.NewGuid().ToString("N");
            }

            result = entity.Id;

            var sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, BaseMessageEntity.FieldId);
            sqlBuilder.SetValue(BaseMessageEntity.FieldId, entity.Id);

            this.SetObject(sqlBuilder, entity);

            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateBy, UserInfo.RealName);
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentId, UserInfo.DepartmentId);
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentName, UserInfo.DepartmentName);
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateCompanyId, entity.CreateCompanyId);
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateCompanyName, entity.CreateCompanyName);
            }
            else if (!string.IsNullOrEmpty(entity.CreateBy))
            {
                sqlBuilder.SetValue(BaseMessageEntity.FieldCreateBy, entity.CreateBy);
            }

            sqlBuilder.SetDBNow(BaseMessageEntity.FieldCreateOn);

            sqlBuilder.EndInsert();

            return(result);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 发送消息
        /// 20151009 吉日嘎拉 消息发送接口参数最少化,能少一个参数,算一个参数,让调用的人更简单一些
        /// </summary>
        /// <param name="receiverId">接收者主键</param>
        /// <param name="contents">消息内容</param>
        /// <param name="functionCode">消息类型</param>
        /// <returns>消息实体</returns>
        public BaseMessageEntity Send(string receiverId, string contents, string functionCode = null)
        {
            BaseMessageEntity result = new BaseMessageEntity();

            result.Id = Guid.NewGuid().ToString("N");
            if (string.IsNullOrEmpty(functionCode))
            {
                functionCode = MessageFunction.UserMessage.ToString();
            }
            result.CategoryCode      = MessageCategory.Send.ToString();
            result.FunctionCode      = functionCode;
            result.ReceiverId        = receiverId;
            result.Contents          = contents;
            result.IsNew             = (int)MessageStateCode.New;
            result.ReadCount         = 0;
            result.DeletionStateCode = 0;
            result.CreateOn          = DateTime.Now;

            if (this.UserInfo != null)
            {
                result.CreateCompanyId      = this.UserInfo.CompanyId;
                result.CreateCompanyName    = this.UserInfo.CompanyName;
                result.CreateDepartmentId   = this.UserInfo.DepartmentId;
                result.CreateDepartmentName = this.UserInfo.DepartmentName;
                result.CreateUserId         = this.UserInfo.Id;
                result.CreateBy             = this.UserInfo.RealName;
            }

            // 发送消息
            this.Send(result, true);
            // 最近联系人, 这个处理得不太好,先去掉
            // this.SetRecent(receiverId);

            // 进行缓存处理
            // CacheProcessing(result);

            return(result);
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseMessageEntity entity)
 {
     SetObjectExpand(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseMessageEntity.FieldParentId, entity.ParentId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentId, entity.ReceiverDepartmentId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentName, entity.ReceiverDepartmentName);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverId, entity.ReceiverId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverRealName, entity.ReceiverRealName);
     sqlBuilder.SetValue(BaseMessageEntity.FieldFunctionCode, entity.FunctionCode);
     sqlBuilder.SetValue(BaseMessageEntity.FieldCategoryCode, entity.CategoryCode);
     sqlBuilder.SetValue(BaseMessageEntity.FieldObjectId, entity.ObjectId);
     sqlBuilder.SetValue(BaseMessageEntity.FieldTitle, entity.Title);
     sqlBuilder.SetValue(BaseMessageEntity.FieldContents, entity.Contents);
     sqlBuilder.SetValue(BaseMessageEntity.FieldEmail, entity.Email);
     sqlBuilder.SetValue(BaseMessageEntity.FieldQQ, entity.QQ);
     sqlBuilder.SetValue(BaseMessageEntity.FieldTelephone, entity.Telephone);
     sqlBuilder.SetValue(BaseMessageEntity.FieldIsNew, entity.IsNew);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReadCount, entity.ReadCount);
     sqlBuilder.SetValue(BaseMessageEntity.FieldReadDate, entity.ReadDate);
     sqlBuilder.SetValue(BaseMessageEntity.FieldTargetURL, entity.TargetURL);
     sqlBuilder.SetValue(BaseMessageEntity.FieldIPAddress, entity.IPAddress);
     sqlBuilder.SetValue(BaseMessageEntity.FieldDeletionStateCode, entity.DeletionStateCode);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseMessageEntity GetObjectByCache(string id)
        {
            BaseMessageEntity result = null;
            // string cacheKey = "Message";
            string cacheKey = "m";

            if (!string.IsNullOrEmpty(id))
            {
                cacheKey = cacheKey + id;
                result   = GetCacheByKey(cacheKey);
                if (result == null || string.IsNullOrWhiteSpace(result.Id))
                {
                    BaseMessageManager manager = new DotNet.Business.BaseMessageManager();
                    result = manager.GetObject(id);
                    // 若是空的不用缓存,继续读取实体
                    if (result != null)
                    {
                        SetCache(result);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 检查信息状态
        /// </summary>
        /// <returns>信息状态数组</returns>
        public string[] MessageChek()
        {
            string[] returnValue = new string[6];
            // 0.新信息的个数
            int messageCount = this.GetNewCount();

            returnValue[0] = messageCount.ToString();
            if (messageCount > 0)
            {
                BaseMessageEntity messageEntity = this.GetNewOne();
                DateTime          lastChekDate  = DateTime.MinValue;
                if (messageEntity.CreateOn != null)
                {
                    // 1.最后检查时间
                    lastChekDate   = Convert.ToDateTime(messageEntity.CreateOn);
                    returnValue[1] = lastChekDate.ToString(BaseSystemInfo.DateTimeFormat);
                }
                returnValue[2] = messageEntity.CreateUserId; // 2.最新消息的发出者
                returnValue[3] = messageEntity.CreateBy;     // 3.最新消息的发出者名称
                returnValue[4] = messageEntity.Id;           // 4.最新消息的主键
                returnValue[5] = messageEntity.Contents;     // 5.最新信息的内容
            }
            return(returnValue);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 阅读短信后设置状态值和阅读次数
        /// </summary>
        /// <param name="messageEntity">实体</param>
        /// <param name="id">短信主键</param>
        /// <returns>影响的条数</returns>
        private int OnRead(BaseMessageEntity messageEntity, string id)
        {
            int returnValue = 0;

            // 针对“已发送”的情况
            if (messageEntity.ReceiverId == UserInfo.Id)
            {
                // 针对“删除的信息”的情况
                if (messageEntity.IsNew == (int)MessageStateCode.New)
                {
                    SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper);
                    sqlBuilder.BeginUpdate(this.CurrentTableName);
                    sqlBuilder.SetValue(BaseMessageEntity.FieldIsNew, ((int)MessageStateCode.Old).ToString());
                    sqlBuilder.SetDBNow(BaseMessageEntity.FieldReadDate);
                    sqlBuilder.SetWhere(BaseMessageEntity.FieldId, id);
                    sqlBuilder.EndUpdate();
                }
            }
            // 增加阅读次数
            messageEntity.ReadCount++;
            this.SetProperty(id, new KeyValuePair <string, object>(BaseMessageEntity.FieldReadCount, messageEntity.ReadCount.ToString()));
            returnValue++;
            return(returnValue);
        }