ZhuDongming
2019-11-08 b284d078f196af80a105dc3bcb610d8ed37d9251
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
package com.moral.controller;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
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.RestController;
 
import com.moral.common.bean.PageBean;
import com.moral.common.bean.ResultBean;
import com.moral.entity.Role;
import com.moral.service.RoleService;
 
@RestController
@RequestMapping("role")
@CrossOrigin(origins = "*", maxAge = 3600)
public class RoleController {
 
    @Autowired
    RoleService roleService;
 
    @GetMapping("page-list")
    public PageBean pageList(PageBean pageBean) {
        return roleService.queryByPageBean(pageBean);
    }
 
    @GetMapping("count-by-example")
    public ResultBean<Integer> countByExample(PageBean pageBean){
        return  new ResultBean<Integer>(roleService.countByExample(pageBean));
    }
 
    @GetMapping("role-list")
    public PageBean getRoleList(PageBean pageBean) {
        return roleService.getRoleList(pageBean);
    }
 
    @PostMapping("add-or-modify")
    public ResultBean addOrModify(@RequestBody Role role) {
        roleService.addOrModify(role);
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        return resultBean;
    }
 
    @PostMapping("delete-by-ids")
    public ResultBean deleteByIds(@RequestBody Integer [] ids){
        roleService.deleteByIds(ids);
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        return resultBean;
    }
 
    @GetMapping("get-role-ids")
    public List<Integer> getRoleIds(int accountId){
        return roleService.getRoleIds(accountId);
    }
 
    @PostMapping("allot-role/{id}")
    public ResultBean allotRole(@PathVariable("id") Integer accountId, @RequestBody Integer [] roleIds){
        ResultBean resultBean = new ResultBean();
        if(accountId==null){
            resultBean.setCode(ResultBean.NO_PERMISSION);
            resultBean.setMessage("账户ID不能为null");
            return resultBean;
        }else{
            roleService.allotRole(accountId,roleIds);
            resultBean.setCode(ResultBean.SUCCESS);
        }
        return resultBean;
    }
 
}