参考用例之“本地Excel导入系统测试方案”

本地Excel导入系统测试方案

Excel

 

代码

    @Test
    public void importperson() throws FileNotFoundException
    {
        FileInputStream fis = new FileInputStream(new File("C:\\Users\\wzw\\Desktop\\wzwcs.xlsx"));
        Workbook sheets = ExcelUtils.readExcel(fis);
        Sheet sheet = sheets.getSheetAt(0);
        int rowNum = sheet.getLastRowNum();

        List<Order> orders = new ArrayList<Order>();

        Row row = null;
        for (int i = 1; i < rowNum + 1; i++)
        {

            row = sheet.getRow(i);
            if (row != null)
            {
                Order order = new Order();
                orders.add(order);

                // 1列
                Cell cell0 = row.getCell(0);
                String account = ExcelUtils.getCellTrimValue(cell0);
                if (cell0 != null || StringUtils.isNotBlank(account))
                {
                    order.setAccount(account);
                }

                // 2列
                Cell cell1 = row.getCell(1);
                String platformOrderId = ExcelUtils.getCellTrimValue(cell1);
                if (cell1 != null || StringUtils.isNotBlank(platformOrderId))
                {
                    order.setPlatformOrderId(platformOrderId);
                }

                // 3列
                Cell cell2 = row.getCell(2);
                String successFee = ExcelUtils.getCellTrimValue(cell2);
                if (cell2 != null || StringUtils.isNotBlank(successFee))
                {
                    order.setSuccessFee(Double.valueOf(successFee));
                }

                // 4列
                Cell cell3 = row.getCell(3);
                String successFeeConvert = ExcelUtils.getCellTrimValue(cell3);
                if (cell3 != null || StringUtils.isNotBlank(successFeeConvert))
                {
                    order.setSuccessFeeConvert(Double.valueOf(successFeeConvert));
                }

                // 5列
                Cell cell4 = row.getCell(4);
                String orderTotalMoney = ExcelUtils.getCellTrimValue(cell4);
                if (cell4 != null || StringUtils.isNotBlank(orderTotalMoney))
                {
                    order.setOrderTotalMoney(Double.valueOf(orderTotalMoney));
                }

                // 6列
                Cell cell5 = row.getCell(5);
                String orderTotalMoneyConvert = ExcelUtils.getCellTrimValue(cell5);
                if (cell5 != null || StringUtils.isNotBlank(orderTotalMoneyConvert))
                {
                    order.setOrderTotalMoneyConvert(Double.valueOf(orderTotalMoneyConvert));
                }

                // 7列
                Cell cell6 = row.getCell(6);
                String rmbExchange = ExcelUtils.getCellTrimValue(cell6);
                if (cell6 != null || StringUtils.isNotBlank(rmbExchange))
                {
                    order.setRmbExchange(Double.valueOf(rmbExchange));
                }

                // 8列
                Cell cell7 = row.getCell(7);
                String shipmentsTime = ExcelUtils.getCellTrimValue(cell7);
                if (cell7 != null || StringUtils.isNotBlank(shipmentsTime))
                {
                    order.setShipmentsTime(LocalDateTime.parse(shipmentsTime, DateTimeFormatter
                            .ofPattern("yyyy-MM-dd HH:mm:ss")));
                }

                // 9列
                order.setIsShipments(1);
            }
        }
      KafkaUtils.batchSaveKafka(主题, orders); System.out.println(
"orders = " + orders.size()); }

 结果图

posted @ 2023-08-04 17:27  骚哥  阅读(41)  评论(0编辑  收藏  举报