ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
@@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; 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.ISysMenuService; @@ -54,6 +55,25 @@ return ajax; } /** * 登录方法 * * @param loginBody 单点登录信息 * @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("用户名或组织机构不能为空"); } String token = loginService.loginByUserName(loginBody.getUsername() + "&" + loginBody.getOrgid()); ajax.put(Constants.TOKEN, token); return ajax; } @GetMapping("/getToken") public void getToken(HttpServletResponse response) throws IOException { // 生成或获取token ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java
@@ -1,6 +1,9 @@ package com.ruoyi.web.controller.system; import java.util.List; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -27,8 +30,7 @@ */ @RestController @RequestMapping("/system/notice") public class SysNoticeController extends BaseController { public class SysNoticeController extends BaseController { @Autowired private ISysNoticeService noticeService; @@ -37,9 +39,11 @@ */ //@PreAuthorize("@ss.hasPermi('system:notice:list')") @GetMapping("/list") public TableDataInfo list(SysNotice notice) { public TableDataInfo list(SysNotice notice) { startPage(); LoginUser loginUser = getLoginUser(); SysUser user = loginUser.getUser(); notice.setOrgid(user.getOrgid()); List<SysNotice> list = noticeService.selectNoticeList(notice); return getDataTable(list); } @@ -49,8 +53,7 @@ */ //@PreAuthorize("@ss.hasPermi('system:notice:query')") @GetMapping(value = "/{noticeId}") public AjaxResult getInfo(@PathVariable Long noticeId) { public AjaxResult getInfo(@PathVariable Long noticeId) { return success(noticeService.selectNoticeById(noticeId)); } @@ -60,8 +63,7 @@ //@PreAuthorize("@ss.hasPermi('system:notice:add')") @Log(title = "通知公告", businessType = BusinessType.INSERT) @PostMapping("/add") public AjaxResult add(@Validated @RequestBody SysNotice notice) { public AjaxResult add(@Validated @RequestBody SysNotice notice) { notice.setCreateBy(getUsername()); return toAjax(noticeService.insertNotice(notice)); } @@ -72,8 +74,7 @@ //@PreAuthorize("@ss.hasPermi('system:notice:edit')") @Log(title = "通知公告", businessType = BusinessType.UPDATE) @PostMapping("/edit") public AjaxResult edit(@Validated @RequestBody SysNotice notice) { public AjaxResult edit(@Validated @RequestBody SysNotice notice) { notice.setUpdateBy(getUsername()); return toAjax(noticeService.updateNotice(notice)); } @@ -84,8 +85,7 @@ //@PreAuthorize("@ss.hasPermi('system:notice:remove')") @Log(title = "通知公告", businessType = BusinessType.DELETE) @GetMapping("/remove/{noticeIds}") public AjaxResult remove(@PathVariable Long[] noticeIds) { public AjaxResult remove(@PathVariable Long[] noticeIds) { return toAjax(noticeService.deleteNoticeByIds(noticeIds)); } } ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
@@ -3,6 +3,7 @@ import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; @@ -92,6 +93,22 @@ return tokenService.createToken(loginUser); } public String loginByUserName(String userName) { SysUser sysUser = userService.selectUserByUserName2(userName); if (ObjectUtils.isNotEmpty(sysUser)) { // 构建登录用户对象 LoginUser loginUser = new LoginUser(); loginUser.setUser(sysUser); loginUser.setUserId(sysUser.getUserId()); // 创建 token String token = tokenService.createToken(loginUser); // 生成token return token; } return null; } /** * 校验验证码 * ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java
@@ -1,6 +1,8 @@ package com.ruoyi.system.service.impl; import java.util.List; import com.ruoyi.common.core.domain.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.domain.SysNotice; ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml
@@ -52,6 +52,9 @@ <if test="createBy != null and createBy != ''"> AND create_by like concat('%', #{createBy}, '%') </if> <if test="orgid != null and orgid != ''"> AND orgid = #{orgid} </if> </where> </select>