private int trySendTimes = 3; // 5 * 60 * 1000 / scanInerval; //尝试推送5分钟 private void SendItemData(object obj) { try { DataRow dr = (DataRow)((object[])obj)[1]; string push_type = dr.GetDataRowStringValue("push_type"); string push_id = dr.GetDataRowStringValue("push_id"); string content_type = dr.GetDataRowStringValue("content_type"); string content_title = dr.GetDataRowStringValue("content_title"); string content_value = dr.GetDataRowStringValue("content_value"); string content_url = dr.GetDataRowStringValue("content_url"); string push_address = dr.GetDataRowStringValue("push_address"); string user_code = dr.GetDataRowStringValue("user_code"); string remark = dr.GetDataRowStringValue("remark"); string pushcount = dr.GetDataRowStringValue("push_count"); if (string.IsNullOrWhiteSpace(pushcount)) { pushcount = "1"; } string doc_code = dr.GetDataRowStringValue("doc_code"); if (string.IsNullOrWhiteSpace(push_type)) { return; } PushType pushtype = (PushType)Enum.Parse(typeof(PushType), push_type); string strTxt = string.Format("推送 {0} {1} ...", TmoShare.GetDescription(pushtype), push_address); // SendMessage(strTxt); string emailTitle = content_title; string err_tip = ""; //发送失败提示 int rt_code = -99; //返回错误码 bool send_success = false; //是否发送成功 switch (pushtype) { //发送消息 case PushType.doc_notification: //医生弹窗 //医生编码,内容,用户编码; string[] str = { push_address, content_value, user_code }; send_success = false; // PushInvoke.SendDocInvoke(str, out err_tip); break; case PushType.user_notification: //用户站内信 DataSet notificationDs = TmoShare.getDataSetFromXML(NotificationXML, true); DataRow notificationDr = notificationDs.Tables[0].NewRow(); notificationDr["user_code"] = user_code; notificationDr["title"] = emailTitle; notificationDr["content"] = content_type;//暂时设置为type notificationDr["content_value"] = content_value; notificationDr["remark"] = remark; notificationDs.Tables[0].Rows.Add(notificationDr); notificationDs.AcceptChanges(); send_success = PushInvoke.SendMsg(notificationDs, out err_tip); break; //发送短信 case PushType.doc_sms: case PushType.user_sms: DataSet smsDS = TmoShare.getDataSetFromXML(SMSXml); DataRow smsdr = smsDS.Tables[0].Rows[0]; smsdr["user_code"] = user_code; smsdr["mobile"] = push_address; smsdr["message"] = content_value; smsdr["type"] = "1"; smsdr["doc_code"] = doc_code; send_success = PushInvoke.SendSMS(TmoShare.getXMLFromDataSet(smsDS), out err_tip, out rt_code); break; //发送微信 case PushType.doc_wechat: case PushType.user_wechat: send_success = PushInvoke.SendWeChat(new object[] { "admin", push_address, content_type, content_value }, out err_tip); break; //发送电子邮件 case PushType.doc_mail: case PushType.user_mail: var emailDS = TmoShare.getDataSetFromXML(EmailXml); DataRow emaildr = emailDS.Tables[0].Rows[0]; emaildr["user_code"] = user_code; emaildr["sendaccount"] = "健康干预"; emaildr["sendToaccount"] = push_address; emaildr["sendcontent"] = content_value; emaildr["sendtitle"] = emailTitle; emaildr["sendtype"] = "1"; emaildr["doc_code"] = doc_code; send_success = PushInvoke.SendEmail(TmoShare.getXMLFromDataSet(emailDS), out err_tip); break; } if (send_success) { tmo_push_listManager.Instance.Delete(push_id, trySendTimes, true); if (remark == "weMonitor") //来自设备监测数据 { tmo_monitorManager.Instance.UpdateWXState(push_id); } else { tmo_interveneManager.Instance.SetInterveneSuccess(push_id); } strTxt += "成功"; } else if (pushtype == PushType.doc_notification) { } //医生弹窗排除 else if (err_tip == "err_wx_time_limit") { } //系统限制微信消息回复 排除 else { //非真实删除 而是按失败处理 重试次数加1 if (rt_code == -99 || rt_code == -11 || rt_code == -20) { bool isTrue = err_tip.Contains("err_43004"); //取消关注公众号不再重试 tmo_push_listManager.Instance.Delete(push_id, trySendTimes, isTrue); } else //剩下的错误无需重试 { tmo_push_listManager.Instance.Delete(push_id, 1, true); } if (remark == "weMonitor") //来自设备监测数据 { tmo_monitorManager.Instance.UpdateWXState(push_id, 4); //推送失败 } else { tmo_interveneManager.Instance.SetInterveneFailed(push_id, string.Format("失败:{1} 重试{0}次", pushcount, err_tip)); } strTxt += $"失败:{rt_code} {err_tip} (重试{pushcount}次)"; LogHelper.Log.Fatal($"{pushtype}第{pushcount}次发送失败!=>{rt_code} {err_tip}"); } SendMessage(strTxt); } catch (Exception ex) { SendMessage(ex.Message); } finally { ((ManualResetEvent)((object[])obj)[0]).Set(); //将事件状态设置为终止 } }
/// <summary> /// 获得实体数据 /// </summary> /// <param name="param"></param> /// <returns></returns> public DataSet GetData(FE_GetDataParam param) { if (param == null) { return(null); } if (string.IsNullOrWhiteSpace(param.Sources)) { return(null); } DataSet ds = new DataSet("tmo_entity"); string columnsStr; //列筛选条件处理 if (param.Columns.Any()) { columnsStr = string.Join(",", param.Columns); } else { columnsStr = "*"; } //Where特殊情况处理 if (param.Where.ToString().TrimEnd().EndsWith("and", StringComparison.CurrentCultureIgnoreCase)) //包含and字符 { param.Where.Append(" 1=1 "); } //假删除条件附加 if (!param.Where.ToString().ToLower().Contains("is_del")) { if (MySQLHelper.IsFalseDelete(param.Sources)) { param.Where.AppendFormat(" and ({0}.is_del!='1' or {0}.is_del is null) ", param.Sources); } } //DicWhere条件处理 if (param.DicWhere.Any()) { foreach (var item in param.DicWhere) { string col = item.Key; string val = item.Value; if (string.IsNullOrWhiteSpace(col) || string.IsNullOrWhiteSpace(val)) { continue; //筛选无效值 } val = val.StartsWith(",") ? string.Format("{0} {1}", col, val.TrimStart(',')) : string.Format("{0}='{1}'", col, val); param.Where.AppendFormat(" and {0} ", val); } } //主键条件附加 if (!string.IsNullOrWhiteSpace(param.PrimaryKey) && !string.IsNullOrWhiteSpace(param.PrimaryKeyValue)) { param.Where.AppendFormat(" and {0}='{1}'", param.PrimaryKey, param.PrimaryKeyValue); } //join条件处理 if (param.JoinConditions.Any()) { foreach (var jc in param.JoinConditions) { if (string.IsNullOrWhiteSpace(jc.Table) || string.IsNullOrWhiteSpace(jc.OnCol)) { continue; //忽略无效的连接条件 } if (string.IsNullOrWhiteSpace(jc.MainTable)) { jc.MainTable = param.Sources; } if (string.IsNullOrWhiteSpace(jc.MainCol)) { jc.MainCol = jc.OnCol; } param.Sources += " " + TmoShare.GetDescription(jc.JoinType); if (string.IsNullOrWhiteSpace(jc.TableAsName)) { param.Sources += string.Format(" {0} on {0}.{1}={2}.{3}", jc.Table, jc.OnCol, jc.MainTable, jc.MainCol); } else { param.Sources += string.Format(" {0} {4} on {4}.{1}={2}.{3}", jc.Table, jc.OnCol, jc.MainTable, jc.MainCol, jc.TableAsName); } } } StringBuilder sbSql = new StringBuilder(); StringBuilder sbSqlCount = new StringBuilder(); sbSql.AppendFormat("select {0} from {1}", columnsStr, param.Sources); sbSqlCount.AppendFormat("select count(*) from {0}", param.Sources); if (param.Where.Length > 0) { sbSql.AppendFormat(" where {0}", param.Where); sbSqlCount.AppendFormat(" where {0}", param.Where); } //排序条件附加 if (param.OrderByConditons.Any()) { string orderCols = null; foreach (OrderByCondition o in param.OrderByConditons) { if (string.IsNullOrWhiteSpace(o.Col)) { continue; } orderCols += string.Format(" {0} {1},", o.Col, o.IsDesc ? "desc" : "asc"); } if (!string.IsNullOrWhiteSpace(orderCols)) { sbSql.AppendFormat(" order by {0}", orderCols.TrimEnd(',')); } } if (param.PageSize != -1 || param.PageIndex != -1) { //分页模式 if (param.PageSize < 1) { param.PageSize = 100; //错误页码过滤 } if (param.PageIndex < 1) { param.PageIndex = 1; } int count = 0; int pageCount = 1; DataTable dtCount = new DataTable("tmo_count"); dtCount.Columns.AddRange(new DataColumn[] { new DataColumn("count"), new DataColumn("pageCount"), new DataColumn("pageIndex"), new DataColumn("pageSize") }); DataRow drCount = dtCount.NewRow(); object objCount = MySQLHelper.GetSingle(sbSqlCount.ToString()); if (objCount != null) { count = Convert.ToInt32(objCount); } drCount["count"] = count; pageCount = (int)Math.Ceiling((double)count / param.PageSize); drCount["pageCount"] = pageCount; if (param.PageIndex > pageCount) { param.PageIndex = pageCount; } drCount["pageIndex"] = param.PageIndex; drCount["pageSize"] = param.PageSize; dtCount.Rows.Add(drCount); if (count != 0) { sbSql.AppendFormat(" limit {0},{1}", (param.PageIndex - 1) * param.PageSize, param.PageSize); DataTable dt = MySQLHelper.QueryTable(sbSql.ToString()); if (dt != null) { dt.TableName = "tmo_data"; ds.Tables.Add(dt); } } ds.Tables.Add(dtCount); } else { //无需分页 DataTable dt = MySQLHelper.QueryTable(sbSql.ToString()); if (dt != null) { dt.TableName = "tmo_data"; ds.Tables.Add(dt); } } return(ds); }