class OauthServiceImpl implements OauthService {

    @Override
    public CommonResult login(LoginParam loginParam, HttpServletRequest request) {
        // sha加密后密码
        String pwd = SHAUtils.encodeData(loginParam.getPassword());
        loginParam.setPassword(pwd);
        User user = userMapper.userAuthentication(loginParam.getUserId(), loginParam.getPassword());

        JSONObject result = new JSONObject();
        if(user != null){
            result.put("userId", user.getId());
            result.put("userName", user.getName());
            result.put("avatar", user.getAvatar());
            List<Role> roles = roleMapper.listRole(loginParam.getUserId());
            result.put("roles", roles);

            String token = JwtUtil.getToken(user.getId().toString());

            result.put("web_token", "Bearer:" + token);
            System.out.println();

            hospitalLogger.info("登录成功: " + loginParam.getUserId() + " with token: " + token);
            //异步记录登录操作
            loginLog.run(loginParam, request);

            return CommonResult.success(result);
        } else{
            hospitalLogger.info("登录失败: " + loginParam.getUserId());
            return CommonResult.fail(E_601);
        }
    }

}