/// <summary> /// 短信发送 /// </summary> /// <returns></returns> public ActionResult MessageSendIndex() { var model = YJ_DCSMS_TMPCls.GetListModel(new YJ_DCSMS_TMP_SW() { DANGERCLASS = "5", ISENABLE = "1" }); //默认红色预警模板 return(View(model)); }
/// <summary> /// ajax 获取预警等级模板短信 /// </summary> /// <returns></returns> public JsonResult GetSmsTmpModel() { MessageListObject ms = null; string level = Request.Params["level"]; var list = YJ_DCSMS_TMPCls.GetListModel(new YJ_DCSMS_TMP_SW() { DANGERCLASS = level, ISENABLE = "1" }); ms = new MessageListObject(true, list); return(Json(ms)); }
/// <summary> /// 自动发送短信 /// </summary> /// <returns></returns> public JsonResult AutoSendMsg() { Message ms = null; var st = ConfigCls.getIsAutoSendFireLevelMsg(); //读取配置 if (st == "1") //自动 { var smsmodel = YJ_DCSMS_TMPCls.GetListModel(new YJ_DCSMS_TMP_SW { ISENABLE = "1" }); //获取短信模板 if (smsmodel.Any()) { int levelnum = 0; foreach (var sms in smsmodel) { var FireLevellist = YJ_DANGERCLASSCls.getListModelTop(new YJ_DANGERCLASS_SW() { }).Where(p => p.DANGERCLASS == sms.DANGERCLASS); //获取最新的火险等级 if (FireLevellist.Any()) { var _cityorg = ""; //市机构中间变量 var _contyorg = ""; //县机构中间变量 int i = 0; levelnum = FireLevellist.Count(); //当前火险等级个数 foreach (var level in FireLevellist) { var info = new YJ_DCSMS_SEND_SW(); info.opMethod = "Add"; info.SMSSENDUSERLIST = sms.SMSSENDUSERLIST; info.DCDATE = level.DCDATE; info.BYORGNO = level.BYORGNO; info.YJ_DCSMS_TMPID = sms.YJ_DCSMS_TMPID; //info.TMPCONTENT = sms.TMPCONTENT; #region 通讯录接收人员 if (!string.IsNullOrEmpty(info.SMSSENDUSERLIST)) { var arrperson = info.SMSSENDUSERLIST.Split(','); info.TMPCONTENT = sms.TMPCONTENT.Replace("[num]", levelnum.ToString());//短信内容replace if (!string.IsNullOrEmpty(info.TMPCONTENT)) { foreach (var p in arrperson) { var txlmodel = T_SYS_ADDREDDBOOKCls.getModel(new T_SYS_ADDREDDBOOK_SW { ADID = p }); //通讯录 if (txlmodel != null && !string.IsNullOrEmpty(txlmodel.PHONE)) { try { ////TODO Send Message //add redis //队列 var msg = txlmodel.PHONE.Trim() + "|" + info.TMPCONTENT; redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 logs.Info("==入队列号码信息==" + msg); // client.SendMsg(info.TMPCONTENT, txlmodel.PHONE); Thread.Sleep(200); } catch (Exception ex) { logs.Error(ex.Message); } } } info.SMSSENDSTATUS = "1";//0 未发送 1 已发送 -1 发送失败 } } #endregion #region 发送值班员与护林员 if (string.IsNullOrEmpty(sms.SMSSENDUSERLIST))//接收人为空 发送值班员与护林员 { #region 值班员 与护林员 if (sms.SMSGROUPTYPE == "1") //值班员 { var cityorg = level.BYORGNO.Substring(0, 4) + "00000"; //市机构码 var contyorg = level.BYORGNO.Substring(0, 6) + "000"; //县机构码 if (i == 0) //初次 { _cityorg = cityorg; _contyorg = contyorg; } else { if (_cityorg == cityorg)//循环相同的市级单位 跳出循环 { continue; } if (_contyorg == contyorg)//循环相同的县级单位 跳出循环 { continue; } } info.TMPCONTENT = sms.TMPCONTENT.Replace("[cityconty]", level.TOPTOWNNAME).Replace("[num]", levelnum.ToString()); //短信内容replace string str = cityorg + "," + contyorg; var zbylist = OD_USERCls.GetOndutyUserid(level.DCDATE, str); //获取值班员useridlist if (zbylist.Any()) { var zbystr = ""; foreach (var zby in zbylist) { var m = T_SYSSEC_IPSUSERCls.getModel(new T_SYSSEC_IPSUSER_SW { USERID = zby.ToString() }); if (!string.IsNullOrEmpty(m.PHONE)) { if (zbylist.Count() == 1) { zbystr = zby; } else { zbystr += zby + ","; } try { ////TODO Send Message //add redis //队列 var msg = m.PHONE.Trim() + "|" + info.TMPCONTENT; redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 logs.Info("==入队列号码信息==" + msg); //client.SendMsg(info.TMPCONTENT, m.PHONE); Thread.Sleep(200); } catch (Exception ex) { logs.Error(ex.Message); } } } info.SMSSENDUSERLIST = zbystr; //值班员人员 info.SMSSENDSTATUS = "1"; //0 未发送 1 已发送 -1 发送失败 // ms = YJ_DCSMS_SENDCls.Manager(info); } ++i; } else if (sms.SMSGROUPTYPE == "2") //护林员 { info.TMPCONTENT = sms.TMPCONTENT.Replace("[cityconty]", level.TOWNNAME); //短信内容replace var hlylist = T_IPSFR_USERCls.getListModel(new T_IPSFR_USER_SW { BYORGNO = info.BYORGNO }); //护林员 if (hlylist.Any()) { var hlystr = "";//护林员人员 逗号分隔 foreach (var hly in hlylist) { if (!string.IsNullOrEmpty(hly.PHONE)) { if (hlylist.Count() == 1) { hlystr = hly.HID; } else { hlystr += hly.HID + ","; } try { //TODO Send Message //add redis //队列 var msg = hly.PHONE.Trim() + "|" + info.TMPCONTENT; redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 logs.Info("==入队列号码信息==" + msg); //client.SendMsg(info.TMPCONTENT, hly.PHONE); Thread.Sleep(200); } catch (Exception ex) { logs.Error(ex.Message); } } } info.SMSSENDUSERLIST = hlystr; //护林员人员 info.SMSSENDSTATUS = "1"; //0 未发送 1 已发送 -1 发送失败 //ms = YJ_DCSMS_SENDCls.Manager(info); } } #endregion } #endregion } } } } else { ms = new Message(true, "短信未设置模板!", ""); } } else { ms = new Message(true, "短信发送已设置为手动发送,请手动发送短信!", ""); } return(Json(ms)); }
/// <summary> /// 手动发送短信 /// </summary> /// <returns></returns> public JsonResult SendMsg() { Message ms = new Message(false, "错误信息初始化!", ""); string SubjectPerson = Request.Params["SubjectPerson"]; var paraArry1 = SubjectPerson.Split('|');//获取主题+;+人员+;+短信内容| if (paraArry1.Length > 0) { foreach (var item in paraArry1) { if (string.IsNullOrEmpty(item)) { continue; } var subject = item.Split(';');//获取主题+;+人员+;+短信内容 var model = YJ_DCSMS_TMPCls.GetListModel(new YJ_DCSMS_TMP_SW { YJ_DCSMS_TMPID = subject[0], ISENABLE = "1" }).FirstOrDefault(); if (model != null && !string.IsNullOrEmpty(model.TMPCONTENT)) { var info = new YJ_DCSMS_SEND_SW(); info.opMethod = "Add"; //增加 info.YJ_DCSMS_TMPID = subject[0]; info.SMSSENDUSERLIST = subject[1]; //接收人员 info.TMPCONTENT = subject[2]; //获取界面的短信内容 info.DCDATE = DateTime.Now.ToString(); //火险等级时间 info.BYORGNO = ""; //所属机构 适用于值班员与护林员 int levelnum = 0; var FireLevellist = YJ_DANGERCLASSCls.getListModelTop(new YJ_DANGERCLASS_SW() { }).Where(p => p.DANGERCLASS == model.DANGERCLASS); //获取最新的火险等级 if (FireLevellist.Any()) { levelnum = FireLevellist.Count();//当前火险等级个数 #region 通讯录接收人员 if (!string.IsNullOrEmpty(info.SMSSENDUSERLIST)) { info.DCDATE = FireLevellist.FirstOrDefault().DCDATE; info.TMPCONTENT = subject[2].Replace("[num]", levelnum.ToString());//短信内容replace if (!string.IsNullOrEmpty(info.TMPCONTENT)) { var arrpersonlist = info.SMSSENDUSERLIST.Split(',').Where(p => p != "" && p != null); string arrperson = string.Join(",", arrpersonlist); string txlMobile = arrperson; //通讯录电话列表 string txlContent = ""; // 通讯录模板 #region 注释 // foreach (var p in arrperson) // { // var txlmodel = T_SYS_ADDREDDBOOKCls.getModel(new T_SYS_ADDREDDBOOK_SW { ADID = p });//通讯录 // if (txlmodel != null && !string.IsNullOrEmpty(txlmodel.PHONE)) // { ////TODO Send Message //add redis //队列 //try //{ // var msg = txlmodel.PHONE.Trim() + "|" + info.TMPCONTENT; // redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 // logs.Info("==入队列号码信息==" + msg); // Thread.Sleep(100); // // client.SendMsg(info.TMPCONTENT, txlmodel.PHONE); // // Thread.Sleep(200); //} //catch (Exception ex) //{ // logs.Error(ex.Message); //} // txlMobile += txlmodel.PHONE.Trim() + ","; // } //} #endregion txlContent = info.TMPCONTENT; var mm = SmsCom.SendMsg(txlContent, txlMobile.TrimEnd(','));//发送短信 if (mm.Success) { ms.Msg = mm.Msg; ms.Success = mm.Success; ms.Url = ""; } //ms // var mm = Smsclient.SendMsg(txlContent, txlMobile); // ms = SmsMsgCom.SendMsg(txlContent, txlMobile);//发送短信 // info.SMSSENDSTATUS = "1";//0 未发送 1 已发送 -1 发送失败 // ms = YJ_DCSMS_SENDCls.Manager(info); } } #endregion #region 值班员 、护林员 if (string.IsNullOrEmpty(info.SMSSENDUSERLIST)) //值班员 、护林员 { var _cityorg = ""; //市机构中间变量 var _contyorg = ""; //县机构中间变量 int i = 0; if (model.SMSGROUPTYPE == "2" || model.SMSGROUPTYPE == "1") //护林员接收人员 或者 值班员接收人员 { foreach (var level in FireLevellist) { info.DCDATE = level.DCDATE; //火险等级时间 info.BYORGNO = level.BYORGNO; //火险等级所属机构 #region 护林员接收人员 if (model.SMSGROUPTYPE == "2") { info.TMPCONTENT = subject[2].Replace("[cityconty]", level.TOWNNAME);//短信内容replace var hlylist = T_IPSFR_USERCls.getListModel(new T_IPSFR_USER_SW { BYORGNO = level.BYORGNO }); //护林员 if (hlylist.Any()) { // var hlystr = "";//护林员人员 逗号分隔 string hlyMobile = ""; //护林员电话 string hlyContent = ""; //护林员模板 foreach (var hly in hlylist.MyDistinct(s => s.PHONE)) { if (!string.IsNullOrEmpty(hly.PHONE)) { hlyMobile += hly.PHONE.Trim() + ","; //if (hlylist.Count() == 1) //{ // hlystr = hly.HID; //} //else //{ // hlystr += hly.HID + ","; //} //try //{ // //TODO Send Message // //add redis // //队列 // var msg = hly.PHONE.Trim() + "|" + info.TMPCONTENT; // redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 // logs.Info("==入队列号码信息==" + msg); // //client.SendMsg(info.TMPCONTENT, hly.PHONE); // Thread.Sleep(200); //} //catch (Exception ex) //{ // logs.Error(ex.Message); //} } } hlyContent = info.TMPCONTENT; var mm = SmsCom.SendMsg(hlyContent, hlyMobile.TrimEnd(','));//发送短信 if (mm.Success) { ms.Msg = mm.Msg; ms.Success = mm.Success; ms.Url = ""; } //info.SMSSENDUSERLIST = hlystr;//护林员人员 //info.SMSSENDSTATUS = "1";//0 未发送 1 已发送 -1 发送失败 // ms = YJ_DCSMS_SENDCls.Manager(info); } } #endregion #region 值班员接收人员 if (model.SMSGROUPTYPE == "1") { var cityorg = level.BYORGNO.Substring(0, 4) + "00000"; //市机构码 var contyorg = level.BYORGNO.Substring(0, 6) + "000"; //县机构码 if (i == 0) //初次 { _cityorg = cityorg; _contyorg = contyorg; } else { if (_cityorg == cityorg)//循环相同的市级单位 跳出循环 { continue; } if (_contyorg == contyorg)//循环相同的县级单位 跳出循环 { continue; } } info.TMPCONTENT = subject[2].Replace("[cityconty]", level.TOPTOWNNAME).Replace("[num]", levelnum.ToString()); //短信内容replace string str = cityorg + "," + contyorg; var zbylist = OD_USERCls.GetOndutyUserid(level.DCDATE, str); //获取值班员useridlist if (zbylist.Any()) { //var zbystr = ""; string zbyMobile = ""; //值班员电话 string zbyContent = info.TMPCONTENT; //值班员模板 foreach (var zby in zbylist) { var m = T_SYSSEC_IPSUSERCls.getModel(new T_SYSSEC_IPSUSER_SW { USERID = zby.ToString() }); if (!string.IsNullOrEmpty(m.PHONE)) { zbyMobile += m.PHONE.Trim() + ","; //if (zbylist.Count() == 1) //{ // zbystr = zby; //} //else //{ // zbystr += zby + ","; //} //try //{ // ////TODO Send Message // //add redis // //队列 // var msg = m.PHONE.Trim() + "|" + info.TMPCONTENT; // redisclient.EnqueueItemOnList("SendMsg", msg);//入队。 // logs.Info("==入队列号码信息==" + msg); // // client.SendMsg(info.TMPCONTENT, m.PHONE); // Thread.Sleep(200); //} //catch (Exception ex) //{ // logs.Error(ex.Message); //} } } var mm = SmsCom.SendMsg(zbyContent, zbyMobile.TrimEnd(','));//发送短信 if (mm.Success) { ms.Msg = mm.Msg; ms.Success = mm.Success; ms.Url = ""; } // info.SMSSENDUSERLIST = zbystr;//值班员人员 //info.SMSSENDSTATUS = "1";//0 未发送 1 已发送 -1 发送失败 //ms = YJ_DCSMS_SENDCls.Manager(info); } ++i; } #endregion } } } #endregion } else { ms = new Message(false, "当前火险等级未达到预警,无需发短信!", ""); } } else { ms = new Message(false, "没有短信模板,不发短信!", ""); } } } else { ms = new Message(false, "传递短信模板主题与人员id参数错误!", ""); } return(Json(ms)); }