EchartData 统计报表以及导出Excel

jsp界面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <!--日历  -->
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/back/My97DatePicker/WdatePicker.js"></script>
    <!--柱状图  -->
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/back/echarts.min.js"></script>
    
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/back/comm.css" />
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/back/comm.css" />    
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/themes/icon.css">


    <script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/time-text/WdatePicker.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/jquery.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/jquery-easyui-1.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/dialog4/artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/thirdparts/dialog4/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/back/table-ghhs.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.form.js"></script>

    <script type="text/javascript">
    $(function(){
        //按钮权限
        var url = "<%=request.getContextPath()%>/jurisdiction/control.do";
        var href = window.location.pathname;
        //alert($(".function input")[0]);
        $.getJSON(url, {href:href}, function(data){
            //alert(data);
            $(".function input").each(function(i, item){
                var btnId = $(item).attr("id");
                //alert(btnId);
                var flag = false;
                $.each(data, function(j, menu){
                    if(menu.funurl == btnId){
                        flag = true;
                    }
                });
                if(flag==true){
                    $(item).show();
                }
            });
        });
        
    })
    
        $(function(){
            
            <%-- var msg = '<%= request.getAttribute(ResourceKeys.ALERT_MESSAGE)==null ? "":request.getAttribute(ResourceKeys.ALERT_MESSAGE).toString()%>';
            if(msg!=""){
                alert(msg);
            } --%>
        });
        
    </script>
    <script type="text/javascript">
        /**
         * 查询 - 分页
         * @param newPageIndex
         * @param formid
         */
        function pageIndexChanging(newPageIndex, formid){
            $("#pageIndex").val(newPageIndex);
            $("#"+formid).submit();
        }
        
        function refresh(){
            pageIndexChanging(1, "form1");
        }
        
        
        
    </script>

</head>
<body class="easyui-layout">
    <form id="form1" action="<%=request.getContextPath()%>/salarystatistic/list.do">
        <div class="container">
            <div class="content">
                <div class="loaction">
                    <p><span class="pl30">当前位置:</span>诺盾管理平台<span class="pl5"></span><span class="pl5">报表统计</span><span class="pl5"></span><span class="pl5">员工工资统计</span></p>
                </div>
                <!--功能按钮区域-->
               <!--  <div class="function">
                   <input style="display:none;" id="btnAddDept" type="button" value="新增工资" class="btn_new commbtn" οnclick="addDept()" />
                   <input style="display:none;" id="btnViewDept" type="button" value="查看详情" class="btn_find commbtn" οnclick="viewDept()" />
                   <input style="display:none;" id="btnUpdateDept" type="button" value="修改工资" class="btn_edit commbtn" οnclick="updateDept()" />
                   <input style="display:none;" id="btnDeleteDept" type="button" value="删除工资" class="btn_del commbtn" οnclick="deleteDept();" />
               </div> -->
                <div class="clear"></div>
                <!--查询条件区域-->
                <div class="funsearch">
                    <div class="search_list">
                        <%--   请选择员工:
                        <select id="empId" name="empid">
                            <option value="-1">请选择</option>
                            <c:forEach items="${empList}" var="emp">
                                                    
                                <option value="${emp.empid}">${emp.empname}</option>
                            </c:forEach>
                        
                        
                        </select>   --%>          
                        请选择年月:
                        <input  name="datetime" style="width: 120px;" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy'})"  value="${param.datetime}" />
    
                    </div>
                    <input type="button" οnclick="pageIndexChanging(1, 'form1');" class="search_bt commbtn" value="搜索" />
                         <!--     <input type="button" οnclick="pageIndexChanging(1, 'form1');" class="statement_bt commbtn" value="制作报表" />
            -->               <a href="<%= request.getContextPath()%>/salarystatistic/export.do?datetime=${datetime}" class="btn_new commbtn">
                     <!-- <i class="Hui-iconfont" >&#xe644;</i> --><span class="Hui-iconfont"> 导出到Excel</span></a>
                </div>
               
            </div>
        </div>
    </form>
    
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div style="font-size:24px;margin-top:10px;margin-bottom:10px;">该员工在该年月的工资明细 如下:</div>
    
    <div id="main" style="width: 600px;height:350px;"></div>
    <script type="text/javascript">
 // 基于准备好的dom,初始化echarts实例
       $(function(){
        var sta =$("input[name=datetime]").val();
        
        //alert(sta);
        //通过Ajax获取数据
        $.ajax({
            type : "get",
            async : false, //同步执行
            url : "<%=request.getContextPath()%>/salarystatistic/echartdata.json",
            
            data : {datetime:sta},
            dataType : "json", //返回数据形式为json
            success : function(result) {
                if (result) {
                    
                    // 基于准备好的dom,初始化echarts实例
                    var myChart = echarts.init(document.getElementById('main'));

                    // 指定图表的配置项和数据

                    var option = {
                        tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                        type : 'bar'        // 默认为直线,可选为:'line' | 'shadow'
                    }
                },
                legend: {
                    data:result.legend
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis : [
                    {
                        type : 'category',
                        data : result.category
                    }
                ],
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series : result.series};

                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                    
                    
                }
            },
            error : function(errorMsg) {
                alert("图表请求数据失败");
                myChart.hideLoading();
            }
        });
        
    });
    </script>
</body>
</html>


业务逻辑层

package com.wskj.ssm.controller;

import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wskj.ssm.framework.ResourceKeys;
import com.wskj.ssm.pojo.Category;
import com.wskj.ssm.pojo.Clientclassify;
import com.wskj.ssm.pojo.EchartData;
import com.wskj.ssm.pojo.Emp;
import com.wskj.ssm.pojo.Salary;
import com.wskj.ssm.pojo.Series;
import com.wskj.ssm.pojo.Tblgoodsbrand;
import com.wskj.ssm.service.CategoryService;
import com.wskj.ssm.service.EmpService;
import com.wskj.ssm.service.SalaryService;
import com.wskj.ssm.service.TblgoodsbrandService;
import com.wskj.ssm.util.ExcelUtil;
import com.wskj.ssm.util.PageUtil;

@Controller
@Scope("request")
@RequestMapping("/salarystatistic")
public class SalaryStatisticController {

    
    @Autowired
    private EmpService empService;
    @Autowired
    private SalaryService salaryService;
    
    
    /**
     * 返回list界面
     * @param model
     * @param datetime
     * @return
     */
    @RequestMapping("/list.do")
    public String list(Model model,String datetime){

        model.addAttribute("datetime", datetime);
        return "houtai/back/salarystatistic/list";
    }
    
    /**
     * 得到json数据
     * @param datetime
     * @param session
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="/echartdata.json",method=RequestMethod.GET)    
    public EchartData tree(String datetime,HttpSession session) throws Exception{
        Emp emp=(Emp) session.getAttribute("USER");
        Integer empid=emp.getEmpid();
         String name=empService.getEmpById(empid).getEmpname();
        //数据分组
        List<String> legend = new ArrayList<String>(Arrays.asList(new String[]{"维修量"}));
        //横坐标
        List<String> category = new ArrayList<String>(Arrays.asList(new String []{name}));
        //纵坐标
        List<Salary> salaryList=salaryService.getAllSalaryByTime(datetime,empid);
        
        List<Series> series = new ArrayList<Series>();
        List<Long> data=new ArrayList<Long>();
        
        for(Salary sa :salaryList){
            
            data.add(sa.getSalarysum());
            
        }
        
        
        
        
        series.add(new Series(name, "bar",data));
       
        EchartData echartData=new EchartData(legend, category, series);
      
        return echartData;
        
    }
    
    
    
    /**
     * 导出员工工资的表格
     * @param response
     * @return
     */
      @RequestMapping(value = "/export.do")
    @ResponseBody
    public Salary exportFeedBack(HttpSession session,String datetime,HttpServletResponse response){
          Emp emp=(Emp) session.getAttribute("USER");
        Integer empid=emp.getEmpid();

           List<Salary> salaryList=salaryService.getAllSalaryByTime(datetime,empid);
                
          String fileName = "员工工资"+System.currentTimeMillis()+".xls";
          
          String sheetName = "员工工资统计";
          
          String []title = new String[]{"员工姓名","员工工资","年月日"};
          
          String [][]values = new String[salaryList.size()][];
          
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
          
          for(int i=0;i<salaryList.size();i++){
            values[i] = new String[title.length];
            Salary salary = salaryList.get(i);
            values[i][0] = salary.getEmp().getEmpname() +"";
            values[i][1] = salary.getSalarysum() +"";
            values[i][2] = salary.getSalarytime() +"";    
            
          }     

          HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName, title, values, null);
             
         //将文件存到指定位置  
         try {  
              this.setResponseHeader(response, fileName);  
              OutputStream os = response.getOutputStream();  
              wb.write(os);  
              os.flush();  
              os.close();  
         } catch (Exception e) {  
              e.printStackTrace();  
         }  
         return null;
      }

      /**
       * 导出的表格的辅助方法
       * @param response
       * @param fileName
       */
    public void setResponseHeader(HttpServletResponse response, String fileName) {  
         try {  
              try {  
                   fileName = new String(fileName.getBytes(),"UTF-8");  
              } catch (UnsupportedEncodingException e) {  
                   // TODO Auto-generated catch block  
                   e.printStackTrace();  
              }  
              response.setContentType("application/octet-stream;charset=UTF-8");  
              response.setHeader("Content-Disposition", "attachment;filename="+ fileName);  
              response.addHeader("Pargam", "no-cache");  
              response.addHeader("Cache-Control", "no-cache");  
         } catch (Exception ex) {  
              ex.printStackTrace();  
         }  
    }    
        
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值