Пример #1
0
        public async Task <IActionResult> LoginAsync([FromBody] HosipitalLoginRequestDto loginRequestDto)
        {
            var hospitalBiz = new HospitalBiz();

            var model = await hospitalBiz.GetModelByAccountAsync(loginRequestDto.Account);

            if (model is null)
            {
                return(Failed(ErrorCode.Empty, "账号不存在或已禁用"));
            }

            if (!model.Password.Equals(CryptoHelper.AddSalt(model.HospitalGuid, loginRequestDto.Password), StringComparison.OrdinalIgnoreCase))
            {
                return(Failed(ErrorCode.Empty, "账号或密码错误"));
            }

            var response = new HospitalLoginResponseDto
            {
                HospitalGuid = model.HospitalGuid,
                HospitalName = model.HosName,
                Token        = CreateToken(model.HospitalGuid, Common.EnumDefine.UserType.Doctor, 30),
            };

            return(Success(response));
        }
Пример #2
0
        public async Task <IActionResult> EnterpriseWeChatLogin(string code)
        {
            HospitalLoginResponseDto response = null;
            var result = await GetEnterpriseWeChatUserInfo(code);

            if (result == null)
            {
                return(Failed(ErrorCode.Empty, "未找到对应用户信息"));
            }
            //根据用户部门Id查找对应医院数据
            var enterprise = new EnterpriseWeChat();

            PlatformSettings.Mappings.Bind(enterprise);
            List <Mapping> mapList = enterprise?.Mapping.ToList();

            if (mapList == null)
            {
                return(Failed(ErrorCode.Empty, "配置信息错误"));
            }
            int[] departmentList = result.department;
            if (departmentList == null || departmentList.Count() == 0)
            {
                return(Failed(ErrorCode.Empty, "所属部门为空"));
            }
            var hospitalBiz = new HospitalBiz();

            foreach (var item in departmentList)
            {
                var mappingModel = mapList.FirstOrDefault(s => s.DepartmentId == item);
                if (mappingModel != null)
                {
                    var model = await hospitalBiz.GetAsync(mappingModel.HosId);

                    if (model == null)
                    {
                        return(Failed(ErrorCode.Empty, "未找到对应医院"));
                    }
                    //找到对应医院账号进行登录
                    response = new HospitalLoginResponseDto
                    {
                        HospitalGuid = model.HospitalGuid,
                        HospitalName = model.HosName,
                        Token        = CreateToken(model.HospitalGuid, Common.EnumDefine.UserType.Doctor, 30),
                    };
                    return(Success(response));
                }
            }
            return(Failed(ErrorCode.Empty, "未找到对应用户所在医院"));
        }