easyui datagrid以及oracle中的多行合并一行

页面显示:

《easyui datagrid以及oracle中的多行合并一行》

前端代码:

<table style="margin-top: 50px;" id="dgs" title="大箱码关联信息列表" class="easyui-datagrid" 
                    toolbar="#toolbar" rownumbers="true"  singleSelect="true" fitColumns="true">  
                <thead>  
                    <tr> 
                         <th data-options="field:'storecode',width:100,align:'center'">大箱码</th>
                            <th data-options="field:'casecode',width:300,align:'center'">关联的箱码(不同箱码用分号分开,相同箱码用逗号分开)</th>
                         <th data-options="field:'count',width:100,align:'center'">关联数量</th>
                     </tr>  
                </thead>  
                </table>  
                
             <div id="pp" class="easyui-pagination" style="border:1px solid #ccc;"  
                data-options="  
                    total: 0,  
                    pageSize:15,
                    pageList: [15,30,50,100],  
                        onSelectPage: function(pageNumber, pageSize){ // 页面切换动作  
                            getDataByPageRows(pageNumber,pageSize);     
                    }">  
            </div>             

js:

 function getDataByPageRows(pageNum, rowsLimit){  
        $("#pp").show();
               pageNum = pageNum || 1;     // 设置默认的页号  
               rowsLimit = rowsLimit || 2;// 设置默认的每页记录数  
               $.ajax({  
                   type: "POST",  
                   dataType: 'json',       // 注意格式是html,不是json  
                   url:"<%=basePath%>outdata/querydetaillist",
                   data: {  
                       startdate: $("#startdate").datetimebox('getValue'),
                       enddate: $("#enddate").datetimebox('getValue'),
                       storecode: $("#storecode").val(),
                       page: pageNum,
                       rows: rowsLimit
                   },  
                   success: function(data){   // 请求成功,将返回的数据(一页的记录数)绑定到 datagrid控件  
                       var count = data.total;   // 总记录个数  
                       var datarow = data.rows;  //获取条数;
                       $('#dgs').datagrid('loadData',datarow);  
                       $('#pp').pagination({  
                           total: count,           // 由于显示 ”共XXX条记录” 等信息用  
                           pageNumber: pageNum    //   
                       });  
                   }  
               });//ajax         
           }

controller:

@RequestMapping(value="/querydetaillist")
    @ResponseBody
    public String querydetaillist(Model model,HttpServletResponse response,HttpServletRequest request,
            @RequestParam(value = "page", required = false, defaultValue = "") String page,
            @RequestParam(value = "storecode", required = false, defaultValue = "") String storecode,
            @RequestParam(value = "startdate", required = false, defaultValue = "") String startdate,
            @RequestParam(value = "enddate", required = false, defaultValue = "") String enddate,
            @RequestParam(value = "rows", required = false, defaultValue = "") String rows){
        
        
        int endindex=Integer.valueOf(page)*Integer.valueOf(rows);
        int startindex=(Integer.valueOf(page)-1)*Integer.valueOf(rows);
        Map<String,Object> params = new HashMap<String, Object>();
        if(!storecode.equals("")){
            storecode = storecode.replaceFirst("^0*", ""); 
        }
        if(!startdate.equals("")){
            startdate = startdate.replaceAll(" ", "");
        }
        if(!enddate.equals("")){
            enddate = enddate.replaceAll(" ", "");
        }
        params.put("endIndex", endindex);
        params.put("storecode", storecode);
        params.put("startIndex", startindex);
        params.put("startdate", startdate);
        params.put("enddate", enddate);
        

        List<Store> datalist=outdataDao.querydetaillist(params);
        String total=outdataDao.querydetaillistcount(params);
        JSONObject obj=new JSONObject();
        obj.put("total", total);
        obj.put("rows", datalist);
        return obj.toJSONString();
    }

xml:

<select id="querydetaillist" resultType="Store" parameterType="Map">
          select  * from  (
        select tt1.*, ROWNUM as rowno
        from ( 
         
         select storecode,listagg(casecode,';') within group (order by casecode) as casecode,count(casecode) as "count" from
                (
                  select s.storecode,c.caseid,listagg(c.casecode,',')  within group (order by c.casecode,c.caseid) as casecode,
                  count(distinct caseid)
                  from ys_store s
                  left join ys_case c on s.id=c.storeid
                  where 1=1 and casecode is not null 
                 <if test="startdate != null   and startdate != ''"> and to_char(s.gldate,'yyyy-MM-dd')>='${startdate}'</if>
                 <if test="enddate != null   and enddate != ''"> and to_char(s.gldate,'yyyy-MM-dd')&lt;='${enddate}'</if>
                 <if test="storecode != null   and storecode != ''"> and s.storecode=${storecode}</if>
                  group by s.storecode,c.caseid
                )
                group by storecode
        
         ) tt1
                   where ROWNUM &lt;= '${endIndex}') tt2
            where tt2.rowno > '${startIndex}'
    
    </select>
    
    <select id="querydetaillistcount" resultType="String" parameterType="Map">
        select count(*) from(
             select storecode,listagg(casecode,';') within group (order by casecode) as casecode,count(casecode) as "count" from
                (
                  select s.storecode,c.caseid,listagg(c.casecode,',')  within group (order by c.casecode,c.caseid) as casecode,
                  count(distinct caseid)
                  from ys_store s
                  left join ys_case c on s.id=c.storeid
                  where 1=1 and casecode is not null 
                 <if test="startdate != null   and startdate != ''"> and to_char(s.gldate,'yyyy-MM-dd')>='${startdate}'</if>
                 <if test="enddate != null   and enddate != ''"> and to_char(s.gldate,'yyyy-MM-dd')&lt;='${enddate}'</if>
                 <if test="storecode != null   and storecode != ''"> and s.storecode=${storecode}</if>
                  group by s.storecode,c.caseid
                )
                group by storecode
        )
    </select>

参考文档:

easyui 中文网:http://www.jeasyui.net/plugin…
oracle多行合并成一行: listagg within group:http://blog.csdn.net/baojiang…

    原文作者:发愤图强的小陈
    原文地址: https://segmentfault.com/a/1190000013336303
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞