导入过程中完成数据校验

//    /**
//     * 导入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 + "条");
//    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值