1
2
3
4
5 package gboat2.web.business.impl;
6
7 import gboat2.base.core.cache.ICacheService;
8 import gboat2.base.core.service.BaseService;
9 import gboat2.web.Constants;
10 import gboat2.web.business.IDataLevelAuthorityBusiness;
11 import gboat2.web.model.DataLevelAuthority;
12 import gboat2.web.model.Resource;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Service;
19 import org.springframework.transaction.annotation.Transactional;
20
21
22
23
24
25
26 @Transactional
27 @Service
28 public class DataLevelAuthorityBusinessImpl extends BaseService implements IDataLevelAuthorityBusiness {
29
30 @Autowired
31 private ICacheService cacheSer;
32
33
34
35
36
37
38 @Override
39 public DataLevelAuthority findDataLevelAuthority(String groupId, String roleId, String resId) {
40 String[][] params = {
41 {DataLevelAuthority.class.getName()},
42 {"_groupId",groupId},
43 {"_roleId",roleId},
44 {"_resId",resId}
45 };
46 return (DataLevelAuthority) baseDAO.get(params);
47 }
48
49 @Override
50 public boolean deleteDataLevelAuthority(String groupId, String roleId, String resId) {
51 String hql = "delete from DataLevelAuthority where groupId = :groupId and roleId = :roleId and resId = :resId";
52 Map<String, Object> params = new HashMap<String, Object>();
53 params.put("groupId", groupId);
54 params.put("roleId", roleId);
55 params.put("resId", resId);
56 super.baseDAO.deleteByQuery(hql, params);
57 return true;
58 }
59
60 @Override
61 public boolean setDataLevelAuthority(String groupId, String roleId, String resId, String dataLevel) {
62
63 boolean flag1 = this.deleteDataLevelAuthority(groupId, roleId, resId);
64
65 boolean flag2 = this.insertDataLevelAuthority(groupId, roleId, resId, dataLevel);
66
67 Resource res = (Resource) super.get(Resource.class, resId);
68 this.cacheSer.remove(Constants.PRIORITY_CACHE_CATALOG, groupId + "." + roleId + "-" + res.getSystemId());
69 this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, groupId + "." + roleId + "-" + res.getSystemId());
70 return flag1 && flag2;
71 }
72
73 @Override
74 public boolean deleteDataLevelAuthority(String groupId, String roleId) {
75 String hql = "delete from DataLevelAuthority where groupId = :groupId and roleId = :roleId";
76 Map<String, Object> params = new HashMap<String, Object>();
77 params.put("groupId", groupId);
78 params.put("roleId", roleId);
79 super.baseDAO.deleteByQuery(hql, params);
80 return true;
81 }
82
83 @Override
84 public boolean deleteDataLevelAuthorityByGroupId(String groupId) {
85 String hql = "delete from DataLevelAuthority where groupId = :groupId";
86 Map<String, Object> params = new HashMap<String, Object>();
87 params.put("groupId", groupId);
88 super.baseDAO.deleteByQuery(hql, params);
89 return true;
90 }
91
92 @Override
93 public boolean deleteDataLevelAuthorityByRoleId(String roleId) {
94 String hql = "delete from DataLevelAuthority where roleId = :roleId";
95 Map<String, Object> params = new HashMap<String, Object>();
96 params.put("roleId", roleId);
97 super.baseDAO.deleteByQuery(hql, params);
98 return true;
99 }
100
101 @Override
102 public boolean insertDataLevelAuthority(String groupId, String roleId, String resId, String dataLevel) {
103 DataLevelAuthority auth = new DataLevelAuthority();
104 auth.setGroupId(groupId);
105 auth.setRoleId(roleId);
106 auth.setResId(resId);
107 auth.setDataLevel(dataLevel);
108 return super.save(auth);
109 }
110
111 @Override
112 public DataLevelAuthority findDataLevelAuthority(String groupId, String roleId, String resId, String userId) {
113 String[][] params = {
114 {DataLevelAuthority.class.getName()},
115 {"_groupId",groupId},
116 {"_roleId",roleId},
117 {"_resId",resId},
118 {"_userId",userId}
119 };
120 return (DataLevelAuthority) baseDAO.get(params);
121 }
122
123 @Override
124 public boolean deleteDataLevelAuthority(String groupId, String roleId, String userId, String resId) {
125 String hql = "delete from DataLevelAuthority where groupId = :groupId and roleId = :roleId and userId=:userId and resId = :resId";
126 Map<String, Object> params = new HashMap<String, Object>();
127 params.put("groupId", groupId);
128 params.put("roleId", roleId);
129 params.put("userId", userId);
130 params.put("resId", resId);
131 super.baseDAO.deleteByQuery(hql, params);
132 return true;
133 }
134
135 @Override
136 public boolean insertDataLevelAuthority(String groupId, String roleId, String userId, String resId, String dataLevel) {
137 DataLevelAuthority auth = new DataLevelAuthority();
138 auth.setGroupId(groupId);
139 auth.setRoleId(roleId);
140 auth.setUserId(userId);
141 auth.setResId(resId);
142 auth.setDataLevel(dataLevel);
143 return super.save(auth);
144 }
145
146 @Override
147 public boolean setDataLevelAuthority(String groupId, String roleId, String userId, String resId, String dataLevel) {
148
149 boolean flag1 = this.deleteDataLevelAuthority(groupId, roleId, userId, resId);
150
151 boolean flag2 = this.insertDataLevelAuthority(groupId, roleId, userId, resId, dataLevel);
152
153 Resource res = (Resource) super.get(Resource.class, resId);
154 String cacheKey = groupId + "." + roleId + "." + userId + "-" + res.getSystemId();
155 this.cacheSer.remove(Constants.PRIORITY_CACHE_CATALOG, cacheKey);
156 this.cacheSer.remove(Constants.MENU_TREE_CACHE_CATALOG, cacheKey);
157 return flag1 && flag2;
158 }
159
160 }