Exemple #1
0
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// <param name="keyValue">主键</param>
 /// <summary>
 /// <returns></returns>
 public void SaveEntity(string keyValue, LR_MS_StrategyInfoEntity entity)
 {
     try
     {
         if (!string.IsNullOrEmpty(keyValue))
         {
             entity.Modify(keyValue);
             this.BaseRepository().Update(entity);
         }
         else
         {
             entity.Create();
             this.BaseRepository().Insert(entity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
 /// <summary>
 /// 保存实体数据(新增、修改)
 /// <param name="keyValue">主键</param>
 /// <summary>
 /// <returns></returns>
 public void SaveEntity(string keyValue, LR_MS_StrategyInfoEntity entity)
 {
     try
     {
         lR_StrategyInfoService.SaveEntity(keyValue, entity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
        /// <summary>
        /// 消息处理,在此处处理好数据,然后调用消息发送方法
        /// </summary>
        /// <param name="code">消息策略编码</param>
        /// <param name="content">消息内容</param>
        /// <param name="userlist">用户列表信息</param>
        /// <returns></returns>
        public ResParameter SendMessage(string code, string content, string userlist)
        {
            try
            {
                ResParameter resParameter = new ResParameter();
                if (string.IsNullOrEmpty(code))//判断code编码是否输入
                {
                    resParameter.code = ResponseCode.fail;
                    resParameter.info = "code编码为空";
                }
                else if (string.IsNullOrEmpty(content))//判断是否输入信息内容
                {
                    resParameter.code = ResponseCode.fail;
                    resParameter.info = "content内容为空";
                }
                else
                {
                    LR_MS_StrategyInfoEntity strategyInfoEntity = GetEntityByCode(code); //根据编码获取消息策略
                    if (strategyInfoEntity == null)                                      //如果获取不到消息策略则code编码无效
                    {
                        resParameter.code = ResponseCode.fail;
                        resParameter.info = "code编码无效";
                    }
                    else
                    {
                        #region 用户信息处理
                        List <UserEntity> list = new List <UserEntity>();//消息发送对象
                        if (string.IsNullOrEmpty(userlist))
                        {
                            if (string.IsNullOrEmpty(strategyInfoEntity.F_SendRole))
                            {
                                resParameter.code = ResponseCode.fail;
                                resParameter.info = "消息策略无发送角色,需要输入人员userlist信息";
                            }
                            else
                            {
                                String[] rolecontent = strategyInfoEntity.F_SendRole.Split(',');//根据角色id获取用户信息
                                foreach (var item in rolecontent)
                                {
                                    var    data    = userRelationIBLL.GetUserIdList(item);
                                    string userIds = "";
                                    foreach (var items in data)
                                    {
                                        if (userIds != "")
                                        {
                                            userIds += ",";
                                        }
                                        userIds += items.F_UserId;
                                    }
                                    var userList = userIBLL.GetListByUserIds(userIds);
                                    foreach (var user in userList)
                                    {
                                        list.Add(user);
                                    }
                                }
                            }
                        }
                        else
                        {
                            list = userlist.ToList <UserEntity>();
                        }
                        #endregion
                        if (list.Count <= 0)//判断用户列表有一个或一个以上的用户用于发送消息
                        {
                            resParameter.code = ResponseCode.fail;
                            resParameter.info = "找不到发送人员";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(strategyInfoEntity.F_MessageType))
                            {
                                resParameter.code = ResponseCode.fail;
                                resParameter.info = "消息类型为空,无法发送消息";
                            }
                            else
                            {
                                string[] typeList = strategyInfoEntity.F_MessageType.Split(',');

                                foreach (var type in typeList)
                                {
                                    switch (type)
                                    {
                                    case "1":    //邮箱,调用邮箱发送方法
                                        EmailSend(content, list);
                                        break;

                                    case "2":    //微信,调用微信发送方法
                                        WeChatSend(content, list);
                                        break;

                                    case "3":     //短信,调用短信发送方法
                                        SMSSend(content, list);
                                        break;

                                    case "4":     //系统IM,效用系统IM发送方法
                                        IMSend(content, list);
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                resParameter.code = ResponseCode.success;
                resParameter.info = "发送成功";

                return(resParameter);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }