Esempio n. 1
0
        public async Task <object> SendMessage()
        {
            try
            {
                using (var _testContext = new TestContext())
                {
                    //读取请求信息
                    Stream reqStream = Request.Body;
                    string key       = "mYOxAyHTFNCoFg3c";
                    string text      = "";
                    using (StreamReader reader = new StreamReader(reqStream))
                    {
                        text = await reader.ReadToEndAsync();
                    }
                    //获取解密后的字符串
                    string      decrypt = AesDecrypt(text, key);
                    JObject     json    = JObject.Parse(decrypt);
                    ParseEntity PE      = new ParseEntity();
                    //获取CGSqlist
                    CGSqlist cg = PE.GetCGSQlist(json);
                    //获取CgsqListentry
                    List <CgsqListentry> cleList = PE.GetCgsqListentry(json, cg.Fbillid);
                    //获取审批痕迹
                    List <Reqlist> rlList = PE.GetReqlist(JObject.Parse(GetFlowRecord(cg.FormInstId, cg.FormCodeId)), cg.Fbillid);
                    //存入数据库
                    _testContext.CGSqlist.Add(cg);
                    _testContext.CgsqListentry.AddRange(cleList);
                    _testContext.Reqlist.AddRange(rlList);

                    var externalLog = new ExternalLog
                    {
                        StartTime  = cg.EventTime,
                        EndTime    = cg.EventTime,
                        QueryState = QueryState.成功
                    };
                    _testContext.ExternalLog.Add(externalLog);
                    await _testContext.SaveChangesAsync();

                    //创建后台任务读取审批状态
                    //BackgroundJob.Schedule(() => new BackJob().GetProcess(JObject.Parse(GetFlowRecord(cg.FormInstId, cg.FormCodeId)), cg.Fbillid), DateTime.Now.AddMinutes(3));
                    //返回值
                    return(new ReturnMessage {
                        Success = true
                    });
                }
            }
            catch (Exception ex)
            {
                return(new ReturnMessage {
                    Success = false, Data = ex.Message.ToString()
                });
            }
        }
Esempio n. 2
0
        public static void AddEntry(ServerLogEntry newEntry)
        {
            lock (SyncRoot)
            {
                Entries.AddLast(newEntry);
                if (Entries.Count > MaxEntries)
                {
                    Entries.RemoveFirst();
                }

                if (MaxLogEntry == null)
                {
                    MaxLogEntry = newEntry;
                }
                else if (MaxLogEntry.CacheAccessTimeInMilliseconds < newEntry.CacheAccessTimeInMilliseconds)
                {
                    MaxLogEntry = newEntry;
                }
            }

            ExternalLog?.LogInfo(newEntry.ToString());
        }
Esempio n. 3
0
        //[Invoke(Begin = "2020-11-11 00:00", Interval = 1000 * 3600, SkipWhileExecuting = true)]
        public void DoTask()
        {
            int totalCount = 0;
            int count      = 0;
            //获取AccessToken
            string accessToken = CallExternal.GetAccessToken();
            //获取外部接口日志
            DateTime time = DateTime.Today.AddDays(-13);//开始时间

            using (var db = new TestContext())
            {
                var query = db.ExternalLog.OrderByDescending(e => e.EndTime).FirstOrDefault();
                if (query != null)
                {
                    time = query.EndTime;
                }
            }
            long          startTime = TimeFormat.ToUnixTimestampByMilliseconds(time.AddMinutes(-1)); //开始时间
            long          endTime   = TimeFormat.ToUnixTimestampByMilliseconds(DateTime.Now);        //结束时间
            string        pageId    = null;                                                          //页码Id 上一页则传当前最小记录id,下一页则传当前最大id,首页或者最后页传null
            string        pageType  = "first";                                                       //页码类型 prev=上一页,next=下一页,first=第一页,last=最后一页
            var           pushLogs  = GetExternalLog(accessToken, startTime, endTime, pageId, pageType);
            List <string> insList   = new List <string>();

            pushLogs.ForEach(p =>
            {
                string ins = GetInstance(p.FormInstId, p.FormCodeId, accessToken);
                insList.Add(ins);
            });
            insList    = insList.Where(i => i.Contains("true")).ToList();
            totalCount = insList.Count();
            //获取实例
            try
            {
                insList.ForEach(p =>
                {
                    JObject jObject = JObject.Parse(p);
                    if (jObject["success"].ToString() == "True")
                    {
                        count += 1;
                        using (var db = new TestContext())
                        {
                            //解析数据存入数据库
                            //获取CGSqlist
                            ParseEntity PE = new ParseEntity();
                            CGSqlist cg    = PE.GetCGSQlist(jObject);
                            cg.FirstInput  = false;
                            //审批流
                            List <Reqlist> rlList = PE.GetReqlist(JObject.Parse(GetFlowRecord(cg.FormInstId, cg.FormCodeId)), cg.Fbillid);
                            rlList.ForEach(r =>
                            {
                                var list = db.Reqlist.AsNoTracking().Where(c => c.CreateTime == r.CreateTime)
                                           .Where(c => c.Fbillno == r.Fbillno).ToList();
                                if (list.Count() == 0)
                                {
                                    db.Reqlist.Add(r);
                                }
                            });
                            var query = db.CGSqlist.AsNoTracking()
                                        .Where(c => c.SerialNumber.Equals(cg.SerialNumber))
                                        .ToList();
                            if (query.Count == 0)
                            {
                                //获取CgsqListentry
                                List <CgsqListentry> cleList = PE.GetCgsqListentry(jObject, cg.Fbillid);
                                db.CGSqlist.Add(cg);
                                db.CgsqListentry.AddRange(cleList);
                            }
                            db.SaveChanges();
                        }
                    }
                });
                using (var DbContext = new TestContext())
                {
                    ExternalLog log = new ExternalLog
                    {
                        StartTime    = TimeFormat.ToLocalTimeTime(startTime),
                        EndTime      = TimeFormat.ToLocalTimeTime(endTime),
                        QueryState   = QueryState.成功,
                        FailTotalNum = totalCount,
                        TakeStatus   = TakeStatus.完全同步,
                        CatchNum     = count,
                        CreationTime = TimeFormat.ToLocalTimeTime(endTime),
                        TakeTime     = TimeFormat.ToLocalTimeTime(endTime)
                    };
                    DbContext.ExternalLog.Add(log);
                    DbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                using (var DbContext = new TestContext())
                {
                    ExternalLog log = new ExternalLog
                    {
                        StartTime    = TimeFormat.ToLocalTimeTime(startTime),
                        EndTime      = TimeFormat.ToLocalTimeTime(endTime),
                        QueryState   = QueryState.失败,
                        FailTotalNum = totalCount,
                        TakeStatus   = TakeStatus.部分同步,
                        CatchNum     = count,
                        CreationTime = TimeFormat.ToLocalTimeTime(endTime),
                        TakeTime     = TimeFormat.ToLocalTimeTime(endTime)
                    };
                    if (totalCount == 0 || count == 0)
                    {
                        log.TakeStatus = TakeStatus.未同步;
                    }
                    DbContext.ExternalLog.Add(log);
                    DbContext.SaveChanges();
                }
            }
        }
Esempio n. 4
0
 public static void LogError(string message)
 {
     ExternalLog?.LogError(message);
 }
Esempio n. 5
0
 public static void LogWarning(string message)
 {
     ExternalLog?.LogWarning(message);
 }
Esempio n. 6
0
 public static void LogInfo(string message)
 {
     Dbg.Trace(message);
     ExternalLog?.LogInfo(message);
 }
Esempio n. 7
0
 public static void LogDebug(string message)
 {
     ExternalLog?.LogDebug(message);
 }