| | |
| | | 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; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.SysLoginService; |
| | | import com.ruoyi.framework.web.service.SysPermissionService; |
| | | import com.ruoyi.system.service.ISysConfigService; |
| | | import com.ruoyi.system.service.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.smartor.mapper.SysUserDeptMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.view.RedirectView; |
| | | |
| | | import javax.annotation.security.PermitAll; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | |
| | | private ISysMenuService menuService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | |
| | | |
| | | @Value("${pri_key}") |
| | | private String pri_key; |
| | | |
| | | @Value("${isEncryp}") |
| | | private Integer isEncryp; |
| | | |
| | | @Autowired |
| | | private SysUserDeptMapper sysUserDeptMapper; |
| | | |
| | | /** |
| | | * 登录方法 |
| | |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * 单点登录方法(需要配置IP白名单) |
| | | * 需要在sys_config表的sys.ip.whitelis中,加入IP才能访问该方法 |
| | | * |
| | | * @return 结果 |
| | | */ |
| | | @IpWhitelist |
| | | @GetMapping("/SSOLogin") |
| | | public RedirectView SSOLogin(@RequestParam String userName, @RequestParam String orgid, @RequestParam(required = false) String deptId) { |
| | | RedirectView redirectView = new RedirectView(); |
| | | // 生成令牌 |
| | | if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(orgid)) { |
| | | throw new BaseException("用户名或组织机构或部门不能为空"); |
| | | } |
| | | if (isEncryp == 1) { |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | userName = rsaPublicKeyExample.decryptedData(userName, pri_key); |
| | | } |
| | | String token = loginService.loginByUserName(userName + "&" + orgid + "&" + deptId); |
| | | if (StringUtils.isEmpty(token)) { |
| | | throw new BaseException("登陆失败"); |
| | | } |
| | | String path = sysConfigService.selectConfigByKey("sys.qddz"); |
| | | 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"); |
| | | redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY); |
| | | return redirectView; |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getToken") |
| | | public void getToken(HttpServletResponse response) throws IOException { |
| | |
| | | ajax.put("user", user); |
| | | ajax.put("roles", roles); |
| | | ajax.put("permissions", permissions); |
| | | List<SysUserDept> sysUserDeptKSs = null; |
| | | List<SysUserDept> sysUserDeptBQs = null; |
| | | SysUserDept sysUserDept = new SysUserDept(); |
| | | sysUserDept.setUserId(user.getUserId()); |
| | | sysUserDept.setDeptType("1"); |
| | | sysUserDept.setOrgid(user.getOrgid()); |
| | | sysUserDeptKSs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); |
| | | ajax.put("belongDepts", sysUserDeptKSs); |
| | | sysUserDept.setDeptType("2"); |
| | | sysUserDeptBQs = sysUserDeptMapper.selectSysUserDeptList(sysUserDept); |
| | | ajax.put("belongWards", sysUserDeptBQs); |
| | | |
| | | return ajax; |
| | | } |
| | | |
| | |
| | | @GetMapping("getRouters") |
| | | public AjaxResult getRouters() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | log.error("----------getRouters的userId入参为:{}", userId); |
| | | log.info("----------getRouters的userId入参为:{}", userId); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |
| | | } |
| | | |
| | | @GetMapping("/getDept/{orgid}") |
| | | public AjaxResult getDept(@PathVariable String orgid) { |
| | | return AjaxResult.success(sysDeptService.selectDept(orgid)); |
| | | } |
| | | } |