zjh
2025-04-08 983d95bdcbb273b4a78efd0058a2a35141be1b51
ltkj-framework/src/main/java/com/ltkj/framework/web/service/SysLoginService.java
@@ -7,12 +7,15 @@
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;
@@ -37,6 +40,7 @@
import com.ltkj.framework.manager.AsyncManager;
import com.ltkj.framework.manager.factory.AsyncFactory;
import com.ltkj.framework.security.context.AuthenticationContextHolder;
import org.springframework.util.DigestUtils;
import java.util.Date;
import java.util.HashMap;
@@ -84,6 +88,8 @@
    @Value("${token.secret_key_login}")
    private boolean secretKeyLogin;
    @Autowired
    private DataSourceConfig dataSourceConfig;
    /**
@@ -93,9 +99,14 @@
     * @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;
@@ -139,6 +150,9 @@
        }
        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()));
        //校验商家过期否
@@ -269,9 +283,13 @@
        }
        for (TjCustomer tjCustomer : customerList) {
            try {
                password = RsaUtils.decryptByPrivateKey(password);
                boolean b = SecurityUtils.matchesPassword(password, tjCustomer.getCusPassword());
                if (b) {
//                password = RsaUtils.decryptByPrivateKey(password);
//                boolean b = SecurityUtils.matchesPassword(password, tjCustomer.getCusPassword());
//                if (b) {
//                    return createLoginCus(tjCustomer);
//                }
                password = DigestUtils.md5DigestAsHex(password.getBytes());
                if (password.equals(tjCustomer.getCusPassword())){
                    return createLoginCus(tjCustomer);
                }
            } catch (Exception e) {