mybatis框架,用List存放HashMap,根据前台返回不同查询条件参数匹配数据库遍历取出导入EXCEL

public String exportToExcel() throws WFException{
    	String page = SUCCESS;
    	try {
    	    String template = getRequest().getParameter("template");//Excel模板名称
    		String tablename =getRequest().getParameter("tablename");//表名
    		String uuid =getRequest().getParameter("uuid");
    		String filepath =this.getRealyPath("/back/excel/"+template+".xlsx");
    		HashMap map = new HashMap();
    		map.put("tablename", tablename);
    		map.put("uuid", uuid);
    		XSSFWorkbook wb = iexportexcelbiz.getExcelTemplate(filepath, map);
    		ByteArrayOutputStream output = new ByteArrayOutputStream();  
            wb.write(output);  
            byte[] ba = output.toByteArray();  
            this.setFilename(DateUtil.getThisDate()+".xlsx");
            this.setDownStream(new ByteArrayInputStream(ba));
            getSession().setAttribute("percent", "100");
    		
 /*           OutputStream os = getResponse().getOutputStream();
            
            getResponse().setContentType("application/vnd.ms-excel");
    		getResponse().setHeader(
    			"Content-disposition",
    			"attachment; filename="+DateUtil.getThisDate()+".xlsx");
    		wb.write(os);*/
		} catch (Exception e) {
			// TODO: handle exception
//			super.outJsonString("");
			log.error("采取导入后导出表单数据信息!",e);
			getRequest().setAttribute("info", "导出数据信息失败请查明原因!");
			getRequest().setAttribute("warning", e);
			throw new WFException("导入后数据信息失败请查明原因!",e);
		} 
    	return page;
    }

//通过前台查询条件分别返回不同list   YJF  2018/06/29
	private List findDataList(HashMap map) throws WFException {	
		String tablename = (String)map.get("tablename");
		String fparentid = (String)map.get("uuid");
		String ddfk = (String)map.get("ddfk");
		String rwjsr = (String)map.get("rwjsr");
		String fxy = (String)map.get("fxy");
		String xyfk = (String)map.get("xyfk");
		String YJ="YJ";
		List list=null;
		//List list=icoredao.findList(tablename, " and FPARENTID='"+fparentid+"'"+" and "+YJ+"='"+ddfk+"'");
		//List list=icoredao.viewList(tablename, " and fparentid='"+fparentid+"'");
		if(ddfk.equals("")&&rwjsr.equals("")&&fxy.equals("")&&xyfk.equals("")){
			 list=icoredao.viewList(tablename, "fparentid='"+fparentid+"'");
		}else if(!ddfk.equals("")&&rwjsr.equals("")&&fxy.equals("")&&xyfk.equals("")){
			if(ddfk.equals("已反馈")){
				String str="(YJ='正常' or YJ='异常')";
			 list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and "+str);}
			else{list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and "+YJ+"='"+ddfk+"'");}
		}
		else if(ddfk.equals("")&&!rwjsr.equals("")&&fxy.equals("")&&xyfk.equals("")){
			 list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and JSR='"+rwjsr+"'");
		}
		else if(ddfk.equals("")&&rwjsr.equals("")&&!fxy.equals("")&&xyfk.equals("")){
			if(fxy.equals("已发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY='1'");
			}else if(fxy.equals("未发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY is NULL");
			}
		}
		else if(ddfk.equals("")&&rwjsr.equals("")&&fxy.equals("")&&!xyfk.equals("")){
			if(xyfk.equals("已反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFK='1'");
			}else if(xyfk.equals("未反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFk is NULL");
			}
		}
		else if(!ddfk.equals("")&&!rwjsr.equals("")&&fxy.equals("")&&xyfk.equals("")){
			if(ddfk.equals("已反馈")){
				String str="(YJ='正常' or YJ='异常')";
			 list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and "+str+" and JSR='"+rwjsr+"'");}
			else { list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and "+YJ+"='"+ddfk+"'"+" and JSR='"+rwjsr+"'");}
		}
		else if(!ddfk.equals("")&&rwjsr.equals("")&&!fxy.equals("")&&xyfk.equals("")){
			if(fxy.equals("已发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY='1'"+" and "+YJ+"='"+ddfk+"'");
			}else if(fxy.equals("未发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY is NULL"+" and "+YJ+"='"+ddfk+"'");
			}
		}
		else if(!ddfk.equals("")&&rwjsr.equals("")&&fxy.equals("")&&!xyfk.equals("")){
			if(xyfk.equals("已反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFK='1'"+" and "+YJ+"='"+ddfk+"'");
			}else if(xyfk.equals("未反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFk is NULL"+" and "+YJ+"='"+ddfk+"'");
			}
		}
		
		else if(ddfk.equals("")&&!rwjsr.equals("")&&!fxy.equals("")&&xyfk.equals("")){
			if(fxy.equals("已发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY='1'"+" and JSR='"+rwjsr+"'");
			}else if(fxy.equals("未发学院")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and FXY is NULL"+" and JSR='"+rwjsr+"'");
			}
		}
		else if(ddfk.equals("")&&!rwjsr.equals("")&&fxy.equals("")&&!xyfk.equals("")){
			if(xyfk.equals("已反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFK='1'"+" and JSR='"+rwjsr+"'");
			}else if(xyfk.equals("未反馈")){
				list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and XYFk is NULL"+" and JSR='"+rwjsr+"'");
			}
		}
		else if(ddfk.equals("")&&rwjsr.equals("")&&!fxy.equals("")&&!xyfk.equals("")){
			list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'");
		}
		else if(!ddfk.equals("")&&!rwjsr.equals("")&&!fxy.equals("")&&!xyfk.equals("")){
			list=icoredao.viewList(tablename, " fparentid='"+fparentid+"'"+" and "+YJ+"='"+ddfk+"'"+" and JSR='"+rwjsr+"'");
		}
		
		return list; 
		
	}

/**
	 * 根据表名和条件查询视图   YJF  2018/07/03
	 */
	public List viewList(String tablename, String condition) {
		CoreEntity core = new CoreEntity();
		String sql = "select * from " + tablename + " where " + condition;
		core.setHisql(sql);
		List result = getSqlMapClientTemplate().queryForList("COREDAO.getDynamicCOL", core);
		return result;
	}

你可能感兴趣的:(mybatis框架,用List存放HashMap,根据前台返回不同查询条件参数匹配数据库遍历取出导入EXCEL)