static void clean(enaboContext db, string identity, businessType bbtype, DateTime dsubmit) { var busi = db.Business.FirstOrDefault(b => b.Identity == identity && b.Businesstype == (short)bbtype && b.Integrated == true && b.Exporttime == dsubmit); if (busi != null) { db.Businesshis.Add(new Businesshis { Identity = busi.Identity, Businesstype = busi.Businesstype, Time = DateTime.Now, }); db.Business.Remove(busi); var pics = db.Businesspic.Where(a => a.Identity == identity && a.Businesstype == (int)bbtype); foreach (var pic in pics) { db.Businesspichis.Add(new Businesspichis { Identity = pic.Identity, Time = DateTime.Now, Businesstype = (short)pic.Businesstype, Pictype = pic.Pictype }); db.Businesspic.Remove(pic); } } db.SaveChanges(); }
public static async Task LogRequest(string content, string method = null, string ip = null, short businessType = 0) { try{ var dbtext = string.Empty; var dbmethod = string.Empty; var dbip = string.Empty; var contentlenth = 4150; var shortlength = 44; if (!string.IsNullOrEmpty(content)) { var lenth = content.Length; dbtext = lenth > contentlenth?content.Substring(0, contentlenth) : content; } if (!string.IsNullOrEmpty(method)) { dbmethod = method.Length > shortlength?method.Substring(0, shortlength) : method; } if (!string.IsNullOrEmpty(ip)) { dbip = ip.Length > shortlength?ip.Substring(0, shortlength) : ip; } await Task.Run(() => { using (var logdb = new enaboContext()) { logdb.Request.Add(new Request { Content = dbtext, Businesstype = businessType, Ip = dbip, Method = dbmethod, Time = DateTime.Now }); logdb.SaveChanges(); } }); } catch (Exception ex) { Console.WriteLine("db log error :{0}", ex.Message); } }
public aballresponse CheckRequestDriver() { var ret = new aballresponse { status = 0, values = new List <values>(), labels = new List <labels>() }; try { using (var driverdb = new enaboContext()) { var ah = driverdb.Request.Where(ab => ab.Time.CompareTo(DateTime.Now.AddDays(-1)) >= 0).Select(a => a.Time); var aaaaa = from one in ah group one by one.ToString("yyyy-MM-dd HH") + "点" into onegroup orderby onegroup.Key descending select new aaa { day = onegroup.Key, count = onegroup.Count() }; foreach (var cc in aaaaa) { ret.labels.Add(new labels { label = cc.day }); ret.values.Add(new values { value = cc.count.ToString() }); } } } catch (Exception ex) { ret.content += ex.Message; } return(ret); }
static void DbToFileForExtranetToIntranet() { var date = DateTime.Now; var dir = string.Format("{0}-{1}-{2}-{3}-{4}-{5}", date.Year, date.Month.ToString("D2"), date.Day.ToString("D2"), date.Hour.ToString("D2"), date.Minute.ToString("D2"), date.Second.ToString("D2")); var dbtofilefname = "abo.txt"; var home = "/home/endriver";// Environment.GetEnvironmentVariable("HOME"); var dbtofp = Path.Combine(home, dbtofilePath); if (!Directory.Exists(dbtofp)) { Directory.CreateDirectory(dbtofp); } var fname = Path.Combine(dbtofp, dbtofilefname); using (var db = new enaboContext()) { //冗余传输,防止边界平台not delivery var rebusi = db.Business.Where(async => async.Integrated == true && async.Exporttime.CompareTo(date.AddDays(-1)) >= 0 ); Console.WriteLine("redundant is {1}, {2} records need to be archived", ",", date, rebusi.Count()); foreach (var rere in rebusi) { var picsr = db.Businesspic.Where(c => c.Businesstype == rere.Businesstype && c.Identity == rere.Identity && c.Uploaded == true); if (picsr.Count() >= global.businesscount[(businessType)rere.Businesstype]) { var aouser = db.Aouser.FirstOrDefault(aa => aa.Identity == rere.Identity); if (aouser == null || string.IsNullOrEmpty(aouser.Name)) { continue; } var bt = (businessType)rere.Businesstype; if (bt == businessType.delay || bt == businessType.overage || bt == businessType.expire || bt == businessType.bodyDelay) { if (!checkSignpic(bt, aouser.Photofile, home)) { continue; } } NewMethod(aouser.Photofile, bt.ToString(), home); var addr = string.Empty; if (!string.IsNullOrEmpty(rere.Province)) { addr += rere.Province; } if (!string.IsNullOrEmpty(rere.City)) { addr += rere.City; } if (!string.IsNullOrEmpty(rere.County)) { addr += rere.County; } if (!string.IsNullOrEmpty(rere.Postaddr)) { addr += rere.Postaddr; } var line = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", rere.Identity, ((businessType)rere.Businesstype).ToString(), addr, rere.Acceptingplace, rere.QuasiDrivingLicense, aouser.Phone, aouser.Name, rere.Losttime.ToString("yyyy/MM/dd HH:mm:ss"), rere.Abroadorservice, rere.Exporttime.ToString("yyyy/MM/dd HH:mm:ss"), aouser.Photofile); File.AppendAllText(fname, line + "\r\n"); } } var theuser = db.Business.Where(async => async.Integrated == false); Console.WriteLine("today is {1}, {2} records need to be archived", ",", date, theuser.Count()); foreach (var re in theuser) { var pics = db.Businesspic.Where(c => c.Businesstype == re.Businesstype && c.Identity == re.Identity && c.Uploaded == true); if (pics.Count() >= global.businesscount[(businessType)re.Businesstype]) { var aouser = db.Aouser.FirstOrDefault(aa => aa.Identity == re.Identity); if (aouser == null || string.IsNullOrEmpty(aouser.Name)) { continue; } var bt = (businessType)re.Businesstype; if (bt == businessType.delay || bt == businessType.overage || bt == businessType.expire || bt == businessType.bodyDelay) { if (!checkSignpic(bt, aouser.Photofile, home)) { continue; } } NewMethod(aouser.Photofile, bt.ToString(), home); var addr = string.Empty; if (!string.IsNullOrEmpty(re.Province)) { addr += re.Province; } if (!string.IsNullOrEmpty(re.City)) { addr += re.City; } if (!string.IsNullOrEmpty(re.County)) { addr += re.County; } if (!string.IsNullOrEmpty(re.Postaddr)) { addr += re.Postaddr; } var line = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", re.Identity, ((businessType)re.Businesstype).ToString(), addr, re.Acceptingplace, re.QuasiDrivingLicense, aouser.Phone, aouser.Name, re.Losttime.ToString("yyyy/MM/dd HH:mm:ss") , re.Abroadorservice, date.ToString("yyyy/MM/dd HH:mm:ss"), aouser.Photofile); File.AppendAllText(fname, line + "\r\n"); re.Integrated = true; re.Status = (short)businessstatus.wait; re.Exporttime = date; re.Waittime = date; } } db.SaveChanges(); } var exp = Path.Combine(home, exportPath); if (!Directory.Exists(exp)) { Directory.CreateDirectory(exp); } var zipfname = Path.Combine(exp, dir + "-abo"); var a = new System.Diagnostics.Process(); a.StartInfo.UseShellExecute = true; a.StartInfo.Arguments = string.Format(" -9 {0} {1}/* -r", zipfname, dbtofp); a.StartInfo.FileName = "zip"; a.Start(); a.WaitForExit(); }
public commonresponse uploadpic([FromBody] uploadpicrequest input) { // highlevel.LogRequest("uploadpic", "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString()); if (input == null) { return(highlevel.commonreturn(responseStatus.requesterror)); } var accinfo = highlevel.GetInfoByToken(Request.Headers); if (accinfo.status != responseStatus.ok) { return(accinfo); } _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now); if (!savePic(input.picture, input.picType, accinfo.photofile, accinfo.businessType)) { return(highlevel.commonreturn(responseStatus.fileprocesserror)); } if (input.picType == picType.unknown) { return(highlevel.commonreturn(responseStatus.pictypeerror)); } if (accinfo.businessType == businessType.unknown) { return(highlevel.commonreturn(responseStatus.businesstypeerror)); } try { using (var ddbb = new enaboContext()) { var already = ddbb.Businesspic.FirstOrDefault(i => i.Businesstype == (int)accinfo.businessType && i.Identity == accinfo.Identity && i.Pictype == (short)input.picType); if (already == null) { var newpic = new Businesspic { Identity = accinfo.Identity, Businesstype = (short)accinfo.businessType, Pictype = (short)input.picType, Uploaded = true, Time = DateTime.Now }; // highlevel.infolog(_log, "uploadpic", JsonConvert.SerializeObject(newpic)); var ret = ddbb.Businesspic.Add(newpic); // highlevel.infolog(_log, "uploadpic88", JsonConvert.SerializeObject(ret.Entity)); } else { already.Uploaded = true; already.Time = DateTime.Now; } ddbb.SaveChanges(); } } catch (Exception ex) { highlevel.errorlog(_log, "uploadpic", ex); } try { var he = Request.Host.ToString(); foreach (var a in Request.Headers) { he += "--" + a.Key + "=" + a.Value; } Task.Run(() => highlevel.LogRequest(he + input.picType + accinfo.Identity, "uploadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)accinfo.businessType)); } catch (Exception ex) { _log.LogError("dblog error:", ex); } _log.LogInformation("uploadpic-{3}: id={0},bt={1},pictype={2}---over", accinfo.Identity, accinfo.businessType, input.picType, DateTime.Now); return(new commonresponse { status = responseStatus.ok }); }
static void FileToDb() { using (var db = new enaboContext()) { var filebase = "result.txt"; var home = "/home/endriver";// Environment.GetEnvironmentVariable("HOME"); var fname = Path.Combine(home, importPath, filebase); if (!File.Exists(fname)) { Console.WriteLine("file {0} does not exist, exit.{1}", fname, DateTime.Now); return; } var content = File.ReadAllLines(fname); Console.WriteLine("{0} lines need to import", content.Length); foreach (var line in content) { var fields = line.Split(','); if (fields.Length < 6) { Console.WriteLine(" invalid data line {0},{1}", fields.Length, line); continue; } var identity = fields[0]; var btype = fields[1]; var bbtype = businessType.unknown; if (!Enum.TryParse(btype, out bbtype)) { Console.WriteLine(" businessType error line {0},{1}", fields.Length, line); continue; } var success = fields[2]; var desc = fields[3]; var timed = fields[4]; var timedd = DateTime.Now; if (!DateTime.TryParse(timed, out timedd)) { Console.WriteLine(" process time error line {0},{1}", timed, line); // Console.WriteLine(" businessType ={0},identity={1},success={2},desc={3},timedd={4},bbtype={5}", // btype, identity, success, desc, timedd, (int)bbtype); continue; } var submittime = fields[5]; var dsubmit = DateTime.Now; if (!DateTime.TryParse(submittime, out dsubmit)) { Console.WriteLine(" submittime error line {0},{1}", submittime, line); continue; } switch (success) { case "1": clean(db, identity, bbtype, dsubmit); break; case "2": clean(db, identity, bbtype, dsubmit); var tuser = db.Aouser.FirstOrDefault(a => a.Identity == identity); if (tuser != null) { tuser.Blacklist = true; db.SaveChanges(); } break; case "3": var busi3 = db.Business.FirstOrDefault(b => b.Identity == identity && b.Businesstype == (short)bbtype && b.Integrated == true && b.Exporttime == dsubmit); if (busi3 != null) { busi3.Status = (short)businessstatus.process; // busi3.Reason=desc; busi3.Processtime = timedd; db.SaveChanges(); } break; case "4": var busi4 = db.Business.FirstOrDefault(b => b.Identity == identity && b.Businesstype == (short)bbtype && b.Integrated == true && b.Exporttime == dsubmit); if (busi4 != null) { busi4.Status = (short)businessstatus.failure; busi4.Reason = desc; busi4.Finishtime = timedd; db.SaveChanges(); } break; case "7": clean(db, identity, bbtype, dsubmit); break; case "8": var tuser8 = db.Aouser.FirstOrDefault(a => a.Identity == identity); if (tuser8 != null) { tuser8.Blacklist = false; db.SaveChanges(); } break; default: Console.WriteLine(" invalid data line {0},{1}", fields.Length, line); break; } } } }