FunctionAction.java
4.69 KB
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
package com.cjs.cms.action.admin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.cjs.cms.dao.admin.FunctionDao;
import com.cjs.cms.dao.admin.RoleDao;
import com.cjs.cms.model.admin.FunctionInfo;
/**
* 权限操作
*
* @author kongmingke
*
*/
@RestController
@RequestMapping("/function")
public class FunctionAction {
@Autowired
private FunctionDao functionDao;
@Autowired
private RoleDao roleDao;
/**根据角色显示权限 */
@RequestMapping("/search")
public List<Map<String, Object>> search(@RequestParam Map<String, Object> params) {
List<FunctionInfo> fList = functionDao.search(null);
List<Integer> f_id = null;
if (params.get("roleId") != null) {
f_id = roleDao.getFidByRid(Integer.parseInt(params.get("roleId").toString()));
}
return createTree(fList, f_id, "0", "text", "pid", "id");
}
/**获取第一级目录列表*/
@RequestMapping("queryFolder")
public List<FunctionInfo> queryFolder() {
Map<String, Object> params = new HashMap<String, Object>();
params.put("parentId", 0);
return functionDao.search(params);
}
/** 树状显示 */
public List<Map<String, Object>> createTree(List<FunctionInfo> list, List<Integer> p,
String pidStart, String functionName,
String parentId, String id) {
List<Map<String, Object>> fList = new ArrayList<Map<String, Object>>();
for (FunctionInfo f : list) {
Map<String, Object> map = new HashMap<String, Object>();
String pid = f.getParentId().toString();
Object fid = f.getId();
String fName = f.getFunctionName();
map.put("id", fid);
map.put("text", fName);
if (pidStart.toString().equals(pid.toString().trim())) {
List<Map<String, Object>> childMap = createTree(list, p, fid.toString(), fName, pid,
id);
if (childMap.size() > 0) {
map.put("children", childMap);
} else {
if (p != null && p.contains(fid)) {
map.put("checked", true);
} else {
map.put("checked", false);
}
}
fList.add(map);
}
}
return fList;
}
/** 查询全部权限 */
@RequestMapping("/queryAll")
public List<FunctionInfo> queryAll() {
List<FunctionInfo> flist = functionDao.search(null);
List<FunctionInfo> list = functionDao.search(null);
List<FunctionInfo> functionList = new ArrayList<FunctionInfo>();
for (int i = 0; i < list.size(); i++) {
FunctionInfo parentFunction = new FunctionInfo();
if (list.get(i).getParentId() == 0) {
parentFunction.setId(flist.get(i).getId());
parentFunction.setFunctionName(flist.get(i).getFunctionName());
parentFunction.setFunctionDescription(flist.get(i).getFunctionDescription());
List<FunctionInfo> children = new ArrayList<FunctionInfo>();
for (FunctionInfo f2 : flist) {
if (list.get(i).getId().equals(f2.getParentId())) {
FunctionInfo f3 = new FunctionInfo();
f3.setId(f2.getId());
f3.setFunctionName(f2.getFunctionName());
f3.setFunctionDescription(f2.getFunctionDescription());
f3.setUrl(f2.getUrl());
f3.setParentId(f2.getParentId());
children.add(f3);
parentFunction.setChildren(children);
}
}
functionList.add(parentFunction);
}
}
return functionList;
}
/**添加或修改权限*/
@RequestMapping("/addOrUpdateFunction")
public void addFunction(FunctionInfo fInfo) {
if (fInfo.getId() != null) {
functionDao.updateFunction(fInfo);
} else {
functionDao.addFunction(fInfo);
}
}
/**删除权限*/
@RequestMapping("/deleteFunction")
public void deleteFunction(int id) {
functionDao.deleteFunction(id);
functionDao.delFunctionByPid(id);
roleDao.deleteByFunction(id);
}
}