Esempio n. 1
0
        public override async Task OnConnected()
        {
            log.Info($"MessageHub-OnConnected {Context.ConnectionId}");
            try
            {
                IDBHelper db   = new MssqlHelper(StaticObject.ConnectionStrings["Kf"]);
                var       data = await db.FindOneAsync <CustomerServiceOnline>($"SELECT TOP 1 * FROM CustomerServiceOnlines WHERE ConnectId='{Context.ConnectionId}'", null, false);

                if (data != null)
                {
                    await db.ExcuteNonQueryAsync($"Insert INTO CustomerInOutLogs (CustomerId,InOutState,CreationTime) VALUES ({data.Id},{(int)InOutState.Login},GetDate())", null, false);

                    await db.ExcuteNonQueryAsync($"Update CustomerServiceOnlines SET ConnectState={(int)ConnectState.Connect} WHERE ConnectId='{Context.ConnectionId}'", null, false);

                    data.ConnectState = (int)ConnectState.Connect;
                    //memberCache.Set(data.OpenID, data, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(StaticObject.CacheDictionary[StaticObject.Cache_Kf_OpenId2Customer]));
                    //redisCache.RemoveValue(data.OpenID, StaticObject.Cache_OpenId2Customer);

                    await StackExchangeRedisHelper.Set(data.OpenID, StaticObject.Cache_Kf_OpenId2Customer, JsonConvert.SerializeObject(data), StaticObject.CacheDictionary[StaticObject.Cache_Kf_OpenId2Customer]);

                    await StackExchangeRedisHelper.Remove(data.OpenID, StaticObject.Cache_OpenId2Customer);
                }
                await base.OnConnected();
            }
            catch (Exception ex)
            {
                log.Error("MessageHub-OnConnected错误:", ex);
                throw ex;
            }
        }
Esempio n. 2
0
        //更新职工类型
        public void setSTAFF()
        {
            string  strSql = "select t.id,t.category,t.dep_id from STAFF t where t.status=1 ";
            DataSet set    = sys_oracle.DbHelperOra.Query(strSql);

            if (set != null)
            {
                //foreach(DataRow dr in set.Tables[0].Rows)
                //{
                //    string strKey = "ls:"+dr["dep_id"] + "";
                //    StackExchangeRedisHelper.Set(strKey, dr["category"] + ""); //更新
                //}

                //{"code":200,"error":"","data":
                DataTable     dt_all = set.Tables[0];
                List <string> list   = GetDistinctSelf(set.Tables[0], "dep_id");
                foreach (string str in list)
                {
                    DataRow[] dr_tmp      = dt_all.Select($"dep_id ='{str}'");
                    string    strJsonData = JsonConvert.SerializeObject(ToDataTable(dr_tmp), new DataTableConverter());
                    string    strValue    = $"{{\"code\":200,\"error\":\"\",\"data\":{strJsonData}}}";
                    string    strKey      = "ls:" + str;
                    StackExchangeRedisHelper.Set(strKey, strValue); //更新
                }
            }
        }
Esempio n. 3
0
        //private RedisHelper redisCache = RedisHelper.GetInstance(StaticObject.RedisServer, StaticObject.RedisPort ?? 0, StaticObject.RedisPassword, StaticObject.RedisDb ?? 0);
        //private WebCacheHelper memberCache = new WebCacheHelper();
        public async Task applyToken()
        {
            var token = Guid.NewGuid().ToString();

            //memberCache.Set(token, Context.ConnectionId, DateTime.Now.AddSeconds(StaticObject.CacheDictionary[StaticObject.Cache_Kf_LoginToken]), TimeSpan.Zero);

            await StackExchangeRedisHelper.Set(token, StaticObject.Cache_Kf_LoginToken, Context.ConnectionId, StaticObject.CacheDictionary[StaticObject.Cache_Kf_LoginToken]);

            await Clients.Client(Context.ConnectionId).getToken(token);
        }
Esempio n. 4
0
        public async Task setState(string messageToken, int state)
        {
            try
            {
                var customer = await GetCustomer(messageToken);

                if (customer != null)
                {
                    IDBHelper db = new MssqlHelper(StaticObject.ConnectionStrings["Kf"]);
                    await db.ExcuteNonQueryAsync($"Update CustomerServiceOnlines SET OnlineState={state},ConnectId='{Context.ConnectionId}',ConnectState={(int)ConnectState.Connect} WHERE ID='{customer.Id}'", null, false);

                    customer.OnlineState  = state;
                    customer.ConnectId    = Context.ConnectionId;
                    customer.ConnectState = 1;

                    //memberCache.Set(messageToken, customer.OpenID, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(StaticObject.CacheDictionary[StaticObject.Cache_Kf_MessageToken2CustomerOpenId]));
                    //memberCache.Set(customer.OpenID, customer, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(StaticObject.CacheDictionary[StaticObject.Cache_Kf_OpenId2Customer]));
                    //redisCache.RemoveValue(customer.OpenID, StaticObject.Cache_OpenId2Customer);



                    await StackExchangeRedisHelper.Set(messageToken, StaticObject.Cache_Kf_MessageToken2CustomerOpenId, customer.OpenID, StaticObject.CacheDictionary[StaticObject.Cache_Kf_MessageToken2CustomerOpenId]);

                    await StackExchangeRedisHelper.Set(customer.OpenID, StaticObject.Cache_Kf_OpenId2Customer, JsonConvert.SerializeObject(customer), StaticObject.CacheDictionary[StaticObject.Cache_Kf_OpenId2Customer]);

                    await StackExchangeRedisHelper.Remove(customer.OpenID, StaticObject.Cache_OpenId2Customer);

                    var a = -1;
                    if (state == (int)OnlineState.OnLine)
                    {
                        a = (int)InOutState.online;
                    }
                    if (state == (int)OnlineState.Leave)
                    {
                        a = (int)InOutState.leave;
                    }
                    if (state == (int)OnlineState.Quit)
                    {
                        a = (int)InOutState.quit;
                    }
                    await db.ExcuteNonQueryAsync($"Insert INTO CustomerInOutLogs (CustomerId,InOutState,CreationTime) VALUES ({customer.Id},{a},GetDate())", null, false);
                }
            }
            catch (Exception ex)
            {
                log.Error("MessageHub-setState错误:", ex);
                throw;
            }
        }
Esempio n. 5
0
 private void muilThreadSetClass(List <string> list, int start, int end)
 {
     // foreach (string str in list)
     for (; start < end; start++)
     {
         try
         {
             string    strSql = $"select wm_concat(grade_no) grade_no from (select d.value grade_no from SYS_DICTIONARY d left join CLASS_NO cn on cn.grade_no = d.value where cn.status = 1 and dep_id = '{list[start]}'  group by d.value,d.code order by to_number(d.code))";//得到排序后的聚合
             DataTable dt     = sys_oracle.DbHelperOra.Query(strSql).Tables[0];
             // string strJsonData = JsonConvert.SerializeObject(dt, new DataTableConverter());
             string strValue = $"{{\"code\":200,\"error\":\"\",\"data\":{dt.Rows[0]["grade_no"]}}}";
             string strKey   = "nj:" + list[start];
             StackExchangeRedisHelper.Set(strKey, strValue); //更新
             Thread.Sleep(10);
         }
         catch { }
     }
 }
Esempio n. 6
0
 //得到学校及对应的区域
 public void setSchoolInfo()
 {
     try
     {
         string  strSql = "select t.id,t.name,t.code,t.province,t.city,t.county,t.nature from SYS_DEP t  where t.status=1";
         DataSet set    = sys_oracle.DbHelperOra.Query(strSql);
         if (set != null)
         {
             foreach (DataRow dr in set.Tables[0].Rows)
             {
                 // string strJsonData = JsonConvert.SerializeObject(dr, new DataTableConverter());
                 string strJsonData = $"{{\"id\":\"{dr["id"]}\",\"name\":\"{dr["name"]}\",\"code\":\"{dr["code"]}\",\"province\":\"{dr["province"]}\",\"city\":\"{dr["city"]}\",\"county\":\"{dr["county"]}\",\"nature\":\"{dr["nature"]}\"}}";
                 // string strJsonData = JsonConvert.SerializeObject();
                 string strValue = $"{{\"code\":200,\"error\":\"\",\"data\":{strJsonData}}}";
                 string strKey   = "xx:" + dr["id"];
                 StackExchangeRedisHelper.Set(strKey, strValue); //更新
                 Thread.Sleep(10);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }