// /** // * 导入Cms指标数据信息Excel // * // * @param file // * @return // * @throws Exception // */ // @SysLog("导入Cms指标数据信息Excel") // @RequestMapping("/import") // @RequiresPermissions("cms:data:import") // public R importExcel(@RequestParam MultipartFile file) throws Exception { // if (file.isEmpty()) { // throw new RRException("上传文件不能为空"); // } // // // 首先校验文件格式是否满足要求 // String[] allowedFileSuffix = { "xls", "xlsx" }; // String fileSuffix = FilenameUtils.getExtension(file.getOriginalFilename()); // if (!ArrayUtils.contains(allowedFileSuffix, fileSuffix)) { // return R.error("请上传xls、xlsx格式数据文件!"); // } // // Workbook wb = WorkbookFactory.create(file.getInputStream()); // // 用getSheetAt(int)方法取得Sheet // Sheet st = wb.getSheetAt(0); // // 获得最后一行的行号 // int rownum = st.getLastRowNum(); // // 记录导入开始时间 // long start = System.currentTimeMillis(); // List<CmsDataEntity> list = new ArrayList<>(); // //处理单元格内数据类型 // Cell cell; // for (int i = 1; i <= rownum; i++) { // Row row = st.getRow(i); // // //获取每一行记录的每个单元格数据信息 // List<Cell> cellList = new ArrayList<>(); // for (int j = 0; j < 6; j++) { // cell = row.getCell(j); // cell.setCellType(CellType.STRING); // cellList.add(cell); // } // // //校验导入的指标信息 // int baseItemCount = cmsBaseItemService.selectCount(new EntityWrapper<CmsBaseItemEntity>().eq("kpi_id",cellList.get(4).toString()) // .like("kpi_name",cellList.get(5).toString())); // //校验导入的团队信息 // int teamCount = cmsTeamService.selectCount(new EntityWrapper<CmsTeamEntity>().eq("id",cellList.get(2).toString()) // .like("name",cellList.get(3).toString())); // // //为每一条记录创建实体 // CmsDataEntity cmsData = new CmsDataEntity(); // // //判断指标是否存在 // if(baseItemCount != 0) { // //判断团队是否存在 // if(teamCount != 0) { // if (row.getCell(0) != null) { // cell = row.getCell(0); // cell.setCellType(CellType.STRING); // cmsData.setCityId(StringUtils.trimToEmpty(String.valueOf(cell))); // } // // if (row.getCell(1) != null) { // cell = row.getCell(1); // cell.setCellType(CellType.STRING); // cmsData.setBizMonth(StringUtils.trimToEmpty(String.valueOf(cell))); // } // // if (row.getCell(2) != null) { // cell = row.getCell(2); // cell.setCellType(CellType.STRING); // cmsData.setTeamId(StringUtils.trimToEmpty(String.valueOf(cell))); // } // // if (row.getCell(3) != null) { // cmsData.setTeamName(StringUtils.trimToEmpty(String.valueOf(row.getCell(3)))); // } // // if (row.getCell(4) != null) { // cell = row.getCell(4); // cell.setCellType(CellType.STRING); // cmsData.setKpiId(StringUtils.trimToEmpty(String.valueOf(cell))); // } // // if (row.getCell(5) != null) { // cmsData.setKpiName(StringUtils.trimToEmpty(String.valueOf(row.getCell(5)))); // } // // if (row.getCell(6) != null) { // cell = row.getCell(6); // String cellStr = String.valueOf(cell); // cell.setCellType(CellType.STRING); // String cellValue = cell.getStringCellValue(); // cmsData.setKpiValue(StringUtils.trimToEmpty(String.valueOf(cell))); // //存在小数点单独处理 // if(cellValue.indexOf(".") > -1) { // cellValue = cellStr; // cmsData.setKpiValue(StringUtils.trimToEmpty(String.valueOf(cellValue))); // } // } // } else { // return R.error("第" + i + "条记录团队数据信息异常"); // } // } else{ // return R.error("第" + i + "条记录指标数据信息异常"); // } // // cmsData.preInsert(); // list.add(cmsData); // } // // if (CollectionUtils.isNotEmpty(list)) { // cmsDataService.saveObj(list); // } // // 记录导入开始时间 // long end = System.currentTimeMillis(); // logger.info("导入耗时::{}毫秒", (end - start)); // return R.ok("成功导入数据信息:" + rownum + "条"); // }
导入过程中完成数据校验
最新推荐文章于 2024-06-07 09:10:48 发布