Merge remote-tracking branch 'origin/satoken' into dev
# Conflicts:
# pom.xml
# ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RepeatSubmitAspect.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/config/AsyncConfig.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/handler/CreateAndUpdateMetaObjectHandler.java
# ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
# ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
# ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserOnlineServiceImpl.java
# ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TokenServiceImpl.java
# ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserDetailsServiceImpl.java
# ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml
已添加9个文件
已删除12个文件
已修改42个文件
| | |
| | | <easyexcel.version>2.2.11</easyexcel.version> |
| | | <cglib.version>3.3.0</cglib.version> |
| | | <velocity.version>2.3</velocity.version> |
| | | <satoken.version>1.28.0</satoken.version> |
| | | <mybatis-plus.version>3.5.0</mybatis-plus.version> |
| | | <p6spy.version>3.9.1</p6spy.version> |
| | | <hutool.version>5.7.18</hutool.version> |
| | |
| | | <version>${velocity.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- Sa-Token æé认è¯, å¨çº¿ææ¡£ï¼http://sa-token.dev33.cn/ --> |
| | | <dependency> |
| | | <groupId>cn.dev33</groupId> |
| | | <artifactId>sa-token-spring-boot-starter</artifactId> |
| | | <version>${satoken.version}</version> |
| | | </dependency> |
| | | <!-- Sa-Token æ´å jwt --> |
| | | <dependency> |
| | | <groupId>cn.dev33</groupId> |
| | | <artifactId>sa-token-jwt</artifactId> |
| | | <version>${satoken.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- jdk11 缺失ä¾èµ jaxb--> |
| | | <dependency> |
| | | <groupId>com.sun.xml.bind</groupId> |
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.springframework.data.redis.connection.RedisServerCommands; |
| | | import org.springframework.data.redis.core.RedisCallback; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | private final RedisTemplate<String, String> redisTemplate; |
| | | |
| | | @ApiOperation("è·åç¼åçæ§è¯¦ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('monitor:cache:list')") |
| | | @SaCheckPermission("monitor:cache:list") |
| | | @GetMapping() |
| | | public AjaxResult<Map<String, Object>> getInfo() throws Exception { |
| | | Properties info = (Properties) redisTemplate.execute((RedisCallback<Object>) RedisServerCommands::info); |
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | private final ISysLogininforService logininforService; |
| | | |
| | | @ApiOperation("æ¥è¯¢ç³»ç»è®¿é®è®°å½å表") |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')") |
| | | @SaCheckPermission("monitor:logininfor:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysLogininfor> list(SysLogininfor logininfor, PageQuery pageQuery) { |
| | | return logininforService.selectPageLogininforList(logininfor, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºç³»ç»è®¿é®è®°å½å表") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')") |
| | | @SaCheckPermission("monitor:logininfor:export") |
| | | @PostMapping("/export") |
| | | public void export(SysLogininfor logininfor, HttpServletResponse response) { |
| | | List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); |
| | |
| | | } |
| | | |
| | | @ApiOperation("å é¤ç³»ç»è®¿é®è®°å½") |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") |
| | | @SaCheckPermission("monitor:logininfor:remove") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{infoIds}") |
| | | public AjaxResult<Void> remove(@PathVariable Long[] infoIds) { |
| | |
| | | } |
| | | |
| | | @ApiOperation("æ¸
空系ç»è®¿é®è®°å½") |
| | | @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')") |
| | | @SaCheckPermission("monitor:logininfor:remove") |
| | | @Log(title = "ç»å½æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult<Void> clean() { |
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | private final ISysOperLogService operLogService; |
| | | |
| | | @ApiOperation("æ¥è¯¢æä½æ¥å¿è®°å½å表") |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:list')") |
| | | @SaCheckPermission("monitor:operlog:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysOperLog> list(SysOperLog operLog, PageQuery pageQuery) { |
| | | return operLogService.selectPageOperLogList(operLog, pageQuery); |
| | |
| | | |
| | | @ApiOperation("å¯¼åºæä½æ¥å¿è®°å½å表") |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:export')") |
| | | @SaCheckPermission("monitor:operlog:export") |
| | | @PostMapping("/export") |
| | | public void export(SysOperLog operLog, HttpServletResponse response) { |
| | | List<SysOperLog> list = operLogService.selectOperLogList(operLog); |
| | |
| | | |
| | | @ApiOperation("å 餿使¥å¿è®°å½") |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.DELETE) |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") |
| | | @SaCheckPermission("monitor:operlog:remove") |
| | | @DeleteMapping("/{operIds}") |
| | | public AjaxResult<Void> remove(@PathVariable Long[] operIds) { |
| | | return toAjax(operLogService.deleteOperLogByIds(operIds)); |
| | |
| | | |
| | | @ApiOperation("æ¸
空æä½æ¥å¿è®°å½") |
| | | @Log(title = "æä½æ¥å¿", businessType = BusinessType.CLEAN) |
| | | @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')") |
| | | @SaCheckPermission("monitor:operlog:remove") |
| | | @DeleteMapping("/clean") |
| | | public AjaxResult<Void> clean() { |
| | | operLogService.cleanOperLog(); |
| | |
| | | package com.ruoyi.web.controller.monitor; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.stp.StpLogic; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.domain.dto.UserOnlineDTO; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.redis.RedisUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | | import com.ruoyi.system.service.ISysUserOnlineService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ·çæ§ |
| | |
| | | @RequestMapping("/monitor/online") |
| | | public class SysUserOnlineController extends BaseController { |
| | | |
| | | private final ISysUserOnlineService userOnlineService; |
| | | |
| | | @ApiOperation("å¨çº¿ç¨æ·å表") |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:list')") |
| | | @SaCheckPermission("monitor:online:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysUserOnline> list(String ipaddr, String userName) { |
| | | Collection<String> keys = RedisUtils.keys(Constants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| | | // è·åæææªè¿æç token |
| | | List<String> keys = StpUtil.searchTokenValue("", -1, 0); |
| | | List<UserOnlineDTO> userOnlineDTOList = new ArrayList<>(); |
| | | for (String key : keys) { |
| | | LoginUser user = RedisUtils.getCacheObject(key); |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { |
| | | userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user)); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(ipaddr)) { |
| | | if (StringUtils.equals(ipaddr, user.getIpaddr())) { |
| | | userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user)); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(userName)) { |
| | | if (StringUtils.equals(userName, user.getUsername())) { |
| | | userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user)); |
| | | } |
| | | } else { |
| | | userOnlineList.add(userOnlineService.loginUserToUserOnline(user)); |
| | | String token = key.replace(Constants.LOGIN_TOKEN_KEY, ""); |
| | | // 妿已ç»è¿æå踢ä¸çº¿ |
| | | if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < 0) { |
| | | continue; |
| | | } |
| | | userOnlineDTOList.add(RedisUtils.getCacheObject(Constants.ONLINE_TOKEN_KEY + token)); |
| | | } |
| | | Collections.reverse(userOnlineList); |
| | | userOnlineList.removeAll(Collections.singleton(null)); |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | StringUtils.equals(ipaddr, userOnline.getIpaddr()) && |
| | | StringUtils.equals(userName, userOnline.getUserName()) |
| | | ).collect(Collectors.toList()); |
| | | } else if (StringUtils.isNotEmpty(ipaddr)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | StringUtils.equals(ipaddr, userOnline.getIpaddr())) |
| | | .collect(Collectors.toList()); |
| | | } else if (StringUtils.isNotEmpty(userName)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | StringUtils.equals(userName, userOnline.getUserName()) |
| | | ).collect(Collectors.toList()); |
| | | } |
| | | Collections.reverse(userOnlineDTOList); |
| | | userOnlineDTOList.removeAll(Collections.singleton(null)); |
| | | List<SysUserOnline> userOnlineList = BeanUtil.copyToList(userOnlineDTOList, SysUserOnline.class); |
| | | return TableDataInfo.build(userOnlineList); |
| | | } |
| | | |
| | |
| | | * 强éç¨æ· |
| | | */ |
| | | @ApiOperation("强éç¨æ·") |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')") |
| | | @SaCheckPermission("monitor:online:forceLogout") |
| | | @Log(title = "å¨çº¿ç¨æ·", businessType = BusinessType.FORCE) |
| | | @DeleteMapping("/{tokenId}") |
| | | public AjaxResult<Void> forceLogout(@PathVariable String tokenId) { |
| | | RedisUtils.deleteObject(Constants.LOGIN_TOKEN_KEY + tokenId); |
| | | try { |
| | | StpUtil.kickoutByTokenValue(tokenId); |
| | | } catch (NotLoginException e) { |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * è·ååæ°é
ç½®å表 |
| | | */ |
| | | @ApiOperation("è·ååæ°é
ç½®å表") |
| | | @PreAuthorize("@ss.hasPermi('system:config:list')") |
| | | @SaCheckPermission("system:config:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysConfig> list(SysConfig config, PageQuery pageQuery) { |
| | | return configService.selectPageConfigList(config, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºåæ°é
ç½®å表") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:config:export')") |
| | | @SaCheckPermission("system:config:export") |
| | | @PostMapping("/export") |
| | | public void export(SysConfig config, HttpServletResponse response) { |
| | | List<SysConfig> list = configService.selectConfigList(config); |
| | |
| | | * æ ¹æ®åæ°ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®åæ°ç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:config:query')") |
| | | @SaCheckPermission("system:config:query") |
| | | @GetMapping(value = "/{configId}") |
| | | public AjaxResult<SysConfig> getInfo(@ApiParam("åæ°ID") @PathVariable Long configId) { |
| | | return AjaxResult.success(configService.selectConfigById(configId)); |
| | |
| | | * æ°å¢åæ°é
ç½® |
| | | */ |
| | | @ApiOperation("æ°å¢åæ°é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:config:add')") |
| | | @SaCheckPermission("system:config:add") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysConfig config) { |
| | |
| | | * ä¿®æ¹åæ°é
ç½® |
| | | */ |
| | | @ApiOperation("ä¿®æ¹åæ°é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:config:edit')") |
| | | @SaCheckPermission("system:config:edit") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysConfig config) { |
| | |
| | | * å é¤åæ°é
ç½® |
| | | */ |
| | | @ApiOperation("å é¤åæ°é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:config:remove')") |
| | | @SaCheckPermission("system:config:remove") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{configIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("忰ID䏲") @PathVariable Long[] configIds) { |
| | |
| | | * å·æ°åæ°ç¼å |
| | | */ |
| | | @ApiOperation("å·æ°åæ°ç¼å") |
| | | @PreAuthorize("@ss.hasPermi('system:config:remove')") |
| | | @SaCheckPermission("system:config:remove") |
| | | @Log(title = "åæ°ç®¡ç", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/refreshCache") |
| | | public AjaxResult<Void> refreshCache() { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * è·åé¨é¨å表 |
| | | */ |
| | | @ApiOperation("è·åé¨é¨å表") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| | | @SaCheckPermission("system:dept:list") |
| | | @GetMapping("/list") |
| | | public AjaxResult<List<SysDept>> list(SysDept dept) { |
| | | List<SysDept> depts = deptService.selectDeptList(dept); |
| | |
| | | * æ¥è¯¢é¨é¨åè¡¨ï¼æé¤èç¹ï¼ |
| | | */ |
| | | @ApiOperation("æ¥è¯¢é¨é¨åè¡¨ï¼æé¤èç¹ï¼") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:list')") |
| | | @SaCheckPermission("system:dept:list") |
| | | @GetMapping("/list/exclude/{deptId}") |
| | | public AjaxResult<List<SysDept>> excludeChild(@ApiParam("é¨é¨ID") @PathVariable(value = "deptId", required = false) Long deptId) { |
| | | List<SysDept> depts = deptService.selectDeptList(new SysDept()); |
| | |
| | | * æ ¹æ®é¨é¨ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®é¨é¨ç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:query')") |
| | | @SaCheckPermission("system:dept:query") |
| | | @GetMapping(value = "/{deptId}") |
| | | public AjaxResult<SysDept> getInfo(@ApiParam("é¨é¨ID") @PathVariable Long deptId) { |
| | | deptService.checkDeptDataScope(deptId); |
| | |
| | | * æ°å¢é¨é¨ |
| | | */ |
| | | @ApiOperation("æ°å¢é¨é¨") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:add')") |
| | | @SaCheckPermission("system:dept:add") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysDept dept) { |
| | |
| | | * ä¿®æ¹é¨é¨ |
| | | */ |
| | | @ApiOperation("ä¿®æ¹é¨é¨") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:edit')") |
| | | @SaCheckPermission("system:dept:edit") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysDept dept) { |
| | |
| | | * å é¤é¨é¨ |
| | | */ |
| | | @ApiOperation("å é¤é¨é¨") |
| | | @PreAuthorize("@ss.hasPermi('system:dept:remove')") |
| | | @SaCheckPermission("system:dept:remove") |
| | | @Log(title = "é¨é¨ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{deptId}") |
| | | public AjaxResult<Void> remove(@ApiParam("é¨é¨ID串") @PathVariable Long deptId) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | private final ISysDictTypeService dictTypeService; |
| | | |
| | | @ApiOperation("æ¥è¯¢åå
¸æ°æ®å表") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:list')") |
| | | @SaCheckPermission("system:dict:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysDictData> list(SysDictData dictData, PageQuery pageQuery) { |
| | | return dictDataService.selectPageDictDataList(dictData, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºåå
¸æ°æ®å表") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:dict:export')") |
| | | @SaCheckPermission("system:dict:export") |
| | | @PostMapping("/export") |
| | | public void export(SysDictData dictData, HttpServletResponse response) { |
| | | List<SysDictData> list = dictDataService.selectDictDataList(dictData); |
| | |
| | | * æ¥è¯¢åå
¸æ°æ®è¯¦ç» |
| | | */ |
| | | @ApiOperation("æ¥è¯¢åå
¸æ°æ®è¯¦ç»") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| | | @SaCheckPermission("system:dict:query") |
| | | @GetMapping(value = "/{dictCode}") |
| | | public AjaxResult<SysDictData> getInfo(@ApiParam("åå
¸code") @PathVariable Long dictCode) { |
| | | return AjaxResult.success(dictDataService.selectDictDataById(dictCode)); |
| | |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @ApiOperation("æ°å¢åå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:add')") |
| | | @SaCheckPermission("system:dict:add") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysDictData dict) { |
| | |
| | | * ä¿®æ¹ä¿ååå
¸ç±»å |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ä¿ååå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:edit')") |
| | | @SaCheckPermission("system:dict:edit") |
| | | @Log(title = "åå
¸æ°æ®", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysDictData dict) { |
| | |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @ApiOperation("å é¤åå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| | | @SaCheckPermission("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictCodes}") |
| | | public AjaxResult<Void> remove(@ApiParam("åå
¸code串") @PathVariable Long[] dictCodes) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | private final ISysDictTypeService dictTypeService; |
| | | |
| | | @ApiOperation("æ¥è¯¢åå
¸ç±»åå表") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:list')") |
| | | @SaCheckPermission("system:dict:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysDictType> list(SysDictType dictType, PageQuery pageQuery) { |
| | | return dictTypeService.selectPageDictTypeList(dictType, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºåå
¸ç±»åå表") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:dict:export')") |
| | | @SaCheckPermission("system:dict:export") |
| | | @PostMapping("/export") |
| | | public void export(SysDictType dictType, HttpServletResponse response) { |
| | | List<SysDictType> list = dictTypeService.selectDictTypeList(dictType); |
| | |
| | | * æ¥è¯¢åå
¸ç±»åè¯¦ç» |
| | | */ |
| | | @ApiOperation("æ¥è¯¢åå
¸ç±»å详ç»") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| | | @SaCheckPermission("system:dict:query") |
| | | @GetMapping(value = "/{dictId}") |
| | | public AjaxResult<SysDictType> getInfo(@ApiParam("åå
¸ID") @PathVariable Long dictId) { |
| | | return AjaxResult.success(dictTypeService.selectDictTypeById(dictId)); |
| | |
| | | * æ°å¢åå
¸ç±»å |
| | | */ |
| | | @ApiOperation("æ°å¢åå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:add')") |
| | | @SaCheckPermission("system:dict:add") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysDictType dict) { |
| | |
| | | * ä¿®æ¹åå
¸ç±»å |
| | | */ |
| | | @ApiOperation("ä¿®æ¹åå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:edit')") |
| | | @SaCheckPermission("system:dict:edit") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysDictType dict) { |
| | |
| | | * å é¤åå
¸ç±»å |
| | | */ |
| | | @ApiOperation("å é¤åå
¸ç±»å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| | | @SaCheckPermission("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{dictIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("åå
¸ID串") @PathVariable Long[] dictIds) { |
| | |
| | | * å·æ°åå
¸ç¼å |
| | | */ |
| | | @ApiOperation("å·æ°åå
¸ç¼å") |
| | | @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| | | @SaCheckPermission("system:dict:remove") |
| | | @Log(title = "åå
¸ç±»å", businessType = BusinessType.CLEAN) |
| | | @DeleteMapping("/refreshCache") |
| | | public AjaxResult<Void> refreshCache() { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | 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.utils.SecurityUtils; |
| | | import com.ruoyi.common.core.service.UserService; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.SysLoginService; |
| | | import com.ruoyi.system.service.SysPermissionService; |
| | | import io.swagger.annotations.Api; |
| | |
| | | |
| | | private final SysLoginService loginService; |
| | | private final ISysMenuService menuService; |
| | | private final ISysUserService userService; |
| | | private final SysPermissionService permissionService; |
| | | |
| | | /** |
| | |
| | | return AjaxResult.success(ajax); |
| | | } |
| | | |
| | | @ApiOperation("ç»åºæ¹æ³") |
| | | @PostMapping("/logout") |
| | | public AjaxResult<Void> logout(){ |
| | | try { |
| | | StpUtil.logout(); |
| | | } catch (NotLoginException e) { |
| | | } |
| | | return AjaxResult.success("éåºæå"); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·ä¿¡æ¯ |
| | | * |
| | |
| | | @ApiOperation("è·åç¨æ·ä¿¡æ¯") |
| | | @GetMapping("getInfo") |
| | | public AjaxResult<Map<String, Object>> getInfo() { |
| | | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); |
| | | SysUser user = SpringUtils.getBean(UserService.class).selectUserById(LoginUtils.getUserId()); |
| | | // è§è²éå |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | // æééå |
| | |
| | | @ApiOperation("è·åè·¯ç±ä¿¡æ¯") |
| | | @GetMapping("getRouters") |
| | | public AjaxResult<List<RouterVo>> getRouters() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Long userId = LoginUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * è·åèåå表 |
| | | */ |
| | | @ApiOperation("è·åèåå表") |
| | | @PreAuthorize("@ss.hasPermi('system:menu:list')") |
| | | @SaCheckPermission("system:menu:list") |
| | | @GetMapping("/list") |
| | | public AjaxResult<List<SysMenu>> list(SysMenu menu) { |
| | | List<SysMenu> menus = menuService.selectMenuList(menu, getUserId()); |
| | |
| | | * æ ¹æ®èåç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®èåç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:menu:query')") |
| | | @SaCheckPermission("system:menu:query") |
| | | @GetMapping(value = "/{menuId}") |
| | | public AjaxResult<SysMenu> getInfo(@ApiParam("èåID") @PathVariable Long menuId) { |
| | | return AjaxResult.success(menuService.selectMenuById(menuId)); |
| | |
| | | * æ°å¢èå |
| | | */ |
| | | @ApiOperation("æ°å¢èå") |
| | | @PreAuthorize("@ss.hasPermi('system:menu:add')") |
| | | @SaCheckPermission("system:menu:add") |
| | | @Log(title = "èå管ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysMenu menu) { |
| | |
| | | * ä¿®æ¹èå |
| | | */ |
| | | @ApiOperation("ä¿®æ¹èå") |
| | | @PreAuthorize("@ss.hasPermi('system:menu:edit')") |
| | | @SaCheckPermission("system:menu:edit") |
| | | @Log(title = "èå管ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysMenu menu) { |
| | |
| | | * å é¤èå |
| | | */ |
| | | @ApiOperation("å é¤èå") |
| | | @PreAuthorize("@ss.hasPermi('system:menu:remove')") |
| | | @SaCheckPermission("system:menu:remove") |
| | | @Log(title = "èå管ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{menuId}") |
| | | public AjaxResult<Void> remove(@ApiParam("èåID") @PathVariable("menuId") Long menuId) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.system.domain.SysNotice; |
| | | import com.ruoyi.system.service.ISysNoticeService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * å
¬å ä¿¡æ¯æä½å¤ç |
| | |
| | | * è·åéç¥å
¬åå表 |
| | | */ |
| | | @ApiOperation("è·åéç¥å
¬åå表") |
| | | @PreAuthorize("@ss.hasPermi('system:notice:list')") |
| | | @SaCheckPermission("system:notice:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysNotice> list(SysNotice notice, PageQuery pageQuery) { |
| | | return noticeService.selectPageNoticeList(notice, pageQuery); |
| | |
| | | * æ ¹æ®éç¥å
¬åç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®éç¥å
¬åç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:notice:query')") |
| | | @SaCheckPermission("system:notice:query") |
| | | @GetMapping(value = "/{noticeId}") |
| | | public AjaxResult<SysNotice> getInfo(@ApiParam("å
ŒID") @PathVariable Long noticeId) { |
| | | return AjaxResult.success(noticeService.selectNoticeById(noticeId)); |
| | |
| | | * æ°å¢éç¥å
Œ |
| | | */ |
| | | @ApiOperation("æ°å¢éç¥å
Œ") |
| | | @PreAuthorize("@ss.hasPermi('system:notice:add')") |
| | | @SaCheckPermission("system:notice:add") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysNotice notice) { |
| | |
| | | * ä¿®æ¹éç¥å
Œ |
| | | */ |
| | | @ApiOperation("ä¿®æ¹éç¥å
Œ") |
| | | @PreAuthorize("@ss.hasPermi('system:notice:edit')") |
| | | @SaCheckPermission("system:notice:edit") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysNotice notice) { |
| | |
| | | * å é¤éç¥å
Œ |
| | | */ |
| | | @ApiOperation("å é¤éç¥å
Œ") |
| | | @PreAuthorize("@ss.hasPermi('system:notice:remove')") |
| | | @SaCheckPermission("system:notice:remove") |
| | | @Log(title = "éç¥å
Œ", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{noticeIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("å
¬åID串") @PathVariable Long[] noticeIds) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * æ¥è¯¢å¯¹è±¡åå¨é
ç½®å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢å¯¹è±¡åå¨é
ç½®å表") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:list')") |
| | | @SaCheckPermission("system:oss:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysOssConfigVo> list(@Validated(QueryGroup.class) SysOssConfigBo bo, PageQuery pageQuery) { |
| | | return iSysOssConfigService.queryPageList(bo, pageQuery); |
| | |
| | | * è·å对象åå¨é
置详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("è·å对象åå¨é
置详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:query')") |
| | | @SaCheckPermission("system:oss:query") |
| | | @GetMapping("/{ossConfigId}") |
| | | public AjaxResult<SysOssConfigVo> getInfo(@ApiParam("OSSé
ç½®ID") |
| | | @NotNull(message = "主é®ä¸è½ä¸ºç©º") |
| | |
| | | * æ°å¢å¯¹è±¡åå¨é
ç½® |
| | | */ |
| | | @ApiOperation("æ°å¢å¯¹è±¡åå¨é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:add')") |
| | | @SaCheckPermission("system:oss:add") |
| | | @Log(title = "对象åå¨é
ç½®", businessType = BusinessType.INSERT) |
| | | @RepeatSubmit() |
| | | @PostMapping() |
| | |
| | | * ä¿®æ¹å¯¹è±¡åå¨é
ç½® |
| | | */ |
| | | @ApiOperation("ä¿®æ¹å¯¹è±¡åå¨é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:edit')") |
| | | @SaCheckPermission("system:oss:edit") |
| | | @Log(title = "对象åå¨é
ç½®", businessType = BusinessType.UPDATE) |
| | | @RepeatSubmit() |
| | | @PutMapping() |
| | |
| | | * å é¤å¯¹è±¡åå¨é
ç½® |
| | | */ |
| | | @ApiOperation("å é¤å¯¹è±¡åå¨é
ç½®") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:remove')") |
| | | @SaCheckPermission("system:oss:remove") |
| | | @Log(title = "对象åå¨é
ç½®", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ossConfigIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("OSSé
置ID串") |
| | |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @ApiOperation("ç¶æä¿®æ¹") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:edit')") |
| | | @SaCheckPermission("system:oss:edit") |
| | | @Log(title = "对象åå¨ç¶æä¿®æ¹", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult<Void> changeStatus(@RequestBody SysOssConfigBo bo) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.http.HttpException; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | * æ¥è¯¢OSS对象åå¨å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢OSS对象åå¨å表") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:list')") |
| | | @SaCheckPermission("system:oss:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo, PageQuery pageQuery) { |
| | | return iSysOssService.queryPageList(bo, pageQuery); |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "file", value = "æä»¶", dataTypeClass = File.class, required = true), |
| | | }) |
| | | @PreAuthorize("@ss.hasPermi('system:oss:upload')") |
| | | @SaCheckPermission("system:oss:upload") |
| | | @Log(title = "OSS对象åå¨", businessType = BusinessType.INSERT) |
| | | @RepeatSubmit |
| | | @PostMapping("/upload") |
| | |
| | | } |
| | | |
| | | @ApiOperation("ä¸è½½OSS对象åå¨") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:download')") |
| | | @SaCheckPermission("system:oss:download") |
| | | @GetMapping("/download/{ossId}") |
| | | public void download(@ApiParam("OSS对象ID") @PathVariable Long ossId, HttpServletResponse response) throws IOException { |
| | | SysOss sysOss = iSysOssService.getById(ossId); |
| | |
| | | * å é¤OSS对象åå¨ |
| | | */ |
| | | @ApiOperation("å é¤OSS对象åå¨") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:remove')") |
| | | @SaCheckPermission("system:oss:remove") |
| | | @Log(title = "OSS对象åå¨", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ossIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("OSS对象ID串") |
| | |
| | | * åæ´å¾çå表é¢è§ç¶æ |
| | | */ |
| | | @ApiOperation("åæ´å¾çå表é¢è§ç¶æ") |
| | | @PreAuthorize("@ss.hasPermi('system:oss:edit')") |
| | | @SaCheckPermission("system:oss:edit") |
| | | @Log(title = "OSS对象åå¨", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changePreviewListResource") |
| | | public AjaxResult<Void> changePreviewListResource(@RequestBody String body) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * è·åå²ä½å表 |
| | | */ |
| | | @ApiOperation("è·åå²ä½å表") |
| | | @PreAuthorize("@ss.hasPermi('system:post:list')") |
| | | @SaCheckPermission("system:post:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysPost> list(SysPost post, PageQuery pageQuery) { |
| | | return postService.selectPagePostList(post, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºå²ä½å表") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:post:export')") |
| | | @SaCheckPermission("system:post:export") |
| | | @PostMapping("/export") |
| | | public void export(SysPost post, HttpServletResponse response) { |
| | | List<SysPost> list = postService.selectPostList(post); |
| | |
| | | * æ ¹æ®å²ä½ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®å²ä½ç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:post:query')") |
| | | @SaCheckPermission("system:post:query") |
| | | @GetMapping(value = "/{postId}") |
| | | public AjaxResult<SysPost> getInfo(@ApiParam("å²ä½ID") @PathVariable Long postId) { |
| | | return AjaxResult.success(postService.selectPostById(postId)); |
| | |
| | | * æ°å¢å²ä½ |
| | | */ |
| | | @ApiOperation("æ°å¢å²ä½") |
| | | @PreAuthorize("@ss.hasPermi('system:post:add')") |
| | | @SaCheckPermission("system:post:add") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysPost post) { |
| | |
| | | * ä¿®æ¹å²ä½ |
| | | */ |
| | | @ApiOperation("ä¿®æ¹å²ä½") |
| | | @PreAuthorize("@ss.hasPermi('system:post:edit')") |
| | | @SaCheckPermission("system:post:edit") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysPost post) { |
| | |
| | | * å é¤å²ä½ |
| | | */ |
| | | @ApiOperation("å é¤å²ä½") |
| | | @PreAuthorize("@ss.hasPermi('system:post:remove')") |
| | | @SaCheckPermission("system:post:remove") |
| | | @Log(title = "å²ä½ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{postIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("å²ä½ID串") @PathVariable Long[] postIds) { |
| | |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.service.UserService; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.SysOss; |
| | | import com.ruoyi.system.service.ISysOssService; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | |
| | | @ApiOperation("个人信æ¯") |
| | | @GetMapping |
| | | public AjaxResult<Map<String, Object>> profile() { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser user = userService.selectUserById(loginUser.getUserId()); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | ajax.put("user", user); |
| | | ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); |
| | | ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername())); |
| | | SysUser user = userService.getById(getUserId()); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | ajax.put("user", user); |
| | | ajax.put("roleGroup", userService.selectUserRoleGroup(user.getUserName())); |
| | | ajax.put("postGroup", userService.selectUserPostGroup(user.getUserName())); |
| | | return AjaxResult.success(ajax); |
| | | } |
| | | |
| | |
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { |
| | | return AjaxResult.error("ä¿®æ¹ç¨æ·'" + user.getUserName() + "'失败ï¼é®ç®±è´¦å·å·²åå¨"); |
| | | } |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser sysUser = userService.selectUserById(loginUser.getUserId()); |
| | | user.setUserId(sysUser.getUserId()); |
| | | user.setUserId(getUserId()); |
| | | user.setUserName(null); |
| | | user.setPassword(null); |
| | | if (userService.updateUserProfile(user) > 0) { |
| | |
| | | @Log(title = "个人信æ¯", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/updatePwd") |
| | | public AjaxResult<Void> updatePwd(String oldPassword, String newPassword) { |
| | | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); |
| | | SysUser user = SpringUtils.getBean(UserService.class).selectUserById(LoginUtils.getUserId()); |
| | | String userName = user.getUserName(); |
| | | String password = user.getPassword(); |
| | | if (!SecurityUtils.matchesPassword(oldPassword, password)) { |
| | |
| | | @Log(title = "ç¨æ·å¤´å", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/avatar") |
| | | public AjaxResult<Map<String, Object>> avatar(@RequestPart("avatarfile") MultipartFile file) { |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | Map<String,Object> ajax = new HashMap<>(); |
| | | if (!file.isEmpty()) { |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysOss oss = iSysOssService.upload(file); |
| | | String avatar = oss.getUrl(); |
| | | if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) { |
| | | SysOss oss = iSysOssService.upload(file); |
| | | String avatar = oss.getUrl(); |
| | | if (userService.updateUserAvatar(getUsername(), avatar)) { |
| | | ajax.put("imgUrl", avatar); |
| | | return AjaxResult.success(ajax); |
| | | } |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.service.TokenService; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | |
| | | import io.swagger.annotations.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | public class SysRoleController extends BaseController { |
| | | |
| | | private final ISysRoleService roleService; |
| | | private final TokenService tokenService; |
| | | private final ISysUserService userService; |
| | | private final SysPermissionService permissionService; |
| | | |
| | | @ApiOperation("æ¥è¯¢è§è²ä¿¡æ¯å表") |
| | | @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysRole> list(SysRole role, PageQuery pageQuery) { |
| | | return roleService.selectPageRoleList(role, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºè§è²ä¿¡æ¯å表") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:role:export')") |
| | | @SaCheckPermission("system:role:export") |
| | | @PostMapping("/export") |
| | | public void export(SysRole role, HttpServletResponse response) { |
| | | List<SysRole> list = roleService.selectRoleList(role); |
| | |
| | | * æ ¹æ®è§è²ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®è§è²ç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @SaCheckPermission("system:role:query") |
| | | @GetMapping(value = "/{roleId}") |
| | | public AjaxResult<SysRole> getInfo(@ApiParam("è§è²ID") @PathVariable Long roleId) { |
| | | roleService.checkRoleDataScope(roleId); |
| | |
| | | * æ°å¢è§è² |
| | | */ |
| | | @ApiOperation("æ°å¢è§è²") |
| | | @PreAuthorize("@ss.hasPermi('system:role:add')") |
| | | @SaCheckPermission("system:role:add") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysRole role) { |
| | |
| | | * ä¿®æ¹ä¿åè§è² |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ä¿åè§è²") |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysRole role) { |
| | |
| | | LoginUser loginUser = getLoginUser(); |
| | | SysUser sysUser = userService.selectUserById(loginUser.getUserId()); |
| | | if (StringUtils.isNotNull(sysUser) && !sysUser.isAdmin()) { |
| | | loginUser.setMenuPermissions(permissionService.getMenuPermission(sysUser)); |
| | | tokenService.setLoginUser(loginUser); |
| | | loginUser.setMenuPermission(permissionService.getMenuPermission(sysUser)); |
| | | LoginUtils.setLoginUser(loginUser); |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | |
| | | * ä¿®æ¹ä¿åæ°æ®æé |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ä¿åæ°æ®æé") |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/dataScope") |
| | | public AjaxResult<Void> dataScope(@RequestBody SysRole role) { |
| | |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @ApiOperation("ç¶æä¿®æ¹") |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult<Void> changeStatus(@RequestBody SysRole role) { |
| | |
| | | * å é¤è§è² |
| | | */ |
| | | @ApiOperation("å é¤è§è²") |
| | | @PreAuthorize("@ss.hasPermi('system:role:remove')") |
| | | @SaCheckPermission("system:role:remove") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{roleIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("å²ä½ID串") @PathVariable Long[] roleIds) { |
| | |
| | | * è·åè§è²éæ©æ¡å表 |
| | | */ |
| | | @ApiOperation("è·åè§è²éæ©æ¡å表") |
| | | @PreAuthorize("@ss.hasPermi('system:role:query')") |
| | | @SaCheckPermission("system:role:query") |
| | | @GetMapping("/optionselect") |
| | | public AjaxResult<List<SysRole>> optionselect() { |
| | | return AjaxResult.success(roleService.selectRoleAll()); |
| | |
| | | * æ¥è¯¢å·²åé
ç¨æ·è§è²å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢å·²åé
ç¨æ·è§è²å表") |
| | | @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/allocatedList") |
| | | public TableDataInfo<SysUser> allocatedList(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectAllocatedList(user, pageQuery); |
| | |
| | | * æ¥è¯¢æªåé
ç¨æ·è§è²å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢æªåé
ç¨æ·è§è²å表") |
| | | @PreAuthorize("@ss.hasPermi('system:role:list')") |
| | | @SaCheckPermission("system:role:list") |
| | | @GetMapping("/authUser/unallocatedList") |
| | | public TableDataInfo<SysUser> unallocatedList(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectUnallocatedList(user, pageQuery); |
| | |
| | | * åæ¶ææç¨æ· |
| | | */ |
| | | @ApiOperation("åæ¶ææç¨æ·") |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancel") |
| | | public AjaxResult<Void> cancelAuthUser(@RequestBody SysUserRole userRole) { |
| | |
| | | @ApiImplicitParam(name = "roleId", value = "è§è²ID", paramType = "query", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "userIds", value = "ç¨æ·ID串", paramType = "query", dataTypeClass = String.class) |
| | | }) |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/cancelAll") |
| | | public AjaxResult<Void> cancelAuthUserAll(Long roleId, Long[] userIds) { |
| | |
| | | @ApiImplicitParam(name = "roleId", value = "è§è²ID", paramType = "query", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "userIds", value = "ç¨æ·ID串", paramType = "query", dataTypeClass = String.class) |
| | | }) |
| | | @PreAuthorize("@ss.hasPermi('system:role:edit')") |
| | | @SaCheckPermission("system:role:edit") |
| | | @Log(title = "è§è²ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authUser/selectAll") |
| | | public AjaxResult<Void> selectAuthUserAll(Long roleId, Long[] userIds) { |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | |
| | | import io.swagger.annotations.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | * è·åç¨æ·å表 |
| | | */ |
| | | @ApiOperation("è·åç¨æ·å表") |
| | | @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | @SaCheckPermission("system:user:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<SysUser> list(SysUser user, PageQuery pageQuery) { |
| | | return userService.selectPageUserList(user, pageQuery); |
| | |
| | | |
| | | @ApiOperation("导åºç¨æ·å表") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:user:export')") |
| | | @SaCheckPermission("system:user:export") |
| | | @PostMapping("/export") |
| | | public void export(SysUser user, HttpServletResponse response) { |
| | | List<SysUser> list = userService.selectUserList(user); |
| | |
| | | @ApiImplicitParam(name = "file", value = "导å
¥æä»¶", dataType = "java.io.File", required = true), |
| | | }) |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.IMPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:user:import')") |
| | | @SaCheckPermission("system:user:import") |
| | | @PostMapping("/importData") |
| | | public AjaxResult<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { |
| | | ExcelResult<SysUserImportVo> result = ExcelUtil.importExcel(file.getInputStream(), SysUserImportVo.class, new SysUserImportListener(updateSupport)); |
| | |
| | | * æ ¹æ®ç¨æ·ç¼å·è·å详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("æ ¹æ®ç¨æ·ç¼å·è·å详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @GetMapping(value = {"/", "/{userId}"}) |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping(value = {"/", "/{userId}" }) |
| | | public AjaxResult<Map<String, Object>> getInfo(@ApiParam("ç¨æ·ID") @PathVariable(value = "userId", required = false) Long userId) { |
| | | userService.checkUserDataScope(userId); |
| | | userService.checkUserDataScope(userId); |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | List<SysRole> roles = roleService.selectRoleAll(); |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | |
| | | * æ°å¢ç¨æ· |
| | | */ |
| | | @ApiOperation("æ°å¢ç¨æ·") |
| | | @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @SaCheckPermission("system:user:add") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult<Void> add(@Validated @RequestBody SysUser user) { |
| | |
| | | * ä¿®æ¹ç¨æ· |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ç¨æ·") |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> edit(@Validated @RequestBody SysUser user) { |
| | |
| | | * å é¤ç¨æ· |
| | | */ |
| | | @ApiOperation("å é¤ç¨æ·") |
| | | @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | @SaCheckPermission("system:user:remove") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public AjaxResult<Void> remove(@ApiParam("è§è²ID串") @PathVariable Long[] userIds) { |
| | |
| | | * éç½®å¯ç |
| | | */ |
| | | @ApiOperation("éç½®å¯ç ") |
| | | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @SaCheckPermission("system:user:resetPwd") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | | public AjaxResult<Void> resetPwd(@RequestBody SysUser user) { |
| | |
| | | * ç¶æä¿®æ¹ |
| | | */ |
| | | @ApiOperation("ç¶æä¿®æ¹") |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult<Void> changeStatus(@RequestBody SysUser user) { |
| | |
| | | * æ ¹æ®ç¨æ·ç¼å·è·åææè§è² |
| | | */ |
| | | @ApiOperation("æ ¹æ®ç¨æ·ç¼å·è·åææè§è²") |
| | | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @SaCheckPermission("system:user:query") |
| | | @GetMapping("/authRole/{userId}") |
| | | public AjaxResult<Map<String, Object>> authRole(@ApiParam("ç¨æ·ID") @PathVariable("userId") Long userId) { |
| | | SysUser user = userService.selectUserById(userId); |
| | |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·Id", paramType = "query", dataTypeClass = String.class), |
| | | @ApiImplicitParam(name = "roleIds", value = "è§è²ID串", paramType = "query", dataTypeClass = String.class) |
| | | }) |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @SaCheckPermission("system:user:edit") |
| | | @Log(title = "ç¨æ·ç®¡ç", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | public AjaxResult<Void> insertAuthRole(Long userId, Long[] roleIds) { |
| | |
| | | # å
许对象忽ç¥jsonä¸ä¸åå¨ç屿§ |
| | | fail_on_unknown_properties: false |
| | | |
| | | # tokené
ç½® |
| | | token: |
| | | # 令çèªå®ä¹æ è¯ |
| | | header: Authorization |
| | | # 令çå¯é¥ |
| | | secret: abcdefghijklmnopqrstuvwxyz |
| | | # ä»¤çæææï¼é»è®¤30åéï¼ |
| | | expireTime: 30 |
| | | # Sa-Tokené
ç½® |
| | | sa-token: |
| | | # tokenåç§° (忶乿¯cookieåç§°) |
| | | token-name: Authorization |
| | | # tokenæææ 设为ä¸å¤© (å¿
å®è¿æ) åä½: ç§ |
| | | timeout: 86400 |
| | | # tokenä¸´æ¶æææ (æå®æ¶é´æ æä½å°±è¿æ) åä½: ç§ |
| | | activity-timeout: 1800 |
| | | # æ¯å¦å
许åä¸è´¦å·å¹¶åç»å½ (为trueæ¶å
许ä¸èµ·ç»å½, 为falseæ¶æ°ç»å½æ¤ææ§ç»å½) |
| | | is-concurrent: true |
| | | # å¨å¤äººç»å½åä¸è´¦å·æ¶ï¼æ¯å¦å
±ç¨ä¸ä¸ªtoken (为trueæ¶ææç»å½å
±ç¨ä¸ä¸ªtoken, 为falseæ¶æ¯æ¬¡ç»å½æ°å»ºä¸ä¸ªtoken) |
| | | is-share: false |
| | | # æ¯å¦å°è¯ä»è¯·æ±ä½é读åtoken |
| | | is-read-body: false |
| | | # æ¯å¦å°è¯ä»headeré读åtoken |
| | | is-read-head: true |
| | | # æ¯å¦å°è¯ä»cookieé读åtoken |
| | | is-read-cookie: false |
| | | # tokenåç¼ |
| | | token-prefix: "Bearer" |
| | | # token飿 ¼ |
| | | token-style: uuid |
| | | # jwtç§é¥ |
| | | jwt-secret-key: abcdefghijklmnopqrstuvwxyz |
| | | # æ¯å¦è¾åºæä½æ¥å¿ |
| | | is-log: true |
| | | |
| | | # securityé
ç½® |
| | | security: |
| | | # ç»åºè·¯å¾ |
| | | logout-url: /logout |
| | | # å¿åè·¯å¾ |
| | | anonymous: |
| | | # æé¤è·¯å¾ |
| | | excludes: |
| | | - /login |
| | | - /logout |
| | | - /register |
| | | - /captchaImage |
| | | # éæèµæº |
| | | - /*.html |
| | | - /**/*.html |
| | | - /**/*.css |
| | | - /**/*.js |
| | | # swagger ææ¡£é
ç½® |
| | | - /doc.html |
| | | - /swagger-resources/** |
| | |
| | | <artifactId>spring-web</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- spring security å®å
¨è®¤è¯ --> |
| | | <!-- Sa-Token æé认è¯, å¨çº¿ææ¡£ï¼http://sa-token.dev33.cn/ --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | | <artifactId>spring-boot-starter-security</artifactId> |
| | | <groupId>cn.dev33</groupId> |
| | | <artifactId>sa-token-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | <!-- Sa-Token æ´å jwt --> |
| | | <dependency> |
| | | <groupId>cn.dev33</groupId> |
| | | <artifactId>sa-token-jwt</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>org.springframework.security</groupId> |
| | | <artifactId>spring-security-crypto</artifactId> |
| | | </dependency> |
| | | |
| | | <!-- èªå®ä¹éªè¯æ³¨è§£ --> |
| | |
| | | package com.ruoyi.common.constant; |
| | | |
| | | |
| | | /** |
| | | * éç¨å¸¸éä¿¡æ¯ |
| | | * |
| | |
| | | /** |
| | | * ç»å½ç¨æ· redis key |
| | | */ |
| | | String LOGIN_TOKEN_KEY = "login_tokens:"; |
| | | public static final String LOGIN_TOKEN_KEY = "Authorization:login:token:"; |
| | | |
| | | /** |
| | | * å¨çº¿ç¨æ· redis key |
| | | */ |
| | | public static final String ONLINE_TOKEN_KEY = "online_tokens:"; |
| | | |
| | | /** |
| | | * é²éæäº¤ redis key |
| | |
| | | /** |
| | | * 令çåç¼ |
| | | */ |
| | | String TOKEN_PREFIX = "Bearer "; |
| | | |
| | | /** |
| | | * 令çåç¼ |
| | | */ |
| | | String LOGIN_USER_KEY = "login_user_key"; |
| | | |
| | | /** |
| | | * ç¨æ·ID |
| | | */ |
| | | String JWT_USERID = "userid"; |
| | | |
| | | /** |
| | | * ç¨æ·åç§° |
| | | */ |
| | | String JWT_USERNAME = "sub"; |
| | | |
| | | /** |
| | | * ç¨æ·å¤´å |
| | | */ |
| | | String JWT_AVATAR = "avatar"; |
| | | |
| | | /** |
| | | * å建æ¶é´ |
| | | */ |
| | | String JWT_CREATED = "created"; |
| | | |
| | | /** |
| | | * ç¨æ·æé |
| | | */ |
| | | String JWT_AUTHORITIES = "authorities"; |
| | | |
| | | /** |
| | | * åæ°ç®¡ç cache key |
| | |
| | | |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | |
| | | /** |
| | |
| | | * è·åç¨æ·ç¼åä¿¡æ¯ |
| | | */ |
| | | public LoginUser getLoginUser() { |
| | | return SecurityUtils.getLoginUser(); |
| | | return LoginUtils.getLoginUser(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½ç¨æ·id |
| | | */ |
| | | public Long getUserId() { |
| | | return getLoginUser().getUserId(); |
| | | return LoginUtils.getUserId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½é¨é¨id |
| | | */ |
| | | public Long getDeptId() { |
| | | return getLoginUser().getDeptId(); |
| | | return LoginUtils.getDeptId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½ç¨æ·å |
| | | */ |
| | | public String getUsername() { |
| | | return getLoginUser().getUsername(); |
| | | return LoginUtils.getUsername(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.core.domain.dto; |
| | | |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * å½åå¨çº¿ä¼è¯ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @Accessors(chain = true) |
| | | public class UserOnlineDTO implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * ä¼è¯ç¼å· |
| | | */ |
| | | private String tokenId; |
| | | |
| | | /** |
| | | * é¨é¨åç§° |
| | | */ |
| | | private String deptName; |
| | | |
| | | /** |
| | | * ç¨æ·åç§° |
| | | */ |
| | | private String userName; |
| | | |
| | | /** |
| | | * ç»å½IPå°å |
| | | */ |
| | | private String ipaddr; |
| | | |
| | | /** |
| | | * ç»å½å°å |
| | | */ |
| | | private String loginLocation; |
| | | |
| | | /** |
| | | * æµè§å¨ç±»å |
| | | */ |
| | | private String browser; |
| | | |
| | | /** |
| | | * æä½ç³»ç» |
| | | */ |
| | | private String os; |
| | | |
| | | /** |
| | | * ç»å½æ¶é´ |
| | | */ |
| | | private Long loginTime; |
| | | |
| | | } |
| | |
| | | package com.ruoyi.common.core.domain.model; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import lombok.experimental.Accessors; |
| | | import org.springframework.security.core.GrantedAuthority; |
| | | import org.springframework.security.core.userdetails.UserDetails; |
| | | |
| | | import java.util.Collection; |
| | | import java.io.Serializable; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | |
| | | @Data |
| | | @NoArgsConstructor |
| | | @Accessors(chain = true) |
| | | public class LoginUser implements UserDetails { |
| | | public class LoginUser implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | |
| | | /** |
| | | * èåæé |
| | | */ |
| | | private Set<String> menuPermissions; |
| | | private Set<String> menuPermission; |
| | | |
| | | /** |
| | | * è§è²æé |
| | | */ |
| | | private Set<String> rolePermissions; |
| | | private Set<String> rolePermission; |
| | | |
| | | /** |
| | | * ç¨æ·å |
| | | */ |
| | | private String username; |
| | | |
| | | /** |
| | | * å¯ç |
| | | */ |
| | | private String password; |
| | | |
| | | @JsonIgnore |
| | | @Override |
| | | public String getPassword() { |
| | | return password; |
| | | } |
| | | |
| | | @Override |
| | | public String getUsername() { |
| | | return username; |
| | | } |
| | | |
| | | /** |
| | | * è´¦æ·æ¯å¦æªè¿æ,è¿ææ æ³éªè¯ |
| | | */ |
| | | @JsonIgnore |
| | | @Override |
| | | public boolean isAccountNonExpired() { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æå®ç¨æ·æ¯å¦è§£é,éå®çç¨æ·æ æ³è¿è¡èº«ä»½éªè¯ |
| | | */ |
| | | @JsonIgnore |
| | | @Override |
| | | public boolean isAccountNonLocked() { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æç¤ºæ¯å¦å·²è¿æçç¨æ·çåæ®(å¯ç ),è¿æç忮鲿¢è®¤è¯ |
| | | */ |
| | | @JsonIgnore |
| | | @Override |
| | | public boolean isCredentialsNonExpired() { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦å¯ç¨ ,ç¦ç¨çç¨æ·ä¸è½èº«ä»½éªè¯ |
| | | */ |
| | | @JsonIgnore |
| | | @Override |
| | | public boolean isEnabled() { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public Collection<? extends GrantedAuthority> getAuthorities() { |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * 设å¤ç±»å |
| | | * é对ä¸å¥ ç¨æ·ä½ç³» |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum DeviceType { |
| | | |
| | | /** |
| | | * pc端 |
| | | */ |
| | | PC("pc"), |
| | | |
| | | /** |
| | | * app端 |
| | | */ |
| | | APP("app"); |
| | | |
| | | private final String device; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.enums; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * 设å¤ç±»å |
| | | * éå¯¹ä¸¤å¥ ç¨æ·ä½ç³» |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum UserType { |
| | | |
| | | /** |
| | | * pc端 |
| | | */ |
| | | SYS_USER("sys_user:"), |
| | | |
| | | /** |
| | | * app端 |
| | | */ |
| | | APP_USER("app_user:"); |
| | | |
| | | private final String userType; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.DeviceType; |
| | | import com.ruoyi.common.enums.UserType; |
| | | import com.ruoyi.common.exception.UtilException; |
| | | |
| | | /** |
| | | * ç»å½é´æå·¥å
· |
| | | * 为éé
å¤ç«¯ç»å½èå°è£
|
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | public class LoginUtils { |
| | | |
| | | private final static String LOGIN_USER_KEY = "loginUser"; |
| | | |
| | | /** |
| | | * ç»å½ç³»ç» |
| | | * é对两å¥ç¨æ·ä½ç³» |
| | | * @param loginUser ç»å½ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public static void login(LoginUser loginUser, UserType userType) { |
| | | StpUtil.login(userType.getUserType() + loginUser.getUserId()); |
| | | setLoginUser(loginUser); |
| | | } |
| | | |
| | | /** |
| | | * ç»å½ç³»ç» åºäº 设å¤ç±»å |
| | | * é对ä¸å¥ç¨æ·ä½ç³» |
| | | * @param loginUser ç»å½ç¨æ·ä¿¡æ¯ |
| | | */ |
| | | public static void loginByDevice(LoginUser loginUser, UserType userType, DeviceType deviceType) { |
| | | StpUtil.login(userType.getUserType() + loginUser.getUserId(), deviceType.getDevice()); |
| | | setLoginUser(loginUser); |
| | | } |
| | | |
| | | /** |
| | | * è®¾ç½®ç¨æ·æ°æ® |
| | | */ |
| | | public static void setLoginUser(LoginUser loginUser) { |
| | | StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ· |
| | | **/ |
| | | public static LoginUser getLoginUser() { |
| | | return (LoginUser) StpUtil.getTokenSession().get(LOGIN_USER_KEY); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·id |
| | | */ |
| | | public static Long getUserId() { |
| | | LoginUser loginUser = getLoginUser(); |
| | | if (ObjectUtil.isNull(loginUser)) { |
| | | String loginId = StpUtil.getLoginIdAsString(); |
| | | String userId; |
| | | String replace = ""; |
| | | if (StringUtils.contains(loginId, UserType.SYS_USER.getUserType())) { |
| | | userId = StringUtils.replace(loginId, UserType.SYS_USER.getUserType(), replace); |
| | | } else if (StringUtils.contains(loginId, UserType.APP_USER.getUserType())){ |
| | | userId = StringUtils.replace(loginId, UserType.APP_USER.getUserType(), replace); |
| | | } else { |
| | | throw new UtilException("ç»å½ç¨æ·: LoginIdå¼å¸¸ => " + loginId); |
| | | } |
| | | return Long.parseLong(userId); |
| | | } |
| | | return loginUser.getUserId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åé¨é¨ID |
| | | **/ |
| | | public static Long getDeptId() { |
| | | return getLoginUser().getDeptId(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·è´¦æ· |
| | | **/ |
| | | public static String getUsername() { |
| | | return getLoginUser().getUsername(); |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·ç±»å |
| | | */ |
| | | public static UserType getUserType() { |
| | | String loginId = StpUtil.getLoginIdAsString(); |
| | | return getUserType(loginId); |
| | | } |
| | | |
| | | public static UserType getUserType(Object loginId) { |
| | | if (StringUtils.contains(loginId.toString(), UserType.SYS_USER.getUserType())) { |
| | | return UserType.SYS_USER; |
| | | } else if (StringUtils.contains(loginId.toString(), UserType.APP_USER.getUserType())){ |
| | | return UserType.APP_USER; |
| | | } else { |
| | | throw new UtilException("ç»å½ç¨æ·: LoginIdå¼å¸¸ => " + loginId); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.common.utils; |
| | | |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import lombok.AccessLevel; |
| | | import lombok.NoArgsConstructor; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | |
| | | /** |
| | | * å®å
¨æå¡å·¥å
·ç±» |
| | | * |
| | | * @author ruoyi |
| | | * @author Long Li |
| | | */ |
| | | @NoArgsConstructor(access = AccessLevel.PRIVATE) |
| | | public class SecurityUtils { |
| | | |
| | | /** |
| | | * ç¨æ·ID |
| | | **/ |
| | | public static Long getUserId() { |
| | | try { |
| | | return getLoginUser().getUserId(); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("è·åç¨æ·IDå¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åé¨é¨ID |
| | | **/ |
| | | public static Long getDeptId() { |
| | | try { |
| | | return getLoginUser().getDeptId(); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("è·åé¨é¨IDå¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ·è´¦æ· |
| | | **/ |
| | | public static String getUsername() { |
| | | try { |
| | | return getLoginUser().getUsername(); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("è·åç¨æ·è´¦æ·å¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç¨æ· |
| | | **/ |
| | | public static LoginUser getLoginUser() { |
| | | try { |
| | | return (LoginUser) getAuthentication().getPrincipal(); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("è·åç¨æ·ä¿¡æ¯å¼å¸¸", HttpStatus.HTTP_UNAUTHORIZED); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åAuthentication |
| | | */ |
| | | public static Authentication getAuthentication() { |
| | | return SecurityContextHolder.getContext().getAuthentication(); |
| | | } |
| | | |
| | | /** |
| | | * çæBCryptPasswordEncoderå¯ç |
| | |
| | | package com.ruoyi.demo.controller; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | |
| | | import io.swagger.annotations.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | * æ¥è¯¢æµè¯å表å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢æµè¯å表å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:list')") |
| | | @SaCheckPermission("demo:demo:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<TestDemoVo> list(@Validated(QueryGroup.class) TestDemoBo bo, PageQuery pageQuery) { |
| | | return iTestDemoService.queryPageList(bo, pageQuery); |
| | | } |
| | | |
| | | /** |
| | | * èªå®ä¹å页æ¥è¯¢ |
| | | */ |
| | | @ApiOperation("èªå®ä¹å页æ¥è¯¢") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:list')") |
| | | @GetMapping("/page") |
| | | public TableDataInfo<TestDemoVo> page(@Validated(QueryGroup.class) TestDemoBo bo, PageQuery pageQuery) { |
| | | return iTestDemoService.customPageList(bo, pageQuery); |
| | | } |
| | | /** |
| | | * èªå®ä¹å页æ¥è¯¢ |
| | | */ |
| | | @ApiOperation("èªå®ä¹å页æ¥è¯¢") |
| | | @SaCheckPermission("demo:demo:list") |
| | | @GetMapping("/page") |
| | | public TableDataInfo<TestDemoVo> page(@Validated(QueryGroup.class) TestDemoBo bo, PageQuery pageQuery) { |
| | | return iTestDemoService.customPageList(bo, pageQuery); |
| | | } |
| | | |
| | | @ApiOperation("导å
¥æµè¯-æ ¡éª") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "file", value = "导å
¥æä»¶", dataType = "java.io.File", required = true), |
| | | }) |
| | | @Log(title = "æµè¯å表", businessType = BusinessType.IMPORT) |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:import')") |
| | | @SaCheckPermission("demo:demo:import") |
| | | @PostMapping("/importData") |
| | | public AjaxResult<Void> importData(@RequestPart("file") MultipartFile file) throws Exception { |
| | | ExcelResult<TestDemoImportVo> excelResult = ExcelUtil.importExcel(file.getInputStream(), TestDemoImportVo.class, true); |
| | |
| | | * å¯¼åºæµè¯å表å表 |
| | | */ |
| | | @ApiOperation("å¯¼åºæµè¯å表å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:export')") |
| | | @SaCheckPermission("demo:demo:export") |
| | | @Log(title = "æµè¯å表", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(@Validated TestDemoBo bo, HttpServletResponse response) { |
| | |
| | | * è·åæµè¯å表详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("è·åæµè¯å表详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:query')") |
| | | @SaCheckPermission("demo:demo:query") |
| | | @GetMapping("/{id}") |
| | | public AjaxResult<TestDemoVo> getInfo(@ApiParam("æµè¯ID") |
| | | @NotNull(message = "主é®ä¸è½ä¸ºç©º") |
| | |
| | | * æ°å¢æµè¯å表 |
| | | */ |
| | | @ApiOperation("æ°å¢æµè¯å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:add')") |
| | | @SaCheckPermission("demo:demo:add") |
| | | @Log(title = "æµè¯å表", businessType = BusinessType.INSERT) |
| | | @RepeatSubmit(interval = 2, timeUnit = TimeUnit.SECONDS, message = "ä¸å
许éå¤æäº¤") |
| | | @PostMapping() |
| | |
| | | * ä¿®æ¹æµè¯å表 |
| | | */ |
| | | @ApiOperation("ä¿®æ¹æµè¯å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:edit')") |
| | | @SaCheckPermission("demo:demo:edit") |
| | | @Log(title = "æµè¯å表", businessType = BusinessType.UPDATE) |
| | | @RepeatSubmit |
| | | @PutMapping() |
| | |
| | | * å 餿µè¯å表 |
| | | */ |
| | | @ApiOperation("å 餿µè¯å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:demo:remove')") |
| | | @Log(title = "æµè¯å表", businessType = BusinessType.DELETE) |
| | | @SaCheckPermission("demo:demo:remove") |
| | | @Log(title = "æµè¯å表" , businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult<Void> remove(@ApiParam("æµè¯ID串") |
| | | @NotEmpty(message = "主é®ä¸è½ä¸ºç©º") |
| | |
| | | package com.ruoyi.demo.controller; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * æ¥è¯¢æµè¯æ 表å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢æµè¯æ 表å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:list')") |
| | | @SaCheckPermission("demo:tree:list") |
| | | @GetMapping("/list") |
| | | public AjaxResult<List<TestTreeVo>> list(@Validated(QueryGroup.class) TestTreeBo bo) { |
| | | List<TestTreeVo> list = iTestTreeService.queryList(bo); |
| | |
| | | * å¯¼åºæµè¯æ 表å表 |
| | | */ |
| | | @ApiOperation("å¯¼åºæµè¯æ 表å表") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:export')") |
| | | @SaCheckPermission("demo:tree:export") |
| | | @Log(title = "æµè¯æ 表", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/export") |
| | | public void export(@Validated TestTreeBo bo, HttpServletResponse response) { |
| | |
| | | * è·åæµè¯æ 表详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("è·åæµè¯æ 表详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:query')") |
| | | @SaCheckPermission("demo:tree:query") |
| | | @GetMapping("/{id}") |
| | | public AjaxResult<TestTreeVo> getInfo(@ApiParam("æµè¯æ ID") |
| | | @NotNull(message = "主é®ä¸è½ä¸ºç©º") |
| | |
| | | * æ°å¢æµè¯æ 表 |
| | | */ |
| | | @ApiOperation("æ°å¢æµè¯æ 表") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:add')") |
| | | @SaCheckPermission("demo:tree:add") |
| | | @Log(title = "æµè¯æ 表", businessType = BusinessType.INSERT) |
| | | @RepeatSubmit |
| | | @PostMapping() |
| | |
| | | * ä¿®æ¹æµè¯æ 表 |
| | | */ |
| | | @ApiOperation("ä¿®æ¹æµè¯æ 表") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:edit')") |
| | | @SaCheckPermission("demo:tree:edit") |
| | | @Log(title = "æµè¯æ 表", businessType = BusinessType.UPDATE) |
| | | @RepeatSubmit |
| | | @PutMapping() |
| | |
| | | * å 餿µè¯æ 表 |
| | | */ |
| | | @ApiOperation("å 餿µè¯æ 表") |
| | | @PreAuthorize("@ss.hasPermi('demo:tree:remove')") |
| | | @Log(title = "æµè¯æ 表", businessType = BusinessType.DELETE) |
| | | @SaCheckPermission("demo:tree:remove") |
| | | @Log(title = "æµè¯æ 表" , businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult<Void> remove(@ApiParam("æµè¯æ ID串") |
| | | @NotEmpty(message = "主é®ä¸è½ä¸ºç©º") |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.service.UserService; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.annotation.Before; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æ°æ®è¿æ»¤å¤ç |
| | | * |
| | | * @author Lion Li |
| | | * @deprecated 3.6.0 ç§»é¤ {@link com.ruoyi.framework.handler.PlusDataPermissionHandler} |
| | | */ |
| | | @Aspect |
| | | @Component |
| | | @Deprecated |
| | | public class DataScopeAspect { |
| | | |
| | | /** |
| | | * å
¨é¨æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_ALL = "1"; |
| | | |
| | | /** |
| | | * èªå®æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_CUSTOM = "2"; |
| | | |
| | | /** |
| | | * é¨é¨æ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_DEPT = "3"; |
| | | |
| | | /** |
| | | * é¨é¨å以䏿°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; |
| | | |
| | | /** |
| | | * ä»
æ¬äººæ°æ®æé |
| | | */ |
| | | public static final String DATA_SCOPE_SELF = "5"; |
| | | |
| | | /** |
| | | * æ°æ®æéè¿æ»¤å
³é®å |
| | | */ |
| | | public static final String DATA_SCOPE = "dataScope"; |
| | | |
| | | @Before("@annotation(controllerDataScope)") |
| | | public void doBefore(JoinPoint point, DataScope controllerDataScope) throws Throwable { |
| | | clearDataScope(point); |
| | | handleDataScope(point, controllerDataScope); |
| | | } |
| | | |
| | | protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope) { |
| | | // è·åå½åçç¨æ· |
| | | SysUser currentUser = SpringUtils.getBean(UserService.class).selectUserById(LoginUtils.getUserId()); |
| | | // 妿æ¯è¶
级管çåï¼åä¸è¿æ»¤æ°æ® |
| | | if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { |
| | | dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), |
| | | controllerDataScope.userAlias(), controllerDataScope.isUser()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ°æ®èå´è¿æ»¤ |
| | | * |
| | | * @param joinPoint åç¹ |
| | | * @param user ç¨æ· |
| | | * @param userAlias å«å |
| | | */ |
| | | public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, boolean isUser) { |
| | | StringBuilder sqlString = new StringBuilder(); |
| | | |
| | | // å° "." æååº,ä¸åå«å为å表æ¥è¯¢,åå«å为å¤è¡¨æ¥è¯¢ |
| | | deptAlias = StringUtils.isNotBlank(deptAlias) ? deptAlias + "." : ""; |
| | | userAlias = StringUtils.isNotBlank(userAlias) ? userAlias + "." : ""; |
| | | |
| | | for (SysRole role : user.getRoles()) { |
| | | String dataScope = role.getDataScope(); |
| | | if (DATA_SCOPE_ALL.equals(dataScope)) { |
| | | sqlString = new StringBuilder(); |
| | | break; |
| | | } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", |
| | | deptAlias, role.getRoleId())); |
| | | } else if (DATA_SCOPE_DEPT.equals(dataScope)) { |
| | | sqlString.append(StringUtils.format(" OR {}dept_id = {} ", |
| | | deptAlias, user.getDeptId())); |
| | | } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) { |
| | | sqlString.append(StringUtils.format( |
| | | " OR {}dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
| | | deptAlias, user.getDeptId(), user.getDeptId())); |
| | | } else if (DATA_SCOPE_SELF.equals(dataScope)) { |
| | | if (isUser) { |
| | | sqlString.append(StringUtils.format(" OR {}user_id = {} ", |
| | | userAlias, user.getUserId())); |
| | | } else { |
| | | // æ°æ®æé为ä»
æ¬äººä¸æ²¡æuserAliaså«å䏿¥è¯¢ä»»ä½æ°æ® |
| | | sqlString.append(" OR 1=0 "); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(sqlString.toString())) { |
| | | putDataScope(joinPoint, sqlString.substring(4)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¼æ¥æésqlåå
æ¸
空params.dataScope忰鲿¢æ³¨å
¥ |
| | | */ |
| | | private void clearDataScope(final JoinPoint joinPoint) { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (StringUtils.isNotNull(params)) { |
| | | putDataScope(joinPoint, ""); |
| | | } |
| | | } |
| | | |
| | | private static void putDataScope(JoinPoint joinPoint, String sql) { |
| | | Object params = joinPoint.getArgs()[0]; |
| | | if (StringUtils.isNotNull(params)) { |
| | | if (params instanceof BaseEntity) { |
| | | BaseEntity baseEntity = (BaseEntity) params; |
| | | baseEntity.getParams().put(DATA_SCOPE, sql); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.dto.OperLogDTO; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.service.OperLogService; |
| | | import com.ruoyi.common.enums.BusinessStatus; |
| | | import com.ruoyi.common.enums.HttpMethod; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | |
| | | protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) { |
| | | try { |
| | | |
| | | // è·åå½åçç¨æ· |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | |
| | | // *========æ°æ®åºæ¥å¿=========*// |
| | | OperLogDTO operLog = new OperLogDTO(); |
| | | operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); |
| | |
| | | String ip = ServletUtils.getClientIP(); |
| | | operLog.setOperIp(ip); |
| | | operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); |
| | | if (loginUser != null) { |
| | | operLog.setOperName(loginUser.getUsername()); |
| | | } |
| | | operLog.setOperName(LoginUtils.getUsername()); |
| | | |
| | | if (e != null) { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | |
| | | package com.ruoyi.framework.aspectj; |
| | | |
| | | import cn.dev33.satoken.SaManager; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.ruoyi.common.annotation.RepeatSubmit; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.properties.TokenProperties; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.redis.RedisUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | |
| | | @Component |
| | | public class RepeatSubmitAspect { |
| | | |
| | | private final TokenProperties tokenProperties; |
| | | private final RepeatSubmitProperties repeatSubmitProperties; |
| | | |
| | | @Before("@annotation(repeatSubmit)") |
| | |
| | | String url = request.getRequestURI(); |
| | | |
| | | // å¯ä¸å¼ï¼æ²¡ææ¶æ¯å¤´å使ç¨è¯·æ±å°åï¼ |
| | | String submitKey = StringUtils.trimToEmpty(request.getHeader(tokenProperties.getHeader())); |
| | | String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName())); |
| | | |
| | | submitKey = SecureUtil.md5(submitKey + ":" + nowParams); |
| | | // å¯ä¸æ è¯ï¼æå®key + url + æ¶æ¯å¤´ï¼ |
| | |
| | | public class ResourcesConfig implements WebMvcConfigurer { |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | } |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | // å
¨å±é¾è·¯è·è¸ªæ¦æªå¨ |
| | | registry.addInterceptor(new TLogWebInterceptor()); |
| | |
| | | registry.addInterceptor(new PlusWebInvokeTimeInterceptor()); |
| | | } |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | } |
| | | |
| | | /** |
| | | * è·¨åé
ç½® |
| | | */ |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import cn.dev33.satoken.interceptor.SaAnnotationInterceptor; |
| | | import cn.dev33.satoken.interceptor.SaRouteInterceptor; |
| | | import cn.dev33.satoken.jwt.StpLogicJwtForStyle; |
| | | import cn.dev33.satoken.router.SaRouter; |
| | | import cn.dev33.satoken.stp.StpLogic; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.config.properties.SecurityProperties; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | /** |
| | | * sa-token é
ç½® |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @Configuration |
| | | public class SaTokenConfig implements WebMvcConfigurer { |
| | | |
| | | @Autowired |
| | | private SecurityProperties securityProperties; |
| | | |
| | | /** |
| | | * 注åsa-tokençæ¦æªå¨ |
| | | */ |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | // 注åè·¯ç±æ¦æªå¨ï¼èªå®ä¹éªè¯è§å |
| | | registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> { |
| | | // ç»å½éªè¯ -- æé¤å¤ä¸ªè·¯å¾ |
| | | SaRouter |
| | | // è·åææç |
| | | .match("/**") |
| | | // æé¤ä¸ä¸éè¦æ¦æªç |
| | | .notMatch(securityProperties.getExcludes()) |
| | | .check(() -> { |
| | | if (log.isDebugEnabled()) { |
| | | Long userId = LoginUtils.getUserId(); |
| | | if (StringUtils.isNotNull(userId)) { |
| | | log.debug("å©ä½æææ¶é´: {}", StpUtil.getTokenTimeout()); |
| | | log.debug("ä¸´æ¶æææ¶é´: {}", StpUtil.getTokenActivityTimeout()); |
| | | } |
| | | } |
| | | }); |
| | | })).addPathPatterns("/**"); |
| | | registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**"); |
| | | } |
| | | |
| | | @Bean |
| | | public StpLogic getStpLogicJwt() { |
| | | // Sa-Token æ´å jwt (Style模å¼) |
| | | return new StpLogicJwtForStyle(); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.framework.config; |
| | | |
| | | import cn.dev33.satoken.config.SaTokenConfig; |
| | | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; |
| | | import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver; |
| | | import com.ruoyi.common.properties.TokenProperties; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.framework.config.properties.SwaggerProperties; |
| | |
| | | public class SwaggerConfig { |
| | | |
| | | private final SwaggerProperties swaggerProperties; |
| | | private final TokenProperties tokenProperties; |
| | | private final SaTokenConfig saTokenConfig; |
| | | private final OpenApiExtensionResolver openApiExtensionResolver; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private List<SecurityScheme> securitySchemes() { |
| | | List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>(); |
| | | String header = tokenProperties.getHeader(); |
| | | String header = saTokenConfig.getTokenName(); |
| | | apiKeyList.add(new ApiKey(header, header, In.HEADER.toValue())); |
| | | return apiKeyList; |
| | | } |
| | |
| | | AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; |
| | | authorizationScopes[0] = authorizationScope; |
| | | List<SecurityReference> securityReferences = new ArrayList<>(); |
| | | securityReferences.add(new SecurityReference(tokenProperties.getHeader(), authorizationScopes)); |
| | | securityReferences.add(new SecurityReference(saTokenConfig.getTokenName(), authorizationScopes)); |
| | | return securityReferences; |
| | | } |
| | | |
| | |
| | | public class SecurityProperties { |
| | | |
| | | /** |
| | | * éåºç»å½url |
| | | * æé¤è·¯å¾ |
| | | */ |
| | | private String logoutUrl; |
| | | private String[] excludes; |
| | | |
| | | /** |
| | | * å¿åæ¾è¡è·¯å¾ |
| | | */ |
| | | private String[] anonymous; |
| | | |
| | | /** |
| | | * ç¨æ·ä»»æè®¿é®æ¾è¡è·¯å¾ |
| | | */ |
| | | private String[] permitAll; |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åç»å½ç¨æ·å |
| | | */ |
| | | private String getLoginUsername() { |
| | | LoginUser loginUser; |
| | | try { |
| | | loginUser = SecurityUtils.getLoginUser(); |
| | | } catch (Exception e) { |
| | | log.warn("èªå¨æ³¨å
¥è¦å => ç¨æ·æªç»å½"); |
| | | return null; |
| | | } |
| | | return loginUser.getUsername(); |
| | | } |
| | | /** |
| | | * è·åç»å½ç¨æ·å |
| | | */ |
| | | private String getLoginUsername() { |
| | | LoginUser loginUser; |
| | | try { |
| | | loginUser = LoginUtils.getLoginUser(); |
| | | } catch (Exception e) { |
| | | log.warn("èªå¨æ³¨å
¥è¦å => ç¨æ·æªç»å½"); |
| | | return null; |
| | | } |
| | | return loginUser.getUsername(); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.ruoyi.common.enums.DataScopeType; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.helper.DataPermissionHelper; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | } |
| | | SysUser currentUser = DataPermissionHelper.getVariable("user"); |
| | | if (ObjectUtil.isNull(currentUser)) { |
| | | currentUser = SpringUtils.getBean(UserService.class).selectUserById(SecurityUtils.getUserId()); |
| | | currentUser = SpringUtils.getBean(UserService.class).selectUserById(LoginUtils.getUserId()); |
| | | DataPermissionHelper.setVariable("user", currentUser); |
| | | } |
| | | // 妿æ¯è¶
级管çåï¼åä¸è¿æ»¤æ°æ® |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.listener; |
| | | |
| | | import cn.dev33.satoken.config.SaTokenConfig; |
| | | import cn.dev33.satoken.listener.SaTokenListener; |
| | | import cn.dev33.satoken.stp.SaLoginModel; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.http.useragent.UserAgent; |
| | | import cn.hutool.http.useragent.UserAgentUtil; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.dto.UserOnlineDTO; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.service.UserService; |
| | | import com.ruoyi.common.enums.UserType; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.RedisUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * ç¨æ·è¡ä¸º 侦å¬å¨çå®ç° |
| | | */ |
| | | @Component |
| | | @Slf4j |
| | | public class UserActionListener implements SaTokenListener { |
| | | |
| | | @Autowired |
| | | private SaTokenConfig saTokenConfig; |
| | | |
| | | /** |
| | | * æ¯æ¬¡ç»å½æ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) { |
| | | UserType userType = LoginUtils.getUserType(loginId); |
| | | if (userType == UserType.SYS_USER) { |
| | | UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); |
| | | String ip = ServletUtils.getClientIP(); |
| | | SysUser user = SpringUtils.getBean(UserService.class).selectUserById(LoginUtils.getUserId()); |
| | | String tokenValue = StpUtil.getTokenValue(); |
| | | UserOnlineDTO userOnlineDTO = new UserOnlineDTO() |
| | | .setIpaddr(ip) |
| | | .setLoginLocation(AddressUtils.getRealAddressByIP(ip)) |
| | | .setBrowser(userAgent.getBrowser().getName()) |
| | | .setOs(userAgent.getOs().getName()) |
| | | .setLoginTime(System.currentTimeMillis()) |
| | | .setTokenId(tokenValue) |
| | | .setUserName(user.getUserName()); |
| | | if (StringUtils.isNotNull(user.getDept())) { |
| | | userOnlineDTO.setDeptName(user.getDept().getDeptName()); |
| | | } |
| | | RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, userOnlineDTO, saTokenConfig.getTimeout(), TimeUnit.SECONDS); |
| | | log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue); |
| | | } else if (userType == UserType.APP_USER) { |
| | | // app端 èªè¡æ ¹æ®ä¸å¡ç¼å |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡æ³¨éæ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doLogout(String loginType, Object loginId, String tokenValue) { |
| | | RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); |
| | | log.info("user doLogout, useId:{}, token:{}", loginId, tokenValue); |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡è¢«è¸¢ä¸çº¿æ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doKickout(String loginType, Object loginId, String tokenValue) { |
| | | RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); |
| | | log.info("user doLogoutByLoginId, useId:{}, token:{}", loginId, tokenValue); |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡è¢«é¡¶ä¸çº¿æ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doReplaced(String loginType, Object loginId, String tokenValue) { |
| | | RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); |
| | | log.info("user doReplaced, useId:{}, token:{}", loginId, tokenValue); |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡è¢«å°ç¦æ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doDisable(String loginType, Object loginId, long disableTime) { |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡è¢«è§£å°æ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doUntieDisable(String loginType, Object loginId) { |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡å建Sessionæ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doCreateSession(String id) { |
| | | } |
| | | |
| | | /** |
| | | * æ¯æ¬¡æ³¨éSessionæ¶è§¦å |
| | | */ |
| | | @Override |
| | | public void doLogoutSession(String id) { |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.satoken.dao; |
| | | |
| | | import cn.dev33.satoken.dao.SaTokenDao; |
| | | import cn.dev33.satoken.util.SaFoxUtil; |
| | | import com.ruoyi.common.utils.RedisUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Sa-Tokenæä¹
屿¥å£(ä½¿ç¨æ¡æ¶èªå¸¦RedisUtilså®ç° åè®®ç»ä¸) |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | public class PlusSaTokenDao implements SaTokenDao { |
| | | |
| | | /** |
| | | * è·åValueï¼å¦æ è¿ç©º |
| | | */ |
| | | @Override |
| | | public String get(String key) { |
| | | return RedisUtils.getCacheObject(key); |
| | | } |
| | | |
| | | /** |
| | | * åå
¥Valueï¼å¹¶è®¾å®åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public void set(String key, String value, long timeout) { |
| | | if(timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { |
| | | return; |
| | | } |
| | | // 夿æ¯å¦ä¸ºæ°¸ä¸è¿æ |
| | | if(timeout == SaTokenDao.NEVER_EXPIRE) { |
| | | RedisUtils.setCacheObject(key, value); |
| | | } else { |
| | | RedisUtils.setCacheObject(key, value, timeout, TimeUnit.SECONDS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ä¿®ä¿®æ¹æå®key-valueé®å¼å¯¹ (è¿ææ¶é´ä¸å) |
| | | */ |
| | | @Override |
| | | public void update(String key, String value) { |
| | | long expire = getTimeout(key); |
| | | // -2 = æ æ¤é® |
| | | if(expire == SaTokenDao.NOT_VALUE_EXPIRE) { |
| | | return; |
| | | } |
| | | this.set(key, value, expire); |
| | | } |
| | | |
| | | /** |
| | | * å é¤Value |
| | | */ |
| | | @Override |
| | | public void delete(String key) { |
| | | RedisUtils.deleteObject(key); |
| | | } |
| | | |
| | | /** |
| | | * è·åValueçå©ä½åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public long getTimeout(String key) { |
| | | return RedisUtils.getTimeToLive(key) / 1000; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹Valueçå©ä½åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public void updateTimeout(String key, long timeout) { |
| | | // 夿æ¯å¦æ³è¦è®¾ç½®ä¸ºæ°¸ä¹
|
| | | if(timeout == SaTokenDao.NEVER_EXPIRE) { |
| | | long expire = getTimeout(key); |
| | | if(expire == SaTokenDao.NEVER_EXPIRE) { |
| | | // 妿å
¶å·²ç»è¢«è®¾ç½®ä¸ºæ°¸ä¹
ï¼åä¸ä½ä»»ä½å¤ç |
| | | } else { |
| | | // 妿尿ªè¢«è®¾ç½®ä¸ºæ°¸ä¹
ï¼é£ä¹å次set䏿¬¡ |
| | | this.set(key, this.get(key), timeout); |
| | | } |
| | | return; |
| | | } |
| | | RedisUtils.expire(key, timeout, TimeUnit.SECONDS); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * è·åObjectï¼å¦æ è¿ç©º |
| | | */ |
| | | @Override |
| | | public Object getObject(String key) { |
| | | return RedisUtils.getCacheObject(key); |
| | | } |
| | | |
| | | /** |
| | | * åå
¥Objectï¼å¹¶è®¾å®åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public void setObject(String key, Object object, long timeout) { |
| | | if(timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { |
| | | return; |
| | | } |
| | | // 夿æ¯å¦ä¸ºæ°¸ä¸è¿æ |
| | | if(timeout == SaTokenDao.NEVER_EXPIRE) { |
| | | RedisUtils.setCacheObject(key, object); |
| | | } else { |
| | | RedisUtils.setCacheObject(key, object, timeout, TimeUnit.SECONDS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°Object (è¿ææ¶é´ä¸å) |
| | | */ |
| | | @Override |
| | | public void updateObject(String key, Object object) { |
| | | long expire = getObjectTimeout(key); |
| | | // -2 = æ æ¤é® |
| | | if(expire == SaTokenDao.NOT_VALUE_EXPIRE) { |
| | | return; |
| | | } |
| | | this.setObject(key, object, expire); |
| | | } |
| | | |
| | | /** |
| | | * å é¤Object |
| | | */ |
| | | @Override |
| | | public void deleteObject(String key) { |
| | | RedisUtils.deleteObject(key); |
| | | } |
| | | |
| | | /** |
| | | * è·åObjectçå©ä½åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public long getObjectTimeout(String key) { |
| | | return RedisUtils.getTimeToLive(key) / 1000; |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹Objectçå©ä½åæ´»æ¶é´ (åä½: ç§) |
| | | */ |
| | | @Override |
| | | public void updateObjectTimeout(String key, long timeout) { |
| | | // 夿æ¯å¦æ³è¦è®¾ç½®ä¸ºæ°¸ä¹
|
| | | if(timeout == SaTokenDao.NEVER_EXPIRE) { |
| | | long expire = getObjectTimeout(key); |
| | | if(expire == SaTokenDao.NEVER_EXPIRE) { |
| | | // 妿å
¶å·²ç»è¢«è®¾ç½®ä¸ºæ°¸ä¹
ï¼åä¸ä½ä»»ä½å¤ç |
| | | } else { |
| | | // 妿尿ªè¢«è®¾ç½®ä¸ºæ°¸ä¹
ï¼é£ä¹å次set䏿¬¡ |
| | | this.setObject(key, this.getObject(key), timeout); |
| | | } |
| | | return; |
| | | } |
| | | RedisUtils.expire(key, timeout, TimeUnit.SECONDS); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æç´¢æ°æ® |
| | | */ |
| | | @Override |
| | | public List<String> searchData(String prefix, String keyword, int start, int size) { |
| | | Collection<String> keys = RedisUtils.keys(prefix + "*" + keyword + "*"); |
| | | List<String> list = new ArrayList<>(keys); |
| | | return SaFoxUtil.searchList(list, start, size); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.framework.satoken.service; |
| | | |
| | | import cn.dev33.satoken.stp.StpInterface; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.enums.UserType; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class SaInterfaceImpl implements StpInterface { |
| | | |
| | | @Override |
| | | public List<String> getPermissionList(Object loginId, String loginType) { |
| | | UserType userType = LoginUtils.getUserType(loginId); |
| | | if (userType == UserType.SYS_USER) { |
| | | LoginUser loginUser = LoginUtils.getLoginUser(); |
| | | return new ArrayList<>(loginUser.getMenuPermission()); |
| | | } else if (userType == UserType.APP_USER) { |
| | | // app端æéè¿å èªè¡æ ¹æ®ä¸å¡ç¼å |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRoleList(Object loginId, String loginType) { |
| | | UserType userType = LoginUtils.getUserType(loginId); |
| | | if (userType == UserType.SYS_USER) { |
| | | LoginUser loginUser = LoginUtils.getLoginUser(); |
| | | return new ArrayList<>(loginUser.getRolePermission()); |
| | | } else if (userType == UserType.APP_USER) { |
| | | // app端æéè¿å èªè¡æ ¹æ®ä¸å¡ç¼å |
| | | } |
| | | return new ArrayList<>(); |
| | | } |
| | | } |
| | |
| | | package com.ruoyi.framework.web.exception; |
| | | |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.exception.NotPermissionException; |
| | | import cn.dev33.satoken.exception.NotRoleException; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.exception.DemoModeException; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.RedisUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.support.DefaultMessageSourceResolvable; |
| | | import org.springframework.security.access.AccessDeniedException; |
| | | import org.springframework.validation.BindException; |
| | | import org.springframework.web.HttpRequestMethodNotSupportedException; |
| | | import org.springframework.web.bind.MethodArgumentNotValidException; |
| | |
| | | /** |
| | | * æéæ ¡éªå¼å¸¸ |
| | | */ |
| | | @ExceptionHandler(AccessDeniedException.class) |
| | | public AjaxResult<Void> handleAccessDeniedException(AccessDeniedException e, HttpServletRequest request) { |
| | | @ExceptionHandler(NotPermissionException.class) |
| | | public AjaxResult<Void> handleAccessDeniedException(NotPermissionException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',æéæ ¡éªå¤±è´¥'{}'", requestURI, e.getMessage()); |
| | | return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "没ææéï¼è¯·è系管çåææ"); |
| | | } |
| | | |
| | | /** |
| | | * è§è²æ ¡éªå¼å¸¸ |
| | | */ |
| | | @ExceptionHandler(NotRoleException.class) |
| | | public AjaxResult<Void> handleAccessDeniedException(NotRoleException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',è§è²æ ¡éªå¤±è´¥'{}'", requestURI, e.getMessage()); |
| | | return AjaxResult.error(HttpStatus.HTTP_FORBIDDEN, "没æè§è²ï¼è¯·è系管çåææ"); |
| | | } |
| | | |
| | | /** |
| | | * 认è¯å¤±è´¥ |
| | | */ |
| | | @ExceptionHandler(NotLoginException.class) |
| | | public AjaxResult<Void> handleAccessDeniedException(NotLoginException e, HttpServletRequest request) { |
| | | String requestURI = request.getRequestURI(); |
| | | log.error("请æ±å°å'{}',认è¯å¤±è´¥'{}',æ æ³è®¿é®ç³»ç»èµæº", requestURI, e.getMessage()); |
| | | return AjaxResult.error(HttpStatus.HTTP_UNAUTHORIZED, StringUtils.format("请æ±å°å'{}',认è¯å¤±è´¥'{}',æ æ³è®¿é®ç³»ç»èµæº", requestURI)); |
| | | } |
| | | |
| | | /** |
| | | * è¯·æ±æ¹å¼ä¸æ¯æ |
| | | */ |
| | | @ExceptionHandler(HttpRequestMethodNotSupportedException.class) |
| | |
| | | package com.ruoyi.generator.controller; |
| | | |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * æ¥è¯¢ä»£ç çæå表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢ä»£ç çæå表") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:list')") |
| | | @SaCheckPermission("tool:gen:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo<GenTable> genList(GenTable genTable, PageQuery pageQuery) { |
| | | return genTableService.selectPageGenTableList(genTable, pageQuery); |
| | |
| | | * ä¿®æ¹ä»£ç çæä¸å¡ |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ä»£ç çæä¸å¡") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:query')") |
| | | @SaCheckPermission("tool:gen:query") |
| | | @GetMapping(value = "/{talbleId}") |
| | | public AjaxResult<Map<String, Object>> getInfo(@PathVariable Long talbleId) { |
| | | GenTable table = genTableService.selectGenTableById(talbleId); |
| | |
| | | * æ¥è¯¢æ°æ®åºå表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢æ°æ®åºå表") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:list')") |
| | | @SaCheckPermission("tool:gen:list") |
| | | @GetMapping("/db/list") |
| | | public TableDataInfo<GenTable> dataList(GenTable genTable, PageQuery pageQuery) { |
| | | return genTableService.selectPageDbTableList(genTable, pageQuery); |
| | |
| | | * æ¥è¯¢æ°æ®è¡¨å段å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢æ°æ®è¡¨å段å表") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:list')") |
| | | @SaCheckPermission("tool:gen:list") |
| | | @GetMapping(value = "/column/{talbleId}") |
| | | public TableDataInfo<GenTableColumn> columnList(Long tableId) { |
| | | TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>(); |
| | |
| | | * 导å
¥è¡¨ç»æï¼ä¿åï¼ |
| | | */ |
| | | @ApiOperation("导å
¥è¡¨ç»æï¼ä¿åï¼") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:import')") |
| | | @SaCheckPermission("tool:gen:import") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importTable") |
| | | public AjaxResult<Void> importTableSave(String tables) { |
| | |
| | | * ä¿®æ¹ä¿å代ç çæä¸å¡ |
| | | */ |
| | | @ApiOperation("ä¿®æ¹ä¿å代ç çæä¸å¡") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @SaCheckPermission("tool:gen:edit") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult<Void> editSave(@Validated @RequestBody GenTable genTable) { |
| | |
| | | * å é¤ä»£ç çæ |
| | | */ |
| | | @ApiOperation("å é¤ä»£ç çæ") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:remove')") |
| | | @SaCheckPermission("tool:gen:remove") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{tableIds}") |
| | | public AjaxResult<Void> remove(@PathVariable Long[] tableIds) { |
| | |
| | | * é¢è§ä»£ç |
| | | */ |
| | | @ApiOperation("é¢è§ä»£ç ") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:preview')") |
| | | @SaCheckPermission("tool:gen:preview") |
| | | @GetMapping("/preview/{tableId}") |
| | | public AjaxResult<Map<String, String>> preview(@PathVariable("tableId") Long tableId) throws IOException { |
| | | Map<String, String> dataMap = genTableService.previewCode(tableId); |
| | |
| | | * çæä»£ç ï¼ä¸è½½æ¹å¼ï¼ |
| | | */ |
| | | @ApiOperation("çæä»£ç ï¼ä¸è½½æ¹å¼ï¼") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')") |
| | | @SaCheckPermission("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/download/{tableName}") |
| | | public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { |
| | |
| | | * çæä»£ç ï¼èªå®ä¹è·¯å¾ï¼ |
| | | */ |
| | | @ApiOperation("çæä»£ç ï¼èªå®ä¹è·¯å¾ï¼") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')") |
| | | @SaCheckPermission("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/genCode/{tableName}") |
| | | public AjaxResult<Void> genCode(@PathVariable("tableName") String tableName) { |
| | |
| | | * åæ¥æ°æ®åº |
| | | */ |
| | | @ApiOperation("åæ¥æ°æ®åº") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:edit')") |
| | | @SaCheckPermission("tool:gen:edit") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.UPDATE) |
| | | @GetMapping("/synchDb/{tableName}") |
| | | public AjaxResult<Void> synchDb(@PathVariable("tableName") String tableName) { |
| | |
| | | * æ¹éçæä»£ç |
| | | */ |
| | | @ApiOperation("æ¹éçæä»£ç ") |
| | | @PreAuthorize("@ss.hasPermi('tool:gen:code')") |
| | | @SaCheckPermission("tool:gen:code") |
| | | @Log(title = "代ç çæ", businessType = BusinessType.GENCODE) |
| | | @GetMapping("/batchGenCode") |
| | | public void batchGenCode(HttpServletResponse response, String tables) throws IOException { |
| | |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.file.FileUtils; |
| | | import com.ruoyi.generator.domain.GenTable; |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importGenTable(List<GenTable> tableList) { |
| | | String operName = SecurityUtils.getUsername(); |
| | | String operName = LoginUtils.getUsername(); |
| | | try { |
| | | for (GenTable table : tableList) { |
| | | String tableName = table.getTableName(); |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.constraints.*; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | * æ¥è¯¢${functionName}å表 |
| | | */ |
| | | @ApiOperation("æ¥è¯¢${functionName}å表") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") |
| | | @SaCheckPermission("${permissionPrefix}:list") |
| | | @GetMapping("/list") |
| | | #if($table.crud || $table.sub) |
| | | public TableDataInfo<${ClassName}Vo> list(@Validated(QueryGroup.class) ${ClassName}Bo bo, PageQuery pageQuery) { |
| | |
| | | * 导åº${functionName}å表 |
| | | */ |
| | | @ApiOperation("导åº${functionName}å表") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") |
| | | @SaCheckPermission("${permissionPrefix}:export") |
| | | @Log(title = "${functionName}", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(@Validated ${ClassName}Bo bo, HttpServletResponse response) { |
| | |
| | | * è·å${functionName}详ç»ä¿¡æ¯ |
| | | */ |
| | | @ApiOperation("è·å${functionName}详ç»ä¿¡æ¯") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") |
| | | @SaCheckPermission("${permissionPrefix}:query") |
| | | @GetMapping("/{${pkColumn.javaField}}") |
| | | public AjaxResult<${ClassName}Vo> getInfo(@ApiParam("主é®") |
| | | @NotNull(message = "主é®ä¸è½ä¸ºç©º") |
| | |
| | | * æ°å¢${functionName} |
| | | */ |
| | | @ApiOperation("æ°å¢${functionName}") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") |
| | | @SaCheckPermission("${permissionPrefix}:add") |
| | | @Log(title = "${functionName}", businessType = BusinessType.INSERT) |
| | | @RepeatSubmit() |
| | | @PostMapping() |
| | |
| | | * ä¿®æ¹${functionName} |
| | | */ |
| | | @ApiOperation("ä¿®æ¹${functionName}") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") |
| | | @SaCheckPermission("${permissionPrefix}:edit") |
| | | @Log(title = "${functionName}", businessType = BusinessType.UPDATE) |
| | | @RepeatSubmit() |
| | | @PutMapping() |
| | |
| | | * å é¤${functionName} |
| | | */ |
| | | @ApiOperation("å é¤${functionName}") |
| | | @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") |
| | | @SaCheckPermission("${permissionPrefix}:remove") |
| | | @Log(title = "${functionName}" , businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{${pkColumn.javaField}s}") |
| | | public AjaxResult<Void> remove(@ApiParam("主é®ä¸²") |
| | |
| | | import com.ruoyi.common.excel.ExcelListener; |
| | | import com.ruoyi.common.excel.ExcelResult; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ValidatorUtils; |
| | |
| | | this.userService = SpringUtils.getBean(ISysUserService.class); |
| | | this.password = SecurityUtils.encryptPassword(initPassword); |
| | | this.isUpdateSupport = isUpdateSupport; |
| | | this.operName = SecurityUtils.getUsername(); |
| | | this.operName = LoginUtils.getUsername(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | package com.ruoyi.system.service; |
| | | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.service.LogininforService; |
| | | import com.ruoyi.common.core.service.TokenService; |
| | | import com.ruoyi.common.enums.DeviceType; |
| | | import com.ruoyi.common.enums.UserStatus; |
| | | import com.ruoyi.common.enums.UserType; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.user.CaptchaException; |
| | | import com.ruoyi.common.exception.user.CaptchaExpireException; |
| | | import com.ruoyi.common.exception.user.UserException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.MessageUtils; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.redis.RedisUtils; |
| | | import com.ruoyi.common.utils.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | * @author Lion Li |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Slf4j |
| | | @Service |
| | | public class SysLoginService { |
| | | |
| | | private final TokenService tokenService; |
| | | private final AuthenticationManager authenticationManager; |
| | | private final ISysUserService userService; |
| | | private final ISysConfigService configService; |
| | | private final LogininforService asyncService; |
| | | private final SysPermissionService permissionService; |
| | | |
| | | /** |
| | | * ç»å½éªè¯ |
| | |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME), request); |
| | | throw new UserException("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME); |
| | | } |
| | | // ç¨æ·éªè¯ |
| | | Authentication authentication = null; |
| | | try { |
| | | // è¯¥æ¹æ³ä¼å»è°ç¨UserDetailsServiceImpl.loadUserByUsername |
| | | authentication = authenticationManager |
| | | .authenticate(new UsernamePasswordAuthenticationToken(username, password)); |
| | | } catch (Exception e) { |
| | | if (e instanceof BadCredentialsException) { |
| | | // æ¯å¦ç¬¬ä¸æ¬¡ |
| | | errorNumber = ObjectUtil.isNull(errorNumber) ? 1 : errorNumber + 1; |
| | | // è¾¾å°è§å®éè¯¯æ¬¡æ° åéå®ç»å½ |
| | | if (errorNumber.equals(Constants.LOGIN_ERROR_NUMBER)) { |
| | | RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber, Constants.LOGIN_ERROR_LIMIT_TIME, TimeUnit.MINUTES); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME), request); |
| | | throw new UserException("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME); |
| | | } else { |
| | | // æªè¾¾å°è§å®éè¯¯æ¬¡æ° åéå¢ |
| | | RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.count", errorNumber), request); |
| | | throw new UserException("user.password.retry.limit.count", errorNumber); |
| | | } |
| | | |
| | | SysUser user = userService.selectUserByUserName(username); |
| | | if (StringUtils.isNull(user)) { |
| | | log.info("ç»å½ç¨æ·ï¼{} ä¸åå¨.", username); |
| | | throw new UserException("user.not.exists", username); |
| | | } else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { |
| | | log.info("ç»å½ç¨æ·ï¼{} 已被å é¤.", username); |
| | | throw new UserException("user.password.delete", username); |
| | | } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { |
| | | log.info("ç»å½ç¨æ·ï¼{} 已被åç¨.", username); |
| | | throw new UserException("user.blocked", username); |
| | | } |
| | | if (!SecurityUtils.matchesPassword(password, user.getPassword())) { |
| | | // æ¯å¦ç¬¬ä¸æ¬¡ |
| | | errorNumber = ObjectUtil.isNull(errorNumber) ? 1 : errorNumber + 1; |
| | | // è¾¾å°è§å®éè¯¯æ¬¡æ° åéå®ç»å½ |
| | | if (errorNumber.equals(Constants.LOGIN_ERROR_NUMBER)) { |
| | | RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber, Constants.LOGIN_ERROR_LIMIT_TIME, TimeUnit.MINUTES); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME), request); |
| | | throw new UserException("user.password.retry.limit.exceed", Constants.LOGIN_ERROR_LIMIT_TIME); |
| | | } else { |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request); |
| | | throw new ServiceException(e.getMessage()); |
| | | // æªè¾¾å°è§å®éè¯¯æ¬¡æ° åéå¢ |
| | | RedisUtils.setCacheObject(Constants.LOGIN_ERROR + username, errorNumber); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.retry.limit.count", errorNumber), request); |
| | | throw new UserException("user.password.retry.limit.count", errorNumber); |
| | | } |
| | | } |
| | | |
| | | // ç»å½æå æ¸
空éè¯¯æ¬¡æ° |
| | | RedisUtils.deleteObject(Constants.LOGIN_ERROR + username); |
| | | asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request); |
| | | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); |
| | | recordLoginInfo(loginUser.getUserId(), username); |
| | | recordLoginInfo(user.getUserId(), username); |
| | | |
| | | LoginUser loginUser = new LoginUser(); |
| | | loginUser.setUserId(user.getUserId()); |
| | | loginUser.setDeptId(user.getDeptId()); |
| | | loginUser.setUsername(user.getUserName()); |
| | | loginUser.setMenuPermission(permissionService.getMenuPermission(user)); |
| | | loginUser.setRolePermission(permissionService.getRolePermission(user)); |
| | | |
| | | // çætoken |
| | | return tokenService.createToken(loginUser); |
| | | LoginUtils.loginByDevice(loginUser, UserType.SYS_USER, DeviceType.PC); |
| | | return StpUtil.getTokenValue(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.TreeBuildUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | |
| | | */ |
| | | @Override |
| | | public void checkDeptDataScope(Long deptId) { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId())) { |
| | | if (!SysUser.isAdmin(LoginUtils.getUserId())) { |
| | | SysDept dept = new SysDept(); |
| | | dept.setDeptId(deptId); |
| | | List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); |
| | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.system.domain.SysRoleDept; |
| | |
| | | */ |
| | | @Override |
| | | public void checkRoleDataScope(Long roleId) { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId())) { |
| | | if (!SysUser.isAdmin(LoginUtils.getUserId())) { |
| | | SysRole role = new SysRole(); |
| | | role.setRoleId(roleId); |
| | | List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); |
| | |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.service.UserService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.LoginUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | |
| | | */ |
| | | @Override |
| | | public void checkUserDataScope(Long userId) { |
| | | if (!SysUser.isAdmin(SecurityUtils.getUserId())) { |
| | | if (!SysUser.isAdmin(LoginUtils.getUserId())) { |
| | | SysUser user = new SysUser(); |
| | | user.setUserId(userId); |
| | | List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user); |