| | |
| | | package com.ltkj.framework.security.handle; |
| | | |
| | | import java.io.IOException; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletException; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.db.DataSourceContextHolder; |
| | | import com.ltkj.framework.web.service.TokenService; |
| | | import com.ltkj.hosp.domain.DictHosp; |
| | | import com.ltkj.hosp.service.IDictHospService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.core.Authentication; |
| | |
| | | public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Resource |
| | | private IDictHospService hospService; |
| | | /** |
| | | * 退出处理 |
| | | * |
| | |
| | | @Override |
| | | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) |
| | | throws IOException, ServletException { |
| | | String hospId = request.getHeader("hospId"); |
| | | LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(DictHosp::getCode,hospId); |
| | | DictHosp hosp = hospService.getOne(wrapper); |
| | | DataSourceContextHolder.setDataSourceKey(hosp.getDbname()); |
| | | |
| | | LoginUser loginUser = tokenService.getLoginUser(request); |
| | | if (StringUtils.isNotNull(loginUser)) { |
| | | String userName = loginUser.getUsername(); |
| | | // 删除用户缓存记录 |
| | | tokenService.delLoginUser(loginUser.getToken(), loginUser.getUser().getUserId()); |
| | | // 记录用户退出日志 |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功",hosp.getDbname())); |
| | | // AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功"); |
| | | } |
| | | ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success("退出成功"))); |
| | | } |