public ActionResult AddUser(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = new T_PropertyUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email, PropertyPlaceId = GetSessionModel().PropertyPlaceId.Value }; // 保存到数据库 propertyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult PropertyLogin(AccountModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } string code = (string)Session["ValidateCode"]; if (model.CheckCode != code) { ModelState.AddModelError("CheckCode", "验证码不正确"); return(View(model)); } //根据用户名查找用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = propertyUserBll.GetEntity(u => u.UserName == model.UserName.Trim() && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View(model)); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { ModelState.AddModelError("Password", "密码不正确"); return(View(model)); } //3.如果未设置角色 if (user.PropertyUserRoles.Count == 0) { ModelState.AddModelError("UserName", "该用户未设置角色,请联系管理员"); return(View(model)); } //4.获取用户对象信息(权限菜单,Action等)保存基本信息到session中 this.SetUserSessiong(user, propertyUserBll); //5.判断是否拥有访问首页的权限 UserSessionModel session = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; if (session.IsMgr == ConstantParam.USER_ROLE_DEFAULT && !session.ActionDic.ContainsKey("/Property/Index")) { ModelState.AddModelError("UserName", "该用户无访问权限,请联系管理员"); return(View(model)); } BreadCrumb.ClearState(); //5.跳转到 return(RedirectToAction("Index", "Property")); }
public ApiPageResultModel OwnInspectionExceptionList([FromUri] PagedSearchModel model) { ApiPageResultModel resultModel = new ApiPageResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); Expression <Func <T_InspectionResult, bool> > where = u => u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.InspectionTimePlan.InspectionPlan.PropertyPlaceId == user.PropertyPlaceId && u.Status == ConstantParam.EXCEPTION && u.DisposerId == user.Id; //获取巡检异常总个数和分页数据 IInspectionResultBLL resultBll = BLLFactory <IInspectionResultBLL> .GetBLL("InspectionResultBLL"); resultModel.Total = resultBll.Count(where); resultModel.result = new { ExceptionList = resultBll.GetOwnInspectionResultPageList(where, model.PageIndex, ConstantParam.PAGE_SIZE).Select(r => new { Id = r.Id, PlanName = r.InspectionTimePlan.InspectionPlan.PlanName, PointName = r.InspectionPoint.PointName, Desc = string.IsNullOrEmpty(r.Desc) ? "" : r.Desc, DisposeStatus = r.DisposeStatus == null ? ConstantParam.NO_DISPOSE : r.DisposeStatus.Value, UploadTime = r.UploadTime.ToString("yyyy-MM-dd HH:mm:ss"), Uploader = r.UploadUser.UserName, Imgs = string.IsNullOrEmpty(r.Imgs) ? new string[] { } : r.Imgs.Split(';'), DisposeDesc = r.DisposeStatus == ConstantParam.DISPOSED ? r.ExceptionDisposes.FirstOrDefault().DisposeDesc : "", DisposeTime = r.DisposeStatus == ConstantParam.DISPOSED ? r.ExceptionDisposes.FirstOrDefault().DisposeTime.ToString("yyyy-MM-dd HH:mm:ss") : "", DisposeUser = r.DisposeStatus == ConstantParam.DISPOSED ? r.ExceptionDisposes.FirstOrDefault().DisposeUser.UserName : (r.DisposerId != null ? r.Disposer.UserName : "") }) }; } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel GetVersionInfo([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取当前用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //调用版本信息BLL层获取最新的版本信息 IMobileVersionBLL versionBll = BLLFactory <IMobileVersionBLL> .GetBLL("MobileVersionBLL"); var Versions = versionBll.GetList(v => v.Type == ConstantParam.MOBILE_TYPE_PROPERTY, "VersionCode", false); //如果版本信息不为空 if (Versions != null && Versions.Count() > 0) { var highestVersion = Versions.First(); if (highestVersion != null) { resultModel.result = new { VersionCode = highestVersion.VersionCode, VersionName = highestVersion.VersionName, Desc = highestVersion.Desc, ApkFilePath = highestVersion.ApkFilePath }; } } else { resultModel.Msg = APIMessage.NO_APP; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel DisposeException(DisposerModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取要处理的巡检异常 IInspectionResultBLL resultBll = BLLFactory <IInspectionResultBLL> .GetBLL("InspectionResultBLL"); T_InspectionResult result = resultBll.GetEntity(m => m.Id == model.Id); if (result != null) { //修改处理状态并添加处理记录 result.DisposeStatus = ConstantParam.DISPOSED; T_InspectionExceptionDispose exceptionDispose = new T_InspectionExceptionDispose() { DisposeDesc = model.DisposeDesc, DisposeUserId = user.Id, ExceptionResultId = model.Id, DisposeTime = DateTime.Now }; //保存到数据库 resultBll.DisposeException(result, exceptionDispose); } else { resultModel.Msg = APIMessage.EXCEPTION_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiPageResultModel PropertyNewsList([FromUri] PagedSearchModel model) { ApiPageResultModel resultModel = new ApiPageResultModel(); try { //根据用户ID查找物业用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果物业用户存在 if (propertyUser != null) { //如果验证Token不通过或已过期 if (DateTime.Now > propertyUser.TokenInvalidTime || model.Token != propertyUser.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 propertyUser.LatelyLoginTime = DateTime.Now; propertyUser.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); propertyUserBll.Update(propertyUser); // 获取指定物业小区id的公告列表 IPostBLL postBll = BLLFactory <IPostBLL> .GetBLL("PostBLL"); Expression <Func <T_Post, bool> > where = u => u.PropertyPlaceId == propertyUser.PropertyPlaceId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.PublishedFlag == ConstantParam.PUBLISHED_TRUE; // TODO:此处Content不需要全部返回,待优化 var list = postBll.GetPageList(where, "PublishedTime", false, model.PageIndex).Select(s => new { ID = s.Id, propertyName = s.PropertyPlace.Name, propertyPic = string.IsNullOrEmpty(s.PropertyPlace.ImgThumbnail) ? "/Images/news_item_default.png" : s.PropertyPlace.ImgThumbnail, pubDate = s.PublishedTime.ToString(), title = s.Title, content = s.Content.Replace("\n", "") }).ToList(); resultModel.result = list; resultModel.Total = postBll.GetList(where).Count(); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel SetQuestionDisposer(SetDisposerModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取要指派处理人的问题 IQuestionBLL questionBll = BLLFactory <IQuestionBLL> .GetBLL("QuestionBLL"); T_Question question = questionBll.GetEntity(m => m.Id == model.Id); if (question != null) { //指派处理人 question.DisposerId = model.DisposerId; //保存到数据库 if (!questionBll.Update(question)) { resultModel.Msg = APIMessage.SET_DISPOSER_FAIL; } } else { resultModel.Msg = APIMessage.QUESTION_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiPageResultModel CompanyNewsList([FromUri] PagedSearchModel model) { ApiPageResultModel resultModel = new ApiPageResultModel(); try { //根据用户ID查找物业用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果物业用户存在 if (propertyUser != null) { //如果验证Token不通过或已过期 if (DateTime.Now > propertyUser.TokenInvalidTime || model.Token != propertyUser.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 propertyUser.LatelyLoginTime = DateTime.Now; propertyUser.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); propertyUserBll.Update(propertyUser); //获取指定公司发布的公开新闻公告 ICompanyPostBLL postBll = BLLFactory <ICompanyPostBLL> .GetBLL("CompanyPostBLL"); Expression <Func <T_CompanyPost, bool> > where = u => u.CompanyId == propertyUser.PropertyPlace.CompanyId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.PublishStatus == ConstantParam.PUBLISHED_TRUE && u.IsOpen == ConstantParam.PUBLISHED_TRUE; var list = postBll.GetPageList(where, "PublishedTime", false, model.PageIndex).Select(s => new { ID = s.Id, CompanyName = s.Company.Name, CompanyIcon = string.IsNullOrEmpty(s.Company.Img) ? "/Images/news_item_default.png" : s.Company.Img, PublishedTime = s.PublishedTime.Value.ToString("yyyy-MM-dd HH:mm:ss"), Title = s.Title }).ToList(); resultModel.result = list; resultModel.Total = postBll.Count(where); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel ChangePassword(OwnerChangePasswordModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取要修改密码的物业用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); string OldMd5Pwd = PropertyUtils.GetMD5Str(model.OldPwd); //如果输入的旧密码与数据库中不一致 if (OldMd5Pwd != user.Password) { resultModel.Msg = APIMessage.OLD_PWD_ERROR; } else { //修改密码并保存 user.Password = PropertyUtils.GetMD5Str(model.NewPwd); userBll.Update(user); } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ActionResult SetPropUserInfo(LoggedInAccountModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { // 获取Session Model UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = sessionModel.UserID; IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (propertyUser != null) { propertyUser.UserName = model.UserName; propertyUser.TrueName = model.TrueName; propertyUser.Memo = model.Memo; propertyUser.Tel = model.Tel; propertyUser.Phone = model.Phone; propertyUser.Email = model.Email; // 保存到数据库 propertyUserBll.Update(propertyUser); //更新SessionModel中的最新个人信息 sessionModel.TrueName = model.TrueName; //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ApiResultModel GetDisposerList([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取物业用户列表 Expression <Func <T_PropertyUser, bool> > where = u => u.PropertyPlaceId == user.PropertyPlaceId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT; var userList = userBll.GetList(where, "Id", false).ToList(); resultModel.result = userList.Select(u => new { UserId = u.Id, Name = string.IsNullOrEmpty(u.TrueName) ? u.UserName : (userList.Count(p => p.TrueName == u.TrueName) > 1 ? u.TrueName + "(" + u.UserName + ")" : u.TrueName) }); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
/// <summary> /// 设置管理员提交 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonModel SetAdmin(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = new T_PropertyUser() { PropertyPlaceId = model.PlaceId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 IPropertyRoleBLL roleBll = BLLFactory <IPropertyRoleBLL> .GetBLL("PropertyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.PropertyPlaceId == model.PlaceId); if (role != null) { propertyUser.PropertyUserRoles.Add(new R_PropertyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(jm); }
public ApiResultModel GetUserInfo([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //初始化物业用户基本信息并返回 OwnerModel ownerM = new OwnerModel() { UserName = string.IsNullOrEmpty(user.TrueName) ? user.UserName : user.TrueName, HeadPath = user.HeadPath, Gender = user.Gender == null ? -1 : user.Gender.Value }; resultModel.result = ownerM; } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
/// <summary> /// 用户是否拥有指定权限 /// </summary> /// <param name="user">用户</param> /// <param name="href">权限对应的Href地址</param> /// <returns></returns> private bool IsHaveAction(T_PropertyUser user, string href) { if (user.IsMgr == ConstantParam.USER_ROLE_MGR) { return(true); } var roleActions = user.PropertyUserRoles.Select(ur => ur.PropertyRole.PropertyRoleActions); foreach (var roleAction in roleActions) { var actions = roleAction.Select(obj => obj.Action); foreach (var action in actions) { if (action.Href == href) { return(true); } } } return(false); }
public ApiResultModel CompanyNewsDetail([FromUri] NewsDetailModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户ID查找物业用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果物业用户存在 if (propertyUser != null) { //如果验证Token不通过或已过期 if (DateTime.Now > propertyUser.TokenInvalidTime || model.Token != propertyUser.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 propertyUser.LatelyLoginTime = DateTime.Now; propertyUser.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); propertyUserBll.Update(propertyUser); // 返回详细页面url resultModel.result = "MobilePage/CompanyNewsDetail?id=" + model.PostId; } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ActionResult EditUser(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (propertyUser != null) { propertyUser.UserName = model.UserName; propertyUser.TrueName = model.TrueName; propertyUser.Memo = model.Memo; propertyUser.Tel = model.Tel; propertyUser.Phone = model.Phone; propertyUser.Email = model.Email; // 保存到数据库 propertyUserBll.Update(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditPropUserPwd(AccountPasswordChangeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = sessionModel.UserID; // 若当前登录用户为物业用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (propertyUser != null) { propertyUser.Password = PropertyUtils.GetMD5Str(model.Password); propertyUser.Token = null; propertyUser.TokenInvalidTime = null; // 保存到数据库 propertyUserBll.Update(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfigRole(PropertyUserConfigRoleModel model) { JsonModel jm = new JsonModel(); IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); //获取要分配角色的物业用户 T_PropertyUser user = propertyUserBll.GetEntity(m => m.Id == model.userId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); // 新建用户角色关联表 List <R_PropertyUserRole> roles = new List <R_PropertyUserRole>(); if (model.ids != null) { //没有设置任何角色 则不执行循环操作 foreach (var id in model.ids) { R_PropertyUserRole item = new R_PropertyUserRole() { UserId = model.userId, RoleId = id }; roles.Add(item); } } //修改物业用户对应的角色集合 if (propertyUserBll.ConfigRole(user, roles)) { jm.Content = "物业用户 " + user.TrueName + " 分配角色"; } else { jm.Msg = "分配角色失败"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfigRole(int id) { // 创建物业用户角色模型 PropertyUserRoleModel userRoleModel = new PropertyUserRoleModel(); // 获取指定id的物业用户模型 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = propertyUserBll.GetEntity(m => m.Id == id && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); userRoleModel.User = new PropertyUserModel() { UserId = propertyUser.Id, UserName = propertyUser.UserName, TrueName = propertyUser.TrueName, Tel = propertyUser.Tel, Phone = propertyUser.Phone, Memo = propertyUser.Memo, Email = propertyUser.Email }; // 获取本小区中所有的物业角色 IPropertyRoleBLL propertyRoleBll = BLLFactory <IPropertyRoleBLL> .GetBLL("PropertyRoleBLL"); //排序 var sortModel = this.SettingSorting("Id", false); var roleList = propertyRoleBll.GetList(p => p.PropertyPlaceId == propertyUser.PropertyPlaceId && p.IsSystem == ConstantParam.USER_ROLE_DEFAULT, sortModel.SortName, sortModel.IsAsc).ToList(); userRoleModel.RoleList = roleList; //获取该用户已分配的角色id的集合 userRoleModel.RoleIds = propertyUser.PropertyUserRoles.Select(m => m.RoleId).ToList(); return(View(userRoleModel)); }
public ApiResultModel Login(OwnerLoginModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户名查找用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = propertyUserBll.GetEntity(u => u.UserName == model.UserName && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { resultModel.Msg = APIMessage.NAME_ERROR; return(resultModel); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { resultModel.Msg = APIMessage.PWD_ERROR; return(resultModel); } //产生随机令牌 var token = System.Guid.NewGuid().ToString("N"); //更新用户令牌和最近登录时间及Token失效时间 user.Token = token; user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); propertyUserBll.Update(user); //返回登录用户的ID和用户名以及令牌 resultModel.result = new { token = token, userId = user.Id, userName = user.UserName, isMgr = user.IsMgr }; //推送设备管理 IPropertyUserPushBLL userPushBll = BLLFactory <IPropertyUserPushBLL> .GetBLL("PropertyUserPushBLL"); var userPush = userPushBll.GetEntity(p => p.UserId == user.Id); var userPush1 = userPushBll.GetEntity(p => p.RegistrationId == model.RegistrationId); if (userPush != null) { userPush.RegistrationId = model.RegistrationId; userPushBll.Update(userPush); } else if (userPush1 != null) { userPush1.UserId = user.Id; userPushBll.Update(userPush1); } else { userPush = new T_PropertyUserPush() { UserId = user.Id, RegistrationId = model.RegistrationId }; userPushBll.Save(userPush); } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel DisposeQuestion(DisposerModel model) { ApiResultModel resultModel = new ApiResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取要处理的问题 IQuestionBLL questionBll = BLLFactory <IQuestionBLL> .GetBLL("QuestionBLL"); T_Question question = questionBll.GetEntity(m => m.Id == model.Id); if (question != null) { //修改处理状态并添加处理记录 question.Status = ConstantParam.DISPOSED; question.IsPublish = model.IsPublish; T_QuestionDispose questionDispose = new T_QuestionDispose() { DisposeDesc = model.DisposeDesc, DisposeUserId = user.Id, QuestionId = model.Id, DisposeTime = DateTime.Now }; //保存到数据库 questionBll.DisposeQuestion(question, questionDispose); //推送通知 IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL"); var userPush = userPushBLL.GetEntity(p => p.UserId == question.UploadUserId); if (userPush != null) { string registrationId = userPush.RegistrationId; string alert = "您" + question.UploadTime.ToString("yyyy-MM-dd HH:mm") + "上报的问题已处理"; //通知信息 bool flag = PropertyUtils.SendPush("上报问题处理", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationId); if (!flag) { resultModel.Msg = "问题处理完成,推送失败"; } } } else { resultModel.Msg = APIMessage.QUESTION_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel SetUserInfo(OwnerInfoModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取要设置基本信息的物业用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); //设定头像路径及文件名 string dir = HttpContext.Current.Server.MapPath(ConstantParam.PROPERTY_USER_HEAD_DIR); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } //设置头像 if (!string.IsNullOrEmpty(model.HeadPic)) { var fileName = DateTime.Now.ToFileTime().ToString() + ".jpg"; string filepath = Path.Combine(dir, fileName); using (FileStream fs = new FileStream(filepath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] datas = Convert.FromBase64String(model.HeadPic); bw.Write(datas); bw.Close(); } } //删除旧头像 if (!string.IsNullOrEmpty(user.HeadPath)) { FileInfo f = new FileInfo(HttpContext.Current.Server.MapPath(user.HeadPath)); if (f.Exists) { f.Delete(); } } //头像路径保存 user.HeadPath = ConstantParam.PROPERTY_USER_HEAD_DIR + "/" + fileName; } user.Gender = model.Gender; userBll.Update(user); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiPageResultModel OwnQuestionList([FromUri] PagedSearchModel model) { ApiPageResultModel resultModel = new ApiPageResultModel(); try { IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); Expression <Func <T_Question, bool> > where = u => u.PropertyPlaceId == user.PropertyPlaceId && u.DisposerId == user.Id; //获取问题总个数和分页数据 IQuestionBLL questionBll = BLLFactory <IQuestionBLL> .GetBLL("QuestionBLL"); resultModel.Total = questionBll.Count(where); resultModel.result = new { ownQuestionList = questionBll.GetOwnQuestionPageList(where, model.PageIndex, ConstantParam.PAGE_SIZE).Select(q => new { Id = q.Id, Title = q.Title, Desc = string.IsNullOrEmpty(q.Desc) ? "" : q.Desc, Status = q.Status, UploadTime = q.UploadTime.ToString("yyyy-MM-dd HH:mm:ss"), Uploader = q.UploadUser.UserName, Imgs = string.IsNullOrEmpty(q.Imgs) ? new string[] { } : q.Imgs.Split(';'), AudioPath = q.AudioPath, VoiceDuration = q.VoiceDuration, DisposeDesc = q.Status == ConstantParam.DISPOSED ? q.QuestionDisposes.FirstOrDefault().DisposeDesc : "", DisposeTime = q.Status == ConstantParam.DISPOSED ? q.QuestionDisposes.FirstOrDefault().DisposeTime.ToString("yyyy-MM-dd HH:mm:ss") : "", DisposeUser = q.Status == ConstantParam.DISPOSED ? q.QuestionDisposes.FirstOrDefault().DisposeUser.UserName : (q.DisposerId != null ? q.Disposer.UserName : ""), IsPublish = q.IsPublish }) }; } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel InspectionPlans([FromUri] TokenModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取当前用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); //获取包含当日的巡检时间安排 IInspectionTimePlanBLL planTimeBll = BLLFactory <IInspectionTimePlanBLL> .GetBLL("InspectionTimePlanBLL"); //查询条件 Expression <Func <T_InspectionTimePlan, bool> > where = p => p.InspectionPlan.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && p.InspectionPlan.PublishedFlag == ConstantParam.PUBLISHED_TRUE && p.InspectionPlan.PropertyPlaceId == user.PropertyPlaceId && p.InspectionPlan.BeginDate <= DateTime.Today && p.InspectionPlan.EndDate >= DateTime.Today; where = PredicateBuilder.And(where, p => p.InspectionPlan.Type == ConstantParam.INSPECTION_TYPE_DAY || (p.InspectionPlan.Type == ConstantParam.INSPECTION_TYPE_WEEK && p.BeginNum == (int)DateTime.Today.DayOfWeek) || (p.InspectionPlan.Type == ConstantParam.INSPECTION_TYPE_MONTH && p.BeginNum == DateTime.Today.Day) || p.InspectionPlan.IsRandom == ConstantParam.DELIVERY_FLAG_TRUE); //获取当前可以巡检的任务列表 var planTimeList = planTimeBll.GetList(where).ToList(); resultModel.result = planTimeList.Select(pt => new { PlanId = pt.PlanId, PlanName = pt.InspectionPlan.PlanName, Type = pt.InspectionPlan.Type, IsRandom = pt.InspectionPlan.IsRandom, Number = pt.Number, PlanTimeId = pt.Id, PlanDate = DateTime.Today.ToString("yyyy-MM-dd"), TimeSpan = pt.InspectionPlan.IsRandom == ConstantParam.DELIVERY_FLAG_TRUE ? "随机" : (pt.InspectionPlan.Type == ConstantParam.INSPECTION_TYPE_DAY ? pt.BeginNum + ":00 - " + pt.EndNum + ":00" : "本日"), PointList = pt.InspectionPlan.PlanPoints.Select(p => new { PointId = p.PointId, PointName = p.InspectionPoint.PointName, Memo = p.InspectionPoint.Memo, IsInspectioned = IsInspectioned(pt, p.PointId) }) }); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
/// <summary> /// 保存物业用户的session信息 /// </summary> /// <param name="user"></param> private void SetUserSessiong(T_PropertyUser user, IPropertyUserBLL bll) { //用户session模型 UserSessionModel sessionInfo = new UserSessionModel(); //设置基本信息 sessionInfo.UserID = user.Id; sessionInfo.UserName = user.UserName; sessionInfo.TrueName = user.TrueName; sessionInfo.IsMgr = user.IsMgr; sessionInfo.UserType = ConstantParam.USER_TYPE_PROPERTY; sessionInfo.PropertyPlaceId = user.PropertyPlaceId; sessionInfo.HeadPath = user.HeadPath; //构造菜单业务对象 IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); #region 设置物业用户菜单以及权限 //管理员 if (user.IsMgr == ConstantParam.USER_ROLE_MGR) { //获取菜单 var list = menuBll.GetList(m => m.MenuFlag == ConstantParam.MENU_LEFT && m.IsPlatform == ConstantParam.USER_TYPE_PROPERTY).Select(m => new MenuModel { MenuId = m.Id, MenuName = m.MenuName, MenuCode = m.MenuCode, MenuUrl = m.Href, MenuFlag = m.MenuFlag, MenuCss = m.IconClass, ParentId = m.ParentId, Order = m.Order, IsPlatform = m.IsPlatform }).ToList(); //设置左边菜单 sessionInfo.MenuList = list; } else { //获取物业用户对应的角色权限表 var roleActions = user.PropertyUserRoles.Select(ur => ur.PropertyRole.PropertyRoleActions); //菜单字典 Dictionary <string, MenuModel> menuDic = new Dictionary <string, MenuModel>(); //权限字典 Dictionary <string, string> actionDic = new Dictionary <string, string>(); foreach (var item in roleActions) { var actions = item.Select(obj => obj.Action); foreach (var action in actions) { //添加权限 if (!actionDic.ContainsKey(action.Href)) { actionDic.Add(action.Href, action.ActionName); } foreach (var li in action.ActionItems) { //添加权限 if (!actionDic.ContainsKey(li.Href)) { actionDic.Add(li.Href, li.ItemName); } } var menu = action.Menu; if (menu.ParentId != null) { if (!menuDic.ContainsKey(menu.ParentMenu.MenuCode)) { menuDic.Add(menu.ParentMenu.MenuCode, GetMenuModel(menu.ParentMenu)); } } if (!menuDic.ContainsKey(menu.MenuCode)) { menuDic.Add(menu.MenuCode, GetMenuModel(menu)); } } } //设置菜单和权限 sessionInfo.MenuList.AddRange(menuDic.Values.ToList()); sessionInfo.ActionDic = actionDic; } #endregion //设置session信息 Session[ConstantParam.SESSION_USERINFO] = sessionInfo; }
public ApiResultModel UploadResult(InspectionResultModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取当前用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); IInspectionTimePlanBLL planTimeBll = BLLFactory <IInspectionTimePlanBLL> .GetBLL("InspectionTimePlanBLL"); if (!planTimeBll.Exist(p => p.Id == model.TimePlanId)) { resultModel.result = "该巡检安排已不存在"; return(resultModel); } IInspectionResultBLL resultBll = BLLFactory <IInspectionResultBLL> .GetBLL("InspectionResultBLL"); //单条巡检结果初始化 T_InspectionResult result = new T_InspectionResult() { TimePlanId = model.TimePlanId, PointId = model.PointId, Status = model.Status, Desc = model.Desc, UploadUserId = model.UserId, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, Longitude = model.Longitude, Latitude = model.Latitude }; //如果状态为异常,则设置处理状态为未处理 if (model.Status == ConstantParam.EXCEPTION) { result.DisposeStatus = ConstantParam.NO_DISPOSE; } //巡检异常文件资源保存目录 string dir = HttpContext.Current.Server.MapPath(ConstantParam.QUESTION_FILE + user.PropertyPlaceId); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } //问题图片上传 if (!string.IsNullOrEmpty(model.ImgFiles)) { var fileName = DateTime.Now.ToFileTime().ToString() + ".zip"; string filepath = Path.Combine(dir, fileName); using (FileStream fs = new FileStream(filepath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] datas = Convert.FromBase64String(model.ImgFiles); bw.Write(datas); bw.Close(); } } //图片集路径保存 result.Imgs = PropertyUtils.UnZip(filepath, dir, ConstantParam.QUESTION_FILE + user.PropertyPlaceId); } //语音文件上传 if (!string.IsNullOrEmpty(model.AudioFile)) { var fileName = DateTime.Now.ToFileTime().ToString() + ".amr"; string filepath = Path.Combine(dir, fileName); using (FileStream fs = new FileStream(filepath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] datas = Convert.FromBase64String(model.AudioFile); bw.Write(datas); bw.Close(); } } //语音路径保存 result.AudioPath = ConstantParam.QUESTION_FILE + user.PropertyPlaceId + "/" + fileName; } result.ClientSaveTime = model.ClientSaveTime; result.PlanDate = model.PlanDate; result.UploadTime = DateTime.Now; //上传巡检结果 resultBll.Save(result); } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }