/// <summary> /// 获取新增弹窗消息接口参数 /// </summary> /// <param name="popupMsgPlan">弹窗信息计划</param> /// <param name="userName">此次调用接口用户</param> /// <returns></returns> private string GetAddOutWindowParameter(PopupMsgPlan popupMsgPlan, string userName) { JavaScriptSerializer jss = new JavaScriptSerializer(); AddKey ak = new AddKey(); ak.id = popupMsgPlan.PlanId; if (popupMsgPlan.DataType == "资讯弹窗") { ak.url = OutWindowUrlInfo + popupMsgPlan.PlanId; } else { ak.url = OutWindowUrl + popupMsgPlan.PlanId; } ak.app_user = userName; if (popupMsgPlan.BeginTime != null) { ak.begin_time = (DateTime)popupMsgPlan.BeginTime; } if (popupMsgPlan.EndTime != null) { ak.end_time = (DateTime)popupMsgPlan.EndTime; } ak.popup_type = (int)popupMsgPlan.PopupType; string jsonStr = jss.Serialize(ak); return(EncodeString(jsonStr)); }
public int AddPopup(PopupMsgPlan pop, string type) { if (type == "add") { pop.PopupType = 1; pop.DataType = "广告弹窗"; if (pop.Content == "" || pop.Content == null) { pop.PopupType = 0; } pop.Status = 0; pop.CreatedTime = DateTime.Now; pop.Editor = UserCookies.AdminName; //不设置开始时间,默认当前时间 if (pop.BeginTime == null) { pop.BeginTime = DateTime.Now; } //不设置时效的情况下,默认时效为30分钟 if (pop.EndTime == null) { pop.EndTime = Convert.ToDateTime(pop.BeginTime).AddMinutes(30); } int res = opupMsgPlanBll.Add(pop); SsoServer.SsoPush(res, "0"); return(res); } return(0); }
/// <summary> /// 更新Oracle移动终端推送信息表(指定用户) /// </summary> /// <param name="popupMsgPlan">推送信息</param> /// <param name="news">资讯</param> /// <param name="userId">用户ID, 以逗号分隔</param> /// <returns></returns> public int UpDataTB_MOBPUSH_USERINFO(PopupMsgPlan popupMsgPlan, News news, string userId) { var dbFactory = new OrmLiteConnectionFactory(SqlConnectFactory.BaiduPush, OracleDialect.Provider); int res = 0; string users = ""; if (userId != "") { users = " and UP_USERID in (" + userId + ") "; } string PLATFORM = "0"; if (popupMsgPlan.PushPlatform.IndexOf("android") >= 0 && popupMsgPlan.PushPlatform.IndexOf("ios") >= 0) { PLATFORM = "2"; } else if (popupMsgPlan.PushPlatform.IndexOf("ios") >= 0) { PLATFORM = "1"; } string addDeviceType = string.Empty; if (PLATFORM != "2") { addDeviceType = " and DeviceType = '" + PLATFORM + "' "; } string statictag = string.Empty; statictag = popupMsgPlan.PushColumn == "公告" ? "1" : (popupMsgPlan.PushColumn == "解盘" ? "2" : "0"); string set = "PUSHEDSTATUS = '1' " + ", PUSHTYPE = '2' " + ", STATICTAG = '" + statictag + "' " + ", CREATETIME = to_date('" + DateTime.Now.ToString() + "','yyyy-mm-dd hh24:mi:ss')" + ", PUSHTIME = null " + ", PLATFORM = " + PLATFORM + ", MSGTITLE = " + "'" + news.Title.Replace("'", "\'") + "'" + ", MSGCONTENT = '" + popupMsgPlan.NewsId + "'"; //if (DateTime.Now.ToString("yyyy-MM-dd") == "2014-06-17") // Loger.Info("TB_MOBPUSH_USERINFO\r\n" + set + "\r\n" + "(PUSHEDSTATUS is null or PUSHEDSTATUS != '1')" + addDeviceType + users); using (var db = dbFactory.OpenDbConnection()) { res = db.Update("TB_MOBPUSH_USERINFO", set, "(PUSHEDSTATUS is null or PUSHEDSTATUS != '1')" + addDeviceType + users); } return(res); }
public string CancelPlan(int PlanId) { PopupMsgPlan = popupMsgPlanBLL.Get("PlanId", PlanId); PopupMsgPlan.Status = 3; if (SsoServer.UpDateStatus(PlanId, 0) == 0) { if (popupMsgPlanBLL.UpdateReceiveMsg(PlanId)) { popupMsgPlanBLL.Update(PopupMsgPlan).ToString(); } return("000000"); } return("000001"); }
public int AddPopupzx(PopupMsgPlan pop, string type, int NewsId) { News news = newsBLL.Get("NewsId", NewsId); NewsContent newsContent = newsContentBLL.Get("NewsId", NewsId); pop.Title = news.Title; pop.ImgUrl = news.ImgUrl; pop.PageUrl = "id=" + news.NewsId; pop.NewsId = news.NewsId; pop.Content = string.IsNullOrEmpty(news.NewsAbstract) ? (newsContent.Content.Length > 90 ? StringHelper.NoHTML(newsContent.Content.Substring(0, 90).Trim()) : newsContent.Content) : (news.NewsAbstract.Length > 90 ? news.NewsAbstract.Substring(0, 90).Trim() : news.NewsAbstract.Trim()); if (type == "add") { pop.PopupType = 1; //if (pop.Content == "" || pop.Content == null) // pop.PopupType = 0; pop.Status = 0; pop.CreatedTime = DateTime.Now; pop.Editor = UserCookies.AdminName; //不设置开始时间,默认当前时间 if (pop.BeginTime == null) { pop.BeginTime = DateTime.Now; } //不设置时效的情况下,默认时效为30分钟 if (pop.EndTime == null) { pop.EndTime = Convert.ToDateTime(pop.BeginTime).AddMinutes(30); } int res = opupMsgPlanBll.Add(pop); if (res > 0) { NewsPopup np = new NewsPopup(); np.NewsId = NewsId; np.Title = news.Title; np.Author = news.Author; np.CreatedTime = news.CreatedTime; np.PushColumn = pop.PushColumn; newsPopupBll.Add(np); } SsoServer.SsoPush(res, pop.PushVersion); return(res); } return(0); }
/// <summary> /// 更新Oracle移动终端推送信息表 /// </summary> private void UpDataMoveData(PopupMsgPlan popupMsgPlan, List <CustomerGroup> userName) { try { DateTime b1 = DateTime.Now; Loger.Info("[移动终端][开始] 移动终端推送信息表更新中..."); NewsBLL newsBll = Factory.BusinessFactory.CreateBll <NewsBLL>(); News news = newsBll.GetNewsInfo(popupMsgPlan.NewsId ?? 0); SsoOutWindowBLL ssoOutWindowBll = Factory.BusinessFactory.CreateBll <SsoOutWindowBLL>(); int upDataNum = 0; if (String.Compare(popupMsgPlan.Receiver, "UP所有用户", true) == 0) { upDataNum = ssoOutWindowBll.UpDataTB_MOBPUSH_USERINFO(popupMsgPlan, news); } else { StringBuilder sb = new StringBuilder(); List <string> sqlList = new List <string>(); for (int i = 0; i < userName.Count; i++) { sb.Append("," + userName[i].CustomerId); if (i != 0 && (i % 990 == 0 || i == userName.Count - 1)) { sqlList.Add(sb.ToString().Substring(1, sb.Length - 1)); sb.Remove(0, sb.Length); } } //int myNum = 1; foreach (var item in sqlList) { //DateTime b = DateTime.Now; upDataNum += ssoOutWindowBll.UpDataTB_MOBPUSH_USERINFO(popupMsgPlan, news, item); //Loger.Debug("第 " + myNum++ + " 次 " + (int)(DateTime.Now - b).TotalMilliseconds + " 毫秒"); } } Loger.Info("[移动终端] 移动终端推送信息表更新完毕, 更新数据: " + upDataNum + " 条, 用时: " + (int)(DateTime.Now - b1).TotalSeconds + " 秒"); ssoOutWindowBll.AddTB_PUSH_INFO(news, popupMsgPlan.PushColumn, popupMsgPlan); Loger.Info("[移动终端][结束] 资讯入库完毕"); } catch (Exception ex) { Loger.Error(ex, "更新Oracle移动终端推送信息表异常: "); } }
/// <summary> /// 弹窗消息进用户收件箱 /// </summary> /// <param name="planId"></param> private void ReceiveMsgPush(PopupMsgPlan popupMsgPlan, List <CustomerGroup> userName) { //批量插入数量 int batchNum = 0; batchNum = Convert.ToInt32(ConfigurationManager.AppSettings["batchNum"]); if (batchNum == 0) { batchNum = 100000; } DataTable dt = new DataTable(); dt = GetTableSchema(); for (int i = 0; i < userName.Count; i++) { DataRow r = dt.NewRow(); r[0] = 0; r[1] = popupMsgPlan.Title; r[2] = popupMsgPlan.Content; r[3] = popupMsgPlan.ImgUrl; r[4] = popupMsgPlan.PageUrl; r[5] = 0; r[6] = "UP量化安全炒股卫士"; r[7] = userName[i].CustomerId == null ? 0 : userName[i].CustomerId; r[8] = userName[i].CustomerName; r[9] = popupMsgPlan.CreatedTime; r[10] = popupMsgPlan.BeginTime == null ? DateTime.Now : popupMsgPlan.BeginTime; r[11] = 1; r[12] = popupMsgPlan.PlanId; r[13] = ""; r[14] = 1; dt.Rows.Add(r); if ((i > 0 && i % batchNum == 0) || i == userName.Count - 1) { BulkToDB(dt, "ReceiveMsg"); dt.Reset(); dt = GetTableSchema(); } } }
/// <summary> /// 更新资讯弹窗关联表(in 批量更新) /// </summary> /// <param name="popupMsgPlan"></param> /// <param name="userName"></param> private void NewsPopupUserUpdataIn(PopupMsgPlan popupMsgPlan, List <CustomerGroup> userName, string version) { try { Loger.Info("[入库][开始] 资讯弹窗关联表更新中..."); DateTime begin = DateTime.Now; StringBuilder sb = new StringBuilder(); List <string> sqlList = new List <string>(); for (int i = 0; i < userName.Count; i++) { sb.Append("," + userName[i].CustomerId); if (i != 0 && (i % 5000 == 0 || i == userName.Count - 1)) { sqlList.Add(sb.ToString().Substring(1, sb.Length - 1)); sb.Remove(0, sb.Length); } } //int myNum = 1; foreach (var item in sqlList) { //DateTime b = DateTime.Now; string sql = "update NewsPopupUser set NewsIds = CAST(NewsIds AS VARCHAR(MAX)) + '," + popupMsgPlan.NewsId + "' where ReceiverId in(" + item + ")"; SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings["CMS"].ConnectionString, CommandType.Text, sql); //Loger.Debug("第 " + myNum++ + " 次 " + (int)(DateTime.Now - b).TotalMilliseconds + " 毫秒"); } Loger.Info("[入库] 批量更新完成, 处理新增关联用户中..."); List <CustomerGroup> nsertUser = GetUserNameNonexistent(popupMsgPlan.Receiver, version); int insNum = 0; if (nsertUser != null) { NewsPopupUserPush(popupMsgPlan, nsertUser); insNum = nsertUser.Count; } Loger.Info("[入库][结束] 资讯弹窗关联表更新完毕, 推送用户: " + userName.Count + " 条, 新增关联: " + insNum + " 条, 用时: " + (int)(DateTime.Now - begin).TotalSeconds + " 秒"); } catch (Exception ex) { Loger.Error(ex, "更新资讯弹窗关联表(in 批量更新):"); } }
/// <summary> /// 添加Oracle移动终端资讯内容表 /// </summary> /// <returns></returns> public long AddTB_PUSH_INFO(PopupMsgPlan popupMsgPlan) { long res = 0; OracleConnection Con = new System.Data.OracleClient.OracleConnection(SqlConnectFactory.BaiduPush); Con.Open(); string cmdText = "insert into tb_push_info " + "(fid, infoid, title, infoabstract, author, createdtime, infotype, infocontent,OperateDate,PlanCount,RealCount,ClickCount,EDITOR,PLATFORM) " + "values " + "(seq_push_info.nextval, 'ds" + popupMsgPlan.PlanId + "', '" + popupMsgPlan.Title + "', '" + popupMsgPlan.Content + "', '系统推送', to_date('" + popupMsgPlan.CreatedTime + "','yyyy-mm-dd hh24:mi:ss'), '" + popupMsgPlan.PushColumn + "', :infocontent,sysdate,0,0,0,'" + popupMsgPlan.Editor + "','" + popupMsgPlan.PushPlatform + "')"; OracleCommand cmd = new OracleCommand(cmdText, Con); OracleParameter op = new OracleParameter("infocontent", OracleType.Clob); op.Value = StringHelper.RetentionHTML(popupMsgPlan.Content); cmd.Parameters.Add(op); cmd.ExecuteNonQuery(); Con.Close(); return(res); }
/// <summary> /// SSO数据推送, 重推 /// </summary> /// <param name="ssoResultId">ssoResultId</param> public void SsoPushOne(int ssoResultId) { int planId = 0; try { SSOResultBLL ssoResultBll = Factory.BusinessFactory.CreateBll <SSOResultBLL>(); SSOResult ssoResult = ssoResultBll.Get("Id", ssoResultId); if (ssoResult != null) { PopupMsgPlanBLL opupMsgPlanBll = Factory.BusinessFactory.CreateBll <PopupMsgPlanBLL>(); PopupMsgPlan popupMsgPlan = opupMsgPlanBll.Get("PlanId", ssoResult.PlanId); planId = (int)ssoResult.PlanId; if (popupMsgPlan != null) { List <string> listUserName = GetUserNameToGroup(ssoResult.ErrorUser); //所有错误用户, 每100个一组 string parameter = string.Empty; int i = 0; foreach (var userName in listUserName) { parameter = GetAddOutWindowParameter(popupMsgPlan, userName); string res = RequestHelper.WebRequest(AddOutWindow, "post", parameter, "UTF-8", true); if (!string.IsNullOrEmpty(res)) { res = new EncDecUtil().decyptData(res, accesskey); } Loger.Info("PlanId:" + planId + ",SSO数据重推返回结果:" + res); UpDataSsoResult(userName, res, ssoResult, i); i++; } } } } catch (Exception ex) { Loger.Error(ex, "\r\n=====error=====\r\nPlanId:" + planId + ",SSO数据重推异常:"); } }
/// <summary> /// 资讯弹窗消息进关联表(新) /// </summary> private void NewsPopupUserPush(PopupMsgPlan popupMsgPlan, List <CustomerGroup> userName) { if (userName == null || popupMsgPlan == null) { return; } //批量插入数量 int batchNum = 0; batchNum = Convert.ToInt32(ConfigurationManager.AppSettings["batchNum"]); if (batchNum == 0) { batchNum = 100000; } DataTable dt = new DataTable(); dt = GetTableSchemaNpu(); for (int i = 0; i < userName.Count; i++) { DataRow r = dt.NewRow(); r[0] = 0; r[1] = userName[i].CustomerId == null ? 0 : userName[i].CustomerId; r[2] = userName[i].CustomerName; r[3] = popupMsgPlan.NewsId; dt.Rows.Add(r); if ((i > 0 && i % batchNum == 0) || i == userName.Count - 1) { BulkToDB(dt, "NewsPopupUser"); dt.Reset(); dt = GetTableSchemaNpu(); } } }
/// <summary> /// 添加Oracle移动终端资讯内容表 /// </summary> /// <returns></returns> public long AddTB_PUSH_INFO(News news, string infoType, PopupMsgPlan popupMsgPlan) { long res = 0; //var dbFactory = new OrmLiteConnectionFactory(SqlConnectFactory.BaiduPush, OracleDialect.Provider); //TB_PUSH_INFO pushInfo = new TB_PUSH_INFO(); //pushInfo.INFOID = news.NewsId; //pushInfo.TITLE = news.Title; //pushInfo.INFOABSTRACT = news.NewsAbstract; //pushInfo.AUTHOR = news.Author; //pushInfo.CREATEDTIME = news.CreatedTime; //pushInfo.INFOTYPE = infoType; //pushInfo.INFOCONTENT = news.Content; //using (var db = dbFactory.OpenDbConnection()) //{ // res = db.InsertParam<TB_PUSH_INFO>(pushInfo); //} //return res; OracleConnection Con = new System.Data.OracleClient.OracleConnection(SqlConnectFactory.BaiduPush); Con.Open(); string cmdText = "insert into tb_push_info " + "(fid, infoid, title, infoabstract, author, createdtime, infotype, infocontent,OperateDate,PlanCount,RealCount,ClickCount,EDITOR,PLATFORM) " + "values " + "(seq_push_info.nextval, '" + news.NewsId + "', '" + news.Title + "', '" + news.NewsAbstract + "', '" + news.Author + "', to_date('" + news.CreatedTime + "','yyyy-mm-dd hh24:mi:ss'), '" + infoType + "', :infocontent,sysdate,0,0,0,'" + popupMsgPlan.Editor + "','" + popupMsgPlan.PushPlatform + "')"; OracleCommand cmd = new OracleCommand(cmdText, Con); OracleParameter op = new OracleParameter("infocontent", OracleType.Clob); op.Value = StringHelper.RetentionHTML(news.Content); cmd.Parameters.Add(op); cmd.ExecuteNonQuery(); Con.Close(); return(res); }
/// <summary> /// 删除单条数据 /// </summary> /// <param name="obj"></param> /// <returns></returns> public int Delete(PopupMsgPlan obj) { return(dal.Delete(obj)); }
/// <summary> /// 更新单条数据 /// </summary> /// <param name="obj"></param> /// <returns></returns> public int Update(PopupMsgPlan obj) { return(dal.Update(obj)); }
/// <summary> /// 添加单条数据 /// </summary> /// <param name="obj"></param> /// <returns></returns> public int Add(PopupMsgPlan obj) { return(dal.Add(obj)); }
/// <summary> /// SSO接口调用记录更新(失败部分) /// </summary> /// <param name="popupMsgPlan">弹窗信息计划</param> /// <param name="userName">此次调用接口用户</param> /// <param name="res">SSO接口返回值</param> /// <param name="ssoResultId">调用SSO结果表ID</param> /// <returns></returns> private int UpDataSsoResult(PopupMsgPlan popupMsgPlan, string userName, SsoRes ssoRes, int ssoResultId) { SSOResultBLL ssoResultBll = Factory.BusinessFactory.CreateBll <SSOResultBLL>(); //if(string.IsNullOrEmpty(res))//sso接口返回空时,不往下执行了 // return 0; //SsoRes ssoRes = JsonHelper.DeserializeJson<SsoRes>(res); SSOResult ssoResult; if (ssoResultId > 0) { ssoResult = ssoResultBll.Get("Id", ssoResultId); } else { ssoResult = new SSOResult(); } ssoResult.PlanId = popupMsgPlan.PlanId; ssoResult.Url = OutWindowUrl + popupMsgPlan.PlanId; ssoResult.BeginTime = popupMsgPlan.BeginTime; ssoResult.EndTime = popupMsgPlan.EndTime; ssoResult.PopupType = popupMsgPlan.PopupType; ssoResult.Status = ssoRes.error; //SSO接口返回调用成功 if (ssoRes.error == 0) { //数据库已经存在这条数据 if (ssoResultId > 0) { ssoResult.Id = ssoResultId; ssoResult.SuccessUser += UserArryToString(ssoRes.success_user) == "" ? "" : "," + UserArryToString(ssoRes.success_user); ssoResult.ErrorUser += UserArryToString(ssoRes.error_user) == "" ? "" : "," + UserArryToString(ssoRes.error_user); ssoResult.RepeatUser += UserArryToString(ssoRes.repeat_user) == "" ? "" : "," + UserArryToString(ssoRes.repeat_user); ssoResult.UndefinedUser += UserArryToString(ssoRes.undefined_user) == "" ? "" : "," + UserArryToString(ssoRes.undefined_user); ssoResultBll.Update(ssoResult); return(ssoResultId); } else { ssoResult.SuccessUser = UserArryToString(ssoRes.success_user); ssoResult.ErrorUser = UserArryToString(ssoRes.error_user); ssoResult.RepeatUser = UserArryToString(ssoRes.repeat_user); ssoResult.UndefinedUser = UserArryToString(ssoRes.undefined_user); return(ssoResultBll.Add(ssoResult)); } } else //SSO接口调用失败,所有用户加到出错用户字段 { //数据库已经存在这条数据 if (ssoResultId > 0) { ssoResult.Id = ssoResultId; ssoResult.ErrorUser += ssoResult.ErrorUser == "" ? "" : "," + userName; ssoResultBll.Update(ssoResult); return(ssoResultId); } else { ssoResult.ErrorUser = userName; return(ssoResultBll.Add(ssoResult)); } } }
/// <summary> /// 更新Oracle移动终端推送信息表(所有) /// </summary> /// <param name="popupMsgPlan">推送信息</param> /// <param name="news">资讯</param> public int UpDataTB_MOBPUSH_USERINFO(PopupMsgPlan popupMsgPlan, News news) { return(UpDataTB_MOBPUSH_USERINFO(popupMsgPlan, news, "")); }
/// <summary> /// 更新资讯弹窗关联表(新)(SqlDataAdapter 批量更新) /// </summary> private void NewsPopupUserUpdata(PopupMsgPlan popupMsgPlan, List <CustomerGroup> userName) { try { Loger.Info("[入库][开始] (手动输入用户)资讯弹窗关联表更新中..."); DateTime begin = DateTime.Now; string constr = ConfigurationManager.ConnectionStrings["CMS"].ConnectionString; SqlConnection sqlConn = new SqlConnection(constr); NewsPopupUserBLL popupUserBll = Factory.BusinessFactory.CreateBll <NewsPopupUserBLL>(); int userCount = popupUserBll.GetCount(); int selectNum = 10000; //每次从数据库中提取作查询的数据数量 int eachNum = userCount; //需要从数据库中循环读取的次数 if (userCount != 0) //如果数据库存在数据, 则计算需要读取的次数 { eachNum = userCount / selectNum + (userCount % selectNum == 0 ? 0 : 1); } Loger.Info("[入库] (手动输入用户)批量更新关联表已存用户总数 " + userCount + " 条, 每次提取 " + selectNum + " 条, 需要读取 " + eachNum + " 次, 本次需更新用户 " + userName.Count + " 条"); string connectionString = constr; for (int k = 0; k < eachNum; k++) { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); int unTopNum = k * selectNum; //排除已经提取过的条目数 string sql = string.Empty; if (unTopNum == 0) { sql = "select top " + selectNum + " * from NewsPopupUser"; } else { sql = "select top " + selectNum + " * from NewsPopupUser where id not in (select top " + unTopNum + " id from NewsPopupUser)"; } SqlDataAdapter sd = new SqlDataAdapter(); sd.SelectCommand = new SqlCommand(sql, conn); DataSet dataset = new DataSet(); sd.Fill(dataset); sd.UpdateCommand = new SqlCommand("update NewsPopupUser set ReceiverId = @ReceiverId,Receiver = @Receiver,NewsIds = @NewsIds where Id = @Id", conn); sd.UpdateCommand.Parameters.Add("@Id", SqlDbType.Int, 8, "Id"); sd.UpdateCommand.Parameters.Add("@ReceiverId", SqlDbType.Int, 8, "ReceiverId"); sd.UpdateCommand.Parameters.Add("@Receiver", SqlDbType.NVarChar, 20, "Receiver"); sd.UpdateCommand.Parameters.Add("@NewsIds", SqlDbType.Text, 10000, "NewsIds"); sd.UpdateCommand.UpdatedRowSource = UpdateRowSource.None; sd.UpdateBatchSize = 0; for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { CustomerGroup thisUser = userName.Where(a => a.CustomerName == dataset.Tables[0].Rows[i]["Receiver"].ToString()).FirstOrDefault(); if (thisUser != null) { dataset.Tables[0].Rows[i].BeginEdit(); dataset.Tables[0].Rows[i]["NewsIds"] = dataset.Tables[0].Rows[i]["NewsIds"] + "," + popupMsgPlan.NewsId; //增加资讯关联 dataset.Tables[0].Rows[i].EndEdit(); userName.Remove(thisUser); //删除需要推送的用户记录 } } sd.Update(dataset.Tables[0]); //更新数据库 dataset.Tables[0].Clear(); sd.Dispose(); dataset.Dispose(); conn.Close(); //如果用户列表已清空, 跳出循环 if (userName.Count == 0) { break; } } } //剩下用户列表为数据库不存在用户, 批量插入 if (userName.Count > 0) { NewsPopupUserPush(popupMsgPlan, userName); } Loger.Info("[入库][结束] (手动输入用户)资讯弹窗关联表更新完毕, 用时: " + (int)(DateTime.Now - begin).TotalSeconds + " 秒"); } catch (Exception ex) { Loger.Error(ex, "更新资讯弹窗关联表(新)(SqlDataAdapter 批量更新):"); } }
/// <summary> /// SSO数据推送 /// </summary> /// <param name="planId">planId</param> /// <param name="version">推送版本,金蝴蝶:1000, 严林版:3100, 金牡丹:5100, 渤商版:6100, 所有版本:0</param> public void SsoPush(int planId, string version) { if (string.IsNullOrEmpty(version)) { version = "0"; } try { PopupMsgPlanBLL opupMsgPlanBll = Factory.BusinessFactory.CreateBll <PopupMsgPlanBLL>(); PopupMsgPlan popupMsgPlan = opupMsgPlanBll.Get("PlanId", planId); List <string> listUserName = new List <string>(); if (popupMsgPlan != null) { int ssoResultId = 0; List <CustomerGroup> allUserName = new List <CustomerGroup>(); //判断是否用户组 if (popupMsgPlan.ReceiverType == 0 || popupMsgPlan.ReceiverType == 2) { allUserName = GetUserName(popupMsgPlan.Receiver, version); string versionLog = version == "0" ? "所有" : (version == "1000" ? "金蝴蝶" : (version == "3100" ? "严林版" : (version == "5100" ? "金牡丹" : (version == "6100" ? "渤商版" : "其它")))); Loger.Info("\r\n=====推送类型: " + popupMsgPlan.DataType + "\r\n=====推送用户组: " + popupMsgPlan.Receiver + "\r\n=====推送版本: " + versionLog + "\r\n=====推送平台: " + popupMsgPlan.PushPlatform + "\r\n=====planId: " + planId); if (allUserName != null) { listUserName = GetUserNameToGroup(allUserName); } else { Loger.Info("PlanId:" + planId + ", 此用户组, 不存在用户!"); return; } } else if (popupMsgPlan.ReceiverType == 1) { allUserName = AddUserName(popupMsgPlan.Receiver); listUserName.Add(popupMsgPlan.Receiver); } //更新计划接收用户数 popupMsgPlan.ReceiverCount = allUserName.Count; opupMsgPlanBll.Update(popupMsgPlan); if (popupMsgPlan.DataType == "资讯弹窗") { //包括移动终端推送 if (popupMsgPlan.PushPlatform.IndexOf("android") >= 0 || popupMsgPlan.PushPlatform.IndexOf("ios") >= 0) { Thread thOracle = new Thread(new ThreadStart(delegate() { UpDataMoveData(popupMsgPlan, allUserName); })); thOracle.Start(); } //不包括PC终端, 返回 if (popupMsgPlan.PushPlatform.IndexOf("pc") < 0) { return; } if (popupMsgPlan.ReceiverType == 0 || popupMsgPlan.ReceiverType == 2) //用户组 { Thread th = new Thread(new ThreadStart(delegate() { NewsPopupUserUpdataIn(popupMsgPlan, allUserName, version); })); th.Start(); } else if (popupMsgPlan.ReceiverType == 1) //用户(手动输入) { Thread th = new Thread(new ThreadStart(delegate() { NewsPopupUserUpdata(popupMsgPlan, allUserName); })); th.Start(); } } ; //return; string parameter = string.Empty; List <SsoRes> listSsoRes = new List <SsoRes>(); if (listUserName.Count > 0) { Loger.Info(" [SSO][开始] SSO推送中..."); } else { return; } DateTime srb = DateTime.Now; foreach (var userName in listUserName) { parameter = GetAddOutWindowParameter(popupMsgPlan, userName); string res = RequestHelper.WebRequest(AddOutWindow, "post", parameter, "UTF-8", true); if (!string.IsNullOrEmpty(res)) { res = new EncDecUtil().decyptData(res, accesskey); SsoRes ssoRes = JsonHelper.DeserializeJson <SsoRes>(res); listSsoRes.Add(ssoRes); // 调用接口状态码,0:成功,1:该消息id 已存在,2:链接地址不存在,3:用户群组不存在,4:开始时间与结束时间不匹配,9:其它异常 if (ssoRes.error != 0)//失败部分单独更新 { Loger.Info("SSO接口调用返回失败, 此批用户入库<失败用户>"); Loger.Info("PlanId:" + planId + ",SSO数据推送返回结果:" + res); ssoResultId = UpDataSsoResult(popupMsgPlan, userName, ssoRes, ssoResultId); } //Loger.Info("PlanId:" + planId + ",SSO数据推送返回结果: ssoRes = " + ssoRes.error); } else { Loger.Info("SSO接口调用返回空=====error=====(一般情况不会出现, 出现在超时或者无法调用)"); } } Loger.Info(" [SSO][结束] SSO推送完毕, 用时: " + (int)(DateTime.Now - srb).TotalSeconds + " 秒"); UpDataSsoResult(popupMsgPlan, listSsoRes, ssoResultId); //if (popupMsgPlan.DataType == "广告弹窗") // ReceiveMsgPush(popupMsgPlan, allUserName); //else //if (popupMsgPlan.DataType == "资讯弹窗") //{ // //InformationOfUserPush(popupMsgPlan, allUserName); // NewsPopupUserUpdata(popupMsgPlan, allUserName); //} } } catch (Exception ex) { Loger.Error(ex, "\r\n=====error=====\r\nPlanId:" + planId + ",SSO数据推送异常:"); } }
/// <summary> /// SSO接口调用记录更新(成功部分) /// </summary> /// <param name="popupMsgPlan">弹窗信息计划</param> /// <param name="userName">此次调用接口用户</param> /// <param name="res">SSO接口返回值</param> /// <param name="ssoResultId">调用SSO结果表ID</param> /// <returns></returns> private int UpDataSsoResult(PopupMsgPlan popupMsgPlan, List <SsoRes> listSsoRes, int ssoResultId) { SSOResultBLL ssoResultBll = Factory.BusinessFactory.CreateBll <SSOResultBLL>(); //if(string.IsNullOrEmpty(res))//sso接口返回空时,不往下执行了 // return 0; //SsoRes ssoRes = JsonHelper.DeserializeJson<SsoRes>(res); SSOResult ssoResult; if (ssoResultId > 0) { ssoResult = ssoResultBll.Get("Id", ssoResultId); } else { ssoResult = new SSOResult(); } ssoResult.PlanId = popupMsgPlan.PlanId; ssoResult.Url = OutWindowUrl + popupMsgPlan.PlanId; ssoResult.BeginTime = popupMsgPlan.BeginTime; ssoResult.EndTime = popupMsgPlan.EndTime; ssoResult.PopupType = popupMsgPlan.PopupType; ssoResult.Status = 0; string success_user = ""; string error_user = ""; string repeat_user = ""; string undefined_user = ""; foreach (var item in listSsoRes) { string success = UserArryToString(item.success_user); string error = UserArryToString(item.error_user); string repeat = UserArryToString(item.repeat_user); string undefined = UserArryToString(item.undefined_user); if (success != "") { success_user += (success_user == "" ? success : "," + success); } if (error != "") { error_user += (error_user == "" ? error : "," + error); } if (repeat != "") { repeat_user += (repeat_user == "" ? repeat : "," + repeat); } if (undefined != "") { undefined_user += (undefined_user == "" ? undefined : "," + undefined); } } //数据库已经存在这条数据 if (ssoResultId > 0) { ssoResult.Id = ssoResultId; ssoResult.SuccessUser += success_user; ssoResult.ErrorUser += error_user; ssoResult.RepeatUser += repeat_user; ssoResult.UndefinedUser += undefined_user; ssoResultBll.Update(ssoResult); Loger.Info("[调用结果][更新] SSO调用记录: PlanId = " + popupMsgPlan.PlanId + ", 成功 = " + (ssoResult.SuccessUser == "" ? "0" : ssoResult.SuccessUser.Split(',').Length.ToString()) + " , 失败 = " + (ssoResult.ErrorUser == "" ? "0" : ssoResult.ErrorUser.Split(',').Length.ToString()) + " , 重复 = " + (ssoResult.RepeatUser == "" ? "0" : ssoResult.RepeatUser.Split(',').Length.ToString()) + " , 不存在 = " + (ssoResult.UndefinedUser == "" ? "0" : ssoResult.UndefinedUser.Split(',').Length.ToString())); return(ssoResultId); } else { ssoResult.SuccessUser = success_user; ssoResult.ErrorUser = error_user; ssoResult.RepeatUser = repeat_user; ssoResult.UndefinedUser = undefined_user; Loger.Info("[调用结果][新增] SSO调用记录: PlanId = " + popupMsgPlan.PlanId + ", 成功 = " + (ssoResult.SuccessUser == "" ? "0" : ssoResult.SuccessUser.Split(',').Length.ToString()) + " , 失败 = " + (ssoResult.ErrorUser == "" ? "0" : ssoResult.ErrorUser.Split(',').Length.ToString()) + " , 重复 = " + (ssoResult.RepeatUser == "" ? "0" : ssoResult.RepeatUser.Split(',').Length.ToString()) + " , 不存在 = " + (ssoResult.UndefinedUser == "" ? "0" : ssoResult.UndefinedUser.Split(',').Length.ToString())); return(ssoResultBll.Add(ssoResult)); } }