public JsonResult Login(string username, string password, string vcode) { Model.BaseResponse res = new Model.BaseResponse(); var code = TempData["SecurityCode"]?.ToString() ?? "TEST"; vcode = vcode?.ToUpper(); if (vcode != code) { res.error = 1; res.data = "验证码错误"; return(Json(res)); } BLL.manager bll = new BLL.manager(); Model.manager model = bll.GetModel(username, password, true); if (model == null) { res.error = 1; res.data = "帐号或密码不正确"; } else { model.password = string.Empty; Session[DTKeys.SESSION_ADMIN_INFO] = model; Session.Timeout = 45; Utils.WriteCookie("DTRememberName", model.user_name, 14400); Utils.WriteCookie("AdminName", "DTcms", model.user_name); Utils.WriteCookie("AdminPwd", "DTcms", model.password); res.data = model; } return(Json(res, JsonRequestBehavior.AllowGet)); }
public Model.BaseResponse ChangePwd(string username, string password, string phone) { Model.BaseResponse res = new Model.BaseResponse(); try { var m = dal.GetModel(username); if (m.telephone == phone) { string salt = m.salt; string newpassword = DESEncrypt.Encrypt(password, salt); var r = dal.ChangePwd(username, newpassword); if (!r) { res.error = 1; res.data = "修改失败"; } else { res.error = 0; res.data = "修改成功"; } } else { res.error = 1; res.data = "手机号非帐号绑定的号码"; } } catch (Exception ex) { Log.Error(ex.Message); res.error = 4; res.data = ex.Message; } return(res); }
public HttpResponseMessage AddDeviceRepair([FromBody] Model.dt_device_h item) { item.id = Guid.NewGuid().ToString(); item.addtime = DateTime.Now; item.user_id = CurrentUser.USERID; if (string.IsNullOrEmpty(item.device_sn)) { resObj = new Model.BaseResponse(1, "请输入设备编号"); } else { item.photolist = item.photolist.Replace("[", "").Replace("]", "").Replace(" ", ""); if (!item.Insert(2)) { resObj = new Model.BaseResponse(1, "操作失败"); } } return(Json(resObj)); }
public JsonResult EasyLoginWx(string weichatid) { Model.BaseResponse res = new Model.BaseResponse(); BLL.manager bll = new BLL.manager(); Model.manager model = bll.GetModel(weichatid); if (model == null) { res.error = 1; res.data = "未绑定微信"; } else { model.password = string.Empty; Session[DTKeys.SESSION_ADMIN_INFO] = model; Session.Timeout = 240; res.data = model; } return(Json(res, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage Send([FromBody] Model.PushMessage msg) { Model.siteconfig sc = new BLL.siteconfig().loadConfig(); Common.JPush jpclient = new Common.JPush(sc.pushappkey, sc.pushappsecret); Dictionary <string, object> ed = new Dictionary <string, object>(); if (msg.extras != null) { msg.extras.ForEach(p => { if (!ed.Keys.Contains(p.Key)) { ed.Add(p.Key, p.Value); } }); } if (jpclient.SendPush(msg.message, msg.regids, ed)) { resObj = new Model.BaseResponse(0, "success"); } else { resObj = new Model.BaseResponse(1, "fail"); } return(Json(resObj)); }
public override void OnActionExecuting(HttpActionContext actionContext) { // check null parameter if (actionContext.ActionArguments.Count > 0) { if (actionContext.ActionArguments.Any(p => { return(p.Value == null); })) { Model.BaseResponse res = new Model.BaseResponse { error = 5, data = "参数缺失" }; actionContext.Response = ApiBaseController.Json(res); base.OnActionExecuting(actionContext); } } var attr = actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().OfType <AllowAnonymousAttribute>(); bool isAnonymous = attr.Any(a => a is AllowAnonymousAttribute); if (isAnonymous) { base.OnActionExecuting(actionContext); } else { // token in header var request = actionContext.Request; string token = string.Empty; if (request.Headers.Contains("token")) { token = HttpUtility.UrlDecode(request.Headers.GetValues("token").FirstOrDefault()); } if (!string.IsNullOrEmpty(token)) // app Access { var currentUser = new Models.UserSession().GetUserSession(token); if (currentUser == null) { Model.BaseResponse res = new Model.BaseResponse { error = 2, data = "用户信息已失效,请重新登录" }; actionContext.Response = ApiBaseController.Json(res); } else { new Models.UserSession().SetUserSession(currentUser); } } else // web access { if (Models.UserSession.GetCurrentUser() == null) { Model.BaseResponse res = new Model.BaseResponse { error = 2, data = "用户信息已失效,请重新登录" }; actionContext.Response = ApiBaseController.Json(res); } } base.OnActionExecuting(actionContext); } }
public HttpResponseMessage GetMutiReport([FromBody] Model.ReportParam param) { if (!param.item_id.HasValue) { resObj = new Model.BaseResponse(1, "无效设备"); } if (!param.dim_id.HasValue) { resObj = new Model.BaseResponse(1, "未知维度"); } if (resObj.error == 0) { string where = " 1=1 "; if (!param.starttime.HasValue || !param.endtime.HasValue) { where += " and a.updatetime >= '" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "' "; } else { where += " and a.updatetime >= '" + param.starttime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "' and a.updatetime <= '" + param.endtime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'"; } if (!string.IsNullOrEmpty(param.hid)) { var h = new BLL.dt_historydata().GetModel(new Guid(param.hid)); if (h != null) { where += " and a.updatetime >= '" + h.updatetime.Value.AddHours(-12).ToString("yyyy-MM-dd HH:mm:ss") + "' and a.updatetime <= '" + h.updatetime.Value.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss") + "'"; } new BLL.dt_msg().SetReaded(param.msgid); } BLL.dt_dimensioninfo bll = new BLL.dt_dimensioninfo(); var data = bll.GetModelList($"{where} and a.dimension={param.dim_id} and b.item_id = '{param.item_id}'"); string newwhere = " 1=1 "; if (param.endtime.HasValue) { newwhere += " and a.updatetime >= '" + param.endtime.Value.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss") + "' and a.updatetime <= '" + param.endtime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'"; } var data2 = bll.GetModelList($"{newwhere} and a.dimension={param.dim_id} and b.item_id = '{param.item_id}'"); if (data.Count == 0) { resObj = new Model.BaseResponse(1, "无数据"); } else { var ex = from p in data group p by p.updatetime.ToString("yyyy-MM-dd") into g select new Model.ReportData { time = Convert.ToDateTime(g.Key), value = g.Max(p => p.value) }; var ex2 = from p in data group p by p.updatetime.ToString("yyyy-MM-dd HH:00:00") into g select new Model.ReportData { time = Convert.ToDateTime(g.Key), value = g.Max(p => p.value) }; var ex3 = from p in data2 group p by p.updatetime.ToString("yyyy-MM-dd HH:mm:00") into g select new Model.ReportData { time = Convert.ToDateTime(g.Key), value = g.Max(p => p.value) }; var ex4 = from p in data2.Where(c => c.updatetime >= data2.Max(d => d.updatetime).AddMinutes(-20)) group p by p.updatetime.ToString("yyyy-MM-dd HH:mm:00") into g select new Model.ReportData { time = Convert.ToDateTime(g.Key), value = g.Max(p => p.value) }; resObj.data = new { MessageCount = new BLL.dt_msg().GetUnRecordCount(CurrentUser.USERID), ReportData_DD = ex.OrderBy(p => p.time).ToList(), ReportData_HH = ex2.OrderBy(p => p.time).ToList(), ReportData_mm = ex3.OrderBy(p => p.time).ToList(), ReportData_mm2 = ex4.OrderBy(p => p.time).ToList() }; } } return(Json(resObj)); }
public HttpResponseMessage GetReport([FromBody] Model.ReportParam param) { if (!param.item_id.HasValue) { resObj = new Model.BaseResponse(1, "无效设备"); } if (!param.dim_id.HasValue) { resObj = new Model.BaseResponse(1, "未知维度"); } if (resObj.error == 0) { string where = " 1=1 "; if (!param.starttime.HasValue || !param.endtime.HasValue) { where += " and a.updatetime >= '" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "' "; } else { where += " and a.updatetime >= '" + param.starttime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "' and a.updatetime <= '" + param.endtime.Value.ToString("yyyy-MM-dd HH:mm:ss") + "'"; } if (!string.IsNullOrEmpty(param.hid)) { var h = new BLL.dt_historydata().GetModel(new Guid(param.hid)); if (h != null) { where += " and a.updatetime >= '" + h.updatetime.Value.AddHours(-12).ToString("yyyy-MM-dd HH:mm:ss") + "' and a.updatetime <= '" + h.updatetime.Value.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss") + "'"; } new BLL.dt_msg().SetReaded(param.msgid); } BLL.dt_dimensioninfo bll = new BLL.dt_dimensioninfo(); var data = bll.GetModelList($"{where} and a.dimension={param.dim_id} and b.item_id = '{param.item_id}'"); if (data.Count == 0) { resObj = new Model.BaseResponse(1, "无数据"); } else { // DD string format = "yyyy-MM-dd"; switch (param.Acc) { case "DD": format = "yyyy-MM-dd"; break; case "HH": format = "yyyy-MM-dd HH:00:00"; break; case "mm": format = "yyyy-MM-dd HH:mm:00"; break; default: break; } var ex = from p in data group p by p.updatetime.ToString(format) into g select new Model.ReportData { time = Convert.ToDateTime(g.Key), value = g.Max(p => p.value) }; resObj.data = new { MessageCount = new BLL.dt_msg().GetUnRecordCount(CurrentUser.USERID), ReportData = ex.OrderBy(p => p.time).ToList() }; } } return(Json(resObj)); }