/// <summary> /// 更新用户级别(0-普通用户、10 以上 Vip等级) /// </summary> public void UpdateUserLevel() { using (var db = new DBEntities()) { var users = (from ua in db.Users where !ua.IsDeleted && ua.UserLevel == -1 select ua.UserID).ToList(); if (users != null && users.Count > 0) { db.Database.ExecuteSqlCommand(@"update Users set UserLevel=isnull(aa.UserLevel,0) from users left join ( select isnull(users.UserID,UserRoleMaps.UserID) UserID,max(UserLevelRules.UserLevel) UserLevel from UserLevelRules left join users on UserLevelRules.OrgCode=users.OrgCode left join UserRoleMaps on UserLevelRules.RoleID=UserRoleMaps.RoleID where UserLevelRules.IsDeleted=0 and ((UserLevelRules.RuleDimension=0 and users.UserID is not null) or (UserLevelRules.RuleDimension=1 and UserRoleMaps.UserID is not null)) group by users.UserID,UserRoleMaps.UserID)aa on users.UserID = aa.UserID where Users.UserLevel=-1"); foreach (var item in users) { var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, item); User_CacheKey.RemoveCache(); } } } }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public ApiResult UpdateUserInfo([FromBody] UserDTO model) { userService = new BLL.User.Implements.UserService(); model.UserID = CurrentOperatorUserID; if (userService.UpdateUserInfo(model)) { var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, model.UserID); GetUserIDByMobile_CacheKey.RemoveCache(); return(true.ToApiResultForBoolean()); } return(EnumApiStatus.BizError.ToApiResultForApiStatus()); }
/// <summary> /// 找回密码 /// </summary> /// <param name="userID"></param> /// <param name="userPwd"></param> /// <returns></returns> public bool ResetPassword(string userID, string userPwd) { if (base.Update(userID, i => new Entity.User { Password = StringEncrypt.EncryptWithMD5(userPwd) })) { //采用缓存淘汰策略 var cacheKey_User = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, userID); cacheKey_User.RemoveCache(); return(true); } else { return(false); } }
/// <summary> /// 修改密码信息 /// </summary> /// <param name="userModel"></param> public ApiResult ChangePassword(RequestUserChangePasswordDTO passwordModel) { try { using (DBEntities db = new DBEntities()) { if (passwordModel.NewPassword != passwordModel.ConfirmPassword.Trim()) { return(EnumApiStatus.BizChangePasswordConfirmPasswordError.ToApiResultForApiStatus()); } if (passwordModel.NewPassword == passwordModel.OldPassword) { return(EnumApiStatus.BizChangePasswordNewPasswordEqualOld.ToApiResultForApiStatus()); } string oldMD5 = StringEncrypt.EncryptWithMD5(passwordModel.OldPassword); string oldSHA = StringEncrypt.EncryptWithSHA(passwordModel.OldPassword); var user = db.Users.Where(t => t.UserID == passwordModel.UserID && (t.Password == oldMD5 || t.Password == oldSHA)).FirstOrDefault(); if (user == null) { return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus()); } user.Password = StringEncrypt.EncryptWithMD5(passwordModel.NewPassword); if (db.SaveChanges() > 0) { var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(StringCacheKeyType.User, passwordModel.UserID); GetUserIDByMobile_CacheKey.RemoveCache(); return(EnumApiStatus.BizOK.ToApiResultForApiStatus("密码修改成功")); } else { return(EnumApiStatus.BizChangePasswordOldPasswordError.ToApiResultForApiStatus()); } } } catch (Exception ex) { LogHelper.WriteError(ex); return(EnumApiStatus.BizError.ToApiResultForApiStatus("修改密码失败")); } }
/// <summary> /// 更新会员信息 /// 日期:2017年4月15日 /// </summary> /// <param name="model"></param> /// <returns></returns> public EnumApiStatus UpdateMemberInfo(BLL.User.DTOs.Request.RequestUserMemberDTO request) { using (DBEntities db = new DBEntities()) { using (db.BeginTransaction()) { var model = db.UserMembers.Where(q => q.UserID == request.MemberID && q.MemberID == request.MemberID && q.IsDeleted == false).FirstOrDefault(); if (model == null) { return(EnumApiStatus.BizError); } // 当前用户不能有相同身份证的就诊人 add by lrj 2017-7-20 if (!string.IsNullOrEmpty(request.IDNumber)) { var mid = db.UserMembers.Where(q => q.IDNumber == request.IDNumber && q.MemberID != model.MemberID && q.IsDeleted == false).Select(q => q.MemberID).FirstOrDefault(); } #region 必填参数 model.MemberName = request.MemberName; // model.Relation = request.Relation; model.Gender = request.Gender; model.Marriage = request.Marriage; model.IDType = request.IDType; model.MemberName = request.MemberName; #endregion #region 可选参数(有值才修改) if (request.Birthday != null) { model.Birthday = request.Birthday; } if (request.Mobile != null) { model.Mobile = request.Mobile; } if (request.IDNumber != null) { model.IDNumber = request.IDNumber; } if (request.Nationality != null) { model.Nationality = request.Nationality; } if (request.Province != null) { model.Province = request.Province; } if (request.ProvinceRegionID != null) { model.ProvinceRegionID = request.ProvinceRegionID; } if (request.City != null) { model.City = request.City; } if (request.CityRegionID != null) { model.CityRegionID = request.CityRegionID; } if (request.District != null) { model.District = request.District; } if (request.DistrictRegionID != null) { model.DistrictRegionID = request.DistrictRegionID; } if (request.Town != null) { model.Town = request.Town; } if (request.TownRegionID != null) { model.TownRegionID = request.TownRegionID; } if (request.Village != null) { model.Village = request.Village; } if (request.VillageRegionID != null) { model.VillageRegionID = request.VillageRegionID; } if (request.Address != null) { model.Address = request.Address; } if (request.Email != null) { model.Email = request.Email; } if (request.PostCode != null) { model.PostCode = request.PostCode; } #endregion #region 是否已经存在本人关系的就诊人 if (request.Relation == EnumUserRelation.MySelf) { var members = GetMemberList(request.UserID); //本人关系已经存在 if (members.Any(a => a.Relation == EnumUserRelation.MySelf && a.MemberID != model.MemberID)) { return(EnumApiStatus.BizUserMemberRejectUpdateMySelfExists); } } #endregion #region 通过身份证号码获取性别和身份证号码 if (model.IDType == EnumUserCardType.IDCard && !string.IsNullOrEmpty(model.IDNumber)) { string birthday, sex; var res = ToolHelper.GetBirthdaySexFromIdCard(model.IDNumber, out birthday, out sex); //身份证号码正确 if (res) { model.Birthday = birthday; model.Gender = sex == "0" ? EnumUserGender.Male : EnumUserGender.Female; } else { //身份证号码格式错误 return(EnumApiStatus.BizUserMemberRejectInsertUpdateIDNumberFormatError); } } #endregion model.Relation = request.Relation; if (request.IsDefault.HasValue && request.IsDefault == true) { model.IsDefault = true; } else if (request.IsDefault.HasValue && request.IsDefault == false) { model.IsDefault = false; } if (request.Relation == EnumUserRelation.MySelf) { var user = db.Users.Where(a => a.UserID == request.UserID).FirstOrDefault(); user.UserCNName = model.MemberName; user.UserENName = model.MemberName; } if (db.SaveChanges() > 0) { db.Commit(); var userMemberCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserMemberDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, model.MemberID); userMemberCacheKey.RemoveCache(); var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User, request.UserID); User_CacheKey.RemoveCache(); } } //设置默认 if (request.IsDefault.HasValue && request.IsDefault.Value) { SetDefaultMember(request.MemberID, request.UserID); } return(EnumApiStatus.BizOK); } }
/// <summary> /// 新增成员 /// 日期:2017年4月15日 /// </summary> /// <param name="userMemberEntity"></param> /// <returns></returns> public ApiResult InsertMemberInfo(BLL.User.DTOs.Request.RequestUserMemberDTO request) { ApiResult result = new ApiResult(); string memberid = string.Empty; #region 身份证号码格式校验 if (!string.IsNullOrEmpty(request.IDNumber) && request.IDType == EnumUserCardType.IDCard) { string birthday, sex; var res = ToolHelper.GetBirthdaySexFromIdCard(request.IDNumber, out birthday, out sex); //身份证号码正确 if (res) { request.Birthday = birthday; request.Gender = sex == "0" ? EnumUserGender.Male : EnumUserGender.Female; } else { result.Status = EnumApiStatus.BizUserMemberRejectInsertUpdateIDNumberFormatError; result.Msg = result.Status.GetEnumDescript(); return(result); } } #endregion using (DBEntities db = new DBEntities()) { using (db.BeginTransaction()) { db.Configuration.AutoDetectChangesEnabled = true; bool isAdd = false; UserMember userMemberEntity = null; if (!string.IsNullOrEmpty(request.IDNumber)) { userMemberEntity = (from q in db.UserMembers where q.IDNumber == request.IDNumber && q.MemberName == request.MemberName && q.IsDeleted == false orderby q.ModifyTime descending, q.CreateTime descending, q.MemberID select q).FirstOrDefault(); } if (userMemberEntity == null) { isAdd = true; #region 可选参数(默认值) if (request.Birthday == null) { request.Birthday = ""; } if (request.Mobile == null) { request.Mobile = ""; } if (request.IDNumber == null) { request.IDNumber = ""; } if (request.Nationality == null) { request.Nationality = ""; } if (request.Province == null) { request.Province = ""; } if (request.ProvinceRegionID == null) { request.ProvinceRegionID = ""; } if (request.City == null) { request.City = ""; } if (request.CityRegionID == null) { request.CityRegionID = ""; } if (request.District == null) { request.District = ""; } if (request.DistrictRegionID == null) { request.DistrictRegionID = ""; } if (request.Town == null) { request.Town = ""; } if (request.TownRegionID == null) { request.TownRegionID = ""; } if (request.Village == null) { request.Village = ""; } if (request.VillageRegionID == null) { request.VillageRegionID = ""; } if (request.Address == null) { request.Address = ""; } if (request.Email == null) { request.Email = ""; } if (request.PostCode == null) { request.PostCode = ""; } if (request.IsDefault == null || !request.IsDefault.HasValue) { request.IsDefault = false; } #endregion userMemberEntity = request.Map <RequestUserMemberDTO, Entity.UserMember>(); userMemberEntity.MemberID = Guid.NewGuid().ToString("N"); userMemberEntity.CreateTime = DateTime.Now; userMemberEntity.CreateUserID = request.UserID; } //默认成员 var defaultMemberEntity = GetDefaultMemberInfo(request.UserID).Map <ResponseUserMemberDTO, Entity.UserMember>(); memberid = userMemberEntity.MemberID; //默认成员不存在 if (defaultMemberEntity == null) { //当前成员为默认 userMemberEntity.IsDefault = true; } if (request.Relation == EnumUserRelation.MySelf) { var userEntity = db.Users.Where(a => a.UserID == request.UserID).FirstOrDefault(); userEntity.UserCNName = request.MemberName; userEntity.UserENName = request.MemberName; var mySelfMember = (from m in db.UserMembers where m.UserID == request.UserID && m.Relation == EnumUserRelation.MySelf && m.IsDeleted == false && m.IsDeleted == false select m).FirstOrDefault(); //如果默认成员已经存在则更新默认成员 if (mySelfMember != null) { //兼容bat 服务站,新增自己关系是,要是原来的自己关系信息不完整(身份证号为空),则覆盖 //身份证不为空,且操作机构不为网络医院 var webapiConfig = SysConfigService.Get <XuHos.Common.Config.Sections.Api>(); if (string.IsNullOrEmpty(mySelfMember.IDNumber) && request.OrgID != webapiConfig.OrgID) { mySelfMember.Gender = request.Gender; mySelfMember.Marriage = request.Marriage; mySelfMember.MemberName = request.MemberName; #region 可选参数(有值才修改) if (request.Birthday != null) { mySelfMember.Birthday = request.Birthday; } if (request.Mobile != null) { mySelfMember.Mobile = request.Mobile; } if (request.IDNumber != null) { mySelfMember.IDNumber = request.IDNumber; } if (request.Nationality != null) { mySelfMember.Nationality = request.Nationality; } if (request.Province != null) { mySelfMember.Province = request.Province; } if (request.ProvinceRegionID != null) { mySelfMember.ProvinceRegionID = request.ProvinceRegionID; } if (request.City != null) { mySelfMember.City = request.City; } if (request.CityRegionID != null) { mySelfMember.CityRegionID = request.CityRegionID; } if (request.District != null) { mySelfMember.District = request.District; } if (request.DistrictRegionID != null) { mySelfMember.DistrictRegionID = request.DistrictRegionID; } if (request.Town != null) { mySelfMember.Town = request.Town; } if (request.TownRegionID != null) { mySelfMember.TownRegionID = request.TownRegionID; } if (request.Village != null) { mySelfMember.Village = request.Village; } if (request.VillageRegionID != null) { mySelfMember.VillageRegionID = request.VillageRegionID; } if (request.Address != null) { mySelfMember.Address = request.Address; } if (request.Email != null) { mySelfMember.Email = request.Email; } if (request.PostCode != null) { mySelfMember.PostCode = request.PostCode; } #endregion memberid = mySelfMember.MemberID; db.Update(mySelfMember); } else { result.Status = EnumApiStatus.BizUserMemberRejectUpdateMySelfExists; result.Msg = result.Status.GetEnumDescript(); return(result); } } } if (isAdd) { db.UserMembers.Add(userMemberEntity); } //db.Update(userEntity); var count = db.SaveChanges(); db.Commit(); if (count > 0) { var userMemberCacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserMemberDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User_Member, userMemberEntity.MemberID); userMemberCacheKey.RemoveCache(); var User_CacheKey = new XuHos.Common.Cache.Keys.EntityCacheKey <ResponseUserDTO>(XuHos.Common.Cache.Keys.StringCacheKeyType.User, request.UserID); User_CacheKey.RemoveCache(); result.Status = EnumApiStatus.BizOK; } else { result.Status = EnumApiStatus.BizError; } } //设置默认 if (request.IsDefault.HasValue && request.IsDefault.Value) { SetDefaultMember(memberid, request.UserID); } result.Data = memberid; result.Msg = result.Status.GetEnumDescript(); return(result); } }