public static RES SyncDB <T1, T2>(string redis = null) where T1 : class
            where T2 : class
        {
            var qName    = $"MODIFY:{typeof(T1).FullName.Replace(".", ":")}";
            var dictName = $"LIST:{typeof(T1).FullName.Replace(".", ":")}";
            var res      = REDIS.Current.GetQueueLength(qName);

            if (res.SUCCESS)
            {
                var length = (long)res.DATA;
                while (0 < length)
                {
                    var resItem = REDIS.Current.Dequeue <Item>(qName);
                    if (resItem.SUCCESS && resItem.DATA is Item)
                    {
                        var sourceItem = resItem.DATA as Item;
                        var sourceJson = REDIS.Current.DictGet(dictName, sourceItem.ItemID.ToString());
                        var targetItem = JSON.ToObject <T2>(sourceJson.DATA as string);
                        var task       = DB.SaveEntity <T2>(targetItem);
                        Console.WriteLine(task.Result);
                        if (length == 1)
                        {
                            Console.WriteLine($"同步完毕{task.Result}");
                        }
                    }
                    res    = REDIS.Current.GetQueueLength(qName);
                    length = (long)res.DATA;
                }
            }
            return(RES.OK("全部同步完毕"));
        }
Пример #2
0
        public RES GetTree <T>(string filter, Action <T> callback = null) where T : Category, new()
        {
            try
            {
                var checkRes = this.CheckBeforeQueryList(filter);
                if (!checkRes.SUCCESS)
                {
                    return(checkRes);
                }

                var queryFilter = checkRes.DATA as QueryFilter;

                var res  = RedisDB.Current.QueryList <T>(queryFilter.ToDictionary());
                var list = res.DATA as List <T>;
                if (null != list && null != callback)
                {
                    list.ForEach(p => {
                        callback(p);
                    });
                }
                return(RES.OK(list));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
        public RES UpdateArticle(string keyName, string jsonReq, string jsonRes)
        {
            var setName    = $"Stock:Article";
            var qSyncName  = $"Stock:Sync:2DB:{setName}";
            var methodName = MethodBase.GetCurrentMethod().Name;

            try
            {
                var list  = JSON.ToObject <List <Article> >(jsonRes);
                var count = 0;
                if (null != list && 0 < list.Count)
                {
                    list.ForEach(p =>
                    {
                        p.Id     = GUID.FromStringToGuid(p.Content);
                        var res1 = REDIS.Current.Enqueue(qSyncName, p);
                        var res2 = REDIS.Current.SortedSetAdd(setName, p, double.Parse(p.PublishTime.ToString("yyyyMMddhhmm")));
                        var res  = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                        if (res.SUCCESS)
                        {
                            count += 1;
                        }
                    });
                }
                Console.WriteLine($"{MethodBase.GetCurrentMethod().Name} 传入 {list.Count} 实际 {count}");
                return(RES.OK(count, $"传入 {list.Count} 实际 {count}"));
            }
            catch (Exception ex)
            {
                return(RES.FAIL($"{methodName} {ex.Message}"));
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            HttpServer.GetInst("http://127.0.0.1:9090/cache/").Run((req) => {
                var res = RES.FAIL("尚未进行任何处理");
                try
                {
                    var buffer = req.DATA as byte[];
                    if (0 < buffer.Length)
                    {
                        var jsonString = Encoding.UTF8.GetString(buffer);
                        var jquest     = JRequest.Parse(jsonString);
                        if (jquest.Method == "Execute")
                        {
                            var serverId = jquest.Param[0];
                            var command  = jquest.Param[1];
                            var paramArr = jquest.Param.ToList().Skip(2).Take(jquest.Param.Length - 2).ToArray();
                            var resExe   = REDIS.GetInst("127.0.0.1", 7379).Execute(serverId, command, paramArr);
                            return(RES.OK(resExe, ENUM.数据类型.ByteArray));
                        }
                    }

                    return(res);
                }
                catch (Exception ex)
                {
                    return(RES.FAIL(ex, ENUM.数据类型.ByteArray));
                }
                finally
                {
                }
            });
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
 public RES Update所有北向持股明细链接(string jsonReq, string jsonRes)
 {
     try
     {
         var list  = JSON.ToObject <List <Dictionary <string, string> > >(jsonRes);
         var count = 0;
         if (null != list && 0 < list.Count)
         {
             list.ForEach(p =>
             {
                 var dateTag  = p["DateTag"];
                 var listName = $"Stock:Task:BXCGMXURL:{dateTag}";
                 var res      = REDIS.Current.Enqueue(listName, p);
                 if (res.SUCCESS)
                 {
                     count += 1;
                 }
             });
         }
         Console.WriteLine($"{MethodBase.GetCurrentMethod().Name} 传入 {list.Count} 实际 {count}");
         return(RES.OK(count, $"传入 {list.Count} 实际 {count}"));
     }
     catch (Exception ex)
     {
         return(RES.FAIL($"Update所有北向持股明细链接 {ex.Message}"));
     }
 }
        public RES Update所有机构(string jsonReq, string jsonRes)
        {
            var setName   = $"Stock:JG";
            var qSyncName = $"Stock:Sync:2DB:{setName}";

            try
            {
                var list  = JSON.ToObject <List <所有机构> >(jsonRes);
                var count = 0;
                if (null != list && 0 < list.Count)
                {
                    list.ForEach(p =>
                    {
                        var res1 = REDIS.Current.Enqueue(qSyncName, p);
                        var res2 = REDIS.Current.SortedSetAdd(setName, p.Href, p.Sort);
                        var res  = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                        if (res.SUCCESS)
                        {
                            count += 1;
                        }
                    });
                }
                Console.WriteLine($"{MethodBase.GetCurrentMethod().Name} 传入 {list.Count} 实际 {count}");
                return(RES.OK(count, $"传入 {list.Count} 实际 {count}"));
            }
            catch (Exception ex)
            {
                return(RES.FAIL($"JG {ex.Message}"));
            }
        }
        public RES QueryList(string filter)
        {
            try
            {
                var checkRes = this.CheckBeforeQueryList(filter);
                if (!checkRes.SUCCESS)
                {
                    return(checkRes);
                }

                var queryFilter = checkRes.DATA as QueryFilter;

                var res  = RedisDB.Current.QueryList <Document>(queryFilter.ToDictionary());
                var list = res.DATA as List <Document>;
                list.ForEach(p =>
                {
                    p.Detail = null;
                });
                return(RES.OK(list));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
        public RES GetTask(string keyName, string taskId)
        {
            var listName = $"Stock:Task:{keyName}:{taskId}";

            var res  = REDIS.Current.GetListLastItems(listName, -1000);
            var list = res.DATA as List <string>;

            if (null != list)
            {
                var res4     = RES.FAIL("尚未进行任务分配");
                var hasFound = false;
                list.ForEach(p =>
                {
                    if (!hasFound)
                    {
                        var res2 = this.IsExistTaskStatus(listName, JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(p)));
                        if (!res2.SUCCESS)
                        {
                            var res3 = this.SaveTaskStatus(listName, p);
                            hasFound = true;
                            res4     = RES.OK(p);
                        }
                    }
                });
                return(res4);
            }
            return(RES.FAIL($"{listName} 为空"));
        }
Пример #9
0
        public static void Main(string[] args)
        {
            HttpServer.GetInst("http://localhost:9090/").Run((req) =>
            {
                Console.WriteLine("处理");
                return(RES.OK(Encoding.UTF8.GetBytes("OK"), 数据类型.ByteArray));
            });

            Console.ReadKey();
        }
Пример #10
0
 /// <summary>
 /// 保存前业务数据检查
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 protected RES CheckBeforeSave <T>(string data) where T : Item, new()
 {
     try
     {
         var inst = JSON.ToObject <T>(data);
         return(RES.OK(inst));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
 protected RES CheckBeforeRemove(string data)
 {
     try
     {
         var inst = JSON.ToObject <Document>(data);
         return(RES.OK(inst));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
Пример #12
0
 public RES Execute(string serverId, string command, object[] paramArr)
 {
     try
     {
         var res = (RedisValue[])REDIS.redis.GetDatabase().Execute(command, paramArr);
         return(RES.OK(res));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
 protected RES CheckBeforeQueryList(string data)
 {
     try
     {
         var inst = JSON.ToObject <QueryFilter>(data);
         return(RES.OK(inst));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
        protected RES IsExistTaskStatus(string keyName, string val)
        {
            var id = GUID.FromStringToGuid(val);
            var taskStatusKeyName = $"Stock:Task:Status:{keyName}:{id}";
            var res  = REDIS.Current.QueryKeys(taskStatusKeyName);
            var keys = res.DATA as List <string>;

            if (keys.Contains(taskStatusKeyName))
            {
                return(RES.OK(taskStatusKeyName));
            }
            return(RES.FAIL(keys));
        }
Пример #15
0
        ///清空队列
        public RES QueueClear(string appId, string queueName)
        {
            try
            {
                var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "DEL", $"{redisKeyQueue}:{queueName}" }));

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
Пример #16
0
        ///入队列
        public RES EnQueue(string appId, string queueName, string data)
        {
            try
            {
                var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "RPUSH", $"{redisKeyQueue}:{queueName}", data }));

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
Пример #17
0
        public RES CacheRemove(string appId, string cacheName, string key)
        {
            try
            {
                var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "DEL", $"{cacheName}:{key}" }));

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
Пример #18
0
        public RES DictExistItem(string appId, string dictName, string key)
        {
            try
            {
                var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "HEXISTS", $"{redisKeyDict}:{dictName}", key }));

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
Пример #19
0
        ///栈深度
        public RES StackDepth(string appId, string stackName)
        {
            try
            {
                var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "LLEN", $"{redisKeyStack}:{stackName}" }));

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
        public RES SaveProcData(string keyName, string taskId, string jsonReq, string jsonRes)
        {
            var listName = $"Stock:Task:{keyName}:{taskId}";

            try
            {
                if ("BXCJMX" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <北向成交明细> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        list.ForEach(p =>
                        {
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}";
                            var setName   = $"Stock:{keyName}:{p.Code}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("RZRQ" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <融资融券> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        var code = list.First().Code;
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid($"{p.Code}_{p.交易日期tag}");
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}:{p.Code}";
                            var setName   = $"Stock:{keyName}:{p.Code}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.交易日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("ZJLX" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <资金流向> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        var code = list.First().Code;
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid($"{p.Code}_{p.日期tag}");
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}:{p.Code}";
                            var setName   = $"Stock:{keyName}:{p.Code}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("CWFX" == keyName)
                {
                    var count = 0;
                    jsonRes = jsonRes.Replace("(天)", string.Empty).Replace("(元)", string.Empty).Replace("(%)", string.Empty).Replace("/", string.Empty).Replace("(次)", string.Empty);
                    var list = JSON.ToObject <List <财务主要指标> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        var code = list.First().Code;
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid($"{p.Code}_{p.DateTag}");
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}:{p.Code}";
                            var setName   = $"Stock:{keyName}:{p.Code}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.DateTag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("BXCGTJ" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <北向持股统计> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid($"{p.JgCode}_{p.持股日期tag}");
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}";
                            var setName   = $"Stock:{keyName}:{p.机构名称}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.持股日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("BXCGMXURL" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <北向机构持股明细> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid($"{p.Code}_{p.持股日期tag}_{p.JgCode}");
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}";
                            var setName   = $"Stock:{keyName}:{p.机构名称}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.持股日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                else if ("JGDYLB" == keyName)
                {
                    var count = 0;
                    var list  = JSON.ToObject <List <Jgdylb> >(jsonRes);
                    if (null != list && 0 < list.Count)
                    {
                        list.ForEach(p =>
                        {
                            p.Id          = GUID.FromStringToGuid(JSON.ToJson(p));
                            var qSyncName = $"Stock:Sync:2DB:Stock:{keyName}";
                            var setName   = $"Stock:{keyName}:{p.Code}";
                            var res1      = REDIS.Current.Enqueue(qSyncName, p);
                            var res2      = REDIS.Current.SortedSetAdd(setName, p, p.公告日期tag);
                            var res       = (res1.SUCCESS && res2.SUCCESS) ? RES.OK() : RES.FAIL();
                            if (res.SUCCESS)
                            {
                                count += 1;
                            }
                        });
                    }
                    if ((0 < list.Count && count == list.Count) || 0 == list.Count)
                    {
                        jsonReq = JSON.ToJson(JSON.ToObject <Dictionary <string, object> >(jsonReq));
                        var res = REDIS.Current.RemoveListItem(listName, jsonReq, -1);
                        this.RemoveTaskStatus(listName, jsonReq);
                        return(res);
                    }
                }
                return(RES.FAIL($"传入参数无效"));
            }
            catch (Exception ex)
            {
                return(RES.FAIL($"SaveProcData {ex.Message}"));
            }
        }
 public RES Get(string keyName, string taskId)
 {
     return(RES.OK());
 }