@Override public String insertFinanceReport(HttpServletRequest request, HttpServletResponse response) throws Exception { // 获得上传的附件 InputStream is = null; MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("tableImportTemplate"); if (null == multipartFile) { throw new BusinessException("没有上传财务报表"); } // 上传的参数据 Map<String, String> model = QueryUtil.getRequestParameterMapByAjax(request); // 列名对象解析 String financeparams = model.get("parames"); if (null == financeparams || "".equals(financeparams) || "null".equalsIgnoreCase(financeparams.trim())) { throw new BusinessException("没有对Excel的配置"); } try { BaseFile bf = templateService.saveUpFiletoService(multipartFile, model); String custid = ""; CustInfo custinfo = null; if (model.containsKey("custid")) { custid = model.get("custid"); custinfo = this.tableService.findEntityByID(CustInfo.class, custid); if (null == custinfo) { throw new BusinessException("给定的客户的ID没有找到客户"); } } else { throw new BusinessException("没有给定客户的ID"); } Workbook wb = null; is = multipartFile.getInputStream(); String importFileName = multipartFile.getOriginalFilename().toLowerCase(); if (importFileName.endsWith("xlsx")) { wb = PoiExcelUtil.readWorkbook(is, ExcelVersionEnum.VERSION2007); } else { wb = PoiExcelUtil.readWorkbook(is, ExcelVersionEnum.VERSION2003); } List<FinanceReportParamBean> inintParam = this.getImportParams(financeparams); if (inintParam.size() > 0) { for (FinanceReportParamBean param : inintParam) { Map<String, FinanceReportBean> Mapfield = this.getClassFieldExcel(param.getSheeName(), param.getTargetClass()); if (Mapfield.keySet().size() > 0) { try { Sheet sheet = wb.getSheet(param.getSheeName()); if (null != sheet) { List finance = (List) this.getFinanceReprotEntitysByConfig(sheet, Mapfield, param, bf, custinfo); // 保证实体 if (null != finance) { this.tableService.saveOrUpdateAllEntities(finance); } } else { throw new BusinessException("上传的EXCEL中没有" + param.getSheeName()); } } catch (Exception e) { // TODO Auto-generated catch block throw new BusinessException( "上传的EXCEL中没有" + param.getSheeName() + ":" + e.getMessage()); } } else { throw new BusinessException("excel中" + param.getSheeName() + "没有配置相应的类"); } } } else { throw new BusinessException("没有对Excel的配置"); } } catch (BusinessException b) { throw new BusinessException(b.getMessage()); } catch (Exception e) { e.printStackTrace(); // TODO Auto-generated catch block throw new BusinessException(e.getMessage()); } return "成功"; }