poi导入案例

poi导入案例

/**
     * 门店导入
     *
     * @param file
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public List<MerchantExcelEntity> uploadMerchant(MultipartFile file) throws Exception {
        XSSFWorkbook book = null;
        List<MerchantExcelEntity> dataList = new ArrayList<>();
        try {
            book = new XSSFWorkbook(file.getInputStream());
            XSSFSheet sheet = book.getSheetAt(0);

            if (!"身份证".equals(sheet.getRow(0).getCell(3).getStringCellValue())) {
                throw new RuntimeException("请上传正确的门店导入文件");
            }
            if (!"开户行".equals(sheet.getRow(0).getCell(5).getStringCellValue())) {
                throw new RuntimeException("请上传正确的门店导入文件");
            }

            XSSFRow row1 = sheet.getRow(0);
            int i = 0;
            while ((++i) <= sheet.getLastRowNum()) {
                XSSFRow row = sheet.getRow(i);
                MerchantExcelEntity entity = new MerchantExcelEntity();
                if (null != row.getCell(0)) {
                    row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setName(row.getCell(0).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "姓名为空");
                }
                if (null != row.getCell(1)) {
                    row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setTel(row.getCell(1).getStringCellValue());
                    if (entity.getTel().length() > 11) {
                        throw new RuntimeException("请输入正确的手机号");
                    }
                } else {
                    throw new RuntimeException("第" + (i + 1) + "手机号为空");
                }
                if (null != row.getCell(2)) {
                    row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setMerName(row.getCell(2).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "店铺名称为空");
                }
                if (null != row.getCell(3)) {
                    row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setIdNumber(row.getCell(3).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "身份证为空");
                }
                if (null != row.getCell(4)) {
                    row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setBankCard(row.getCell(4).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "银行卡号为空");
                }
                if (null != row.getCell(5)) {
                    row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setBankName(row.getCell(5).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "开户行为空");
                }
                if (null != row.getCell(6)) {
                    row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setRefundAddr(row.getCell(6).getStringCellValue());
                } else {
                    throw new RuntimeException("第" + (i + 1) + "退货地址为空");
                }
                if (null != row.getCell(7)) {
                    row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setIsCheck(Integer.valueOf(row.getCell(7).getStringCellValue()));
                } else {
                    throw new RuntimeException("第" + (i + 1) + "上架审核为空");
                }
                if (null != row.getCell(8)) {
                    row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setStockNum(Integer.valueOf(row.getCell(8).getStringCellValue()));
                } else {
                    throw new RuntimeException("第" + (i + 1) + "库存数量上限为空");
                }
                if (null != row.getCell(9)) {
                    row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setAddNum(Integer.valueOf(row.getCell(9).getStringCellValue()));
                } else {
                    throw new RuntimeException("第" + (i + 1) + "单次补货商品件数为空");
                }
                if (null != row.getCell(10)) {
                    row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
                    entity.setMerCode(row.getCell(10).getStringCellValue());
                }
                dataList.add(entity);
            }
        } catch (IOException e) {
            log.error("保存数据异常", e);
        }
        return dataList;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值