report.jsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ page import="org.springframework.jdbc.core.JdbcTemplate,cn.sinobest.framework.util.Util,cn.sinobest.framework.service.ReportService,cn.sinobest.framework.comm.iface.IReportService,cn.sinobest.framework.service.entities.ReportConfig,cn.sinobest.framework.util.DTOUtil,com.runqian.report4.usermodel.Context,cn.sinobest.framework.comm.transcation.DataSourceCallBack,cn.sinobest.framework.comm.transcation.IDataSourceCallBack,cn.sinobest.framework.comm.exception.AppException,com.runqian.report4.dataset.JNDIConnectionFactory,cn.sinobest.framework.util.ConfUtil,cn.sinobest.framework.comm.iface.IReportFeedback,cn.sinobest.framework.comm.iface.IReportResultSet,java.util.Map.Entry,java.sql.Connection,
  3. cn.sinobest.framework.service.json.JSONUtilities
  4. "%>
  5. <%@ taglib uri="/WEB-INF/runqianReport4.tld" prefix="rq"%>
  6. <%@include file="/jsp/framework/head.jsp"%>
  7. <%-- 下面的第一段都是判断报表跳转的逻辑,维护报表的时候无需关注,只需要关注第二段q<%--------------------------------------------------------------------------------------------%>
  8. <%--------------------- 第一段: 判断报表报表打印是否需要跳转到另外的报表服务器 ----------------------%>
  9. <%--------------------------------------------------------------------------------------------%>
  10. <%
  11. /**
  12. * part1. 判断是否要使用报表服务器,和获取报表服务器的URL
  13. */
  14. String isUseRepSer = "false";//是否使用报表服务器
  15. String repSerUrl = "";//报表服务器URL
  16. //如果IS_USE_REPORT_SERVER不为"true",则表示所有报表打印 不跳转
  17. isUseRepSer = ConfUtil.getParam("IS_USE_REPORT_SERVER","false").toLowerCase();
  18. if(!isUseRepSer.equals("true")){
  19. isUseRepSer = "false";
  20. }else{
  21. isUseRepSer = "true";
  22. }
  23. //如果REPORTURL为空,则表示所有报表打印 不跳转
  24. repSerUrl = ConfUtil.getParam("REPORTURL","");
  25. if("".equals(repSerUrl)){
  26. isUseRepSer = "false";
  27. repSerUrl = "";
  28. }
  29. if("true".equals(isUseRepSer)){
  30. String redirectUrl=ConfUtil.getDict("RPREDIRECTMAP",request.getServerName()+"."+request.getServerPort());
  31. if(redirectUrl!=null&&!"".equals(redirectUrl)){
  32. repSerUrl=redirectUrl;
  33. }
  34. }
  35. if("true".equals(isUseRepSer)){
  36. //如果aa10字典有配置该报表的打印,不管aa01配置如何,都以 aa10的配置为准。URL为空表表示不跳转,URL不为空表示跳转到配置的URL。
  37. Map<String, Map<String, String>> dict = null;
  38. ReportConfig reportConf = (ReportConfig)DTOUtil.getObject("reportConfig");
  39. try{
  40. dict = ConfUtil.getDictKeyItemCode("REPORTREDIRECT");
  41. }catch(Exception e){
  42. dict = null;
  43. }
  44. if(null != dict){
  45. Map<String,String> aa10ReportRedirectConf = dict.get(reportConf.getId());
  46. if(null != aa10ReportRedirectConf){
  47. String aa10ReportUrl = aa10ReportRedirectConf.get("AAA103");
  48. //如果在AA10表AAA103字段配置了URL,则跳转到该URL
  49. if(null != aa10ReportUrl && !"".equals(aa10ReportUrl)){
  50. isUseRepSer = "true";
  51. repSerUrl = aa10ReportUrl;
  52. }
  53. //如果在AA10表AAA103字段配置的URL为空,则不跳转。
  54. else{
  55. isUseRepSer = "false";
  56. repSerUrl = "";
  57. }
  58. }
  59. }
  60. }
  61. /**
  62. * part2. 在判断当前报表需要使用报表服务器的前提下,再判断当前服务器是否为报表服务器,如果是报表服务器则不跳转,否则跳转到报表服务器
  63. */
  64. String isJump = "false";
  65. if("true".equals(isUseRepSer) && !repSerUrl.equals("")){
  66. //当前服务器就是报表服务器,无需跳转
  67. if("true".equals(ConfUtil.getSysParamOnly("app.isReportServer","false").toLowerCase())){
  68. isJump = "false";
  69. }
  70. //当前服务器不是报表服务器,需要跳转
  71. else{
  72. isJump = "true";
  73. }
  74. }
  75. %>
  76. <%-- 不使用当前服务器,使用另外的报表服务器做打印 --%>
  77. <%if("true".equalsIgnoreCase(isJump)){%>
  78. <script>
  79. var href = location.href;
  80. var count = 0;
  81. var pos = -1;
  82. for(var i=0,len=href.length;i<len;i++){
  83. if('/'==href.charAt(i)){
  84. count++;
  85. }
  86. if(4 == count){
  87. pos = i;
  88. break;
  89. }
  90. }
  91. <%-- var curSerUrl = href.substring(0,pos); --%>
  92. var curQuery = href.substring(pos);
  93. <%--动态导入单点登陆所需JS--%>
  94. CFW.oComm.fnLoadScript({
  95. url:contextPath + "/js/comm/fw/encrypt.js",
  96. beforeFunc: function(){return null==document.getElementById("fwencrypt");},//返回true的时候才载入脚本
  97. afterFunc: function(script){
  98. if(null != script){
  99. script.id = "fwencrypt";
  100. }
  101. CFW.oComm.fnLoadScript({
  102. url:contextPath + "/js/comm/fw/encrypt2.js",
  103. beforeFunc: function(){return null==document.getElementById("fwencrypt2");},//返回true的时候才载入脚本
  104. afterFunc: function(script){
  105. if(null != script){
  106. script.id = "fwencrypt2";
  107. }
  108. loginRepSer();
  109. }
  110. });
  111. }
  112. });
  113. <%--单点登陆到指定报表服务器--%>
  114. function loginRepSer(){
  115. ssoLogin("<%=repSerUrl%>",readCookie("LOGINID"),getSsoUid(),
  116. function(jsonpdata){
  117. if(jsonpdata.FHZ<0){
  118. alert(jsonpdata.MSG);
  119. return;
  120. }else{
  121. redirect2RepSer();
  122. }
  123. }
  124. );
  125. }
  126. <%--跳转到指定报表服务器--%>
  127. function redirect2RepSer(){
  128. href = '<%=repSerUrl%>' + curQuery +"&t="+new Date();
  129. location.href = href;
  130. }
  131. </script>
  132. <%}%>
  133. <%--------------------------------------------------------------------------------------------%>
  134. <%--------------------- 第二段: 报表打印 ----------------------%>
  135. <%--------------------------------------------------------------------------------------------%>
  136. <%-- 使用当前服务器做打印 --%>
  137. <%if("false".equalsIgnoreCase(isJump)){
  138. //是否显示按钮 跟Globals.js内 reportGenerate 配合使用
  139. String FWBTNCLOSE =(String)request.getParameter("FWBTNCLOSE")+"";
  140. String FWBTNBACK =(String)request.getParameter("FWBTNBACK")+"";
  141. if(FWBTNCLOSE.equals("")||FWBTNCLOSE.equals("null")){FWBTNCLOSE="YES";}
  142. if(FWBTNBACK.equals("")||FWBTNBACK.equals("null")){FWBTNBACK="YES";}
  143. ReportConfig reportConfig =(ReportConfig)DTOUtil.getObject("reportConfig");
  144. Context context = new Context();
  145. request.setAttribute( "myContext", context );
  146. context.setParamValue("configId",reportConfig.getId());
  147. //拼入参串
  148. StringBuilder param=new StringBuilder();
  149. Map<String,String> jsonMap = new HashMap<String,String>();
  150. Map<String,Object> params = DTOUtil.getData();
  151. for(Entry<String,Object> entry:params.entrySet()){
  152. if("needDirectPrint".equals(entry.getKey())||
  153. "needSelectPrinter".equals(entry.getKey())){
  154. //去掉本模块辅助的参数,这些在报表中使用不到
  155. continue;
  156. }
  157. if(entry.getValue()==null){
  158. continue;
  159. }
  160. //准备json需要的map,这个用在回调函数里,作为额外的参数传递
  161. jsonMap.put(entry.getKey(),entry.getValue().toString());
  162. //把参数拼成name=value;name2=value2;.....的形式
  163. param.append(entry.getKey()).append("=").append(entry.getValue().toString()).append(";");
  164. }
  165. String needDirectPrint = "yes";//默认是直接打印
  166. if("false".equals( DTOUtil.getValue(" "))){
  167. needDirectPrint = "no";
  168. }
  169. String needSelectPrinter = "no";//默认是不弹出选择打印机的窗口
  170. if("false".equals( DTOUtil.getValue("needSelectPrinter"))){
  171. needSelectPrinter = "yes";
  172. }
  173. String needSaveAsExcel = "no";//默认是不显示"保存为EXCEL"
  174. if("true".equals(DTOUtil.getValue("needSaveAsExcel"))){
  175. needSaveAsExcel = "yes";
  176. }
  177. String needSaveAsWord = "no";//默认是不显示"保存为EXCEL"
  178. if("true".equals(DTOUtil.getValue("needSaveAsWord"))){
  179. needSaveAsWord = "yes";
  180. }
  181. String excelPageStyle ="1";
  182. if("false".equals(DTOUtil.getValue("excelPageStyle"))){//默认是按分页导出
  183. excelPageStyle = "0";
  184. }
  185. %>
  186. <table align=center >
  187. <tr>
  188. <td >
  189. <rq:html name="testRpt"
  190. reportFileName="<%=reportConfig.getTemplateName() %>"
  191. funcBarLocation="top"
  192. params="<%=param.toString() %>"
  193. contextName="myContext"
  194. generateParamForm="no"
  195. needDirectPrint="<%=needDirectPrint %>"
  196. needSelectPrinter="<%=needSelectPrinter %>"
  197. exceptionPage="/jsp/framework/error.jsp"
  198. savePrintSetup="yes"
  199. needPrint="yes"
  200. needSaveAsExcel="<%=needSaveAsExcel %>"
  201. needSaveAsWord="<%=needSaveAsWord %>"
  202. excelPageStyle="<%=excelPageStyle %>"
  203. >
  204. </rq:html>
  205. </td>
  206. </tr>
  207. </table>
  208. <% if(FWBTNBACK.equalsIgnoreCase("YES")){%>
  209. <p align="center">
  210. <hnisi:btn id="btnBack" value="返回" onclick="goback()" />
  211. </p>
  212. <%}%>
  213. <script type="text/javascript">
  214. function goback(){
  215. var referer = _getServerUrl(document.referrer).toLowerCase();
  216. var currentUrl = _getServerUrl(document.location.href).toLowerCase();
  217. if(referer == currentUrl){
  218. history.go(-1);
  219. }else{
  220. history.go(-2);
  221. }
  222. function _getServerUrl(url){
  223. var count = 0;
  224. var pos = 0;
  225. for(var i=0;i<url.length;i++){
  226. if(url.charAt(i) == "/"){
  227. count++;
  228. }
  229. if(count == 4){
  230. pos = i;
  231. break;
  232. }
  233. }
  234. return url.substring(0,pos);
  235. }
  236. }
  237. function runqian_printOver(){
  238. var paramsMap = <%=new JSONUtilities(JSONUtilities.BEAUTY_LOOK).parseObject(jsonMap)%>;
  239. paramsMap['configId'] = '<%=reportConfig.getId()%>';
  240. //回调函数
  241. new Service()
  242. .appendServices({
  243. serviceId:'reportService',
  244. method:'afterPrint',
  245. parameters:paramsMap
  246. }).sentAjax('回写打印数据',function(){
  247. //关闭弹出窗口
  248. //CFW.oWin.fnAlert('打印结束!');
  249. if(window.top == window){
  250. var href = window.location.href;
  251. window.open(href,"_self","");
  252. window.close();
  253. }
  254. });
  255. }
  256. $(function(){
  257. <% if(FWBTNCLOSE.equalsIgnoreCase("YES")){%>
  258. if(window.top==window){
  259. $('#btnBack').linkbutton({text:'关闭'}).click(function(){
  260. var href = window.location.href;
  261. window.open(href,"_self","");
  262. window.close();
  263. return false;
  264. });
  265. }
  266. <%}%>
  267. /*url中的.jsp换成.do否则会出异常*/
  268. if(window['testRpt_turnPageForm']!=null){
  269. window['testRpt_turnPageForm'].action=
  270. window['testRpt_turnPageForm'].action.
  271. replace('/report.jsp?','/report.do?');
  272. }
  273. });
  274. document.body.style.zoom = screen.width/900;
  275. $("a",$("div").get(0)).each(function(){
  276. if('打印' == this.innerText){
  277. this.innerText = '打印设置';
  278. return;
  279. }
  280. });
  281. </script>
  282. <% }%><%--if("false".equalsIgnoreCase(isUseRepSer)){--%>
  283. </body>
  284. </html>