/// <summary> /// 登录验证 /// </summary> /// <param name="code">工号</param> /// <param name="password">密码</param> /// <returns>登录结果</returns> public LoginValidateModel Login(string code, string password) { var encryptPwd = EncryptUtil.Md5Hash(password); var user = _dbContext.Set <Employee>().Where(s => s.EmCode == code && (s.Password == encryptPwd || s.Password == password) && s.Disabled != true).FirstOrDefault(); if (user != null) { var userDto = Mapper.Map <Employee, EmployeeDto>(user); userDto.Password = ""; var token = EncryptUtil.AesEncrypt(string.Format("{0}|{1}", user.Id, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); return(new LoginValidateModel() { Valid = true, Token = token, User = userDto, Message = "Success", }); } else { return(new LoginValidateModel() { Valid = false, Token = "", User = null, Message = "账号或密码不正确", }); } }
/// <summary> /// 查询用户可以访问的机构ID列表 /// </summary> /// <param name="userId"></param> /// <param name="context"></param> /// <returns></returns> public static List <string> GetUserMi(string userId, ILisContext context) { if (!UserMi.ContainsKey(userId)) { lock (lockObj1) { var list = context.Set <EmployeeMi>().Where(s => s.EmployeeId == userId).Select(s => s.MiId).ToList(); if (!UserMi.ContainsKey(userId)) { UserMi.Add(userId, list); } } } return(UserMi[userId]); }
/// <summary> /// 查询用户可以访问的患者ID /// </summary> /// <param name="userId"></param> /// <param name="context"></param> /// <returns></returns> public static List <string> GetUserPatient(string userId, ILisContext context) { if (!UserPatient.ContainsKey(userId)) { lock (lockObj2) { var mids = GetUserMi(userId, context); var list = context.Set <Requests>().Where(s => mids.Contains(s.MiId)).Select(s => s.PatientId).Distinct().ToList(); if (!UserPatient.ContainsKey(userId)) { UserPatient.Add(userId, list); } } } return(UserPatient[userId]); }
/// <summary> /// 医疗机构信息维护 /// </summary> /// <param name="source"></param> /// <returns></returns> public MedicalInstitutionDto AddOrUpdateMedicalInstitution(MedicalInstitutionDto source) { var isAddNew = string.IsNullOrEmpty(source.Id); if (isAddNew) { source.Id = Guid.NewGuid().ToString(); var entity = Mapper.Map <MedicalInstitutionDto, MedicalInstitution>(source); _dbContext.Set <MedicalInstitution>().Add(entity); } else { var target = _dbContext.Set <MedicalInstitution>().Where(s => s.Id == source.Id).FirstOrDefault(); if (target == null) { CommonFunc.ThrowExceptionIfRecordNotExists(EntityNames.MedicalInstitution, source.Id, OperateType.Update, _logger); } else if (!Enumerable.SequenceEqual(source.Version, target.Version)) { var modifiedUser = GetEmployeeDetail(target.LastUpdateUserId); CommonFunc.ThrowExceptionIfRecordHasBeenModified(EntityNames.MedicalInstitution, source.Id, modifiedUser.EmName, target.LastUpdateTime, OperateType.Update, _logger); } Mapper.Map(source, target); } _dbContext.SaveChanges(); return(GetMedicalInstitutionDetail(source.Id)); }