帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数

Posted 水狼一族

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数相关的知识,希望对你有一定的参考价值。

下面是页面代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<%
String deptIds = (String)request.getAttribute("departIds");

String dic="t_s_depart";
if(!"".equals(deptIds)){
    dic="t_s_depart where ID in ("+deptIds+")";
}

%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<html>
 <head>
  <title>FineReport Demo</title>
  <script src = "webpage/xiaohaojiao/date.js"></script>    
  <script type="text/javascript">
    $(document).ready(function(){
        $("#dept").change(function(){
              $("#department").val($(this).val());
        });

        //给时间控件加上样式
        $("#dates").click(function(){WdatePicker({dateFmt:yyyy-MM-dd});});
        $("#datez").click(function(){WdatePicker({dateFmt:yyyy-MM-dd});});
        getFineReport();
    });

    function getFineReport() {
        var value="";
        var key="";

        var map = {};
        var str ="";
        map["url"]=window.frames[0].location.toString();
        $(.searchParams).each(function () {
            value = $(this).val().toString();
            key=$(this).attr("id");
            map[key] = value;
            //主要:map转json字符串放入data
            str = JSON.stringify(map); 
        });
        $.ajax({
            type:"POST",
            url:"fineReportController.do?getFineUrl",
            data:{
                strMap:str
            }, 
            success:function(data){
                var d = $.parseJSON($.parseJSON(data).msg)[0];
                //姓名name是真实姓名_工号拼出来的,例如:张赛梅_160707302X
                window.frames[0].location=encodeURI(encodeURI(d.fineUrl));
            }
        });
    }
</script>
 </head>
 <body>
<div style="height:50px;">
    开始时间:<input id="dates" class="searchParams Wdate" type="text" value="${dates}" />
    结束时间:<input id="datez" class="searchParams Wdate" type="text"  value="${datez}"/>
    部门:
    <t:dictSelect id="dept" field="dept" type="list" dictTable="<%=dic%>" dictField="departname" dictText="departname" defaultVal="" hasLabel="false"  title="部门" ></t:dictSelect>     
    <input id="department" class="searchParams" value="" type="hidden" />
    姓名:<input id="name" class="searchParams" value="" type="text" />     
         
    <a class="l-btn" onclick="getFineReport()" href="#">
        <span class="l-btn-left">
            <span class="l-btn-text icon-search l-btn-icon-left">查询</span>
        </span>
    </a>
</div>
 
 <iframe id="reportFrame" width="100%" height="100%" src="${fineReport}" ></iframe>
 </body>
</html>

下面是后台代码:

package com.jeecg.xiaohaojiao.controller;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Validator;

import org.apache.log4j.Logger;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jeecg.xiaohaojiao.service.XhjUserDepartServiceI;
import com.jeecg.xiaohaojiao.util.RoleUtil;

import freemarker.template.SimpleDate;
import net.sf.json.JSONObject;


/**   
 * @Title: Controller  
 * @Description: 帆软报表页面跳转action
 * @author liuf
 * @date 2017-10-02 10:49:19
 * @version V1.0   
 *
 */
@Controller
@RequestMapping("/fineReportController")
public class FineReportController extends BaseController{
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(FineReportController.class);
    
    //不同角色对应的部门ids
    private String departIds = "";
    @Autowired
    private SystemService systemService;
    @Autowired
    private UserService userService;
    @Autowired
    private XhjUserDepartServiceI xhjUserDepartService;
    
    /**
     * 无查询条件帆软报表页面跳转方法
     * @param req
     * @return
     */
    @RequestMapping(params = "goFineReport")
    public ModelAndView goFineReport(HttpServletRequest req) {
        String id = req.getParameter("id");
        String fineReportPath = "../WebReport/ReportServer?reportlet="+id+".cpt";
        req.setAttribute("fineReport", fineReportPath);
        return new ModelAndView("xiaohaojiao/fineReport");
    }
    
    /**
     * 有查询条件需要控制页面权限帆软报表页面跳转方法
     * @param req
     * @return
     * @throws ParseException 
     */
    @RequestMapping(params = "goFineReportForParams")
    public ModelAndView goFineReportForParams(HttpServletRequest req) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM");
        
        Date date = new Date();
        String beginTime = sd.format(date);
        String endTime = sdf.format(date);
        req.setAttribute("dates", beginTime+"-01");
        req.setAttribute("datez", endTime);
        
        try {
            departIds = RoleUtil.getDeptIds(req,systemService,userService,xhjUserDepartService);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String id = req.getParameter("id");
        String fineReportPath = "../WebReport/ReportServer?reportlet="+id+".cpt";
        req.setAttribute("fineReport", fineReportPath);
        req.setAttribute("departIds", departIds);
        return new ModelAndView("xiaohaojiao/fineReportForParams");
    }
    
    /**
     * 页面点击查询的时候重新拼接的url,用于重新加载iframe
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(params = "getFineUrl")
    @ResponseBody
    public AjaxJson getFineUrl(HttpServletRequest request, HttpServletResponse response) throws Exception{
        String fineUrl = "";
        AjaxJson j = new AjaxJson();
        Map<String,Object> map = new HashMap<String ,Object>();
        String strMap = request.getParameter("strMap");
        JSONObject jb = JSONObject.fromObject(strMap);
        Map filterMap = (Map)jb;
        fineUrl = ((String) filterMap.get("url")).split("&")[0];
        Iterator<String> iter = filterMap.keySet().iterator();

        while (iter.hasNext()) {
           String key = iter.next();
           String value = (String) filterMap.get(key);
           if (!"url".equals(key)) {
               fineUrl = fineUrl + "&" + key + "=" + (value==null?"":value); 
           }               
        }
        map.put("fineUrl", fineUrl);
        net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(map);
        j.setMsg(jsonArray.toString());
        return j;
    }
}

 

以上是关于帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数的主要内容,如果未能解决你的问题,请参考以下文章

帆软报表单独部署后怎么调用servlet

在帆软报表中怎么设置区间控件

帆软报表获取当前tab的数据

在国内报表领域,广州思迈特Smartbi,帆软软件和润乾报表哪个比较强

帆软Bi报表工具和思迈特软件哪个更好用呢?

国内报表软件领域,Smartbi、帆软和润乾报表哪个比较强?