3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.landtool.lanbase.modules.sys.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.landtool.lanbase.modules.sys.entity.SysResource;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.sys.service.SysResourceService;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.PageUtils;
import com.landtool.lanbase.common.utils.Query;
import com.landtool.lanbase.common.utils.Result;
 
/**
 * @author lanbase
 * @Description: TODO(8系统权限资源管理表)
 * @date 2018-01-16 08:57:26
 */
@RestController
@RequestMapping("/sys/resource")
@Api(value = "", tags = {"系统权限资源管理"})
public class SysResourceController extends AbstractController{
 
    @Autowired
    private SysResourceService resourceService;
    
    /**
     * 列表
     */
    @RequestMapping(value ="/list", method ={RequestMethod.POST, RequestMethod.GET})
//    @RequiresPermissions("sys:resource:list")
    @RequiresPermissions(value = {"sys:resource:list","sys:resource:edit"}, logical = Logical.OR)
    @ApiOperation(
            value = "系统权限资源管理列表",
            notes = ""
            )
    @LogAction("平台管理,权限标识,权限标识查询,查询")
    public Result list(@ApiParam(name="params",value="系统权限资源管理",required=true)@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<SysResource> resourceList = resourceService.queryList(query);
        int total = resourceService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(resourceList, total, query.getLimit(), query.getPage());
        
        return Result.ok().put("page", pageUtil);
    }
    
    
    /**
     * 信息
     */
    @GetMapping("/info/{resourceid}")
//    @RequiresPermissions("sys:resource:list")
    @RequiresPermissions(value = {"sys:resource:list","sys:resource:edit"}, logical = Logical.OR)
    @ApiOperation(
            value = "权限资源信息列表",
            notes = ""
            )
    public Result info(@ApiParam(name="resourceid",value="权限资源Id",required=true)@PathVariable("resourceid") Long resourceid){
        SysResource resource = resourceService.queryObject(resourceid);
        
        return Result.ok().put("resource", resource);
    }
    
    /**
     * 保存
     */
    @LogAction("平台管理,权限标识,权限标识新增,新增")
    @PostMapping("/save")
    @RequiresPermissions("sys:resource:edit")
    @ApiOperation(
            value = "保存权限资源信息",
            notes = ""
            )
    public Result save(@ApiParam(name="权限资源信息对象",value="传入json格式",required=true)@RequestBody SysResource resource){
        if(resource.getResourcername() == null || resource.getResourcername() .length() == 0
                || resource.getResourcercode() == null || resource.getResourcercode().length() == 0){
            return Result.error("保存失败,存在特殊字符,请重新输入!");
        }
        //资源名称是否重复
        SysResource info = resourceService.queryObjectByName(resource.getAppid(), resource.getResourcername());
        if(info != null){
            return Result.error("所属系统已存在该资源名称!");
        }
        Long userid =((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid();
        resource.setRcreateuser(userid);
        resource.setRcreatedate(new Date());
        resourceService.save(resource);
        
        //保存后获取自增id
        int resourceid = resourceService.querySysResourceWithSEQ();
        return Result.ok().put("resourceid",resourceid);
    }
    
    /**
     * 修改
     */
    @LogAction("平台管理,权限标识,权限标识修改,修改")
    @PostMapping("/update")
    @RequiresPermissions("sys:resource:edit")
    @ApiOperation(
            value = "修改权限资源信息",
            notes = ""
            )
    public Result update(@ApiParam(name="权限资源信息对象",value="传入json格式",required=true)@RequestBody SysResource resource){
        if(resource.getResourcername() == null || resource.getResourcername() .length() == 0
                || resource.getResourcercode() == null || resource.getResourcercode().length() == 0){
            return Result.error("保存失败,存在特殊字符,请重新输入!");
        }
        //资源名称是否重复
        SysResource info = resourceService.queryObjectByName(resource.getAppid(), resource.getResourcername());
        if(info != null && !info.getResourceid().equals(resource.getResourceid())){
            return Result.error("所属系统已存在该资源名称!");
        }
        resourceService.update(resource);
        
        return Result.ok();
    }
    
    /**
     * 删除
     */
    @LogAction("平台管理,权限标识,权限标识删除,删除")
    @PostMapping("/delete")
    @RequiresPermissions("sys:resource:edit")
    @ApiOperation(
            value = "删除权限资源信息",
            notes = ""
            )
    public Result delete(@ApiParam(name="resourceids",value="权限资源信息Id",required=true)@RequestBody Long[] resourceids){
        resourceService.deleteBatch(resourceids);
        
        return Result.ok();
    }
}