1
2
3
4
5 package gboat2.web.action;
6
7 import gboat2.base.core.web.BaseActionSupport;
8 import gboat2.base.core.web.JsonResultSupport;
9 import gboat2.base.bridge.model.UserSession;
10 import gboat2.base.bridge.GboatAppContext;
11 import gboat2.web.business.IRoleBusiness;
12 import gboat2.web.business.IWidgetAuthorityConfigBusiness;
13 import gboat2.web.model.Role;
14 import gboat2.web.service.IWidgetService;
15 import gboat2.web.util.WidgetServiceTracker;
16 import net.sf.json.JSONArray;
17 import net.sf.json.JSONObject;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired;
22
23
24
25
26
27
28
29
30
31 public class WidgetAction extends BaseActionSupport {
32
33 private static final long serialVersionUID = 1L;
34
35 protected final static Logger logger = LoggerFactory.getLogger(WidgetAction.class.getName());
36
37 private String serviceId;
38
39 private int count;
40
41 @Autowired
42 IRoleBusiness roleBusi;
43
44 @Autowired
45 IWidgetAuthorityConfigBusiness widgetService;
46
47 public void widgetMsgs() {
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 JSONArray msgs = null;
66
67 try {
68 IWidgetService widgetSer = WidgetServiceTracker.getWidgetService(serviceId);
69 if (null != widgetSer) {
70 msgs = widgetSer.fetchMsgs(GboatAppContext.getUserSession(), count);
71 }
72 } catch (Exception e) {
73 logger.error("获取widget消息出错", e);
74 }
75 JsonResultSupport.output(JsonResultSupport.wrap(msgs));
76 }
77
78
79 public void widgetsMeta() {
80 UserSession session = GboatAppContext.getUserSession();
81 JSONArray widgets = new JSONArray();
82 JSONObject widget = null;
83 IWidgetService[] services = WidgetServiceTracker.getWidgetServices();
84 try {
85 if (null != services) {
86 for (IWidgetService widgetSer : services) {
87 Role role = roleBusi.findRoleByRoleCode(session.getRoleCode());
88 if (widgetSer.hasMsg(session)
89 && widgetService.hasAuthorityOfCurrentWidget(session.getSystemId(), role.getRoleId(), widgetSer.getId())) {
90 widget = widgetSer.getWidgetConfig(session);
91 if (null == widget) {
92 widget = new JSONObject();
93 }
94
95
96 if (!widget.containsKey("url")) {
97 widget.put("url", "widget!widgetMsgs.do");
98 }
99
100
101 JSONObject params = widget.optJSONObject("params");
102 if (null == params) {
103 params = new JSONObject();
104 }
105 params.put("serviceId", widgetSer.getId());
106 widget.put("params", params);
107
108
109 widgets.add(widget);
110 }
111 }
112 }
113 } catch (Exception e) {
114 logger.error("请求Widget消息组件配置信息时出错!", e);
115 }
116 JsonResultSupport.output(JsonResultSupport.wrap(widgets));
117 }
118
119 public int getCount() {
120 return count;
121 }
122
123 public void setCount(int count) {
124 this.count = count;
125 }
126
127 public String getServiceId() {
128 return serviceId;
129 }
130
131 public void setServiceId(String serviceId) {
132 this.serviceId = serviceId;
133 }
134
135 }