liujie
2026-04-03 0d78540be462dab087bbdce8dc0775872c939d72
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.xiaopeng.account.controller;
 
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
 
import com.xiaopeng.account.service.ISysUserRoleService;
import com.xiaopeng.api.model.account.SysUserRole;
import com.xiaopeng.common.core.domain.R;
import org.springframework.web.bind.annotation.*;
import com.xiaopeng.common.log.annotation.Log;
import com.xiaopeng.common.log.enums.BusinessType;
import com.xiaopeng.common.core.web.controller.BaseController;
import com.xiaopeng.common.core.web.domain.AjaxResult;
import com.xiaopeng.common.core.utils.poi.ExcelUtil;
import com.xiaopeng.common.core.web.page.TableDataInfo;
 
/**
 * 用户和角色关联Controller
 *
 * @author xiaochen
 * @date 2023-06-12
 */
@RestController
@RequestMapping("/userRole")
public class SysUserRoleController extends BaseController {
 
 
    @Resource
    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));
    }
 
 
    /**
     * 查询用户和角色关联
     * @param userId
     * @return
     */
    @PostMapping(value = "/selectSysUserRoleByUserId")
    public R<SysUserRole> selectSysUserRoleByUserId(@RequestParam("userId") Long userId) {
        return R.ok(sysUserRoleService.selectSysUserRoleByUserId(userId));
    }
}