js实现关于分页的一种实现方式

项目中用到列表的地方很多,二页面列表的显示必然要求分页,
所以分页和查询几乎密不可分,如果说你不会分页查询数据,
那你基本上还属于菜鸟。

分页的原理很简单,从sql上看就是从哪一条开始,往后差几条。
所以sql只需要传2个参数,这只是原理罢了,关键是实现。
而实现的方法就多了去了,架构师干这个是小菜一碟。

在我的项目中,关于分页架构师已经写好了一个管理分页的类,
这个类与sql耦合,控制分页只需哟啊控制这个类的对象的参数,
说白了这个类就是管理上面sql中需要的那2个参数,无论怎么写
实质是一样的。

在定义HibernateTemplete是定义分页的查询方法,例如:

 

[java]  view plain copy
  1. public List queryNativeSQL(final String sql, final PaginationSupport ps) {    
  2.     return (List) execute(new HibernateCallback() {      
  3.             public Object doInHibernate(Session session) throws HibernateException {      
  4.                    try {      
  5.                        SQLQuery query = session.createSQLQuery(sql);  
  6.                        query.setFirstResult(ps.getStartIndex());  
  7.                        query.setMaxResults(ps.getCountOnEachPage());  
  8.                        return query.list();      
  9.                    } catch (RuntimeException e) {      
  10.                        log.error("query sql catch exception: " , e);      
  11.                        throw e;      
  12.                    }      
  13.             }      
  14.         });      
  15. }  


 

核心就是
query.setFirstResult(ps.getStartIndex());
query.setMaxResults(ps.getCountOnEachPage());

关于PaginationSupport ps就是管理这两个参数与分页其他参数的逻辑。

 

[java]  view plain copy
  1. package org.rd.framework.query.support;  
  2.   
  3. import java.io.Serializable;  
  4. import org.rd.framework.query.sort.SortCriterion;  
  5.   
  6. public class PaginationSupport implements Serializable {  
  7.     private static final long serialVersionUID = 1L;  
  8.     private static int DEFAULT_COUNT_ON_EACH_PAGE = 20;      
  9.     private int totalCount;  
  10.     private int startIndex;  
  11.     private int countOnEachPage;  
  12.       
  13.     // support field sort  
  14.     private boolean sortingEnabled = false// default  
  15.     private SortCriterion sorter = null;  
  16.       
  17.     public PaginationSupport() {  
  18.         this(DEFAULT_COUNT_ON_EACH_PAGE);  
  19.     }  
  20.   
  21.     /** 
  22.      * @param sortingEnabled default false 
  23.      */  
  24.     public PaginationSupport(boolean sortingEnabled) {  
  25.         this(DEFAULT_COUNT_ON_EACH_PAGE);  
  26.         this.sortingEnabled = sortingEnabled;  
  27.     }  
  28.       
  29.     public PaginationSupport(int countOnEachPage) {  
  30.         startIndex = 0;  
  31.         this.countOnEachPage = countOnEachPage < 1  
  32.             ? DEFAULT_COUNT_ON_EACH_PAGE  
  33.             : countOnEachPage;  
  34.     }  
  35.   
  36.     public PaginationSupport(int startIndex, int totalCount, int countOnEachPage) {  
  37.         this.startIndex = startIndex;  
  38.         this.totalCount = totalCount;  
  39.         this.countOnEachPage = countOnEachPage;  
  40.     }  
  41.   
  42.     public void setStartIndex(int startIndex) {  
  43.         this.startIndex = startIndex;  
  44.     }  
  45.   
  46.     public void setCountOnEachPage(int countOnEachPage) {  
  47.         this.countOnEachPage = countOnEachPage;  
  48.     }  
  49.   
  50.     public int getTotalCount() {  
  51.         return totalCount;  
  52.     }  
  53.   
  54.     public int getEndIndex() {  
  55.         int endIndex = getStartIndex() + countOnEachPage;  
  56.         return endIndex > totalCount ? totalCount : endIndex;  
  57.     }  
  58.   
  59.     public int getStartIndex() {  
  60.         if (startIndex > totalCount) {  
  61.             return totalCount;  
  62.         } else if (startIndex < 0) {  
  63.             return 0;  
  64.         } else {  
  65.             return startIndex;  
  66.         }  
  67.     }  
  68.   
  69.     public int getNextIndex() {  
  70.         int[] nextStartIndexes = getNextStartIndexes();  
  71.         if (nextStartIndexes == null) {  
  72.             return getTotalCount();  
  73.         } else {  
  74.             return nextStartIndexes[0];  
  75.         }  
  76.     }  
  77.   
  78.     public int getPreviousIndex() {  
  79.         int[] previousIndexes = getPreviousStartIndexes();  
  80.         if (previousIndexes == null) {  
  81.             return getStartIndex();  
  82.         } else {  
  83.             return previousIndexes[previousIndexes.length - 1];  
  84.         }  
  85.     }  
  86.   
  87.     public int[] getNextStartIndexes() {  
  88.         int index = getEndIndex();  
  89.         if (index == totalCount) {  
  90.             return null;  
  91.         }  
  92.         int count = (totalCount - index) / countOnEachPage;  
  93.         if ((totalCount - index) % countOnEachPage > 0) {  
  94.             count++;  
  95.         }  
  96.         int result[] = new int[count];  
  97.         for (int i = 0; i < count; i++) {  
  98.             result[i] = index;  
  99.             index += countOnEachPage;  
  100.         }  
  101.   
  102.         return result;  
  103.     }  
  104.   
  105.     public int[] getPreviousStartIndexes() {  
  106.         int index = getStartIndex();  
  107.         if (index == 0) {  
  108.             return null;  
  109.         }  
  110.         int count = index / countOnEachPage;  
  111.         if (index % countOnEachPage > 0) {  
  112.             count++;  
  113.         }  
  114.         int result[] = new int[count];  
  115.         for (int i = count - 1; i > 0; i--) {  
  116.             index -= countOnEachPage;  
  117.             result[i] = index;  
  118.         }  
  119.   
  120.         return result;  
  121.     }  
  122.       
  123.     public int getCountOnEachPage() {  
  124.         return countOnEachPage;  
  125.     }  
  126.   
  127.     public void setTotalCount(int totalCount) {  
  128.         this.totalCount = totalCount;  
  129.           
  130.         validate();  
  131.     }  
  132.   
  133.     private void validate() {  
  134.         if (startIndex >= totalCount) {  
  135.             int i = getTotalCount() % countOnEachPage;  
  136.             startIndex = totalCount - i;  
  137.         }  
  138.         if (startIndex < 0) {  
  139.             startIndex = 0;  
  140.         }  
  141.     }  
  142.       
  143.     /** 
  144.      * Return the number of pages for the current query. 
  145.      */  
  146.     public int getPageCount() {  
  147.         int pages = getTotalCount() / countOnEachPage;  
  148.         int i = getTotalCount() % countOnEachPage;  
  149.         if (i > 0) {  
  150.             pages++;  
  151.         }  
  152.         if (getTotalCount() == 0) {  
  153.             pages = 1;  
  154.         }  
  155.         return pages;  
  156.     }  
  157.       
  158.     /** 
  159.      * Return the current page number. 
  160.      * Page numbering starts with 1. 
  161.      */  
  162.     public int getPage() {  
  163.         int page = startIndex / countOnEachPage;  
  164.         return page + 1;  
  165.     }  
  166.       
  167.     public void setPage(int page) {  
  168.         startIndex = page < 1 ? 0 : (page - 1) * countOnEachPage;  
  169.     }  
  170.       
  171.     public boolean isSortingEnabled() {  
  172.         return sortingEnabled;  
  173.     }  
  174.   
  175.     public void setSortingEnabled(boolean sortingEnabled) {  
  176.         this.sortingEnabled = sortingEnabled;  
  177.     }  
  178.   
  179.     public SortCriterion getSorter() {  
  180.         return sorter;  
  181.     }  
  182.   
  183.     public void setSorter(SortCriterion sorter) {  
  184.         this.sorter = sorter;  
  185.     }  
  186.   
  187.     public String toString() {  
  188.         return "PaginationSupport["  
  189.             + "totalCount=" + totalCount  
  190.             + ", startIndex="+ startIndex  
  191.             + ", pageCount=" + getPageCount()  
  192.             + ", page=" + getPage()  
  193.             + ", sorter=" + sorter  
  194.             + "]";  
  195.     }  
  196.       
  197. }  


 


底层的方法已经具备,剩下的就是要在业务层管理传参和在
显示层管理页面展示就可以了。

在页面的展示,

 


我的思路是对一个div,定义好id,根据这个id找到它,然后再里面
写html展示分页。

greenpage.js(使用到jquerty,在使用本js文件时需要同时引入jquery)

[javascript]  view plain copy
  1. function GreenPage(divid,pageHref,currPage,pageCount,validHref){  
  2.     this.divid=divid;  
  3.     this.pageHref=pageHref;  
  4.     this.currPage=currPage;  
  5.     this.pageCount=pageCount;  
  6.     this.validHref=validHref;  
  7.   
  8. };  
  9. GreenPage.prototype.getCurrPageInfo=function ()  
  10. {  
  11.    return "GreenPageInfo---"+this.divid+":"+this.pageHref+":"+this.currPage+":"+this.pageCount;  
  12. };  
  13. GreenPage.prototype.getDivInfo=function ()  
  14. {  
  15.    return "getDivInfo---"+$("#"+this.divid).html();  
  16. };  
  17. GreenPage.prototype.currPageClick=function (currPage)  
  18. {  
  19.     this.currPage=currPage;  
  20.   
  21.     document.getElementById(divid).innerHTML="";  
  22.     this.makePage();  
  23. };  
  24. GreenPage.prototype.makePage=function ()  
  25. {  
  26.       
  27.       
  28.     $("#"+this.divid).addClass("greenpage");  
  29.   
  30.     if(this.currPage=="1"){  
  31.           
  32.     }else{  
  33.         if(this.validHref=="0"){  
  34.             writeHtml(this.divid,"<a href=\"#\"  οnclick=\"pageClickFunc('1')\">首页</a> ");  
  35.         }else{  
  36.             writeHtml(this.divid,"<a href=\""+this.pageHref+"?targetPageNum=1\"  οnclick=\"pageClickFunc('1')\">首页</a> ");  
  37.         }  
  38.           
  39.     }  
  40.     if(this.currPage=="1"){  
  41.           
  42.     }else{  
  43.         var tempnum=(this.currPage-1>0)?(this.currPage-1):1;  
  44.         if(this.validHref=="0"){  
  45.             writeHtml(this.divid,"<a href=\"#\"  οnclick=\"pageClickFunc('"+tempnum+"')\">上一页</a> ");  
  46.         }else{  
  47.             writeHtml(this.divid,"<a href=\""+this.pageHref+"?targetPageNum="+tempnum+"\"  οnclick=\"pageClickFunc('"+tempnum+"')\">上一页</a> ");  
  48.         }  
  49.     }  
  50.       
  51.   
  52.     var start=0;  
  53.     var end=0;  
  54.     if(this.pageCount<=10){  
  55.          start=1;  
  56.          end=this.pageCount;  
  57.        }else{  
  58.          if(this.currPage<=5){  
  59.              start=1;  
  60.              end=10;  
  61.            }else if(this.currPage>=this.pageCount-5){  
  62.              start=this.currPage-(10-(this.pageCount-this.currPage))+1;  
  63.              end=this.pageCount;  
  64.            }else{  
  65.              start=this.currPage-4;  
  66.              end=(this.currPage+5<=this.pageCount)?(this.currPage+5):this.pageCount;  
  67.            }  
  68.        }  
  69.       
  70.     for(var i=start;i<=end;i++){  
  71.          if(i==this.currPage){  
  72.             writeHtml(this.divid," <span  class=\"current\" id=\""+this.divid+"Selected\">["+i+"] </span> ");  
  73.               
  74.          }else{  
  75.             if(this.validHref=="0"){  
  76.                 writeHtml(this.divid,"<a href=\"#\"   οnclick=\"pageClickFunc('"+i+"')\">"+i+"</a> ");  
  77.             }else{  
  78.                 writeHtml(this.divid,"<a href=\""+this.pageHref+"?targetPageNum="+i+"\"   οnclick=\"pageClickFunc('"+i+"')\">"+i+"</a> ");  
  79.             }  
  80.               
  81.          }  
  82.        }  
  83.       
  84.     if(this.currPage==this.pageCount){  
  85.            
  86.     }else{  
  87.         var pcurr=parseInt(this.currPage);  
  88.         var pcoun=parseInt(this.pageCount);  
  89.        var tempnum=((pcurr+1)<pcoun)?(pcurr+1):pcoun;  
  90.         if(this.validHref=="0"){  
  91.             writeHtml(this.divid,"<a href=\"#\"   οnclick=\"pageClickFunc('"+tempnum+"')\">下一页</a> ");  
  92.         }else{  
  93.             writeHtml(this.divid,"<a href=\""+this.pageHref+"?targetPageNum="+tempnum+"\"   οnclick=\"pageClickFunc('"+tempnum+"')\">下一页</a> ");  
  94.         }  
  95.     }  
  96.     if(this.currPage==this.pageCount){  
  97.        
  98.     }else{  
  99.         if(this.validHref=="0"){  
  100.             writeHtml(this.divid,"<a href=\"#\"  οnclick=\"pageClickFunc('"+this.pageCount+"')\">尾页</a> ");  
  101.         }else{  
  102.             writeHtml(this.divid,"<a href=\""+this.pageHref+"?targetPageNum="+this.pageCount+"\"  οnclick=\"pageClickFunc('"+this.pageCount+"')\">尾页</a> ");  
  103.         }  
  104.           
  105.     }  
  106.       
  107.       
  108. };  
  109.   
  110. GreenPage.prototype.reMakePage=function (divid,pageHref,currPage,pageCount,validHref)  
  111. {  
  112.     this.divid=divid;  
  113.     this.pageHref=pageHref;  
  114.     this.currPage=currPage;  
  115.     this.pageCount=pageCount;  
  116.     this.validHref=validHref;  
  117.   
  118.     document.getElementById(divid).innerHTML="";  
  119.     this.makePage();  
  120. };  
  121.   
  122. function writeHtml(divid,str){  
  123.     //document.getElementById(divid).innerHTML=document.getElementById(divid).innerHTML+str;  
  124.     $("#"+divid).html($("#"+divid).html()+str);  
  125. }  


 


逻辑很简单,可以说算是分页里面的最简单版本了,没有多余的其他控制逻辑,
值根据参数负责显示。
有一个reMakePage方法需要注意,这个是根据参数重新画分页,因为你没点一次
分页的链接,分页都需要变化(你点的那一页选中,有没有上一页,首页等),
所以每点一次必然重画分页,这个方法就是重画分页,在ajax回调方法里要调用这个
方法,当然要给正确的参数,才能保证正确显示。


greenpage.css(没有用到图片,所以样式很容易改,公用性比较强)

 

[javascript]  view plain copy
  1. DIV.greenpage {  
  2. PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM:10px; MARGIN: 3px; PADDING-TOP: 17px; TEXT-ALIGN: center; font-size:12px;   
  3. }   
  4. DIV.greenpage A {  
  5.     BORDER-RIGHT: #ddd 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #ddd 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #ddd 1px solid; COLOR: #88af3f; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #ddd 1px solid; TEXT-DECORATION: none   
  6. }  
  7. DIV.greenpage A:hover {   
  8. BORDER-RIGHT: #85bd1e 1px solid; BORDER-TOP: #85bd1e 1px solid; BORDER-LEFT: #85bd1e 1px solid; COLOR: #638425; BORDER-BOTTOM: #85bd1e 1px solid; BACKGROUND-COLOR: #f1ffd6  
  9. }  
  10. DIV.greenpage A:active {   
  11. BORDER-RIGHT: #85bd1e 1px solid; BORDER-TOP: #85bd1e 1px solid; BORDER-LEFT: #85bd1e 1px solid; COLOR: #638425; BORDER-BOTTOM: #85bd1e 1px solid; BACKGROUND-COLOR: #f1ffd6   
  12. }   
  13. DIV.greenpage SPAN.current {   
  14. BORDER-RIGHT: #b2e05d 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #b2e05d 1px solid; PADDING-LEFT: 5px;   
  15. FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; BORDER-LEFT: #b2e05d 1px solid; COLOR: #fff; MARGIN-RIGHT: 2px; PADDING-TOP: 2px;   
  16. BORDER-BOTTOM: #b2e05d 1px solid; BACKGROUND-COLOR: #b2e05d  
  17. }  
  18. DIV.greenpage SPAN.disabled {   
  19. BORDER-RIGHT: #f3f3f3 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #f3f3f3 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; BORDER-LEFT: #f3f3f3 1px solid;  
  20. COLOR: #ccc; MARGIN-RIGHT: 2px; PADDING-TOP: 2px; BORDER-BOTTOM: #f3f3f3 1px solid   
  21. }  


 

项目中使用的一个实例:

insummary.jsp

[html]  view plain copy
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"%>  
  2. <%@ taglib uri="/struts-tags" prefix="s"%>  
  3. <%@ taglib uri="/WEB-INF/component.tld" prefix="cx"%>  
  4. <%@ taglib uri="/WEB-INF/greenpage.tld" prefix="page"%>  
  5. <%@ page import="java.util.*" %>  
  6. <%@ page import="org.hd.util.ReportUtil" %>  
  7. <%@ page import="org.rd.framework.query.support.PaginationSupport" %>  
  8. <%  
  9.     String path = request.getContextPath();  
  10. %>  
  11. <%  
  12. String xmldata="";  
  13. if(request.getAttribute("InSummaryData")!=null){  
  14.     xmldata=(String)request.getAttribute("InSummaryData");  
  15. }  
  16. String isqueryed="";  
  17. if(request.getAttribute("isqueryed")!=null){  
  18.     isqueryed=(String)request.getAttribute("isqueryed");  
  19. }  
  20. List tablelist=null;  
  21. if(request.getAttribute("InSummaryTableData")!=null){  
  22.     tablelist=(List)request.getAttribute("InSummaryTableData");  
  23. }  
  24.   
  25. PaginationSupport pageset=null;  
  26. if(request.getAttribute("pageset")!=null){  
  27.     pageset=(PaginationSupport)request.getAttribute("pageset");  
  28. }else{  
  29.     pageset=new PaginationSupport(0,0,20);  
  30. }  
  31.   
  32. String pathUrl=path+"/report/reportInSummary.action";  
  33. %>  
  34. <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  35. <html xmlns="http://www.w3.org/1999/xhtml">  
  36. <head>  
  37. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  38.      <title>Single Series Column 2D Chart</title>  
  39. <script src="<%=path%>/script/jquery-1.7.1.js" type="text/javascript"></script>  
  40. <link href="<%=path%>/resource/hd/css/style2.css" rel="stylesheet" type="text/css" />  
  41.   
  42.   
  43. <link href="<%=path%>/script/plugin/FusionCharts_Evaluation/Gallery/assets/ui/css/style.css" rel="stylesheet" type="text/css" />  
  44. <link href="<%=path%>/script/plugin/FusionCharts_Evaluation/Gallery/assets/prettify/prettify.css" rel="stylesheet" type="text/css" />  
  45.   
  46. <script type="text/javascript" src="<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/FusionCharts.js"></script>  
  47. <script type="text/javascript" src="<%=path%>/script/plugin/FusionCharts_Evaluation/Gallery/assets/ui/js/json2.js"></script>  
  48. <script type="text/javascript" src="<%=path%>/script/plugin/FusionCharts_Evaluation/Gallery/assets/prettify/prettify.js"></script>  
  49. <script type="text/javascript" src="<%=path%>/script/plugin/FusionCharts_Evaluation/Gallery/assets/ui/js/lib.js" ></script>  
  50.   
  51. <script src="<%=path%>/script/plugin/My97DatePicker/WdatePicker.js" type="text/javascript"></script>  
  52.   
  53. <script src="<%=path%>/resource/tool/hometab/Style/menu.js" type="text/javascript"></script>  
  54. <link rel="stylesheet" href="<%=path%>/resource/tool/hometab/Style/default.css" type="text/css" />  
  55. <script src="<%=path%>/script/hd/greenpage.js" type="text/javascript"></script>  
  56. <link rel="stylesheet" href="<%=path%>/script/hd/greenpage.css" type="text/css" />  
  57.   
  58.   
  59. <script type="text/javascript" src="<%=path%>/script/hd/greenpage.js"></script>  
  60. <link href="<%=path%>/script/hd/greenpage.css" rel="stylesheet" type="text/css" />  
  61.   
  62. </script>  
  63. <script type="text/javascript">   
  64. var divpage=null;  
  65. $(document).ready(function(){  
  66.     divpage=new GreenPage('divpage','',1,1,'0');  
  67.     divpage.makePage();  
  68. });  
  69.   
  70. </script>  
  71. </head>  
  72.   
  73. <body style=" overflow-y:scroll;">  
  74. <input type="hidden" id="path" value="<%=path%>" />  
  75. <input type="hidden" id="xmldata" value='<%=xmldata%>' />  
  76. <input type="hidden" id="isqueryed" value='<%=isqueryed%>' />  
  77.   
  78. <div style="width:100%;height:10px"></div>  
  79. <h3 style="text-align: center;vertical-align:bottom;padding: 0px,0px,5px,0px; margin: 0px,0px,5px,0px; font-size:14px;color: #0c212b; ">  
  80. 报表系统--呼入汇总</h3>  
  81.   
  82. <div style="width:100%;height:10px"></div>  
  83. <table width="100%" border="0">  
  84.      <tr>  
  85.        <td style="width:100%;">  
  86.             <div >  
  87.             <table>  
  88.               <tr style=" margin: 8px,0px,5px,0px;">  
  89.                  <td style="width:10%"></td>  
  90.                   <td style="width:20%;align:center" id="fromdatetd"><p><font color="#401c44">开始日期: </font><input type="text" id="fromdate"  class="Wdate" onClick="WdatePicker()"></p></td>  
  91.                  <td style="width:20%;align:center" id="todatetd"><p><font color="#401c44">结束日期: </font><input type="text" id="todate"  class="Wdate" onClick="WdatePicker()"></p></td>  
  92.                    
  93.                  <td style="width:5%;align:center"></td>  
  94.                   
  95.                  <td style="width:30%;">  
  96.              <select id="ritypebox"  name="ritypebox"  style="width: 100px; height: 25px;font-size:14px; color:#401c44;">  
  97.    <option value='ttian' selected>按日期统计</option>  
  98.   <option value='dnian' >按年份对比</option>  
  99.   <option value='djidu' >按季度对比</option>  
  100.   <option value='dyuefen'>按月份对比</option>  
  101.   <option value='dtian'>按日期对比</option>  
  102. </select>  
  103.                
  104.                  </td>  
  105.                   <td style="width:5%"><input type="button" id="chaxun" onclick="chaxun()" value="查询"></td>  
  106.               </tr>  
  107.             </table>  
  108.             </div>  
  109.        </td>  
  110.      </tr>  
  111.      <tr>  
  112.        <td style="width:100%;align:center">  
  113.                        
  114.                        
  115. <div id="tablelist" >  
  116.     <table style="margin : 0px 0px 0px 0px;position: relative;left: 0px;top: 0px;  
  117.     width="100%"  height="100%" border="0" cellspacing="0" cellpadding="0" id="box_mid">  
  118.       <tr>  
  119.         <td class="right"><!--列表-->  
  120.   
  121.           <div class="divline2" >  
  122.           <table width="1100px" border="0" cellspacing="0" cellpadding="0" class="tables2">  
  123.               <tr >  
  124.                 <th width="8%">日期</th>  
  125.                 <th width="8%">坐席总数</th>  
  126.                 <th width="8%">呼入总数</th>  
  127.                 <th width="8%">总失败次数</th>  
  128.                 <th width="8%">咨询次数</th>  
  129.   
  130.                 <th width="8%">转移次数 </th>  
  131.                 <th width="8%">总通话时长</th>  
  132.                 <th width="8%">平均通话时长</th>  
  133.                 <th width="8%">平均振铃次数</th>  
  134.                 <th width="8%">平均振铃时长</th>  
  135.               </tr>  
  136.             </table>  
  137.           </div>  
  138.  <div style="height:200px; overflow-y:none;width:100%;">  
  139.             <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table4" id="list">  
  140.                 
  141. <div id="listdata">  
  142.               
  143.             <tr>  
  144.                 <td width="8%"></td>  
  145.                 <td width="8%"></td>  
  146.                 <td width="8%"></td>  
  147.                 <td width="8%"></td>  
  148.                 <td width="8%"></td>  
  149.                   
  150.                 <td width="8%"></td>  
  151.                 <td width="8%"></td>  
  152.                 <td width="8%"></td>  
  153.                 <td width="8%"></td>  
  154.                 <td width="9%"></td>  
  155.                   
  156.               </tr>  
  157.     </div>          
  158.           </table>  
  159.             
  160.           <!--列表END--></td>  
  161.       </tr>  
  162.     </table>  
  163.           <div id="divpage" style="align:center"></div>  
  164.           </div>         
  165.    </div>               
  166.                        
  167.        </td>  
  168.      </tr>  
  169.      <tr>  
  170.        <td style="width:100%">  
  171.        </td>  
  172.      </tr>  
  173.      <tr>  
  174.        <td style="width:100%">  
  175.          
  176.        </td>  
  177.      </tr>  
  178. </table>  
  179.   
  180.   
  181.   
  182.   
  183.         <table  style="width:100%;align:center">  
  184.            <tr>  
  185.               <td style="width:100%;">  
  186.                <div id="chartdiv11" style="align:center"></div>  
  187.               </td>  
  188.            </tr>  
  189.            <tr>  
  190.               <td style="width:100%;">  
  191.                <div id="chartdiv12" style="align:center"></div>  
  192.               </td>  
  193.            </tr>  
  194.            <tr>  
  195.               <td style="width:100%;">  
  196.                <div id="chartdiv13" style="align:center"></div>  
  197.               </td>  
  198.            </tr>  
  199.         </table>  
  200.   
  201.   
  202.          
  203.         <table>  
  204.            <tr>  
  205.               <td style="width:50%">  
  206.               <div id="chartdiv21" style="display:none" align="center"></div>  
  207.       
  208.               </td>  
  209.               <td style="width:50%">  
  210.               <div id="chartdiv22" style="display:none" align="center"></div>  
  211.       
  212.               </td>  
  213.            </tr>  
  214.              <tr>  
  215.               <td style="width:50%">  
  216.               <div id="chartdiv23" style="display:none" align="center"></div>  
  217.       
  218.               </td>  
  219.               <td style="width:50%">  
  220.               <div id="chartdiv24" style="display:none" align="center"></div>  
  221.       
  222.               </td>  
  223.            </tr>  
  224.            </tr>  
  225.              <tr>  
  226.               <td style="width:50%">  
  227.               <div id="chartdiv25" style="display:none" align="center"></div>  
  228.       
  229.               </td>  
  230.               <td style="width:50%">  
  231.               </td>  
  232.            </tr>  
  233.         </table>  
  234.       
  235.      </body>  
  236.  </html>  
  237.  <script type="text/javascript" src="temp/insummary.js" ></script>  
  238.    <script type="text/javascript" src="temp/insummary2.js" ></script>  
  239.           
  240. <script type="text/javascript">  
  241. var path=document.getElementById("path").value;  
  242. var isqueryed=document.getElementById("isqueryed").value;  
  243. var xmldata=document.getElementById("xmldata").value;  
  244.   
  245. if (GALLERY_RENDERER && GALLERY_RENDERER.search(/javascript|flash/i)==0)  FusionCharts.setCurrentRenderer(GALLERY_RENDERER);   
  246.   
  247.   
  248. var chart11 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/Column3D.swf", "ChartId11", "560", "400", "0", "0");  
  249. chart11.setXMLData(dataString11);  
  250. chart11.render("chartdiv11");  
  251.   
  252. var chart12 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSColumn3D.swf", "ChartId12", "560", "400", "0", "0");  
  253. chart12.setXMLData(dataString12);  
  254. chart12.render("chartdiv12");  
  255.   
  256.   
  257.   
  258. var chart13 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/Column3D.swf", "ChartId13", "560", "400", "0", "0");  
  259. chart13.setXMLData( dataString13 );  
  260. chart13.render("chartdiv13");  
  261.   
  262. //if (GALLERY_RENDERER && GALLERY_RENDERER.search(/javascript|flash/i)==0)  FusionCharts.setCurrentRenderer(GALLERY_RENDERER);   
  263. var chart21 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSLine.swf", "ChartId21", "560", "400", "0", "0");  
  264. chart21.setXMLData( dataString21 );  
  265. chart21.render("chartdiv21");  
  266.   
  267. var chart22 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSLine.swf", "ChartId22", "560", "400", "0", "0");  
  268. chart22.setXMLData( dataString22 );  
  269. chart22.render("chartdiv22");  
  270.   
  271. var chart23 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSLine.swf", "ChartId23", "560", "400", "0", "0");  
  272. chart23.setXMLData( dataString23 );  
  273. chart23.render("chartdiv23");  
  274.   
  275. var chart24 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSLine.swf", "ChartId24", "560", "400", "0", "0");  
  276. chart24.setXMLData( dataString24 );  
  277. chart24.render("chartdiv24");  
  278.   
  279. var chart25 = new FusionCharts("<%=path%>/script/plugin/FusionCharts_Evaluation/Charts/MSLine.swf", "ChartId25", "560", "400", "0", "0");  
  280. chart25.setXMLData( dataString25 );  
  281. chart25.render("chartdiv25");  
  282.   
  283.   
  284. $("#ritypebox").change( function() {  
  285.       // 这里可以写些验证代码  
  286.     var tt=getRitypeValueBox();  
  287.     var vv=$("#ritypebox").val();   
  288.       if($.trim(vv)=="dnian"){  
  289.           reNewMy97DatePicker("yyyy");  
  290.           chooseone('d');  
  291.       }else if($.trim(vv)=="djidu"){  
  292.         var hh1="<p>年份: <input type=\"text\" id=\"fromdate\"  class=\"Wdate\" onClick=\"WdatePicker({dateFmt:'yyyy'})\"></p>";  
  293.            
  294.         var hh2="季度:<select id=\"todate\"  name=\"todate\">"  
  295.               +"<option value='1' >第一季度</option><option value='2' >第二季度</option>"+  
  296.               "<option value='3'>第三季度</option>"+  
  297.               "<option value='4'>第四季度</option>"+  
  298.             "</select>";  
  299.           $("#fromdatetd").html(hh1);  
  300.           $("#todatetd").html(hh2);  
  301.           chooseone('d');  
  302.       }else if($.trim(vv)=="dyuefen"){  
  303.           reNewMy97DatePicker("yyyy-MM");  
  304.           chooseone('d');  
  305.       }else if($.trim(vv)=="dtian"){  
  306.           reNewMy97DatePicker("yyyy-MM-dd");  
  307.           chooseone('d');  
  308.       }else if($.trim(vv)=="ttian"){  
  309.           reNewMy97DatePicker("yyyy-MM-dd");  
  310.           chooseone('t');  
  311.       }  
  312.         
  313. });  
  314.   
  315. function reNewMy97DatePicker(fmt){  
  316.     var hh1="<p>开始日期: <input type=\"text\" id=\"fromdate\"  class=\"Wdate\" onClick=\"WdatePicker({dateFmt:'"+fmt+"'})\"></p>";  
  317.      var hh2="<p>结束日期: <input type=\"text\" id=\"todate\"  class=\"Wdate\" onClick=\"WdatePicker({dateFmt:'"+fmt+"'})\"></p>";  
  318.       $("#fromdatetd").html(hh1);  
  319.       $("#todatetd").html(hh2);  
  320. }  
  321. function getRitypeValueBox() {    
  322.     var checkText=$("#ritypebox").find("option:selected").text();   
  323.       return checkText;  
  324. }    
  325.   
  326. function chooseone(t){  
  327.     if(t=="t"){  
  328.         $("#tablelist").show();  
  329.          $("#chartdiv11").show();  
  330.          $("#chartdiv12").show();  
  331.          $("#chartdiv13").show();  
  332.            
  333.          $("#chartdiv21").hide();  
  334.          $("#chartdiv22").hide();  
  335.          $("#chartdiv23").hide();  
  336.          $("#chartdiv24").hide();  
  337.          $("#chartdiv25").hide();  
  338.            
  339.     }else{  
  340.         $("#tablelist").hide();  
  341.         $("#chartdiv11").hide();  
  342.         $("#chartdiv12").hide();  
  343.         $("#chartdiv13").hide();  
  344.           
  345.          $("#chartdiv21").show();  
  346.          $("#chartdiv22").show();  
  347.          $("#chartdiv23").show();  
  348.          $("#chartdiv24").show();  
  349.          $("#chartdiv25").show();  
  350.     }  
  351. }  
  352. //查询  
  353. function chaxun(){  
  354.     var datetype=$.trim($("#ritypebox").val());  
  355.     var date1=$("#fromdate").val();  
  356.     var date2=$("#todate").val();  
  357.     if($.trim(date1)==""&&$.trim(date2)==""){  
  358.         alert("请选择查询条件!");  
  359.     }else{  
  360.         var urlpath=path+'/report/judgeIsTwoRightDate.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;  
  361.         $.ajax({  
  362.                type: "POST",  
  363.                url: urlpath,  
  364.                success: validateBack  
  365.             });  
  366.     }  
  367. }  
  368.   
  369. function validateBack(msg){  
  370.      var mm=$.trim(msg);  
  371.      if(mm=="NO"){  
  372.          alert("开始日期不能大于结束日期!");  
  373.      }else{  
  374.             var datetype=$.trim($("#ritypebox").val());  
  375.             var date1=$("#fromdate").val();  
  376.             var date2=$("#todate").val();  
  377.             //对比还是统计  
  378.               
  379.             if(datetype=="ttian"){  
  380.                 var urlpath=path+'/report/rptInSummaryAll.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;  
  381.                 $.ajax({  
  382.                        type: "POST",  
  383.                        url: urlpath,  
  384.                        success: chaxunBackDealData,  
  385.                        dataType:"json"  
  386.                     });  
  387.             }else{  
  388.                 var urlpath=path+'/report/rptInSummaryCompare.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;  
  389.                 $.ajax({  
  390.                        type: "POST",  
  391.                        url: urlpath,  
  392.                        success: chaxunCompareBackDealData,  
  393.                        dataType:"json"  
  394.                     });  
  395.             }  
  396.       
  397.      }  
  398. }  
  399.   
  400. function chaxunBackDealData(data){  
  401.     //var str=eval('('+data+')');   
  402.     //alert(data.all.page.currPage);  
  403.       
  404.     var page=data.all.page;  
  405.     var listdata=data.all.listdata;  
  406.     var dataString11=data.all.dataString11.data;  
  407.     var dataString12=data.all.dataString12.data;  
  408.     var dataString13=data.all.dataString13.data;  
  409.       
  410.     var datetype=$.trim($("#ritypebox").val());  
  411.     var date1=$("#fromdate").val();  
  412.     var date2=$("#todate").val();  
  413.     var url=path+'/report/rptInSummaryPage.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;  
  414.     divpage.reMakePage('divpage',url,page.currPage,page.pageCount,'0');  
  415.     if(dataString11=="nodata"){  
  416.         alert("结果集无数据,请选择其它条件!");  
  417.     }else{  
  418.         chart11.setXMLData(dataString11);  
  419.         chart12.setXMLData(dataString12);  
  420.         chart13.setXMLData(dataString13);  
  421.     }  
  422.       
  423.       
  424.       
  425.   
  426. var tablehtml="";  
  427.     for(var i=0;i<listdata.length;i++){  
  428.         //alert(listdata[i].agent_count);  
  429.         var agent_count=listdata[i].agent_count;  
  430.         var avg_long_time=listdata[i].avg_long_time;  
  431.         var avg_ring_count=listdata[i].avg_ring_count;  
  432.         var avg_ring_time=listdata[i].avg_ring_time;  
  433.         var fail_count=listdata[i].fail_count;  
  434.           
  435.         var sdf_date=listdata[i].sdf_date;  
  436.         var sum_consult_count=listdata[i].sum_consult_count;  
  437.         var sum_long_time=listdata[i].sum_long_time;  
  438.         var sum_transfer_count=listdata[i].sum_transfer_count;  
  439.         var voice_count=listdata[i].voice_count;  
  440.         var htmlstr="<tr>";  
  441.         htmlstr+="<td width=\"8%\">"+sdf_date+"</td>";  
  442.           htmlstr+="<td width=\"8%\">"+agent_count+"</td>";  
  443.           htmlstr+="<td width=\"8%\">"+voice_count+"</td>";  
  444.           htmlstr+="<td width=\"8%\">"+fail_count+"</td>";  
  445.           htmlstr+="<td width=\"8%\">"+sum_consult_count+"</td>";  
  446.   
  447.           htmlstr+="<td width=\"8%\">"+sum_transfer_count+"</td>";  
  448.           htmlstr+="<td width=\"8%\">"+sum_long_time+"</td>";  
  449.           htmlstr+="<td width=\"8%\">"+avg_long_time+"</td>";  
  450.           htmlstr+="<td width=\"8%\">"+avg_ring_count+"</td>";  
  451.           htmlstr+="<td width=\"9%\">"+avg_ring_time+"</td>";  
  452.         htmlstr+="</tr>";  
  453.         tablehtml+=htmlstr;  
  454.     }  
  455.     $("#list").html(tablehtml);  
  456. }  
  457.   
  458. function chaxunCompareBackDealData(data){  
  459.     var dataString21=data.all.dataString21.data;  
  460.     var dataString22=data.all.dataString22.data;  
  461.     var dataString23=data.all.dataString23.data;  
  462.     var dataString24=data.all.dataString24.data;  
  463.     var dataString25=data.all.dataString25.data;  
  464.     //alert(dataString21);  
  465.     if(dataString21=="nodata"){  
  466.         alert("结果集无数据,请选择其它条件!");  
  467.     }else{  
  468.         chart21.setXMLData(dataString21);  
  469.         chart22.setXMLData(dataString22);  
  470.         chart23.setXMLData(dataString23);  
  471.         chart24.setXMLData(dataString24);  
  472.         chart25.setXMLData(dataString25);  
  473.     }  
  474.       
  475. }  
  476. function pageClickFunc(page){  
  477.     //alert(divpage.getDivInfo());  
  478.     var datetype=$.trim($("#ritypebox").val());  
  479.     var date1=$("#fromdate").val();  
  480.     var date2=$("#todate").val();  
  481. var urlpath=path+'/report/rptInSummaryPage.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype+"&targetPageNum="+page;  
  482. $.ajax({  
  483.        type: "POST",  
  484.        url: urlpath,  
  485.        success: chaxunPageBackDealData,  
  486.        dataType:"json"  
  487.     });  
  488. }  
  489.   
  490. function chaxunPageBackDealData(data){  
  491.       
  492.     var page=data.all.page;  
  493.     var listdata=data.all.listdata;  
  494.       
  495.     var datetype=$.trim($("#ritypebox").val());  
  496.     var date1=$("#fromdate").val();  
  497.     var date2=$("#todate").val();  
  498.     var url=path+'/report/rptInSummaryPage.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;  
  499.     divpage.reMakePage('divpage',url,page.currPage,page.pageCount,'0');  
  500.       
  501.     //alert(page.currPage+"-----"+page.pageCount+"--"+listdata);  
  502.     var tablehtml="";  
  503.         for(var i=0;i<listdata.length;i++){  
  504.             //alert(listdata[i].agent_count);  
  505.             var agent_count=listdata[i].agent_count;  
  506.             var avg_long_time=listdata[i].avg_long_time;  
  507.             var avg_ring_count=listdata[i].avg_ring_count;  
  508.             var avg_ring_time=listdata[i].avg_ring_time;  
  509.             var fail_count=listdata[i].fail_count;  
  510.               
  511.             var sdf_date=listdata[i].sdf_date;  
  512.             var sum_consult_count=listdata[i].sum_consult_count;  
  513.             var sum_long_time=listdata[i].sum_long_time;  
  514.             var sum_transfer_count=listdata[i].sum_transfer_count;  
  515.             var voice_count=listdata[i].voice_count;  
  516.             var htmlstr="<tr>";  
  517.             htmlstr+="<td width=\"8%\">"+sdf_date+"</td>";  
  518.               htmlstr+="<td width=\"8%\">"+agent_count+"</td>";  
  519.               htmlstr+="<td width=\"8%\">"+voice_count+"</td>";  
  520.               htmlstr+="<td width=\"8%\">"+fail_count+"</td>";  
  521.               htmlstr+="<td width=\"8%\">"+sum_consult_count+"</td>";  
  522.   
  523.               htmlstr+="<td width=\"8%\">"+sum_transfer_count+"</td>";  
  524.               htmlstr+="<td width=\"8%\">"+sum_long_time+"</td>";  
  525.               htmlstr+="<td width=\"8%\">"+avg_long_time+"</td>";  
  526.               htmlstr+="<td width=\"8%\">"+avg_ring_count+"</td>";  
  527.               htmlstr+="<td width=\"9%\">"+avg_ring_time+"</td>";  
  528.             htmlstr+="</tr>";  
  529.             tablehtml+=htmlstr;  
  530.         }  
  531.         $("#list").html(tablehtml);  
  532. }  
  533. /*  
  534. var xmlurl=path+'/business/changeComeUserInfo.action?jobNumber='+cusid2;  
  535.           
  536.         $.ajax({  
  537.                type: "POST",  
  538.                url: urlpath,  
  539.                success: function(msg){  
  540.                  var mm=$.trim(msg);  
  541.                  if(mm=="NO"){  
  542.                      //alert("NO");  
  543.                  }else{  
  544.                     changeUser(mm);  
  545.                  }  
  546.                }  
  547.             });  
  548. */  
  549. </script>  


 


关于分页的使用,有几个地方:

var divpage=null;
$(document).ready(function(){
 divpage=new GreenPage('divpage','',1,1,'0');
 divpage.makePage();
});
divpage要拿到方法外面,因为后面刷新数据,需要这个对象,
初始化方法如上。

<div id="divpage" style="align:center"></div>
对这个div话分页


在ajax回调方法里要有
var url=path+'/report/rptInSummaryPage.action?fromdate='+date1+'&todate='+date2+'&datetype='+datetype;
divpage.reMakePage('divpage',url,page.currPage,page.currPage,'0');

这个就是为了重新画分页currPage,currPage是我用json返回的参数,这个你在后台自己
拼好在这里能取到就可以。


整体的思路就是这样,我的完整实例如下:
(逻辑有些复杂,因为不是为了分页专门写的例子,是项目中的实例)

insummary.jsp如上,
RptInSummaryAction.java

[java]  view plain copy
  1. package org.hd.report.action;  
  2.   
  3. import java.io.PrintWriter;  
  4. import java.util.List;  
  5.   
  6. import javax.servlet.http.HttpServletRequest;  
  7. import javax.servlet.http.HttpServletResponse;  
  8.   
  9. import org.apache.struts2.ServletActionContext;  
  10. import org.hd.report.model.GreenPageVo;  
  11. import org.hd.report.service.ReportService;  
  12. import org.hd.report.service.RptService;  
  13. import org.rd.framework.common.container.ContainerManager;  
  14. import org.rd.framework.query.support.PaginationSupport;  
  15. import org.rd.framework.struts.action.CommonAction;  
  16.   
  17. import com.opensymphony.xwork2.ActionContext;  
  18.   
  19. //呼入汇总  
  20. public class RptInSummaryAction  extends CommonAction{  
  21.     private RptService rptService = (RptService)ContainerManager.getComponent(RptService.BEAN_ID);  
  22.     private int targetPageNum;//目标页  
  23.     private PaginationSupport pageset=new PaginationSupport();  
  24.     private GreenPageVo greenpage=new GreenPageVo();//分页的设置开关  
  25.     public String rptInSummaryAll() throws Exception{  
  26.           
  27.         ActionContext ctx = ActionContext.getContext();  
  28.         HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);   
  29.         HttpServletRequest request  = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);   
  30.         response.setCharacterEncoding("UTF-8");  
  31.         PrintWriter out = response.getWriter();  
  32.         String fromdate="";  
  33.         String todate="";  
  34.         String datetype="";//下拉框5个参数  
  35.           
  36.         if(request.getParameter("fromdate")==null||request.getParameter("fromdate").trim().equals("")){  
  37.         }else{  
  38.             fromdate=request.getParameter("fromdate").trim();  
  39.         }  
  40.         if(request.getParameter("todate")==null||request.getParameter("todate").trim().equals("")){  
  41.         }else{  
  42.             todate=request.getParameter("todate").trim();  
  43.         }  
  44.         if(request.getParameter("datetype")==null||request.getParameter("datetype").trim().equals("")){  
  45.         }else{  
  46.             datetype=request.getParameter("datetype").trim();  
  47.         }  
  48.         getGreenpage().setEachItemsOfPage(5);  
  49.         String xmlData=rptService.getAllDataForInSummary(fromdate, todate, datetype,getGreenpage());  
  50.           
  51.         out.println(xmlData);  
  52.         return NONE;  
  53.     }  
  54.     public String rptInSummaryPage() throws Exception{  
  55.           
  56.         ActionContext ctx = ActionContext.getContext();  
  57.         HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);   
  58.         HttpServletRequest request  = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);   
  59.         response.setCharacterEncoding("UTF-8");  
  60.         PrintWriter out = response.getWriter();  
  61.         String fromdate="";  
  62.         String todate="";  
  63.         String datetype="";//下拉框5个参数  
  64.         String targetPageNum="";//目标页  
  65.           
  66.         if(request.getParameter("targetPageNum")==null||request.getParameter("targetPageNum").trim().equals("")){  
  67.         }else{  
  68.             targetPageNum=request.getParameter("targetPageNum").trim();  
  69.             getGreenpage().setCurrPage(Integer.valueOf(targetPageNum));  
  70.         }  
  71.         if(request.getParameter("fromdate")==null||request.getParameter("fromdate").trim().equals("")){  
  72.         }else{  
  73.             fromdate=request.getParameter("fromdate").trim();  
  74.         }  
  75.         if(request.getParameter("todate")==null||request.getParameter("todate").trim().equals("")){  
  76.         }else{  
  77.             todate=request.getParameter("todate").trim();  
  78.         }  
  79.         if(request.getParameter("datetype")==null||request.getParameter("datetype").trim().equals("")){  
  80.         }else{  
  81.             datetype=request.getParameter("datetype").trim();  
  82.         }  
  83.         //设置分页  
  84.         getGreenpage().setEachItemsOfPage(5);  
  85.         String xmlData=rptService.getPageJsonForInSummary(fromdate, todate, datetype,getGreenpage());  
  86.           
  87.         out.println(xmlData);  
  88.         return NONE;  
  89.     }  
  90.     //对比查询  
  91.     public String rptInSummaryCompare() throws Exception{  
  92.           
  93.         ActionContext ctx = ActionContext.getContext();  
  94.         HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);   
  95.         HttpServletRequest request  = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);   
  96.         response.setCharacterEncoding("UTF-8");  
  97.         PrintWriter out = response.getWriter();  
  98.         String fromdate="";  
  99.         String todate="";  
  100.         String datetype="";//下拉框5个参数  
  101.           
  102.         if(request.getParameter("fromdate")==null||request.getParameter("fromdate").trim().equals("")){  
  103.         }else{  
  104.             fromdate=request.getParameter("fromdate").trim();  
  105.         }  
  106.         if(request.getParameter("todate")==null||request.getParameter("todate").trim().equals("")){  
  107.         }else{  
  108.             todate=request.getParameter("todate").trim();  
  109.         }  
  110.         if(request.getParameter("datetype")==null||request.getParameter("datetype").trim().equals("")){  
  111.         }else{  
  112.             datetype=request.getParameter("datetype").trim();  
  113.         }  
  114.         String xmlData=rptService.getCompareDataForInSummary(fromdate, todate, datetype);  
  115.           
  116.         out.println(xmlData);  
  117.         return NONE;  
  118.     }  
  119.     public String execute() throws Exception{  
  120.         return SUCCESS;  
  121.     }  
  122.   
  123.     public int getTargetPageNum() {  
  124.         return targetPageNum;  
  125.     }  
  126.   
  127.     public PaginationSupport getPageset() {  
  128.         return pageset;  
  129.     }  
  130.   
  131.     public void setTargetPageNum(int targetPageNum) {  
  132.         this.targetPageNum = targetPageNum;  
  133.     }  
  134.   
  135.     public void setPageset(PaginationSupport pageset) {  
  136.         this.pageset = pageset;  
  137.     }  
  138.     public GreenPageVo getGreenpage() {  
  139.         return greenpage;  
  140.     }  
  141.     public void setGreenpage(GreenPageVo greenpage) {  
  142.         this.greenpage = greenpage;  
  143.     }  
  144.   
  145. }  

GreenPageVo.java
管理传参,但不控制分页逻辑。
真正管理分页参数传到sql的是PaginationSupport,
因为传参过程只是传递,不需要逻辑,有逻辑的反而会把参数
传丢(因为它判断参数之间关系,你穿过去的不对,它就给你改正,这样参数就传丢了)

[java]  view plain copy
  1. package org.hd.report.model;  
  2.   
  3. import org.rd.framework.query.support.PaginationSupport;  
  4.   
  5. public class GreenPageVo {  
  6.     private int currPage=0;  
  7.     private int pageCount=0;  
  8.     private int eachItemsOfPage=5;  
  9.       
  10.     public int getCurrPage() {  
  11.         return currPage;  
  12.     }  
  13.     public int getPageCount() {  
  14.         return pageCount;  
  15.     }  
  16.     public void setCurrPage(int currPage) {  
  17.         this.currPage = currPage;  
  18.     }  
  19.     public void setPageCount(int pageCount) {  
  20.         this.pageCount = pageCount;  
  21.     }  
  22.     public int getEachItemsOfPage() {  
  23.         return eachItemsOfPage;  
  24.     }  
  25.     public void setEachItemsOfPage(int eachItemsOfPage) {  
  26.         this.eachItemsOfPage = eachItemsOfPage;  
  27.     }  
  28.       
  29.       
  30. }  


 

 

action中有两个请求,一个是查询总数据的数据,包括分页数据;
,另一个是只查询分页列表数据的请求。

实现的底层方法(包括数据查询,拼装,返回)
RptServiceImpl.java

[java]  view plain copy
  1. package org.hd.report.service.impl;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.HashMap;  
  5. import java.util.List;  
  6. import java.util.Map;  
  7.   
  8. import org.hd.report.model.GreenPageVo;  
  9. import org.hd.report.model.resultvo.InDetailResult;  
  10. import org.hd.report.model.resultvo.InsummaryResult;  
  11. import org.hd.report.service.RptService;  
  12. import org.hd.util.ReportUtil;  
  13. import org.rd.framework.dao.impl.CommonServiceImpl;  
  14. import org.rd.framework.query.support.PaginationSupport;  
  15.   
  16. public class RptServiceImpl extends CommonServiceImpl implements RptService {  
  17.   
  18.     // 点击查询,呼入汇总insummary.sql  
  19.     public String getAllDataForInSummary(String fromdate, String todate,  
  20.             String datetype,GreenPageVo page) {  
  21.         String jsonData = "";  
  22.         List list = new ArrayList();  
  23.   
  24.         String sql = "select vo.* " + " ,con.sum_consult_count  "  
  25.                 + " ,con.sum_transfer_count  " + "  from  " + " ( "  
  26.                 + "   select " + "   sdf_date  "  
  27.                 + "   ,count(distinct a.agent_id) agent_count "  
  28.                 + "   ,count(voice_id) voice_count"  
  29.                 + "   ,sum(decode(a.start_time,null,1,'',1,0)) fail_count"  
  30.                 + "   ,avg(ring_long_time)/60 avg_ring_time"  
  31.                 + "   ,avg(decode(voice_id,null,0,1))/60 avg_ring_count"  
  32.                 + "   ,sum(long_time)/60 sum_long_time "  
  33.                 + "   ,avg(long_time)/60 avg_long_time " + "   from  "  
  34.                 + "   ( " + "     select  "  
  35.                 + " substr(ring_time,0,10) sdf_date "  
  36.                 + "  , t.*   from hd_agent_voice_seq t   " + "  where 1=1  ";  
  37.         if (fromdate != null && !fromdate.trim().equals("")) {  
  38.             sql += "   and t.ring_time>='"  
  39.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  40.                             true, todate) + "'  ";  
  41.         }  
  42.         if (todate != null && !todate.trim().equals("")) {  
  43.             sql += " and t.ring_time<='"  
  44.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  45.                             false, todate) + "' ";  
  46.         }  
  47.         sql += "  and t.voice_direct_id='0'  "  
  48.                 + "   ) a  "  
  49.                 + "  group by sdf_date "  
  50.                 + " ) vo, "  
  51.                 + " ( "  
  52.                 + "    select  "  
  53.                 + " zc.sdf_consult_date "  
  54.                 + " ,sum(decode(zc.consult_start_time,null,0,'',0,1)) sum_consult_count  "  
  55.                 + " ,sum(decode(zc.transfer_flag,null,0,'',0,0,0,1)) sum_transfer_count "  
  56.                 + " ,sum(decode(zc.conference_start_time,null,0,'',0,1)) sum_conference_count  "  
  57.                 + " ,sum(consult_long_time)/60 sum_consult_time "  
  58.                 + " ,sum(conference_long_time)/60 sum_consult_time "  
  59.                 + " from  "  
  60.                 + " ( "  
  61.                 + " select za.*,substr(consult_start_time,0,10) sdf_consult_date,zb.voice_id bvoice_id  "  
  62.                 + "  from hd_consult_log za , hd_agent_voice_seq zb  "  
  63.                 + "  where za.voice_id=zb.voice_id(+)  ";  
  64.         if (fromdate != null && !fromdate.trim().equals("")) {  
  65.             sql += "  and za.consult_start_time>='"  
  66.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  67.                             true, todate) + "'  ";  
  68.         }  
  69.         if (todate != null && !todate.trim().equals("")) {  
  70.             sql += "   and za.consult_start_time<='"  
  71.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  72.                             false, todate) + "' ";  
  73.         }  
  74.         sql += "  ) zc  " + "  group by sdf_consult_date " + " ) con  "  
  75.                 + "  where vo.sdf_date=con.sdf_consult_date(+)  "  
  76.                 + "  order by vo.sdf_date ";  
  77.         System.out.println("getAllListForInSummary--" + sql);  
  78.         list = this.queryNativeSQL(sql);  
  79.         jsonData = this.getAllJsonForInSummaryByList(list,page);  
  80.         return jsonData;  
  81.     }  
  82.   
  83.     // 列表,分页,报表 的数据  
  84.     public String getAllJsonForInSummaryByList(List list,GreenPageVo page) {  
  85.         String res = "";  
  86.         // "page":{"currPage":"6","pageCount":"67"}  
  87.         String pageJson = "";  
  88.         // [{"agent_count":"12","avg_long_time":"345"},{}]  
  89.         String listJson = "\"listdata\":[";  
  90.   
  91.         String dataString11 = "";  
  92.         String dataString12 = "";  
  93.         String dataString13 = "";  
  94.         String rptJson11 = "<chart caption='呼入总数 ' palette='2' xAxisName='' yAxisName='单位:个' "  
  95.                 + "formatNumberScale='0' numberPrefix='' labeldisplay='ROTATE' slantLabels='1'"  
  96.                 + " sNumberSuffix=' pcs.' showLabels='1' showValues='1' labelDisplay='STAGGER'>";  
  97.         String rptJson11Set = "";  
  98.   
  99.         String rptJson12 = "<chart caption='平均值比对' XAxisName='' palette='2' animation='1' "  
  100.                 + "formatNumberScale='0' numberPrefix='' showValues='1' numDivLines='4' "  
  101.                 + "legendPosition='BOTTOM'>";  
  102.         String rptJson12categories = "<categories>";  
  103.         String rptJson12dataset1 = "<dataset seriesName='平均振铃时长'>";  
  104.         String rptJson12dataset2 = "<dataset seriesName='平均通话时长'>";  
  105.   
  106.         String rptJson13 = "<chart caption='呼损率' palette='2' formatNumberScale='0' xAxisName=''"  
  107.                 + " yAxisName='单位:百分比' numberSuffix='%' numberPrefix='' labeldisplay='ROTATE' "  
  108.                 + "slantLabels='1' sNumberSuffix=' pcs.' showValues='1' labelDisplay='STAGGER'>";  
  109.         String rptJson13set = "";  
  110.         if (list != null) {  
  111.             // 分页显示数据  
  112.             pageJson = "\"page\":{\"currPage\":\"1\",\"pageCount\":\""  
  113.                     + (ReportUtil.getPageCountByDivide(list.size(), page.getEachItemsOfPage())) + "\"}";  
  114.             int f = 1;  
  115.             boolean dataset = false;  
  116.             for (int i = 0; i < list.size(); i++) {  
  117.                 Object[] o1 = (Object[]) list.get(i);  
  118.                 if (o1 != null && o1.length >= 10) {  
  119.                     String sdf_date = ReportUtil.objectToString(o1[0]);  
  120.                     String agent_count = ReportUtil.objectToString(o1[1]);  
  121.                     agent_count=ReportUtil.getNumberFormatForCount(agent_count);  
  122.                     String voice_count = ReportUtil.objectToString(o1[2]);  
  123.                     voice_count=ReportUtil.getNumberFormatForCount(voice_count);  
  124.                     String fail_count = ReportUtil.objectToString(o1[3]);  
  125.                     fail_count=ReportUtil.getNumberFormatForCount(fail_count);  
  126.                     String avg_ring_time = ReportUtil.objectToString(o1[4]);  
  127.   
  128.                     String avg_ring_count = ReportUtil.objectToString(o1[5]);  
  129.                     avg_ring_count=ReportUtil.getNumberFormatForCount(avg_ring_count);  
  130.                     String sum_long_time = ReportUtil.objectToString(o1[6]);  
  131.                     String avg_long_time = ReportUtil.objectToString(o1[7]);  
  132.                     String sum_consult_count = ReportUtil.objectToString(o1[8]);  
  133.                     sum_consult_count=ReportUtil.getNumberFormatForCount(sum_consult_count);  
  134.                     String sum_transfer_count = ReportUtil  
  135.                             .objectToString(o1[9]);  
  136.                     sum_transfer_count=ReportUtil.getNumberFormatForCount(sum_transfer_count);  
  137.                     // 列表数据  
  138.                     InsummaryResult is = new InsummaryResult(sdf_date,  
  139.                             agent_count, voice_count, fail_count,  
  140.                             avg_ring_time, avg_ring_count, sum_long_time,  
  141.                             avg_long_time, sum_consult_count,  
  142.                             sum_transfer_count);  
  143.                     // {"agent_count":"12","avg_long_time":"345","avg_ring_count":"","avg_ring_time":"","fail_count":"","sdf_date":"","sum_consult_count":"","sum_long_time":"","sum_transfer_count":"","voice_count":""}  
  144.                     String isJson = ReportUtil.getJsonFromObject(is);  
  145.                     if(i<page.getEachItemsOfPage()){  
  146.                         if (f == 1) {  
  147.                             listJson += isJson;  
  148.                         } else {  
  149.                             listJson += "," + isJson;  
  150.                         }  
  151.                     }  
  152.                       
  153.                     f++;  
  154.                     // 报表dataString11的数据  
  155.                     rptJson11Set += "<set label='" + sdf_date + "' value='"  
  156.                             + voice_count + "' />";  
  157.                     // 报表dataString12的数据  
  158.                     rptJson12categories += "<category label='" + sdf_date  
  159.                             + "' />";  
  160.                     rptJson12dataset1 += "<set value='" + avg_ring_time  
  161.                             + "' />";  
  162.                     rptJson12dataset2 += "<set value='" + avg_long_time  
  163.                             + "' />";  
  164.                     // 报表dataString13的数据  
  165.                     rptJson13set += "<set label='"  
  166.                             + sdf_date  
  167.                             + "' value='"  
  168.                             + ReportUtil.getTwoStrDivision(fail_count,  
  169.                                     voice_count) + "' />";  
  170.   
  171.                 }// end if  
  172.                 dataset = true;  
  173.             }// end for  
  174.   
  175.             listJson += "]";  
  176.             rptJson11 += rptJson11Set;  
  177.             rptJson11 += "<styles>"  
  178.                     + "<definition><style type='font' name='CaptionFont' size='15' color='666666' />"  
  179.                     + "<style type='font' name='SubCaptionFont' bold='0' />"  
  180.                     + "</definition><application>"  
  181.                     + "<apply toObject='caption' styles='CaptionFont' />"  
  182.                     + "<apply toObject='SubCaption' styles='SubCaptionFont' />"  
  183.                     + "</application>" + "</styles>" + "</chart>'";  
  184.   
  185.             rptJson12categories += "</categories>";  
  186.             rptJson12dataset1 += "</dataset>";  
  187.             rptJson12dataset2 += "</dataset>";  
  188.             rptJson12 += rptJson12categories;  
  189.             rptJson12 += rptJson12dataset1;  
  190.             rptJson12 += rptJson12dataset2;  
  191.             rptJson12 += "<styles>"  
  192.                     + "<definition>"  
  193.                     + "<style type='font' name='CaptionFont' color='666666' size='15' />"  
  194.                     + "<style type='font' name='SubCaptionFont' bold='0' />"  
  195.                     + "</definition><application>"  
  196.                     + "<apply toObject='caption' styles='CaptionFont' />"  
  197.                     + "<apply toObject='SubCaption' styles='SubCaptionFont' />"  
  198.                     + "</application>" + "</styles>" + "</chart>'";  
  199.   
  200.             rptJson13 += rptJson13set;  
  201.             rptJson13 += "<styles>"  
  202.                     + "<definition><style type='font' name='CaptionFont' size='15' color='666666' />"  
  203.                     + "<style type='font' name='SubCaptionFont' bold='0' />"  
  204.                     + "</definition><application>"  
  205.                     + "<apply toObject='caption' styles='CaptionFont' />"  
  206.                     + "<apply toObject='SubCaption' styles='SubCaptionFont' />"  
  207.                     + "</application>" + "</styles></chart>'";  
  208.             // {"dataString11":"xxxxx"}  
  209.             if (dataset) {  
  210.                 dataString11 += "\"dataString11\":{\"data\":\"" + rptJson11  
  211.                         + "\"}";  
  212.                 dataString12 += "\"dataString12\":{\"data\":\"" + rptJson12  
  213.                         + "\"}";  
  214.                 dataString13 += "\"dataString13\":{\"data\":\"" + rptJson13  
  215.                         + "\"}";  
  216.             } else {  
  217.                 dataString11 += "\"dataString11\":{\"data\":\"nodata\"}";  
  218.                 dataString12 += "\"dataString12\":{\"data\":\"nodata\"}";  
  219.                 dataString13 += "\"dataString13\":{\"data\":\"nodata\"}";  
  220.             }  
  221.   
  222.             // [{"agent_count":"12","avg_long_time":"345"},{}]  
  223.             res += "{\"all\":{" + pageJson + "," + listJson + ","  
  224.                     + dataString11 + "," + dataString12 + "," + dataString13  
  225.                     + "}}";  
  226.             System.out.println("json结果:\n" + res);  
  227.   
  228.         }// end if  
  229.   
  230.         return res;  
  231.     }  
  232.   
  233.     // 分页某一页的数据  
  234.     public String getPageJsonForInSummary(String fromdate, String todate,  
  235.             String datetype, GreenPageVo page) {  
  236.         String jsonData = "";  
  237.         List list = new ArrayList();  
  238.   
  239.         String sql = "select vo.* " + " ,con.sum_consult_count  "  
  240.                 + " ,con.sum_transfer_count  " + "  from  " + " ( "  
  241.                 + "   select " + "   sdf_date  "  
  242.                 + "   ,count(distinct a.agent_id) agent_count "  
  243.                 + "   ,count(voice_id) voice_count"  
  244.                 + "   ,sum(decode(a.start_time,null,1,'',1,0)) fail_count"  
  245.                 + "   ,avg(ring_long_time)/60 avg_ring_time"  
  246.                 + "   ,avg(decode(voice_id,null,0,1)) avg_ring_count"  
  247.                 + "   ,sum(long_time)/60 sum_long_time "  
  248.                 + "   ,avg(long_time)/60 avg_long_time " + "   from  "  
  249.                 + "   ( " + "     select  "  
  250.                 + " substr(ring_time,0,10) sdf_date "  
  251.                 + "  , t.*   from hd_agent_voice_seq t   " + "  where 1=1  ";  
  252.         if (fromdate != null && !fromdate.trim().equals("")) {  
  253.             sql += "   and t.ring_time>='"  
  254.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  255.                             true, todate) + "'  ";  
  256.         }  
  257.         if (todate != null && !todate.trim().equals("")) {  
  258.             sql += " and t.ring_time<='"  
  259.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  260.                             false, todate) + "' ";  
  261.         }  
  262.         sql += "  and t.voice_direct_id='0'  "  
  263.                 + "   ) a  "  
  264.                 + "  group by sdf_date "  
  265.                 + " ) vo, "  
  266.                 + " ( "  
  267.                 + "    select  "  
  268.                 + " zc.sdf_consult_date "  
  269.                 + " ,sum(decode(zc.consult_start_time,null,0,'',0,1)) sum_consult_count  "  
  270.                 + " ,sum(decode(zc.transfer_flag,null,0,'',0,0,0,1)) sum_transfer_count "  
  271.                 + " ,sum(decode(zc.conference_start_time,null,0,'',0,1)) sum_conference_count  "  
  272.                 + " ,sum(consult_long_time)/60 sum_consult_time "  
  273.                 + " ,sum(conference_long_time)/60 sum_consult_time "  
  274.                 + " from  "  
  275.                 + " ( "  
  276.                 + " select za.*,substr(consult_start_time,0,10) sdf_consult_date,zb.voice_id bvoice_id  "  
  277.                 + "  from hd_consult_log za , hd_agent_voice_seq zb  "  
  278.                 + "  where za.voice_id=zb.voice_id(+)  ";  
  279.         if (fromdate != null && !fromdate.trim().equals("")) {  
  280.             sql += "  and za.consult_start_time>='"  
  281.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  282.                             true, todate) + "'  ";  
  283.         }  
  284.         if (todate != null && !todate.trim().equals("")) {  
  285.             sql += "   and za.consult_start_time<='"  
  286.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  287.                             false, todate) + "' ";  
  288.         }  
  289.         sql += "  ) zc  " + "  group by sdf_consult_date " + " ) con  "  
  290.                 + "  where vo.sdf_date=con.sdf_consult_date(+)  "  
  291.                 + "  order by vo.sdf_date ";  
  292.         System.out.println("getAllListForInSummary--" + sql);  
  293.   
  294.         String countSql = "select count(sdf_date) countNumber " + "  from  ("  
  295.                 + sql + " )";  
  296.         List listCount = new ArrayList();  
  297.         listCount = this.queryNativeSQL(countSql);  
  298.           
  299.         PaginationSupport pageset=new PaginationSupport();  
  300.         pageset.setTotalCount(this.getCountNumberFromList(listCount));// 记录总数  
  301.         pageset.setCountOnEachPage(page.getEachItemsOfPage());  
  302.         pageset.setPage(page.getCurrPage());  
  303.           
  304.         list = this.queryNativeSQL(sql, pageset);  
  305.         jsonData = this.getPageJsonForInSummaryByList(list, pageset);  
  306.         return jsonData;  
  307.     }  
  308.   
  309.     public int getCountNumberFromList(List list) {  
  310.         int a = 0;  
  311.         if (list == null) {  
  312.         } else {  
  313.             Object o1 = (Object) list.get(0);  
  314.             String cc = ReportUtil.objectToString(o1);  
  315.             String cc2=ReportUtil.getNumberFormatForCount(cc);  
  316.             a = Integer.valueOf(cc2);  
  317.             System.out.println("getCount--" + a);  
  318.         }  
  319.         return a;  
  320.     }  
  321.   
  322.     // 列表,分页,报表 的数据  
  323.     public String getPageJsonForInSummaryByList(List list,  
  324.             PaginationSupport pageset) {  
  325.         String res = "";  
  326.         // "page":{"currPage":"6","pageCount":"67"}  
  327.         String pageJson = "";  
  328.         // [{"agent_count":"12","avg_long_time":"345"},{}]  
  329.         String listJson = "\"listdata\":[";  
  330.   
  331.         if (list != null) {  
  332.             // 分页显示数据  
  333.             pageJson = "\"page\":{\"currPage\":\"" + pageset.getPage()  
  334.                     + "\",\"pageCount\":\"" + pageset.getPageCount() + "\"}";  
  335.             int f = 1;  
  336.             for (int i = 0; i < list.size(); i++) {  
  337.                 Object[] o1 = (Object[]) list.get(i);  
  338.                 if (o1 != null && o1.length >= 10) {  
  339.                     String sdf_date = ReportUtil.objectToString(o1[0]);  
  340.                     String agent_count = ReportUtil.objectToString(o1[1]);  
  341.                     agent_count=ReportUtil.getNumberFormatForCount(agent_count);  
  342.                     String voice_count = ReportUtil.objectToString(o1[2]);  
  343.                     voice_count=ReportUtil.getNumberFormatForCount(voice_count);  
  344.                     String fail_count = ReportUtil.objectToString(o1[3]);  
  345.                     fail_count=ReportUtil.getNumberFormatForCount(fail_count);  
  346.                     String avg_ring_time = ReportUtil.objectToString(o1[4]);  
  347.   
  348.                     String avg_ring_count = ReportUtil.objectToString(o1[5]);  
  349.                     avg_ring_count=ReportUtil.getNumberFormatForCount(avg_ring_count);  
  350.                     String sum_long_time = ReportUtil.objectToString(o1[6]);  
  351.                     String avg_long_time = ReportUtil.objectToString(o1[7]);  
  352.                     String sum_consult_count = ReportUtil.objectToString(o1[8]);  
  353.                     sum_consult_count=ReportUtil.getNumberFormatForCount(sum_consult_count);  
  354.                     String sum_transfer_count = ReportUtil  
  355.                             .objectToString(o1[9]);  
  356.                     sum_transfer_count=ReportUtil.getNumberFormatForCount(sum_transfer_count);  
  357.                     // 列表数据  
  358.                     InsummaryResult is = new InsummaryResult(sdf_date,  
  359.                             agent_count, voice_count, fail_count,  
  360.                             avg_ring_time, avg_ring_count, sum_long_time,  
  361.                             avg_long_time, sum_consult_count,  
  362.                             sum_transfer_count);  
  363.                     // {"agent_count":"12","avg_long_time":"345","avg_ring_count":"","avg_ring_time":"","fail_count":"","sdf_date":"","sum_consult_count":"","sum_long_time":"","sum_transfer_count":"","voice_count":""}  
  364.                     String isJson = ReportUtil.getJsonFromObject(is);  
  365.                     if (f == 1) {  
  366.                         listJson += isJson;  
  367.                     } else {  
  368.                         listJson += "," + isJson;  
  369.                     }  
  370.                     f++;  
  371.                 }// end if  
  372.             }// end for  
  373.   
  374.             listJson += "]";  
  375.             // [{"agent_count":"12","avg_long_time":"345"},{}]  
  376.             res += "{\"all\":{" + pageJson + "," + listJson + "}}";  
  377.             System.out.println("分页json结果:\n" + res);  
  378.   
  379.         }// end if  
  380.   
  381.         return res;  
  382.     }  
  383.   
  384.     // 对比查询  
  385.     public String getCompareDataForInSummary(String fromdate, String todate,  
  386.             String datetype) {  
  387.         String jsonData = "";  
  388.         List list = new ArrayList();  
  389.   
  390.         String sql = "select vo.* " + " ,con.sum_consult_count  "  
  391.                 + " ,con.sum_transfer_count  " + "  from  " + " ( "  
  392.                 + "   select " + "   sdf_date  "  
  393.                 + "   ,count(distinct a.agent_id) agent_count "  
  394.                 + "   ,count(voice_id) voice_count"  
  395.                 + "   ,sum(decode(a.start_time,null,1,'',1,0)) fail_count"  
  396.                 + "   ,avg(ring_long_time)/60 avg_ring_time"  
  397.                 + "   ,avg(decode(voice_id,null,0,1)) avg_ring_count"  
  398.                 + "   ,sum(long_time)/60 sum_long_time "  
  399.                 + "   ,avg(long_time)/60 avg_long_time " + "   from  "  
  400.                 + "   ( " + "     select  ";  
  401.         sql += this.getSubStrDate(datetype);  
  402.   
  403.         sql += "  , t.*   from hd_agent_voice_seq t   " + "  where 1=1  ";  
  404.         if (fromdate != null && !fromdate.trim().equals("")) {  
  405.             sql += "   and t.ring_time>='"  
  406.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  407.                             true, todate) + "'  ";  
  408.         }  
  409.         if (todate != null && !todate.trim().equals("")) {  
  410.             sql += " and t.ring_time<='"  
  411.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  412.                             false, todate) + "' ";  
  413.         }  
  414.         sql += "  and t.voice_direct_id='0'  "  
  415.                 + "   ) a  "  
  416.                 + "  group by sdf_date "  
  417.                 + " ) vo, "  
  418.                 + " ( "  
  419.                 + "    select  "  
  420.                 + " zc.sdf_consult_date "  
  421.                 + " ,sum(decode(zc.consult_start_time,null,0,'',0,1)) sum_consult_count  "  
  422.                 + " ,sum(decode(zc.transfer_flag,null,0,'',0,0,0,1)) sum_transfer_count "  
  423.                 + " ,sum(decode(zc.conference_start_time,null,0,'',0,1)) sum_conference_count  "  
  424.                 + " ,sum(consult_long_time)/60 sum_consult_time "  
  425.                 + " ,sum(conference_long_time)/60 sum_consult_time "  
  426.                 + " from  "  
  427.                 + " ( "  
  428.                 + " select za.*,substr(consult_start_time,0,10) sdf_consult_date,zb.voice_id bvoice_id  "  
  429.                 + "  from hd_consult_log za , hd_agent_voice_seq zb  "  
  430.                 + "  where za.voice_id=zb.voice_id(+)  ";  
  431.         if (fromdate != null && !fromdate.trim().equals("")) {  
  432.             sql += "  and za.consult_start_time>='"  
  433.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  434.                             true, todate) + "'  ";  
  435.         }  
  436.         if (todate != null && !todate.trim().equals("")) {  
  437.             sql += "   and za.consult_start_time<='"  
  438.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  439.                             false, todate) + "' ";  
  440.         }  
  441.         sql += "  ) zc  " + "  group by sdf_consult_date " + " ) con  "  
  442.                 + "  where vo.sdf_date=con.sdf_consult_date(+)  "  
  443.                 + "  order by vo.sdf_date ";  
  444.         System.out.println("getAllListForInSummary--" + sql);  
  445.         list = this.queryNativeSQL(sql);  
  446.         jsonData = this.getCompareJsonForInSummaryByList(list);  
  447.         return jsonData;  
  448.     }  
  449.   
  450.     public String getSubStrDate(String datetype) {  
  451.         String sub = "   substr(ring_time,0,10) sdf_date ";  
  452.         // substr(ring_time,0,10) sdf_date --按天  
  453.         // --substr(ring_time,0,4) sdf_date --按年  
  454.         // -- substr(ring_time,0,7) sdf_date --按月份  
  455.         if (datetype == null) {  
  456.         } else if (datetype.trim().equals("")) {  
  457.         } else {  
  458.             String dd = datetype.trim();  
  459.             if (dd.equals("dtian")) {  
  460.                 sub = "  substr(ring_time,0,10) sdf_date ";  
  461.             } else if (dd.equals("djidu") || dd.equals("dyuefen")) {  
  462.                 sub = "  substr(ring_time,0,7) sdf_date ";  
  463.             } else if (dd.equals("dnian")) {  
  464.                 sub = "  substr(ring_time,0,4) sdf_date ";  
  465.             }  
  466.         }  
  467.   
  468.         return sub;  
  469.     }  
  470.   
  471.     // 折线的json  
  472.     public String getCompareJsonForInSummaryByList(List list) {  
  473.         String res = "";  
  474.   
  475.         // 第一张折线图--呼叫总数  
  476.         String dataString21 = "";  
  477.         String rpt21 = "<chart canvasPadding='10' caption='呼叫总数' yAxisName='单位:个' formatNumberScale='0' "  
  478.                 + " bgColor='F7F7F7, E9E9E9' numVDivLines='10' divLineAlpha='30' "  
  479.                 + " labelPadding ='30' yAxisValuesPadding ='30' showValues='1' rotateValues='2' valuePosition='auto'>";  
  480.   
  481.         String categories21 = "<categories>";  
  482.         String dataset211 = "<dataset seriesName='呼叫总数' color='F6BD0F'>";  
  483.   
  484.         // 第二张折线图--总通话时长  
  485.         String dataString22 = "<chart canvasPadding='10' caption='总通话时长' yAxisName='单位:分钟'"  
  486.                 + " formatNumberScale='0'  bgColor='F7F7F7, E9E9E9'"  
  487.                 + " numVDivLines='10' divLineAlpha='30'  labelPadding ='30' yAxisValuesPadding ='30' "  
  488.                 + "showValues='1' rotateValues='2' valuePosition='auto'>";  
  489.         String rpt22 = "";  
  490.         String categories22 = "<categories>";  
  491.         String dataset221 = "<dataset seriesName='总通话时长' color='F6BD0F'>";  
  492.   
  493.         // 第三张折线图--平均振铃时长  
  494.         String dataString23 = "<chart canvasPadding='10' caption='平均振铃时长' yAxisName='单位:分钟'"  
  495.                 + " formatNumberScale='0'  bgColor='F7F7F7, E9E9E9'"  
  496.                 + " numVDivLines='10' divLineAlpha='30'  labelPadding ='30' yAxisValuesPadding ='30' "  
  497.                 + "showValues='1' rotateValues='2' valuePosition='auto'>";  
  498.         String rpt23 = "";  
  499.         String categories23 = "<categories>";  
  500.         String dataset231 = "<dataset seriesName='平均振铃时长' color='F6BD0F'>";  
  501.   
  502.         // 第四张折线图--平均通话时长  
  503.         String dataString24 = "<chart canvasPadding='10' caption='平均通话时长' yAxisName='单位:分钟'"  
  504.                 + " formatNumberScale='0'  bgColor='F7F7F7, E9E9E9'"  
  505.                 + " numVDivLines='10' divLineAlpha='30'  labelPadding ='30' yAxisValuesPadding ='30' "  
  506.                 + "showValues='1' rotateValues='2' valuePosition='auto'>";  
  507.         String rpt24 = "";  
  508.         String categories24 = "<categories>";  
  509.         String dataset241 = "<dataset seriesName='平均通话时长' color='F6BD0F'>";  
  510.   
  511.         // 第五张折线图--呼损率  
  512.         String dataString25 = "<chart canvasPadding='10' caption='呼损率' yAxisName='单位:%' "  
  513.                 + " numberSuffix='%'  formatNumberScale='0'  bgColor='F7F7F7, E9E9E9' "  
  514.                 + "numVDivLines='10' divLineAlpha='30'  labelPadding ='30' yAxisValuesPadding ='30' "  
  515.                 + "showValues='1' rotateValues='2' valuePosition='auto'>";  
  516.         String rpt25 = "";  
  517.         String categories25 = "<categories>";  
  518.         String dataset251 = "<dataset seriesName='呼损率' color='F6BD0F'>";  
  519.   
  520.         if (list != null) {  
  521.             int f = 1;  
  522.             // 平均线的值  
  523.             double line_voice_count = 0;  
  524.             double line_sum_long_time = 0;  
  525.             double line_avg_ring_time = 0;  
  526.             double line_avg_long_time = 0;  
  527.             double line_husunlv = 0;  
  528.             boolean dataset = false;  
  529.             // boolean dataset_sum_long_time=false;  
  530.             // boolean dataset_avg_ring_time=false;  
  531.             // boolean dataset_avg_long_time=false;  
  532.             for (int i = 0; i < list.size(); i++) {  
  533.                 Object[] o1 = (Object[]) list.get(i);  
  534.                 if (o1 != null && o1.length >= 10) {  
  535.                     String sdf_date = ReportUtil.objectToString(o1[0]);  
  536.                     String agent_count = ReportUtil.objectToString(o1[1]);  
  537.                     agent_count=ReportUtil.getNumberFormatForCount(agent_count);  
  538.                     String voice_count = ReportUtil.objectToString(o1[2]);  
  539.                     voice_count=ReportUtil.getNumberFormatForCount(voice_count);  
  540.                     String fail_count = ReportUtil.objectToString(o1[3]);  
  541.                     fail_count=ReportUtil.getNumberFormatForCount(fail_count);  
  542.                     String avg_ring_time = ReportUtil.objectToString(o1[4]);  
  543.   
  544.                     String avg_ring_count = ReportUtil.objectToString(o1[5]);  
  545.                     avg_ring_count=ReportUtil.getNumberFormatForCount(avg_ring_count);  
  546.                     String sum_long_time = ReportUtil.objectToString(o1[6]);  
  547.                     String avg_long_time = ReportUtil.objectToString(o1[7]);  
  548.                     String sum_consult_count = ReportUtil.objectToString(o1[8]);  
  549.                     sum_consult_count=ReportUtil.getNumberFormatForCount(sum_consult_count);  
  550.                     String sum_transfer_count = ReportUtil  
  551.                             .objectToString(o1[9]);  
  552.                     sum_transfer_count=ReportUtil.getNumberFormatForCount(sum_transfer_count);  
  553.   
  554.                     categories21 += "<category label='" + sdf_date + "' />";  
  555.                     dataset211 += "<set value='" + voice_count + "' />";  
  556.   
  557.                     categories22 += "<category label='" + sdf_date + "' />";  
  558.                     dataset221 += "<set value='" + sum_long_time + "' />";  
  559.   
  560.                     categories23 += "<category label='" + sdf_date + "' />";  
  561.                     dataset231 += "<set value='" + avg_ring_time + "' />";  
  562.   
  563.                     categories24 += "<category label='" + sdf_date + "' />";  
  564.                     dataset241 += "<set value='" + avg_long_time + "' />";  
  565.   
  566.                     categories25 += "<category label='" + sdf_date + "' /> ";  
  567.                     dataset251 += "<set value='"  
  568.                             + ReportUtil.getTwoStrDivision(fail_count,  
  569.                                     voice_count) + "' /> ";  
  570.   
  571.                     line_voice_count = ReportUtil.getSumLeijiDouble(  
  572.                             line_voice_count, voice_count);  
  573.                     line_sum_long_time = ReportUtil.getSumLeijiDouble(  
  574.                             line_sum_long_time, sum_long_time);  
  575.                     line_avg_ring_time = ReportUtil.getSumLeijiDouble(  
  576.                             line_avg_ring_time, avg_ring_time);  
  577.                     line_avg_long_time = ReportUtil.getSumLeijiDouble(  
  578.                             line_avg_long_time, avg_long_time);  
  579.                     line_husunlv = ReportUtil.getSumLeijiDouble(line_husunlv,  
  580.                             ReportUtil.getTwoStrDivision(fail_count,  
  581.                                     voice_count));  
  582.   
  583.                 }// end if  
  584.                 f++;  
  585.                 dataset = true;  
  586.             }// end for  
  587.             line_voice_count = ReportUtil.getAvgLeijiDouble(line_voice_count,  
  588.                     (f - 1));  
  589.             line_sum_long_time = ReportUtil.getAvgLeijiDouble(  
  590.                     line_sum_long_time, (f - 1));  
  591.             line_avg_ring_time = ReportUtil.getAvgLeijiDouble(  
  592.                     line_avg_ring_time, (f - 1));  
  593.             line_avg_long_time = ReportUtil.getAvgLeijiDouble(  
  594.                     line_avg_long_time, (f - 1));  
  595.             line_husunlv = ReportUtil.getAvgLeijiDouble(line_husunlv, (f - 1));  
  596.   
  597.             categories21 += "</categories>";  
  598.             dataset211 += "</dataset>";  
  599.             rpt21 += categories21 + dataset211;  
  600.             rpt21 += "<trendlines><line startValue='"  
  601.                     + line_voice_count  
  602.                     + "' displayValue='Average:"  
  603.                     + line_voice_count  
  604.                     + "' color='009900' valueOnRight='1' /></trendlines></chart>";  
  605.             dataString21 += rpt21;  
  606.             if (dataset) {  
  607.                 dataString21 = "\"dataString21\":{\"data\":\"" + dataString21  
  608.                         + "\"}";  
  609.             } else {  
  610.                 dataString21 = "\"dataString21\":{\"data\":\"nodata\"}";  
  611.             }  
  612.   
  613.             // //  
  614.             categories22 += "</categories>";  
  615.             dataset221 += "</dataset>";  
  616.             rpt22 += categories22;  
  617.             rpt22 += dataset221;  
  618.             rpt22 += "<trendlines><line startValue='"  
  619.                     + line_sum_long_time  
  620.                     + "' displayValue='Average:"  
  621.                     + line_sum_long_time  
  622.                     + "' color='009900' valueOnRight='1' /></trendlines></chart>";  
  623.             dataString22 += rpt22;  
  624.             if (dataset) {  
  625.                 dataString22 = "\"dataString22\":{\"data\":\"" + dataString22  
  626.                         + "\"}";  
  627.             } else {  
  628.                 dataString22 = "\"dataString22\":{\"data\":\"nodata\"}";  
  629.             }  
  630.   
  631.             // ///  
  632.             categories23 += "</categories>";  
  633.             dataset231 += "</dataset>";  
  634.             rpt23 += categories23;  
  635.             rpt23 += dataset231;  
  636.             rpt23 += "<trendlines><line startValue='"  
  637.                     + line_avg_ring_time  
  638.                     + "' displayValue='Average:"  
  639.                     + line_avg_ring_time  
  640.                     + "' color='009900' valueOnRight='1' /></trendlines></chart>";  
  641.             dataString23 += rpt23;  
  642.             if (dataset) {  
  643.                 dataString23 = "\"dataString23\":{\"data\":\"" + dataString23  
  644.                         + "\"}";  
  645.             } else {  
  646.                 dataString23 = "\"dataString23\":{\"data\":\"nodata\"}";  
  647.             }  
  648.   
  649.             // ///  
  650.             categories24 += "</categories>";  
  651.             dataset241 += "</dataset>";  
  652.             rpt24 += categories24;  
  653.             rpt24 += dataset241;  
  654.             rpt24 += "<trendlines><line startValue='"  
  655.                     + line_avg_long_time  
  656.                     + "' displayValue='Average:"  
  657.                     + line_avg_long_time  
  658.                     + "' color='009900' valueOnRight='1' /></trendlines></chart>";  
  659.             dataString24 += rpt24;  
  660.             if (dataset) {  
  661.                 dataString24 = "\"dataString24\":{\"data\":\"" + dataString24  
  662.                         + "\"}";  
  663.             } else {  
  664.                 dataString24 = "\"dataString24\":{\"data\":\"nodata\"}";  
  665.             }  
  666.             //   
  667.             categories25 += "</categories>";  
  668.             dataset251 += "</dataset>";  
  669.             rpt25 += categories25;  
  670.             rpt25 += dataset251;  
  671.             rpt25 += "<trendlines><line startValue='"  
  672.                     + line_husunlv  
  673.                     + "' displayValue='Average:"  
  674.                     + line_husunlv  
  675.                     + "' color='009900' valueOnRight='1' /></trendlines></chart>";  
  676.             dataString25 += rpt25;  
  677.             if (dataset) {  
  678.                 dataString25 = "\"dataString25\":{\"data\":\"" + dataString25  
  679.                         + "\"}";  
  680.             } else {  
  681.                 dataString25 = "\"dataString25\":{\"data\":\"nodata\"}";  
  682.             }  
  683.             // [{"agent_count":"12","avg_long_time":"345"},{}]  
  684.             res += "{\"all\":{" + dataString21 + "," + dataString22 + ","  
  685.                     + dataString23 + "," + dataString24 + "," + dataString25  
  686.                     + "}}";  
  687.             System.out.println("折线json结果:\n" + res);  
  688.   
  689.         }// end if  
  690.   
  691.         return res;  
  692.     }  
  693.   
  694.     // ///明细开始/  
  695.     // 点击查询,明细sql  
  696.     public String getAllDataForInDetail(String fromdate, String todate,  
  697.             String datetype,GreenPageVo page) {  
  698.         String jsonData = "";  
  699.         List list = new ArrayList();  
  700.   
  701.         String sql = " select "  
  702.                 + " agent_name  "  
  703.                 + "  ,count(voice_id) voice_count "  
  704.                 + " ,sum(decode(a.start_time,null,1,'',1,0)) fail_count "  
  705.                 + " ,count(voice_id)-sum(decode(a.start_time,null,1,'',1,0)) success_count "  
  706.                 + " ,sum(long_time)/60 sum_long_time "  
  707.                 + " ,avg(long_time)/60 avg_long_time "  
  708.                 + " ,avg(ring_long_time)/60 avg_ring_time "  
  709.                 + " ,avg(decode(voice_id,null,0,1)) avg_ring_count "  
  710.                 + "   from  " + "   ( " + " select  "  
  711.                 + "  t.*   from hd_agent_voice_seq t  " + " where 1=1  ";  
  712.         if (fromdate != null && !fromdate.trim().equals("")) {  
  713.             sql += "   and t.ring_time>='"  
  714.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  715.                             true, todate) + "'  ";  
  716.         }  
  717.         if (todate != null && !todate.trim().equals("")) {  
  718.             sql += " and t.ring_time<='"  
  719.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  720.                             false, todate) + "' ";  
  721.         }  
  722.         sql += "  and t.voice_direct_id='0'  " + "  ) a  "  
  723.                 + " group by agent_name ";  
  724.   
  725.         System.out.println("getAllDataForInDetail--" + sql);  
  726.         list = this.queryNativeSQL(sql);  
  727.         jsonData = this.getAllJsonForInDetailByList(list,page);  
  728.         return jsonData;  
  729.     }  
  730.   
  731.     public String getAllJsonForInDetailByList(List list,GreenPageVo page){  
  732.         String res="";  
  733.         //"page":{"currPage":"6","pageCount":"67"}  
  734.         String pageJson="";  
  735.         //[{"agent_count":"12","avg_long_time":"345"},{}]  
  736.         String listJson="\"listdata\":[";  
  737.           
  738.         String dataString11="";  
  739.         String dataString12="";  
  740.         String dataString13="";  
  741.         String dataString14="";  
  742.         String dataString15="";  
  743.         String rptJson11="<chart palette='2' caption='呼入总数--通话次数--呼损次数' " +  
  744.                 "showLabels='1' showvalues='0'  numberPrefix='' showSum='1' " +  
  745.                 "decimals='0' useRoundEdges='1' legendBorderAlpha='0' formatNumberScale='0'>";  
  746.         String rptJson11categories="<categories>";  
  747.         String rptJson11Set1="<dataset seriesName='呼入总数' color='AFD8F8' showValues='0'>";  
  748.         String rptJson11Set2="<dataset seriesName='通话次数 ' color='F6BD0F' showValues='0'>";  
  749.         String rptJson11Set3="<dataset seriesName='呼损次数' color='8BBA00' showValues='0'>";  
  750.           
  751.           
  752.         String rptJson12="<chart caption='平均通话时长 ' bgColor='E0EEEE,90B1DE'  palette='2'" +  
  753.                 " formatNumberScale='0' numberPrefix='' labeldisplay='ROTATE' " +  
  754.                 "slantLabels='1' sNumberSuffix=' pcs.' showValues='1' labelDisplay='STAGGER'>";  
  755.         String rptJson12dataset1="";  
  756.           
  757.         String rptJson13="<chart caption='平均振铃时长 ' bgColor='E0EEEE,90B1DE'  palette='2'" +  
  758.                 " formatNumberScale='0' numberPrefix='' labeldisplay='ROTATE' " +  
  759.                 "slantLabels='1' sNumberSuffix=' pcs.' showValues='1' labelDisplay='STAGGER'>";  
  760.         String rptJson13dataset1="";  
  761.           
  762.         String rptJson14="<chart caption='通话次数'  showValues='1' baseFontColor='FFFFFF'" +  
  763.                 " bgColor='2E4A89,90B1DE' bgAlpha='100,100' pieYScale='30' " +  
  764.                 "pieSliceDepth='8' smartLineColor='FFFFFF'>";  
  765.         String rptJson14dataset1="";  
  766.           
  767.         String rptJson15="<chart caption='通话时长' showValues='1'  baseFontColor='FFFFFF'" +  
  768.                 " bgColor='2E4A89,90B1DE' bgAlpha='100,100' pieYScale='30' " +  
  769.                 "pieSliceDepth='8' smartLineColor='FFFFFF'>";  
  770.         String rptJson15dataset1="";  
  771.         if(list!=null){  
  772.              //分页显示数据  
  773.              pageJson="\"page\":{\"currPage\":\"1\",\"pageCount\":\""  
  774.              +(ReportUtil.getPageCountByDivide(list.size(), page.getEachItemsOfPage()))+"\"}";  
  775.              int f=1;  
  776.              boolean dataset=false;  
  777.              for(int i=0;i<list.size();i++){  
  778.                     Object[] o1=(Object[])list.get(i);  
  779.                     if(o1!=null&&o1.length>=8){  
  780.                         String agent_name=ReportUtil.objectToString(o1[0]);  
  781.                         String voice_count=ReportUtil.objectToString(o1[1]);  
  782.                         voice_count=ReportUtil.getNumberFormatForCount(voice_count);  
  783.                         String fail_count=ReportUtil.objectToString(o1[2]);  
  784.                         fail_count=ReportUtil.getNumberFormatForCount(fail_count);  
  785.                         String success_count=ReportUtil.objectToString(o1[3]);  
  786.                         success_count=ReportUtil.getNumberFormatForCount(success_count);  
  787.                         String sum_long_time=ReportUtil.objectToString(o1[4]);  
  788.                           
  789.                         String avg_long_time=ReportUtil.objectToString(o1[5]);  
  790.                         String avg_ring_time=ReportUtil.objectToString(o1[6]);  
  791.                         String avg_ring_count=ReportUtil.objectToString(o1[7]);  
  792.                         avg_ring_count=ReportUtil.getNumberFormatForCount(avg_ring_count);  
  793.                     //列表数据  
  794.                         InDetailResult id = new InDetailResult(agent_name, voice_count, fail_count, success_count, sum_long_time, avg_long_time, avg_ring_time, avg_ring_count);  
  795.                     //{"agent_count":"12","avg_long_time":"345","avg_ring_count":"","avg_ring_time":"","fail_count":"","sdf_date":"","sum_consult_count":"","sum_long_time":"","sum_transfer_count":"","voice_count":""}  
  796.                     String isJson=ReportUtil.getJsonFromObject(id);  
  797.                     if(i<page.getEachItemsOfPage()){  
  798.                         if(f==1){  
  799.                             listJson+=isJson;  
  800.                         }else{  
  801.                             listJson+=","+isJson;  
  802.                         }  
  803.                     }  
  804.                       
  805.                     f++;  
  806.                     //报表dataString11的数据  
  807.                     rptJson11categories+="<category label='"+agent_name+"' />";  
  808.                     rptJson11Set1+="<set value='"+voice_count+"' />";  
  809.                     rptJson11Set2+="<set value='"+success_count+"' />";  
  810.                     rptJson11Set3+="<set value='"+fail_count+"' />";  
  811.                       
  812.                     //报表dataString12的数据  
  813.                     rptJson12dataset1+="<set value='"+avg_long_time+"' label='"+agent_name+"' color='"+ReportUtil.getColorByInt(i)+"'/>";  
  814.                     //报表dataString13的数据  
  815.                     rptJson13dataset1+="<set value='"+avg_ring_time+"' label='"+agent_name+"' color='"+ReportUtil.getColorByInt(i)+"'/>";  
  816.                     //报表dataString14的数据  
  817.                     rptJson14dataset1+="<set label='"+agent_name+"' value='"+success_count+"' />";  
  818.                     //报表dataString15的数据  
  819.                     rptJson15dataset1+="<set label='"+agent_name+"' value='"+sum_long_time+"' />";  
  820.                       
  821.                     }//end if  
  822.                     dataset=true;  
  823.                 }//end for  
  824.                
  825.              listJson+="]";  
  826.                        
  827.              rptJson11categories+="</categories>";  
  828.              rptJson11Set1+="</dataset>";  
  829.              rptJson11Set2+="</dataset>";  
  830.              rptJson11Set3+="</dataset>";  
  831.              rptJson11+=rptJson11categories;  
  832. //           rptJson11+=rptJson11Set1;  
  833.              rptJson11+=rptJson11Set2;  
  834.              rptJson11+=rptJson11Set3;  
  835.              rptJson11+="</chart>";  
  836.                
  837.                
  838.              rptJson12+=rptJson12dataset1;  
  839.              rptJson12+="<styles>" +  
  840.                     "<definition><style type='font' name='CaptionFont' size='15' color='666666' />" +  
  841.                     "<style type='font' name='SubCaptionFont' bold='0' />" +  
  842.                     "</definition><application>" +  
  843.                     "<apply toObject='caption' styles='CaptionFont' />" +  
  844.                     "<apply toObject='SubCaption' styles='SubCaptionFont' />" +  
  845.                     "</application>" +  
  846.                     "</styles>" +  
  847.                     "</chart>";  
  848.                
  849.              rptJson13+=rptJson13dataset1;  
  850.              rptJson13+="<styles>" +  
  851.                     "<definition><style type='font' name='CaptionFont' size='15' color='666666' />" +  
  852.                     "<style type='font' name='SubCaptionFont' bold='0' />" +  
  853.                     "</definition><application>" +  
  854.                     "<apply toObject='caption' styles='CaptionFont' />" +  
  855.                     "<apply toObject='SubCaption' styles='SubCaptionFont' />" +  
  856.                     "</application>" +  
  857.                     "</styles>" +  
  858.                     "</chart>";  
  859.                
  860.              rptJson14+=rptJson14dataset1;  
  861.              rptJson14+="<styles>" +  
  862.                     "<definition>" +  
  863.                     "<style name='CaptionFont' type='FONT' size='12' bold='1' />" +  
  864.                     "<style name='LabelFont' type='FONT' color='2E4A89' bgColor='FFFFFF' bold='1' />" +  
  865.                     "<style name='ToolTipFont' type='FONT' bgColor='2E4A89' borderColor='2E4A89' />" +  
  866.                     "</definition>" +  
  867.                     "<application>" +  
  868.                     "<apply toObject='CAPTION' styles='CaptionFont' />" +  
  869.                     "<apply toObject='DATALABELS' styles='LabelFont' />" +  
  870.                     "<apply toObject='TOOLTIP' styles='ToolTIpFont' />" +  
  871.                     "</application>" +  
  872.                     "</styles>" +  
  873.                     "</chart>";  
  874.                
  875.              rptJson15+=rptJson15dataset1;  
  876.              rptJson15+="<styles>" +  
  877.                     "<definition>" +  
  878.                     "<style name='CaptionFont' type='FONT' size='12' bold='1' />" +  
  879.                     "<style name='LabelFont' type='FONT' color='2E4A89' bgColor='FFFFFF' bold='1' />" +  
  880.                     "<style name='ToolTipFont' type='FONT' bgColor='2E4A89' borderColor='2E4A89' />" +  
  881.                     "</definition>" +  
  882.                     "<application>" +  
  883.                     "<apply toObject='CAPTION' styles='CaptionFont' />" +  
  884.                     "<apply toObject='DATALABELS' styles='LabelFont' />" +  
  885.                     "<apply toObject='TOOLTIP' styles='ToolTIpFont' />" +  
  886.                     "</application>" +  
  887.                     "</styles>" +  
  888.                     "</chart>";  
  889.              //{"dataString11":"xxxxx"}  
  890.              if(dataset){  
  891.                  dataString11+="\"dataString11\":{\"data\":\""+rptJson11+"\"}";  
  892.                  dataString12+="\"dataString12\":{\"data\":\""+rptJson12+"\"}";  
  893.                  dataString13+="\"dataString13\":{\"data\":\""+rptJson13+"\"}";  
  894.                  dataString14+="\"dataString14\":{\"data\":\""+rptJson14+"\"}";  
  895.                  dataString15+="\"dataString15\":{\"data\":\""+rptJson15+"\"}";  
  896.              }else{  
  897.                  dataString11+="\"dataString11\":{\"data\":\"nodata\"}";  
  898.                  dataString12+="\"dataString12\":{\"data\":\"nodata\"}";  
  899.                  dataString13+="\"dataString13\":{\"data\":\"nodata\"}";  
  900.                  dataString14+="\"dataString14\":{\"data\":\"nodata\"}";  
  901.                  dataString15+="\"dataString15\":{\"data\":\"nodata\"}";  
  902.              }  
  903.                
  904.             //[{"agent_count":"12","avg_long_time":"345"},{}]  
  905.              res+="{\"all\":{"+pageJson+","+listJson+","+dataString11+","+dataString12+","+dataString13+","+dataString14+","+dataString15+"}}";  
  906.              System.out.println("json结果:\n"+res);  
  907.                
  908.         }//end if  
  909.           
  910.         return res;  
  911.     }  
  912.       
  913.     // 明细分页 的数据  
  914.     public String getPageJsonForInDetail(String fromdate,String todate,String datetype,GreenPageVo page){  
  915.         String jsonData = "";  
  916.         List list = new ArrayList();  
  917.   
  918.         String sql = " select "  
  919.                 + " agent_name  "  
  920.                 + "  ,count(voice_id) voice_count "  
  921.                 + " ,sum(decode(a.start_time,null,1,'',1,0)) fail_count "  
  922.                 + " ,count(voice_id)-sum(decode(a.start_time,null,1,'',1,0)) success_count "  
  923.                 + " ,sum(long_time)/60 sum_long_time "  
  924.                 + " ,avg(long_time)/60 avg_long_time "  
  925.                 + " ,avg(ring_long_time)/60 avg_ring_time "  
  926.                 + " ,avg(decode(voice_id,null,0,1)) avg_ring_count "  
  927.                 + "   from  " + "   ( " + " select  "  
  928.                 + "  t.*   from hd_agent_voice_seq t  " + " where 1=1  ";  
  929.         if (fromdate != null && !fromdate.trim().equals("")) {  
  930.             sql += "   and t.ring_time>='"  
  931.                     + ReportUtil.dealDateByDatetype(fromdate.trim(), datetype,  
  932.                             true, todate) + "'  ";  
  933.         }  
  934.         if (todate != null && !todate.trim().equals("")) {  
  935.             sql += " and t.ring_time<='"  
  936.                     + ReportUtil.dealDateByDatetype(todate.trim(), datetype,  
  937.                             false, todate) + "' ";  
  938.         }  
  939.         sql += "  and t.voice_direct_id='0'  " + "  ) a  "  
  940.                 + " group by agent_name ";  
  941.         System.out.println("getAllListForInSummary--" + sql);  
  942.   
  943.         String countSql = "select count(agent_name) countNumber " + "  from  ("  
  944.                 + sql + " )";  
  945.         List listCount = new ArrayList();  
  946.         listCount = this.queryNativeSQL(countSql);  
  947.           
  948.         PaginationSupport pageset=new PaginationSupport();  
  949.         pageset.setTotalCount(this.getCountNumberFromList(listCount));// 记录总数  
  950.         pageset.setCountOnEachPage(page.getEachItemsOfPage());  
  951.         pageset.setPage(page.getCurrPage());  
  952.           
  953.         list = this.queryNativeSQL(sql, pageset);  
  954.         jsonData = this.getPageJsonForInDetailByList(list, pageset);  
  955.         return jsonData;  
  956.     }  
  957.       
  958.     // 明细分页 的数据拼装  
  959.     public String getPageJsonForInDetailByList(List list,  
  960.             PaginationSupport pageset) {  
  961.         String res = "";  
  962.         // "page":{"currPage":"6","pageCount":"67"}  
  963.         String pageJson = "";  
  964.         // [{"agent_count":"12","avg_long_time":"345"},{}]  
  965.         String listJson = "\"listdata\":[";  
  966.   
  967.         if (list != null) {  
  968.             // 分页显示数据  
  969.             pageJson = "\"page\":{\"currPage\":\"" + pageset.getPage()  
  970.                     + "\",\"pageCount\":\"" + pageset.getPageCount() + "\"}";  
  971.             int f = 1;  
  972.             boolean dataset=false;  
  973.             for(int i=0;i<list.size();i++){  
  974.                 Object[] o1=(Object[])list.get(i);  
  975.                 if(o1!=null&&o1.length>=8){  
  976.                     String agent_name=ReportUtil.objectToString(o1[0]);  
  977.                     String voice_count=ReportUtil.objectToString(o1[1]);  
  978.                     voice_count=ReportUtil.getNumberFormatForCount(voice_count);  
  979.                     String fail_count=ReportUtil.objectToString(o1[2]);  
  980.                     fail_count=ReportUtil.getNumberFormatForCount(fail_count);  
  981.                     String success_count=ReportUtil.objectToString(o1[3]);  
  982.                     success_count=ReportUtil.getNumberFormatForCount(success_count);  
  983.                     String sum_long_time=ReportUtil.objectToString(o1[4]);  
  984.                       
  985.                     String avg_long_time=ReportUtil.objectToString(o1[5]);  
  986.                     String avg_ring_time=ReportUtil.objectToString(o1[6]);  
  987.                     String avg_ring_count=ReportUtil.objectToString(o1[7]);  
  988.                     avg_ring_count=ReportUtil.getNumberFormatForCount(avg_ring_count);  
  989.                 //列表数据  
  990.                     InDetailResult id = new InDetailResult(agent_name, voice_count, fail_count, success_count, sum_long_time, avg_long_time, avg_ring_time, avg_ring_count);  
  991.                 //{"agent_count":"12","avg_long_time":"345","avg_ring_count":"","avg_ring_time":"","fail_count":"","sdf_date":"","sum_consult_count":"","sum_long_time":"","sum_transfer_count":"","voice_count":""}  
  992.                 String isJson=ReportUtil.getJsonFromObject(id);  
  993.                 if(f==1){  
  994.                     listJson+=isJson;  
  995.                 }else{  
  996.                     listJson+=","+isJson;  
  997.                 }  
  998.                 f++;  
  999.                 }//end if  
  1000.                 dataset=true;  
  1001.             }//end for  
  1002.   
  1003.             listJson += "]";  
  1004.             // [{"agent_count":"12","avg_long_time":"345"},{}]  
  1005.             res += "{\"all\":{" + pageJson + "," + listJson + "}}";  
  1006.             System.out.println("分页json结果:\n" + res);  
  1007.   
  1008.         }// end if  
  1009.   
  1010.         return res;  
  1011.     }  
  1012. }  


 

 

 

内容很多,一般两个方法对应一个功能,一个查数据,
一个负责对查询的数据进行处理。

例如:
public String getPageJsonForInSummary(String fromdate, String todate,
   String datetype, GreenPageVo page) 
从前台接受参数,拼装sql查询数据。
其中jsonData = this.getPageJsonForInSummaryByList(list, pageset);

public String getPageJsonForInSummaryByList(List list,
   PaginationSupport pageset)
负责对结果集处理数据,所有数据处理后,返回一个json对象,
把需要的数据全部返回到页面。

控制分页能正确显示的json部分:
pageJson = "\"page\":{\"currPage\":\"" + pageset.getPage()
     + "\",\"pageCount\":\"" + pageset.getPageCount() + "\"}";


 

struts配置

[html]  view plain copy
  1. <action name="rptInSummaryAll" class="org.hd.report.action.RptInSummaryAction" method="rptInSummaryAll">  
  2.         </action>  
  3.         <action name="rptInSummaryPage" class="org.hd.report.action.RptInSummaryAction" method="rptInSummaryPage">  
  4.         </action>  
  5.         <action name="rptInSummaryCompare" class="org.hd.report.action.RptInSummaryAction" method="rptInSummaryCompare">  
  6.         </action>  
  7.         <action name="judgeIsTwoRightDate" class="org.hd.report.action.RightDateJudgeAction" method="judgeIsTwoRightDate">  
  8.         </action>  
  9.         <action name="rptInDetailAll" class="org.hd.report.action.RptInDetailAction" method="rptInDetailAll">  
  10.         </action>  
  11.         <action name="rptInDetailPage" class="org.hd.report.action.RptInDetailAction" method="rptInDetailPage">  
  12.         </action>  


 

 效果:

 

 

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值