liusheng
2025-09-29 55f5271f893a25a7be671b24938e49976936a67b
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
@@ -1,13 +1,11 @@
package com.ruoyi.web.controller.system;
import com.ruoyi.common.annotation.IpWhitelist;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysUserDept;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.RSAPublicKeyExample;
import com.ruoyi.common.utils.SecurityUtils;
@@ -18,6 +16,7 @@
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysMenuService;
import com.smartor.mapper.SysUserDeptMapper;
import com.smartor.service.impl.ServiceSLTDHealthcareRecordServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -27,7 +26,9 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -60,6 +61,14 @@
    @Value("${isEncryp}")
    private Integer isEncryp;
    @Value("${sltd_pub_path}")
    private String sltdPubPath;
    @Value("${spring.profiles.active}")
    private String active;
    @Autowired
    private SysUserDeptMapper sysUserDeptMapper;
@@ -81,31 +90,64 @@
    /**
     * 单点登录方法(需要配置IP白名单)
     * 需要在sys_config表的sys.ip.whitelis中,加入IP才能访问该方法
     * <p>
     * 参数同时为空,不给查询数据
     * <p>
     * 【入参规则】
     * 如果userName不为空,那orgid也不能为空
     * 如果上面两个为空,那token不能为空
     *
     * @return 结果
     */
    @IpWhitelist
//    @IpWhitelist
    @GetMapping("/SSOLogin")
    public RedirectView SSOLogin(@RequestParam String userName, @RequestParam String orgid, @RequestParam(required = false) String deptId) {
    public RedirectView SSOLogin(@RequestParam(required = false) String userName, @RequestParam(required = false) String orgid, @RequestParam(required = false) String deptId, @RequestParam(required = false) String token) {
        if (StringUtils.isEmpty(userName) && StringUtils.isEmpty(token)) {
            throw new BaseException("参数不能为空");
        }
        log.info("--------进方法了吗?{}", token);
        // 重定向地址对象(重定向地址
        RedirectView redirectView = new RedirectView();
//        if (active.equals("sltd")) {
//            Map<String, String> headers = buildRequestHeaders();
//            Map<String, String> requestParams = new HashMap<>();
//            requestParams.put("token", token);
//            String reqData = HttpUtil.postFormRequest(sltdPubPath + "/checkSsoTokenId", requestParams, headers, null);
//            log.info("【-----返回的结果为】:{}", reqData);
//            if (StringUtils.isEmpty(reqData)) {
//                throw new BaseException("token验证失败");
//            }
//
//            Map<String, Object> map = JSONObject.parseObject(reqData, Map.class);
//            if (ObjectUtils.isEmpty(map) || (Integer) map.get("code") != 200) {
//                throw new BaseException("token验证失败");
//            }
//
//            Map<String, Object> data = (Map<String, Object>) map.get("data");
//            //员工编码
//            userName = (String) data.get("accountNo");
//        }
        log.info("【-----------userName的值为:{}】", userName);
        // 生成令牌
        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(orgid)) {
            throw new BaseException("用户名或组织机构或部门不能为空");
        }
        if (isEncryp == 1) {
        if (isEncryp != null && isEncryp == 1) {
            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
            userName = rsaPublicKeyExample.decryptedData(userName, pri_key);
        }
        String token = loginService.loginByUserName(userName + "&" + orgid + "&" + deptId);
        if (StringUtils.isEmpty(token)) {
        String token2 = loginService.loginByUserName(userName + "&" + orgid + "&" + deptId);
        if (StringUtils.isEmpty(token2)) {
            throw new BaseException("登陆失败");
        }
        String path = sysConfigService.selectConfigByKey("sys.qddz");
        if(StringUtils.isEmpty(path)){
        if (StringUtils.isEmpty(path)) {
            throw new BaseException("请配置前端地址");
        }
        log.info("单点登陆重定向地址为:{}",path + "/loginSSO?token=" + token + "&orgid=" + orgid + "&orgname=''" + "&ZuHuID=''&deptCode=''");
        redirectView.setUrl(path + "/loginSSO?token=" + token + "&orgid=" + orgid + "&orgname=null" + "&ZuHuID=null&deptCode=null");
        log.info("单点登陆重定向地址为:{}", path + "/loginSSO?token=" + token2 + "&orgid=" + orgid + "&orgname=''" + "&ZuHuID=''&deptCode=''");
        redirectView.setUrl(path + "/loginSSO?token=" + token2 + "&orgid=" + orgid + "&orgname=null" + "&ZuHuID=null&deptCode=null");
        redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
        return redirectView;
    }
@@ -171,4 +213,12 @@
    public AjaxResult getDept(@PathVariable String orgid) {
        return AjaxResult.success(sysDeptService.selectDept(orgid));
    }
    private Map<String, String> buildRequestHeaders() {
        Map<String, String> headers = new HashMap<>();
//        headers.put("Content-Type", "application/json");
        headers.put("app-key", ServiceSLTDHealthcareRecordServiceImpl.APP_KEY);
        return headers;
    }
}