Пример #1
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);
     }
 }
Пример #2
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);
        }
Пример #3
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);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 获取最近联系人
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>用户列表</returns>
        public DataTable GetRecentContacts(BaseUserInfo userInfo)
        {
            DataTable result = null;

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

            ServiceUtil.ProcessMessageDb(userInfo, parameter, (dbHelper) =>
            {
                /*
                 * var manager = new BaseMessageRecentManager(dbHelper, userInfo);
                 * string sqlQuery = string.Empty;
                 * if (dbHelper.CurrentDbType == CurrentDbType.Oracle)
                 * {
                 *  sqlQuery = "SELECT " + BaseMessageRecentEntity.FieldTargetId + " AS " + BaseUserEntity.FieldId
                 + "," + BaseMessageRecentEntity.FieldRealName
                 + "," + BaseMessageRecentEntity.FieldCompanyName
                 + "," + BaseMessageRecentEntity.FieldDepartmentName
                 + "  FROM " + BaseMessageRecentEntity.TableName
                 + " WHERE " + BaseMessageRecentEntity.FieldUserId + "= '" + userInfo.Id + "'"
                 + " AND ROWNUM < = 50 "
                 + " ORDER BY " + BaseMessageRecentEntity.FieldModifiedOn + " DESC ";
                 + }
                 + else
                 + {
                 +  sqlQuery = "SELECT TOP 50 " + BaseMessageRecentEntity.FieldTargetId + " AS " + BaseUserEntity.FieldId
                 + "," + BaseMessageRecentEntity.FieldRealName
                 + "," + BaseMessageRecentEntity.FieldCompanyName
                 + "," + BaseMessageRecentEntity.FieldDepartmentName
                 + "  FROM " + BaseMessageRecentEntity.TableName
                 + " WHERE " + BaseMessageRecentEntity.FieldUserId + "= '" + userInfo.Id + "'"
                 + " ORDER BY " + BaseMessageRecentEntity.FieldModifiedOn + " DESC ";
                 + }
                 */

                // 2015-09-27 吉日嘎拉 最新联系人方式,从缓存服务器里读取
                result = new DataTable(BaseUserEntity.TableName);
                result.Columns.Add(BaseUserEntity.FieldId.ToUpper());
                result.Columns.Add(BaseUserEntity.FieldRealName.ToUpper());
                result.Columns.Add(BaseUserEntity.FieldCompanyName.ToUpper());
                result.Columns.Add(BaseUserEntity.FieldDepartmentName.ToUpper());
                result.Columns.Add(BaseUserEntity.FieldSortCode.ToUpper());

# if Redis
                // 2015-11-20 吉日嘎拉 为了让程序能编译通过
                using (var redisClient = PooledRedisHelper.GetMessageClient())
                {
                    List <string> list = redisClient.GetAllItemsFromSortedSetDesc(("r" + userInfo.Id));
                    for (int i = 0; i < list.Count && i < 100; i++)
                    {
                        BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(list[i]);
                        if (userEntity != null)
                        {
                            DataRow dr = result.NewRow();
                            dr[BaseUserEntity.FieldId]             = userEntity.Id;
                            dr[BaseUserEntity.FieldRealName]       = userEntity.RealName;
                            dr[BaseUserEntity.FieldCompanyName]    = userEntity.CompanyName;
                            dr[BaseUserEntity.FieldDepartmentName] = userEntity.DepartmentName;
                            dr[BaseUserEntity.FieldSortCode]       = i;
                            result.Rows.Add(dr);
                        }
                    }
                }
#endif
                result.AcceptChanges();
            });
Пример #5
0
        public int BroadcastProcess(string systemCode, bool allcompany, string[] roleIds, string[] areaIds, string[] companyIds, bool subCompany, string[] departmentIds, bool subDepartment, string[] userIds, string message, bool onlineOnly, MessageFunction functionCode = MessageFunction.SystemPush, DateTime?expireAt = null)
        {
            int result = 0;

            // 1: 这里需要生成一个sql语句。
            // 2: 只发给中天客户端,中天客户端有登录过的用户?
            // 3: 一边读取一边执行发送指令,马上能见效。
            // 4: 节约数据库资源,节约服务器资源。
            // 5: 广播提醒,过期时间1周就可以了,太时间了,浪费内存资源。

            // 2015-09-29 吉日嘎拉 从最高到最低的顺序判断
            string commandText = " SELECT " + BaseUserEntity.FieldId
                                 + "  FROM " + BaseUserEntity.TableName
                                 + " WHERE " + BaseUserEntity.FieldEnabled + " = 1 "
                                 + "       AND " + BaseUserEntity.FieldDeletionStateCode + " = 0 "
                                 + "       AND " + BaseUserEntity.FieldUserFrom + " = 'Base' ";

            if (allcompany)
            {
                // 什么都不过滤
            }
            if (areaIds != null)
            {
                // 这个需要进行叠加处理
                commandText += " AND " + BaseUserEntity.FieldCompanyId + " IN ( "
                               + " SELECT " + BaseOrganizeEntity.FieldId
                               + "   FROM " + BaseOrganizeEntity.TableName
                               + "  WHERE " + BaseOrganizeEntity.FieldEnabled + " = 1 "
                               + "        AND " + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 "
                               + "        AND (" + BaseOrganizeEntity.FieldProvinceId + " IN (" + StringUtil.ArrayToList(areaIds) + ")"
                               + "         OR " + BaseOrganizeEntity.FieldCityId + " IN (" + StringUtil.ArrayToList(areaIds) + ")"
                               + "         OR " + BaseOrganizeEntity.FieldStreetId + " IN (" + StringUtil.ArrayToList(areaIds) + ")"
                               + "         OR " + BaseOrganizeEntity.FieldDistrictId + " IN (" + StringUtil.ArrayToList(areaIds) + ")) )";
            }
            if (subCompany)
            {
                commandText += " AND " + BaseUserEntity.FieldCompanyId + " IN ( "

                               + "  SELECT " + BaseOrganizeEntity.FieldId
                               + "    FROM " + BaseOrganizeEntity.TableName
                               + "   WHERE " + BaseOrganizeEntity.FieldEnabled + " = 1 "
                               + "AND " + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 "
                               + "AND " + BaseOrganizeEntity.FieldId + " IN (" + StringUtil.ArrayToList(companyIds) + ")  UNION "

                               + "  SELECT " + BaseOrganizeEntity.FieldId
                               + "    FROM " + BaseOrganizeEntity.TableName
                               + "   WHERE " + BaseOrganizeEntity.FieldEnabled + " = 1 "
                               + "AND " + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 "
                               + " START WITH " + BaseOrganizeEntity.FieldParentId + " IN (" + StringUtil.ArrayToList(companyIds) + ") "
                               + " CONNECT BY PRIOR " + BaseOrganizeEntity.FieldId + " = " + BaseOrganizeEntity.FieldParentId + ")";
            }
            if (companyIds != null && companyIds.Length > 0)
            {
                commandText += " AND " + BaseUserEntity.FieldCompanyId + " IN (" + StringUtil.ArrayToList(companyIds) + ")";
            }
            if (subDepartment)
            {
                commandText += " AND " + BaseUserEntity.FieldDepartmentId + " IN ( "
                               + "  SELECT " + BaseDepartmentEntity.FieldId
                               + "    FROM " + BaseDepartmentEntity.TableName
                               + "   WHERE " + BaseDepartmentEntity.FieldEnabled + " = 1 "
                               + " AND " + BaseDepartmentEntity.FieldDeletionStateCode + " = 0 "
                               + " AND " + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 "
                               + "AND " + BaseDepartmentEntity.FieldId + " IN (" + StringUtil.ArrayToList(departmentIds) + ") UNION "

                               + "  SELECT " + BaseDepartmentEntity.FieldId
                               + "    FROM " + BaseDepartmentEntity.TableName
                               + "   WHERE " + BaseDepartmentEntity.FieldEnabled + " = 1 "
                               + " AND " + BaseDepartmentEntity.FieldDeletionStateCode + " = 0 "
                               + " AND " + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 "
                               + " START WITH " + BaseDepartmentEntity.FieldParentId + " IN (" + StringUtil.ArrayToList(departmentIds) + ") "
                               + " CONNECT BY PRIOR " + BaseDepartmentEntity.FieldId + " = " + BaseDepartmentEntity.FieldParentId + ") ";
            }
            if (departmentIds != null && departmentIds.Length > 0)
            {
                commandText += " AND " + BaseUserEntity.FieldDepartmentId + " IN (" + StringUtil.ArrayToList(departmentIds) + ")";
            }
            if (roleIds != null && roleIds.Length > 0)
            {
                string tableName = systemCode + "UserRole";
                commandText += " AND " + BaseUserEntity.FieldId + " IN ( SELECT UserId FROM " + tableName + " WHERE RoleId IN (" + StringUtil.ArrayToList(roleIds) + "))";
            }
            if (userIds != null && userIds.Length > 0)
            {
                commandText += " AND " + BaseUserEntity.FieldId + " IN (" + StringUtil.ArrayToList(userIds) + ")";
            }

            using (var redisClient = PooledRedisHelper.GetMessageClient())
            {
                var userManager = new BaseUserManager(this.UserInfo);
                using (IDataReader dataReader = userManager.ExecuteReader(commandText))
                {
                    while (dataReader.Read())
                    {
                        string[]          receiverIds = new string[] { dataReader[BaseUserEntity.FieldId].ToString() };
                        BaseMessageEntity entity      = new BaseMessageEntity();
                        // entity.Id = BaseBusinessLogic.NewGuid();
                        entity.FunctionCode = functionCode.ToString();
                        // entity.FunctionCode = MessageFunction.SystemPush.ToString();
                        // entity.FunctionCode = MessageFunction.Remind.ToString();
                        entity.Contents             = message;
                        entity.CreateCompanyId      = this.UserInfo.CompanyId;
                        entity.CreateCompanyName    = this.UserInfo.CompanyName;
                        entity.CreateDepartmentId   = this.UserInfo.DepartmentId;
                        entity.CreateDepartmentName = this.UserInfo.DepartmentName;
                        entity.CreateUserId         = this.UserInfo.Id;
                        entity.CreateBy             = this.UserInfo.RealName;
                        entity.IPAddress            = this.UserInfo.IPAddress;
                        entity.CreateOn             = DateTime.Now;
                        entity.IsNew             = 1;
                        entity.ReadCount         = 0;
                        entity.DeletionStateCode = 0;

                        if (!expireAt.HasValue)
                        {
                            expireAt = DateTime.Now.AddDays(5);
                        }
                        result = Send(redisClient, entity, receiverIds, false, expireAt);
                    }
                }
            }

            return(result);
        }