| | |
| | | package com.ruoyi.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.TableDataInfo; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.system.api.model.SysUserRoleVo; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.service.ISysUserRoleService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 前端控制器 |
| | | * </p> |
| | | * 用户和角色关联Controller |
| | | * |
| | | * @author luodangjia |
| | | * @since 2024-11-21 |
| | | * @author xiaochen |
| | | * @date 2023-06-12 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/sys-user-role") |
| | | public class SysUserRoleController { |
| | | @RequestMapping("/userRole") |
| | | public class SysUserRoleController extends BaseController { |
| | | @Autowired |
| | | private ISysUserRoleService sysUserRoleService; |
| | | |
| | | /** |
| | | * 查询用户和角色关联列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysUserRole sysUserRole) { |
| | | startPage(); |
| | | List<SysUserRole> list = sysUserRoleService.selectSysUserRoleList(sysUserRole); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出用户和角色关联列表 |
| | | */ |
| | | @Log(title = "用户和角色关联", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysUserRole sysUserRole) { |
| | | List<SysUserRole> list = sysUserRoleService.selectSysUserRoleList(sysUserRole); |
| | | ExcelUtil<SysUserRole> util = new ExcelUtil<SysUserRole>(SysUserRole.class); |
| | | util.exportExcel(response, list, "用户和角色关联数据"); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户和角色关联详细信息 |
| | | */ |
| | | @GetMapping(value = "/{userId}") |
| | | public AjaxResult getInfo(@PathVariable("userId") Long userId) { |
| | | return success(sysUserRoleService.selectSysUserRoleByUserId(userId)); |
| | | } |
| | | |
| | | /** |
| | | * 新增用户和角色关联 |
| | | */ |
| | | @Log(title = "用户和角色关联", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody SysUserRole sysUserRole) { |
| | | return toAjax(sysUserRoleService.insertSysUserRole(sysUserRole)); |
| | | } |
| | | |
| | | /** |
| | | * 修改用户和角色关联 |
| | | */ |
| | | @Log(title = "用户和角色关联", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody SysUserRole sysUserRole) { |
| | | return toAjax(sysUserRoleService.updateSysUserRole(sysUserRole)); |
| | | } |
| | | |
| | | /** |
| | | * 删除用户和角色关联 |
| | | */ |
| | | @Log(title = "用户和角色关联", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public AjaxResult remove(@PathVariable Long[] userIds) { |
| | | return toAjax(sysUserRoleService.deleteSysUserRoleByUserIds(userIds)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据用户id获取角色 |
| | | * @param userId |
| | | * @return |
| | | */ |
| | | @PostMapping("/getRoleByUserId") |
| | | public R<List<SysUserRoleVo>> getRoleByUserId(@RequestParam("userId") Long userId){ |
| | | List<SysUserRole> list = sysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, userId)); |
| | | List<SysUserRoleVo> data = new ArrayList<>(); |
| | | for (SysUserRole sysUserRole : list) { |
| | | SysUserRoleVo vo = new SysUserRoleVo(); |
| | | BeanUtils.copyProperties(sysUserRole, vo); |
| | | data.add(vo); |
| | | } |
| | | return R.ok(data); |
| | | } |
| | | } |
| | | |