/// <summary> /// 新增上线信息 /// </summary> /// <param name="context"></param> /// <returns></returns> public Stream addOnLine(ImpContext context) { MongOnLine mongOnLine = new MongOnLine(Constants.daname); MongWaitUp mongWaitUp = new MongWaitUp(Constants.daname); //反序列dd化 OnLineModel onLineModel = JsonConvert.DeserializeObject <OnLineModel>(context.json.Replace("\0", ""), new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); if (string.IsNullOrEmpty(onLineModel.guid)) { if (onLineModel.createDate.Year == 1) { onLineModel.createDate = DateTime.Now; } onLineModel.guid = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(onLineModel._id)) { onLineModel._id = Guid.NewGuid().ToString(); } onLineModel.onLine = true; onLineModel.clickN = 0; mongOnLine.insert(onLineModel); mongWaitUp.delete(new WaitUpModel() { _id = onLineModel._id }); //微信小程序同步 saveOnLine(); //微博同步 WeiBoHelper weiBoHelper = new WeiBoHelper(); Dictionary <string, object> asy = new Dictionary <string, object>(); string pic = onLineModel.pictiue.Replace("https://www.aikid360.com:8010/", ""); pic = string.Format("{0}{1}", @"C:\web\akidImg\", pic); FileInfo file = new FileInfo(pic); if (file.Exists) { asy.Add("pic", file); } string content = string.Format("{0} 详情请点击链接查看:https://www.aikid360.com/view.htm?{2}", onLineModel.remark, onLineModel.origin, onLineModel.guid); asy.Add("status", content); weiBoHelper.send(asy); return(new ToStream().ToStreams(mongWaitUp.obtainAll())); } else { mongOnLine.update(onLineModel); //重新保存数据 saveOnLine(); return(new ToStream().ToStreams(mongOnLine.obtainAll())); } }
/// <summary> ///根据条件查询所需要的数据 /// </summary> /// <param name="context"></param> /// <returns></returns> public Stream obtainBrandNo(ImpContext context) { MongOnLine mongOnLine = new MongOnLine(Constants.daname); DateTime dateTime = DateTime.Now.AddDays(-4); //反序列化 OnLineModel onLineModel = JsonConvert.DeserializeObject <OnLineModel>(context.json.Replace("\0", ""), new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); List <OnLineModel> list = mongOnLine.obtainAll(onLineModel); list = (from q in list orderby q.createDate descending select q).ToList(); return(new ToStream().ToStreams(list)); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public Stream obtainAll(ImpContext context) { MongOnLine mongOnLine = new MongOnLine(Constants.daname); bool onLine = true; if (!string.IsNullOrEmpty(context.json)) { //反序列化 OnLineModel onLineModel = JsonConvert.DeserializeObject <OnLineModel>(context.json.Replace("\0", ""), new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); onLine = onLineModel.onLine; } return(new ToStream().ToStreams(mongOnLine.obtainAll(onLine))); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public Stream deleteOnLine(ImpContext context) { MongOnLine mongOnLine = new MongOnLine(Constants.daname); //反序列化 OnLineModel onLineModel = JsonConvert.DeserializeObject <OnLineModel>(context.json.Replace("\0", ""), new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); mongOnLine.delete(onLineModel); string pic = onLineModel.pictiue.Replace("https://www.aikid360.com:8010/", ""); pic = string.Format("{0}{1}", @"C:\web\akidImg\", pic); if (File.Exists(pic)) { File.Delete(pic); } //重新保存数据 saveOnLine(); return(new ToStream().ToStreams(mongOnLine.obtainAll())); }
/// <summary> /// 根据ID获取数据 /// </summary> /// <param name="context"></param> /// <returns></returns> public Stream obtainDetail(ImpContext context) { //记录访问IP string ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); string id = context.json; if (!string.IsNullOrEmpty(id)) { MongOnLine mongOnLine = new MongOnLine(Constants.daname); List <OnLineModel> list = mongOnLine.obtainAll(new OnLineModel()); var p = (from q in list where q.guid == id select q).FirstOrDefault(); if (p != null) { int num = p.clickN + 1; mongOnLine.updateClick(id, num); return(new ToStream().ToStreams(p)); } return(null); } return(new ToStream().ToStreams("")); }
/// <summary> /// 生产JSON格式的数据文档 /// </summary> /// <returns></returns> private void saveOnLine() { //判断文件的存在 if (File.Exists(Constants.wechatjson)) { File.Delete(Constants.wechatjson); } else { File.Create(Constants.wechatjson); } MongOnLine mongOnLine = new MongOnLine(Constants.daname); List <OnLineModel> list = mongOnLine.obtainAll(); IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter(); string dateTimeFormat = "yyyy'-'MM'-'dd"; timeConverter.DateTimeFormat = dateTimeFormat; String json = JsonConvert.SerializeObject(list, timeConverter); saveBrand(list); System.IO.File.WriteAllText(Constants.wechatjson, json, Encoding.UTF8); }