jeecg 综合报表

1。jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>



















2.controller

//班级学生人数比例分析国际化Key
    private static final String CLASS_STUDENT_COUNT_ANALYSIS = "Case type scale";

    @Autowired
    private MutiLangServiceI mutiLangService;
    
    
    /**
	 * 统计集合页面
	 * 
	 * @return
	 */
	@RequestMapping(params = "imgCount")
	public ModelAndView studentStatisticTabs(HttpServletRequest request) {
		return new ModelAndView("cn/com/skyvis/bqaj/count");
	}
	
	@RequestMapping(params = "listAllStatisticByJdbc")
	public void listAllStatisticByJdbc(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		List> maplist=systemService.findForJdbc("select  ajlx,count(ajlx) personcount from bqaj_caseinfo  GROUP BY ajlx", null);
		Long countSutent = systemService.getCountForJdbc("SELECT COUNT(1) FROM bqaj_caseinfo WHERE 1=1");
		for(Map map:maplist){
			Long personcount = Long.parseLong(map.get("personcount").toString());
			Double  percentage = 0.0;
			if (personcount != null && personcount.intValue() != 0) {
				percentage = new Double(personcount)/countSutent;
			}
			
			map.put("rate", String.format("%.2f", percentage*100)+"%");
		}
		Long count = 0L;
		if(JdbcDao.DATABSE_TYPE_SQLSERVER.equals(DBTypeUtil.getDBType())){
			count = systemService.getCountForJdbcParam("select count(0) from ( select  ajlx classname,count(ajlx) totalclass from bqaj_caseinfo  GROUP BY ajlx ) as t( classname, totalclass)",null);
		}else{
			count = systemService.getCountForJdbcParam("select count(0) from (select  ajlx,count(ajlx) from bqaj_caseinfo  GROUP BY ajlx)t",null);
		}
		
		dataGrid.setTotal(count.intValue());
		dataGrid.setResults(maplist);
		TagUtil.datagrid(response, dataGrid);
	}


	/**
	 * 报表数据生成
	 * 
	 * @return
	 */
	@RequestMapping(params = "studentCount")
	@ResponseBody
	public List studentCount(HttpServletRequest request,String reportType, HttpServletResponse response) {
		List list = new ArrayList();
		Highchart hc = new Highchart();
		StringBuffer sb = new StringBuffer();
		sb.append("select ajlx,count(ajlx) from CaseInfosEntity  GROUP BY ajlx");
		List userBroswerList = systemService.findByQueryString(sb.toString());
		Long count = systemService.getCountForJdbc("SELECT COUNT(1) FROM bqaj_caseinfo WHERE 1=1");
		List lt = new ArrayList();
		hc = new Highchart();
        //update-begin--Author:JueYue  Date:20140724 for:国际化--------------------
		hc.setName(mutiLangService.getLang(CLASS_STUDENT_COUNT_ANALYSIS));
        //update-end--Author:JueYue  Date:20140724 for:国际化--------------------
		hc.setType(reportType);
		Map map;
		if (userBroswerList.size() > 0) {
			for (Object object : userBroswerList) {
				map = new HashMap();
				Object[] obj = (Object[]) object;
				map.put("name", obj[0]);
				map.put("y", obj[1]);
				Long groupCount = (Long) obj[1];
				Double  percentage = 0.0;
				if (count != null && count.intValue() != 0) {
					percentage = new Double(groupCount)/count;
				}
				map.put("percentage", percentage*100);
				lt.add(map);
			}
		}
		hc.setData(lt);
		list.add(hc);
		return list;
	}
	
	
	/**
	 * 报表打印
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(params = "export")
	public void export(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String type = request.getParameter("type");
		String svg = request.getParameter("svg");
		String filename = request.getParameter("filename");

		filename = filename == null ? "chart" : filename;
		ServletOutputStream out = response.getOutputStream();
		try {
			if (null != type && null != svg) {
				svg = svg.replaceAll(":rect", "rect");
				String ext = "";
				Transcoder t = null;
				if (type.equals("image/png")) {
					ext = "png";
					t = new PNGTranscoder();
				} else if (type.equals("image/jpeg")) {
					ext = "jpg";
					t = new JPEGTranscoder();
				} else if (type.equals("application/pdf")) {
					ext = "pdf";
					t = (Transcoder) new PDFTranscoder();
				} else if (type.equals("image/svg+xml"))
					ext = "svg";
				response.addHeader("Content-Disposition",
						"attachment; filename=" + new String(filename.getBytes("GBK"),"ISO-8859-1") + "." + ext);
				response.addHeader("Content-Type", type);

				if (null != t) {
					TranscoderInput input = new TranscoderInput(
							new StringReader(svg));
					TranscoderOutput output = new TranscoderOutput(out);

					try {
						t.transcode(input, output);
					} catch (TranscoderException e) {
						out
								.print("Problem transcoding stream. See the web logs for more details.");
						e.printStackTrace();
					}
				} else if (ext.equals("svg")) {
					// out.print(svg);
					OutputStreamWriter writer = new OutputStreamWriter(out,
							"UTF-8");
					writer.append(svg);
					writer.close();
				} else
					out.print("Invalid type: " + type);
			} else {
				response.addHeader("Content-Type", "text/html");
				out
						.println("Usage:\n\tParameter [svg]: The DOM Element to be converted."
								+ "\n\tParameter [type]: The destination MIME type for the elment to be transcoded.");
			}
		} finally {
			if (out != null) {
				out.flush();
				out.close();
			}
		}
	}





你可能感兴趣的:(jeecg)