예제 #1
0
        public void SaveMsg(Model.MsgModel model)
        {
            DAL.MsgDAL dal = new DAL.MsgDAL();

            dal.DeleteList(" SendDeviceId='" + model.SendDeviceId + "' and TargetDeviceId='" + model.TargetDeviceId + "' and MsgTextId='" + model.MsgTextId + "'  ");

            dal.Add(model);
        }
예제 #2
0
        public void SendMsgToDevice(List <string> DeviceList, Model.MsgTextModel MsgTextModel, string SendDeviceId, decimal MerId)
        {
            Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfigCache(MerId, 2000);

            DAL.MsgTextDAL dal = new DAL.MsgTextDAL();

            if (MsgTextModel.MsgClassId == 0)
            {
                throw new Exception("消息类型(MsgClassId)不能为0");
            }

            dal.Add(MsgTextModel);

            Model.MsgModel model = new Model.MsgModel();
            model.MsgTextId    = MsgTextModel.MsgTextId;
            model.SendDeviceId = SendDeviceId;
            model.ZoneId       = "1";
            model.MsgStatusId  = 10;


            string reJson = "";



            DAL.MsgDAL MsgDal = new DAL.MsgDAL();


            foreach (string DeviceId in DeviceList)
            {
                model.TargetDeviceId = DeviceId;
                SaveMsg(model);



                StringBuilder s = new StringBuilder();

                s.Append(" DECLARE @MsgNum AS INT = (SELECT COUNT(0) FROM DBMSG.dbo.Msg WHERE TargetDeviceId='" + DeviceId + "' AND MsgStatusId=10) ");

                s.Append(" DECLARE @MsgTypeName AS VARCHAR(50) =(SELECT MsgTypeName FROM DBMSG.dbo.MsgType WHERE MsgTypeId='" + MsgTextModel.MsgType + "') ");

                s.Append(" UPDATE DBMSG.dbo.Device SET MsgNum=@MsgNum where DeviceId='" + DeviceId + "' ");
                s.Append(" SELECT @MsgNum as MsgNum, @MsgTypeName as MsgTypeName ");

                JObject Extra = new JObject();



                try
                {
                    Extra = JObject.Parse(MsgTextModel.Extra);
                }
                catch (Exception)
                {
                }
                finally
                {
                    DataSet ds = CountMsg(DeviceId);    //统计消息数量

                    DataTable dt = ds.Tables[0];

                    DataRow dr = dt.Rows[0];
                    Extra["MsgTypeId"] = MsgTextModel.MsgType;
                    Extra["MsgNum"]    = int.Parse(dr["MsgNum"].ToString());
                    // Extra["MsgTypeName"] = dr["MsgTypeName"].ToString();
                }

                reJson = RongCloudServer.PublishMessage(MerConfig["RongAppKey"],
                                                        MerConfig["RongAppSecret"],
                                                        SendDeviceId,
                                                        DeviceId,
                                                        "RC:TxtMsg",                                                                          //消息类型
                                                        " {\"content\":\"" + MsgTextModel.MsgTitle + "\",\"extra\":" + Extra.ToString() + "}" //消息内容
                                                        , "");
            }

            //BLL.WxBLL wxBll = new WxBLL();
            //try
            //{
            //    wxBll.SendQyTextMsg(DeviceList, MsgTextModel.MsgTitle, 7);  //这个地方, 以后必须改为配置,这个7是写死的数字
            //}
            //catch (Exception)
            //{

            //    //如果微信推送不成功就算完吧.可能因为网络问题
            //}
        }