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() }); } }
//[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(); } } }
public void DoCheck() { int count = 0; int totalCount = 0; string accessToken = GetAccessToken(); var dbContext = new TestContext(); //查询失败的日志 var query = dbContext.ExternalLog.Where(e => e.QueryState == QueryState.失败).ToList(); //获取外部日志存入数据库 query.ForEach(q => { long startTime = TimeFormat.ToUnixTimestampByMilliseconds(q.StartTime); //开始时间 long endTime = TimeFormat.ToUnixTimestampByMilliseconds(q.EndTime); //结束时间 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(); } } }); q.CatchNum = count; q.TakeStatus = TakeStatus.完全同步; q.QueryState = QueryState.成功; q.TakeTime = DateTime.Now; dbContext.Update(q); dbContext.SaveChanges(); } catch (Exception e) { string content = startTime + "——" + endTime + "云之家外部日志接口同步失败"; //发送邮件 SendMail mailService = new SendMail(); bool fmailback = mailService.Send("*****@*****.**", "*****@*****.**", "云之家外部日志接口问题", content, "*****@*****.**", "naduohua", "smtp.163.com", "", ""); } }); }
public async Task <object> TakeMissingLog([FromBody] ParamInput input) { try { using (var db = new TestContext()) { //获取AccessToken string accessToken = CallExternal.GetAccessToken(); //获取外部接口日志 long startTime = input.StartTime; //开始时间 long endTime = input.EndTime; //结束时间 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(); int totalCount = insList.Count(); //获取实例 pushLogs.ForEach(p => { string ins = GetInstance(p.FormInstId, p.FormCodeId, accessToken); JObject jObject = JObject.Parse(ins); if (jObject["success"].ToString() == "True") { //解析数据存入数据库 //获取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(); } }); } return(new ReturnMessage { Success = true, Data = "ok" }); } catch (Exception e) { return(new ReturnMessage { Success = false, Data = e.Message }); } }
public CGSqlist GetCGSQlist(JObject Json) { //添加信息 //标题 string title = Json["data"]["formInfo"]["widgetMap"]["_S_TITLE"]["value"].ToString(); //流水号 string serialNumber = Json["data"]["formInfo"]["widgetMap"]["_S_SERIAL"]["value"].ToString(); //FormCodeId string formCodeId = Json["data"]["basicInfo"]["formCodeId"].ToString(); //FormInstId string formInstId = Json["data"]["basicInfo"]["formInstId"].ToString(); //申请金额 decimal applyAmount = decimal.Parse(Json["data"]["formInfo"]["widgetMap"]["Mo_1"]["value"].ToString()); //执行人 List <PersonInfo> persons = GetPerson(Json["data"]["formInfo"]["widgetMap"]["Ps_0"]["personInfo"].ToString()); string executor = "";//内容 persons.ForEach(p => { executor += p.Name.ToString() + ","; }); executor = executor.Remove(executor.LastIndexOf(','), 1); //市场区域 List <MarketArea> markets = GetMarket(Json["data"]["formInfo"]["widgetMap"]["Ra_0"]["options"].ToString()); string marketKey = Json["data"]["formInfo"]["widgetMap"]["Ra_0"]["value"].ToString(); string marketArea = "";//内容 foreach (var item in markets) { if (item.Key.Equals(marketKey)) { marketArea = item.Value; } } //提交人 List <PersonInfo> subpersons = GetPerson(Json["data"]["formInfo"]["widgetMap"]["_S_APPLY"]["personInfo"].ToString()); string submitter = "";//内容 persons.ForEach(p => { submitter += p.Name.ToString() + ","; }); submitter = submitter.Remove(submitter.LastIndexOf(','), 1); //申请内容 string content = Json["data"]["formInfo"]["widgetMap"]["Ta_0"]["value"].ToString(); //所属部门 List <DeptInfo> deptInfo = GetDept(Json["data"]["formInfo"]["widgetMap"]["_S_DEPT"]["deptInfo"].ToString()); string department = "";//内容 deptInfo.ForEach(d => { department += d.Name.ToString() + ","; }); department = department.Remove(department.LastIndexOf(','), 1); //时间 DateTime eventTime = TimeFormat.ToLocalTimeTime((long)Json["data"]["basicInfo"]["eventTime"]); //费用类型 List <FeeType> feeTypes = GetFeeType(Json["data"]["formInfo"]["widgetMap"]["Ra_1"]["options"].ToString()); string feeKey = Json["data"]["formInfo"]["widgetMap"]["Ra_1"]["value"].ToString();//内容 string feeType = ""; foreach (var item in feeTypes) { if (item.Key.Equals(feeKey)) { feeType = item.Value; } } List <WidgetValue> widgetValues = GetWidgetValue(Json["data"]["formInfo"]["detailMap"]["Dd_0"]["widgetValue"].ToString()); //总数量 int totalCount = 0; //总金额 decimal totalFee = 0; widgetValues.ForEach(w => { if (w.Nu_1 != "") { totalCount += int.Parse(w.Nu_1); } if (w.Mo_0 != "") { totalFee += decimal.Parse(w.Mo_0); } }); CGSqlist cg = new CGSqlist() { Title = title,//标题 FormCodeId = formCodeId, FormInstId = formInstId, SerialNumber = serialNumber, Fbillid = "DD" + DateTime.Now.ToString("yyMMddHHmmss") + RandomHelper.RandomString(4), //Fbillid Freqamount = applyAmount, //申请金额 Fuseman = executor, //执行人 FmarkertOrea = marketArea, //市场区域 Fsubmitman = submitter, //提交人 FrequestContext = content, //申请内容 Fdepartment = department, //所属部门 FirstInput = true, FeeType = feeType, //费用类型 TotalCount = totalCount, //总数量 TotalFee = totalFee, //总金额 EventTime = eventTime }; return(cg); }