| | |
| | | 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.exception.base.BaseException; |
| | | 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 com.smartor.service.IServiceSLTDHealthcareRecordService; |
| | | 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.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; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | |
| | | private ISysMenuService menuService; |
| | | |
| | | @Autowired |
| | | private ISysDeptService sysDeptService; |
| | | |
| | | @Autowired |
| | | private SysPermissionService permissionService; |
| | | |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | @Autowired |
| | | private IServiceSLTDHealthcareRecordService iServiceSLTDHealthcareRecordService; |
| | | |
| | | @Autowired |
| | | private SysUserDeptMapper sysUserDeptMapper; |
| | | |
| | | /** |
| | | * 登录方法 |
| | |
| | | public AjaxResult login(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid(), loginBody.getOrgid()); |
| | | String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid(), loginBody.getOrgid(), loginBody.getCampusid()); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 登录方法 |
| | | * |
| | | * @param loginBody 单点登录信息 |
| | | * @param map 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @PostMapping("/SSOLogin") |
| | | public AjaxResult SSOLogin(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | if (StringUtils.isEmpty(loginBody.getUsername()) || StringUtils.isEmpty(loginBody.getOrgid())) { |
| | | return AjaxResult.error("用户名或组织机构不能为空"); |
| | | @PostMapping("/test") |
| | | public void test(@RequestBody Map<String, Object> map) { |
| | | iServiceSLTDHealthcareRecordService.aa(map); |
| | | } |
| | | |
| | | /** |
| | | * 单点登录方法(需要配置IP白名单) |
| | | * 需要在sys_config表的sys.ip.whitelis中,加入IP才能访问该方法 |
| | | * <p> |
| | | * 参数同时为空,不给查询数据 |
| | | * <p> |
| | | * 【入参规则】 |
| | | * 如果userName不为空,那orgid也不能为空 |
| | | * 如果上面两个为空,那token不能为空 |
| | | * |
| | | * @return 结果 |
| | | */ |
| | | // @IpWhitelist |
| | | @GetMapping("/SSOLogin") |
| | | public RedirectView SSOLogin(@RequestParam(required = false) String userName, |
| | | @RequestParam(required = false) String orgid, |
| | | @RequestParam(required = false) String campusid, |
| | | @RequestParam(required = false) String deptId, |
| | | String token) { |
| | | if (StringUtils.isEmpty(userName) && StringUtils.isEmpty(token)) { |
| | | throw new BaseException("参数不能为空"); |
| | | } |
| | | |
| | | String token = loginService.loginByUserName(loginBody.getUsername() + "&" + loginBody.getOrgid()); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return ajax; |
| | | String path = sysConfigService.selectConfigByKey("sys.qddz"); |
| | | if (StringUtils.isEmpty(path)) { |
| | | throw new BaseException("请配置前端地址"); |
| | | } |
| | | |
| | | String loginToken = loginService.ssoLogin(userName, orgid, deptId, campusid, token); |
| | | if (StringUtils.isEmpty(loginToken)) { |
| | | log.error("【SSO登录】登录失败,userName={}, orgid={}", userName, orgid); |
| | | return buildRedirect(path + "/login"); |
| | | } |
| | | |
| | | String redirectUrl = path + "/loginSSO?token=" + loginToken + "&orgid=" + orgid + "&orgname=null&ZuHuID=null&deptCode=null"; |
| | | log.info("【SSO登录】重定向地址:{}", redirectUrl); |
| | | return buildRedirect(redirectUrl); |
| | | } |
| | | |
| | | /** |
| | | * 构建重定向视图 |
| | | */ |
| | | private RedirectView buildRedirect(String url) { |
| | | RedirectView redirectView = new RedirectView(); |
| | | redirectView.setUrl(url); |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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)); |
| | | } |
| | | } |