View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-3-2 下午08:32:20
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   * @author tanxw
27   * @since jdk1.6
28   * @date 2012-9-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  		//		String str = "{success:true,data:[]}";
49  		//		//		try {
50  		//		//			ServiceReference refer = context
51  		//		//			        .getServiceReference("com.glodon.gbmp.tenderNotice.service.ITenderNoticeService");
52  		//		//			Object o = context.getService(refer);
53  		//		//			String t = o.getClass().getName();
54  		//		//			Method method = o.getClass().getMethod("getBidNoticeJsonListForGBoatWeb", null);
55  		//		//			str = (String) method.invoke(o, null);
56  		//		//			str = "{success:true,data:" + str + "}";
57  		//		//		} catch (Exception e) {
58  		//		//			str = "{success:true,data:[]}";
59  		//		//		}
60  		//		
61  		//		//str = "{success:true,data:[{'text':'公开自行后审','url':'tender-approve!preView.do?projectInfo.projectId=ff80808138dcc5080138dfab25020082&SID=ff80808138dcc5080138dfdbc6d20150','params':''},{'text':'公开委托后审','url':'tender-approve!preView.do?projectInfo.projectId=ff80808138dcc5080138dfb8a86700a2&SID=ff80808138dcc5080138dfe43dbf0160','params':''},{'text':'1111111111111111','url':'tender-approve!preView.do?projectInfo.projectId=ff80808138dcc5080138dfffb85201c1&SID=4028c4c738eb80e40138eb8b3fed0022','params':''}]}";
62  		//		
63  		//		JsonResultSupport.outputResult(str, response);
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  	//获取widget配置元数据信息
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  						//配置默认url
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 }