| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | 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.model.LoginBody; |
| | | import com.ruoyi.common.dx.MessageSend; |
| | | 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.ISysDeptService; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | 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.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.security.PermitAll; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | private ISysMenuService menuService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | |
| | | @Value("${pri_key}") |
| | | private String pri_key; |
| | | |
| | | @Value("${isEncryp}") |
| | | private Integer isEncryp; |
| | | |
| | | /** |
| | | * 登录方法 |
| | |
| | | public AjaxResult SSOLogin(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | if (StringUtils.isEmpty(loginBody.getUsername()) || StringUtils.isEmpty(loginBody.getOrgid()) || StringUtils.isEmpty(loginBody.getDeptId())) { |
| | | if (StringUtils.isEmpty(loginBody.getUsername()) || StringUtils.isEmpty(loginBody.getOrgid())) { |
| | | return AjaxResult.error("用户名或组织机构或部门不能为空"); |
| | | } |
| | | |
| | | String token = loginService.loginByUserName(loginBody.getUsername() + "&" + loginBody.getOrgid() + "&" + loginBody.getDeptId()); |
| | | if (StringUtils.isEmpty(loginBody.getDeptId())) { |
| | | loginBody.setDeptId(null); |
| | | } |
| | | String userName = loginBody.getUsername(); |
| | | if (isEncryp == 1) { |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | userName = rsaPublicKeyExample.decryptedData(loginBody.getUsername(), pri_key); |
| | | } |
| | | String token = loginService.loginByUserName(userName + "&" + loginBody.getOrgid() + "&" + loginBody.getDeptId()); |
| | | if (StringUtils.isEmpty(token)) { |
| | | return AjaxResult.error("登陆失败"); |
| | | } |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | |
| | | 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)); |
| | | } |
| | | } |