1
2
3
4
5 package gboat2.web.action;
6
7 import gboat2.base.bridge.GboatAppContext;
8 import gboat2.base.bridge.exception.DefaultBusinessNestedException;
9 import gboat2.base.bridge.model.UserSession;
10 import gboat2.base.core.GBoatClassLoader;
11 import gboat2.base.core.annotation.Domain;
12 import gboat2.base.core.annotation.ListDomain;
13 import gboat2.base.core.annotation.Module;
14 import gboat2.base.core.annotation.Operation;
15 import gboat2.base.core.annotation.Operations;
16 import gboat2.base.core.annotation.Preference;
17 import gboat2.base.core.dao.QuerySupport;
18 import gboat2.base.core.logging.IBusinessLogService;
19 import gboat2.base.core.logging.Level;
20 import gboat2.base.core.web.BaseActionSupport;
21 import gboat2.base.core.web.JsonResult;
22 import gboat2.web.Activator;
23 import gboat2.web.Constants;
24 import gboat2.web.business.IAuthorityBusiness;
25 import gboat2.web.business.IGroupBusiness;
26 import gboat2.web.business.IResourceBusiness;
27 import gboat2.web.business.IRoleBusiness;
28 import gboat2.web.business.IShortcutBusiness;
29 import gboat2.web.model.Group;
30 import gboat2.web.model.Resource;
31 import gboat2.web.model.Role;
32 import gboat2.web.model.Shortcut;
33 import gboat2.web.model.ShortcutResourceVO;
34
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Enumeration;
38 import java.util.List;
39 import java.util.Map;
40
41 import org.apache.commons.lang3.StringUtils;
42 import org.apache.struts2.convention.annotation.ResultPath;
43 import org.osgi.framework.Bundle;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47
48
49
50
51
52
53
54
55
56 @Preference("/系统配置/快捷方式配置")
57 @Module(name = "快捷方式管理")
58 @Operations(value = { @Operation(name = "新增快捷方式", code = "add"), @Operation(name = "编辑", code = "edit"),
59 @Operation(name = "删除", code = "delete") })
60 @ResultPath("/content/shortcut")
61 @Domain(value = Shortcut.class)
62 @ListDomain(value = ShortcutResourceVO.class)
63 public class ShortcutAction extends BaseActionSupport {
64
65
66
67
68 private static final long serialVersionUID = 1L;
69
70 private final static String SUPER_PAHT = "/static/gboat2.web/data/super-shortcuts.json";
71
72 private final static Logger logger = LoggerFactory.getLogger(ShortcutAction.class.getName());
73
74 @Autowired
75 private IShortcutBusiness shortcutBusi;
76
77 @Autowired
78 private IBusinessLogService loggingService;
79
80 @Autowired
81 private IAuthorityBusiness authorityBusi;
82
83 @Autowired
84 private IGroupBusiness gropBusi;
85
86 @Autowired
87 private IRoleBusiness roleBusi;
88
89 @Autowired
90 private IResourceBusiness resourceBusi;
91
92 private String resId;
93
94 private String systemId;
95
96 protected void initList(Map<String, Object> params) {
97 params.put(QuerySupport.PARAM_PAGESIZE, -1);
98 String currLoginId = GboatAppContext.getUserSession().getLoginId();
99 if (Constants.SUPER.equals(currLoginId)) {
100 params.put("_userId_null", "");
101 } else {
102 params.put("_userId", GboatAppContext.getUserSession().getUserId());
103 }
104 }
105
106 protected void initSave() {
107 UserSession session = GboatAppContext.getUserSession();
108 Shortcut shortcut = (Shortcut) getModel();
109 String currLoginId = session.getLoginId();
110 if (!Constants.SUPER.equals(currLoginId)) {
111 Group group = gropBusi.findGroupByGroupCode(session.getGroupCode());
112 Role role = roleBusi.findRoleByRoleCode(session.getRoleCode());
113 shortcut.setGroupId(group.getGroupId());
114 shortcut.setRoleId(role.getRoleId());
115 shortcut.setUserId(session.getUserId());
116 }
117
118 String type = StringUtils.isEmpty(shortcut.getShortcutId()) ? "新增" : "编辑";
119 loggingService.log(Level.INFO, type, type + "快捷方式:" + shortcut.getName());
120 }
121
122
123 private List<Shortcut> getAllShortcutIcons() throws IOException, DefaultBusinessNestedException {
124 String theme = Constants.DEFAULT_THEME;
125 String pathPrefix = "static/gboat2.web/themes/" + theme + "/images/shortcuts";
126 List<Shortcut> list = new ArrayList<Shortcut>();
127
128 Enumeration<String> paths = Activator.LOCAL_BUNDLE.getEntryPaths(pathPrefix);
129 String path = "";
130 Shortcut cut;
131 while (paths.hasMoreElements()) {
132 path = (String) paths.nextElement();
133 if (path.matches(".*\\.(((?i)gif)|((?i)png))$")) {
134 cut = new Shortcut();
135 cut.setIconUrl(path);
136 list.add(cut);
137 }
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 return list;
168 }
169
170 public String getAllIcons() throws IOException, DefaultBusinessNestedException {
171 GboatAppContext.output(JsonResult.createSuccess(this.getAllShortcutIcons()));
172 return null;
173 }
174
175 public String addModule() {
176 return null;
177 }
178
179 protected void postDelete() {
180 Shortcut shortcut = (Shortcut) getModel();
181 loggingService.log(Level.INFO, "删除", "删除快捷方式:" + shortcut.getName());
182 }
183
184
185
186
187
188 public void menuTree() {
189 Resource root = null;
190 UserSession userSession = GboatAppContext.getUserSession();
191 String loginId = userSession.getLoginId();
192 if (loginId != null && "super".equals(loginId)) {
193
194 Bundle bundle = GBoatClassLoader.getInstance().getBundle(ShortcutAction.class.getPackage().getName());
195
196 try {
197 root = shortcutBusi.getSuperTree(bundle.getResource(SUPER_PAHT));
198 } catch (Exception e) {
199 logger.error(e.getMessage(), e.getCause());
200 }
201 } else {
202 Group group = gropBusi.findGroupByGroupCode(userSession.getGroupCode());
203 Role role = roleBusi.findRoleByRoleCode(userSession.getRoleCode());
204 String authForId = group.getGroupId() + "." + role.getRoleId();
205 if (StringUtils.isEmpty(this.resId)) {
206
207 if(authorityBusi.isAuthorityCustomize(authForId + "."+userSession.getUserId(),userSession.getSystemId())){
208 authForId = authForId + "."+userSession.getUserId();
209 }
210 root = this.shortcutBusi.findResourceTreeForRoleOfGroup(authForId,userSession.getSystemId());
211
212 } else {
213
214 if(authorityBusi.isAuthorityCustomize(authForId + "."+userSession.getUserId(),userSession.getSystemId())){
215 authForId = authForId + "."+userSession.getUserId();
216 root = this.shortcutBusi.findResourceTreeForRoleOfGroupForRes(authForId, authForId, false);
217 }else{
218 root = this.shortcutBusi.findResourceTreeForRoleOfGroupForRes(authForId, resId,true);
219 }
220
221 }
222 }
223 GboatAppContext.output(root);
224 }
225
226
227
228
229
230 public void shortcutMenuTree() {
231 Resource root = null;
232 UserSession userSession = GboatAppContext.getUserSession();
233 String loginId = userSession.getLoginId();
234 if (loginId != null && Constants.SUPER.equals(loginId)) {
235 root = this.resourceBusi.getResourcesTree(systemId);
236 } else {
237
238 Group group = gropBusi.findGroupByGroupCode(userSession.getGroupCode());
239 Role role = roleBusi.findRoleByRoleCode(userSession.getRoleCode());
240 String authForId = group.getGroupId() + "." + role.getRoleId();
241
242 root = this.shortcutBusi.findResourceTreeForRoleOfGroup(authForId, userSession.getSystemId());
243 }
244 GboatAppContext.output(root, response);
245 }
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 public String getResId() {
261 return resId;
262 }
263
264 public void setResId(String resId) {
265 this.resId = resId;
266 }
267
268 public String getSystemId() {
269 return systemId;
270 }
271
272 public void setSystemId(String systemId) {
273 this.systemId = systemId;
274 }
275
276 }