| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using CallCenter.Utility;
- using CallCenterApi.Common;
- using CallCenterApi.Interface.Models.Common;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Routing;
- using System.Web.Script.Serialization;
- using System.Web.Security;
- namespace CallCenterApi.Interface
- {
- public class MvcApplication : System.Web.HttpApplication
- {
- System.Threading.Timer timer;
- private static int count = 1;
- protected void Application_Start()
- {
- AreaRegistration.RegisterAllAreas();
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- //clq 增加异常日志记录 自定义 HandleErrorAttribute
- FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
- timer = new System.Threading.Timer(SetCensusURL, null, 0, 1000 * 60);
- }
-
- public void SetCensusURL(object obj)
- {
- var modellist = new BLL.T_Bus_WorkOrder().GetModelList("F_IsDelete=0 and F_State in(1,3,5)");
- if (modellist!=null )
- {
- foreach (var it in modellist)
- {
- var modellast = new BLL.T_Wo_WorkOrderItem_New().GetModelList("F_WoID = " + it.F_Id + "and F_IsUsed =0 order by F_ID desc").FirstOrDefault ();
- System.TimeSpan id = DateTime.Now - DateTime.Parse(modellast.F_CreateTime.ToString () );
- if (id.TotalMinutes <120)
- {
- continue;
- }
- else
- {
- try
- {
- int a = (int)modellast.F_IsSMS ;
- if (id.TotalMinutes >= 120 + a*10 && id.TotalMinutes < 130 +a * 10)
- {
- bool n = SendSMS(modellast);
- if (n)
- AddLog(modellast, a + 1);
- }
- else
- continue;
- }
- catch
- {
- bool n = SendSMS(modellast);
- if (n)
- AddLog(modellast, 1);
- }
- }
- }
- }
- }
- private bool SendSMS(Model .T_Wo_WorkOrderItem_New modellast)
- {
- if (!string.IsNullOrEmpty(modellast.F_NextUser))
- {
- var usercount = new BLL.T_Sys_UserAccount().GetModel(modellast.F_NextUser);
- if (usercount != null)
- {
- if (!string.IsNullOrEmpty(usercount.F_Mobile))
- {
- string msg = "你有新的工单,请及时处理";
- Dictionary<string, string> paras = new Dictionary<string, string>();
- paras.Add("@JSHM", usercount.F_Mobile);
- paras.Add("@DXNR", msg);
- paras.Add("@Return", "0");
- var par = RunProcedure("sp_SmsSend", paras, "sp_SmsSend");
- if (par != null)
- return true;
- }
- }
- }
- return false;
- }
- public static string connectionString = ConfigurationManager.ConnectionStrings["connectionSMS"].ConnectionString;
- /// <summary>
- /// 执行存储过程,返回SqlDataReader ( 注意:调用该方法后,一定要对SqlDataReader进行Close )
- /// </summary>
- /// <param name="storedProcName">存储过程名</param>
- /// <param name="parameters">存储过程参数</param>
- /// <returns>SqlDataReader</returns>
- public static DataSet RunProcedure(string storedProcName, Dictionary<String, String> paras, string tableName)
- {
- List<SqlParameter> ps = new List<SqlParameter>();
- foreach (KeyValuePair<string, string> kvp in paras)
- {
- ps.Add(new SqlParameter(kvp.Key, kvp.Value));
- }
- try
- {
- using (SqlConnection connection = new SqlConnection(connectionString))
- {
- DataSet dataSet = new DataSet();
- connection.Open();
- SqlDataAdapter sqlDA = new SqlDataAdapter();
- sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, ps.ToArray());
- sqlDA.Fill(dataSet, tableName);
- connection.Close();
- return dataSet;
- }
- }
- catch (Exception e)
- {
- return null ;
- }
-
- }
- private static SqlCommand BuildQueryCommand(SqlConnection connection, string storedProcName, IDataParameter[] parameters)
- {
- SqlCommand command = new SqlCommand(storedProcName, connection);
- command.CommandType = CommandType.StoredProcedure;
- foreach (SqlParameter parameter in parameters)
- {
- if (parameter != null)
- {
- // 检查未分配值的输出参数,将其分配以DBNull.Value.
- if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
- (parameter.Value == null))
- {
- parameter.Value = DBNull.Value;
- }
- command.Parameters.Add(parameter);
- }
- }
- return command;
- }
- BLL.T_Wo_WorkOrderItem_New itembll = new BLL.T_Wo_WorkOrderItem_New();
- public bool AddLog(Model.T_Wo_WorkOrderItem_New itemlist, int F_IsSMS )
- {
- itemlist.F_IsSMS = F_IsSMS;
- var res = itembll.Update (itemlist);
- return res;
- }
- protected void Application_AuthenticateRequest(object sender, EventArgs e)
- {
- HttpApplication app = (HttpApplication)sender;
- var context = app.Context;
- if (context == null) throw new ArgumentNullException("context");
- var token = context.Request["token"];
- if (string.IsNullOrWhiteSpace(token)) return;
- try
- {
- ////获取缓存
- //var dict = CacheHelper.Get(token);
- //获取redis缓存
- var dict = RedisHelper.StringGet(token);
- if (dict == null) return;
- Cache.Models.CurrentUserInfo userData = null;
- //获取FormsAuthenticationTicket对象
- FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);
- if (ticket != null && string.IsNullOrEmpty(ticket.UserData) == false)
- userData = (new JavaScriptSerializer()).Deserialize<Cache.Models.CurrentUserInfo>(ticket.UserData); //还原用户数据
- if (ticket != null && userData != null)
- context.User = new FormsPrincipal<Cache.Models.CurrentUserInfo> (ticket, userData);//重新给context.User赋值。
- }
- catch { /* 有异常也不要抛出,防止攻击者试探。 */ }
- }
- }
- }
|