c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
1
2
3
4
5
6
7
|
package com.objecteye.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.objecteye.entity.SyPrivilege;
import com.objecteye.entity.SyRole;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
8
9
10
|
import com.objecteye.service.RoleServices;
import com.objecteye.utils.UserTools;
import org.springframework.beans.factory.annotation.Autowired;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
11
12
13
|
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
14
15
16
|
import org.springframework.stereotype.Service;
import java.util.List;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
17
|
import java.util.stream.Collectors;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
18
19
20
21
22
|
@Service
public class RoleServicesImpl implements RoleServices {
@Autowired
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
23
|
private MongoTemplate mongoTemplate;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
24
25
26
|
@Override
public JSONObject rolePage(int currentpage, int pagevolume) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
27
28
|
List<SyRole> syRoles = mongoTemplate.find(new Query().limit(pagevolume).skip((currentpage - 1) * pagevolume), SyRole.class);
long count = mongoTemplate.count(new Query(), SyRole.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
29
30
31
32
33
34
35
|
JSONObject jsonObject = new JSONObject();
jsonObject.put("code", 200);
jsonObject.put("message", "success");
JSONArray rowOld = UserTools.getJSONArrayByList(syRoles);
JSONArray rowNew = new JSONArray();
for (int i = 0; i < rowOld.size(); i++) {
JSONObject jsonRole = rowOld.getJSONObject(i);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
36
|
String id = jsonRole.getString("id");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
37
|
/*通过id获取相应的权限*/
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
38
39
|
List<String> privilegeIdList = mongoTemplate.find(Query.query(Criteria.where("rid").is(id)), SyPrivilege.class)
.stream().map(SyPrivilege::getId).collect(Collectors.toList());
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
40
|
StringBuilder sb = new StringBuilder();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
41
42
|
for (String in : privilegeIdList) {
SyPrivilege syPrivilege = mongoTemplate.findOne(Query.query(Criteria.where("id").is(in)), SyPrivilege.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
43
44
45
46
47
48
49
50
51
52
53
54
55
|
sb.append(syPrivilege.getPrivilegeName()).append(",");
}
String substring = sb.toString().substring(0, sb.length() - 1);
jsonRole.put("jurisdiction", substring);
jsonRole.put("rolename", jsonRole.getString("roleName"));
jsonRole.put("createdate", jsonRole.getString("createDate"));
jsonRole.put("isdelete", jsonRole.getString("isDelete"));
jsonRole.remove("roleName");
jsonRole.remove("createDate");
jsonRole.remove("isDelete");
rowNew.add(jsonRole);
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
56
|
int total = (int) Math.ceil(count / (double) pagevolume);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
57
58
59
60
61
62
63
64
65
66
67
|
JSONObject data = new JSONObject();
data.put("total", total);
data.put("row", rowNew);
jsonObject.put("data", data);
return jsonObject;
}
@Override
public JSONObject roleDis() {
JSONObject jsonObject = new JSONObject();
try {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
68
69
|
List<SyRole> syRoles = mongoTemplate.find(new Query(), SyRole.class);
if (syRoles.size() > 0) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
jsonObject.put("code", 200);
jsonObject.put("message", "success");
JSONArray array = new JSONArray();
for (SyRole sr : syRoles) {
JSONObject kv = new JSONObject();
kv.put("name", sr.getRoleName());
kv.put("value", sr.getId());
array.add(kv);
}
jsonObject.put("data", array);
} else {
jsonObject.put("code", 201);
jsonObject.put("message", "列表信息错误");
jsonObject.put("date", null);
}
} catch (Exception e) {
jsonObject.put("code", 202);
jsonObject.put("message", "下拉列表失败");
jsonObject.put("date", null);
}
return jsonObject;
}
}
|