| | |
| | | import com.ltkj.framework.web.service.SysPermissionService; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import static com.ltkj.common.core.domain.AjaxResult.success; |
| | | |
| | |
| | | @PostMapping("/login") |
| | | @ApiOperation("登录接口") |
| | | @RepeatSubmit |
| | | public AjaxResult login(@RequestBody @ApiParam(value = "登录对象") LoginBody loginBody) { |
| | | |
| | | public AjaxResult login(@RequestBody @ApiParam(value = "登录对象") LoginBody loginBody, HttpServletRequest request) { |
| | | String hospId = request.getHeader("hospId"); |
| | | AjaxResult ajax = success(); |
| | | // 生成令牌 |
| | | String token; |
| | | if (loginBody.getMobile()) { |
| | | token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getType(), loginBody.getCode(), loginBody.getUuid()); |
| | | token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getType(), loginBody.getCode(), loginBody.getUuid(),hospId); |
| | | } else { |
| | | token = loginService.Cuslogin(loginBody.getUsername(), loginBody.getPassword(), loginBody.getType(), loginBody.getCode(), loginBody.getUuid()); |
| | | } |
| | |
| | | |
| | | header.add("token", getToken()); |
| | | header.add("X-Access-Token", getToken()); |
| | | LoginUser loginUser = tokenService.getLoginUser(getToken()); |
| | | header.add("hospId",loginUser.getHospId()); |
| | | header.add("QospId","123"); |
| | | return header; |
| | | } |
| | | } |
| | |
| | | |
| | | private String hospName; |
| | | |
| | | private String hospId; |
| | | |
| | | private String hospDB; |
| | | |
| | | /* */ |
| | | |
| | | /** |
| | |
| | | |
| | | //import com.ltkj.framework.interceptor.DBChangeInterceptor; |
| | | import com.ltkj.framework.interceptor.DBChangeInterceptor; |
| | | import com.ltkj.framework.interceptor.JimuInterceptor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.HttpMethod; |
| | |
| | | |
| | | @Autowired |
| | | private DBChangeInterceptor dbChangeInterceptor; |
| | | @Autowired |
| | | private JimuInterceptor jimuInterceptor; |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | |
| | | "/system/dict/data/**", |
| | | "/system/dict/type/**", |
| | | "/captchaImage","/getCaptchaConfigKey/**", |
| | | "/system/role/execUpdateSql" |
| | | "/system/role/execUpdateSql", |
| | | "/jmreport/**" |
| | | // , |
| | | // "/login", "/register", "/captchaImage","/cus/**","/getCaptchaConfigKey","/report/jmreport/**", |
| | | // "/sqlserver/getdata/**","/api/His/**","/system/config/zx","/system/config/gxxmpym","/system/report/savePdf", |
| | |
| | | // String.valueOf(HttpMethod.GET), "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**", |
| | | // "/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/jmreport/**","/lis/**","/pacs/**","/callBack/**" |
| | | }); |
| | | |
| | | registry.addInterceptor(jimuInterceptor) |
| | | .addPathPatterns("/jmreport/**"); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ltkj.framework.interceptor; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.ltkj.common.core.domain.model.LoginUser; |
| | | import com.ltkj.db.DataSourceConfig; |
| | | import com.ltkj.db.DataSourceContextHolder; |
| | | import com.ltkj.framework.config.UserHoder; |
| | | import com.ltkj.framework.web.service.TokenService; |
| | | import com.ltkj.hosp.service.IDictHospService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Company: 西安路泰科技有限公司 |
| | | * @Author: zhaowenxuan |
| | | * @Date: 2025/2/13 18:44 |
| | | */ |
| | | @Order(2) |
| | | @Component |
| | | public class JimuInterceptor implements HandlerInterceptor { |
| | | |
| | | @Autowired |
| | | private IDictHospService dictHospService; |
| | | @Autowired |
| | | private DataSourceConfig dataSourceConfig; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | private String db; |
| | | |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | Map<String, String[]> parameterMap = request.getParameterMap(); |
| | | String[] tokens = parameterMap.get("token"); |
| | | if (tokens != null && tokens.length > 0){ |
| | | String token = tokens[0]; |
| | | LoginUser loginUser = tokenService.getLoginUser(token); |
| | | System.out.println("loginUser.getHospDB() ->"+loginUser.getHospDB()); |
| | | dataSourceConfig.addDataSource(loginUser.getHospDB()); |
| | | DataSourceContextHolder.setDataSourceKey(loginUser.getHospDB()); |
| | | // UserHoder.setLoginUser(loginUser); |
| | | db = loginUser.getHospDB(); |
| | | }else { |
| | | LoginUser loginUser = UserHoder.getLoginUser(); |
| | | // System.out.println(JSONUtil.toJsonStr(user)); |
| | | dataSourceConfig.addDataSource(db); |
| | | DataSourceContextHolder.setDataSourceKey(db); |
| | | // dataSourceConfig.addDataSource("ltkjpeis10_chkwyy"); |
| | | // DataSourceContextHolder.setDataSourceKey("ltkjpeis10_chkwyy"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { |
| | | HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); |
| | | } |
| | | |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
| | | DataSourceContextHolder.setDataSourceKey("default"); |
| | | DataSourceContextHolder.clear(); |
| | | HandlerInterceptor.super.afterCompletion(request, response, handler, ex); |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.constant.CacheConstants; |
| | | import com.ltkj.common.core.domain.entity.SysDept; |
| | | import com.ltkj.common.enums.DataSourceType; |
| | | import com.ltkj.common.exception.CustomException; |
| | | import com.ltkj.common.exception.user.CaptchaException; |
| | | import com.ltkj.common.exception.user.CaptchaExpireException; |
| | | import com.ltkj.common.exception.user.SecretKeyException; |
| | | import com.ltkj.common.utils.*; |
| | | import com.ltkj.common.utils.sign.RsaUtils; |
| | | import com.ltkj.db.DataSourceConfig; |
| | | import com.ltkj.db.DataSourceContextHolder; |
| | | import com.ltkj.framework.config.JwtUtils; |
| | | import com.ltkj.framework.config.UserHoder; |
| | | import com.ltkj.hosp.domain.DictHosp; |
| | |
| | | |
| | | @Value("${token.secret_key_login}") |
| | | private boolean secretKeyLogin; |
| | | @Autowired |
| | | private DataSourceConfig dataSourceConfig; |
| | | |
| | | |
| | | /** |
| | |
| | | * @param password 密码 |
| | | * @return 结果 |
| | | */ |
| | | public String login(String username, String password, Boolean type,String code,String uuid) { |
| | | public String login(String username, String password, Boolean type,String code,String uuid,String hospId) { |
| | | |
| | | DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name()); |
| | | LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(DictHosp::getCode,hospId); |
| | | DictHosp hosp = hospService.getOne(wrapper); |
| | | |
| | | DataSourceContextHolder.setDataSourceKey(hosp.getDbname()); |
| | | String aSwitch = configService.selectConfigByKey("captcha_switch"); |
| | | if(null !=aSwitch && aSwitch.equalsIgnoreCase("Y")){ |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid; |
| | |
| | | } |
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); |
| | | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| | | loginUser.setHospDB(hosp.getDbname()); |
| | | loginUser.setHospId(hospId); |
| | | tokenService.setLoginUser(loginUser); |
| | | |
| | | recordLoginInfo(Long.valueOf(loginUser.getUserId())); |
| | | //校验商家过期否 |