自动化立体仓库 - WMS系统
#
whycq
2024-04-28 4478d33ff79360c804f8bcad41384d5a4e040991
src/main/java/com/zy/asrs/controller/OrderController.java
@@ -596,4 +596,51 @@
        return R.ok("导入成功");
    }
    /**
     * excel导入
     */
    @PostMapping(value = "/order/excel/import2/auth")
    @ManagerAuth(memo = "销售单Excel导入")
    @Transactional
    public R cstmrExcelImport2(MultipartFile file) throws IOException {
        InputStream inStream = file.getInputStream();
        String fileMime = file.getContentType();
        int excelVersion = 2007;
        if ("application/vnd.ms-excel".equals(fileMime)) {
            excelVersion = 2003;
        }
        Workbook book = null;
        try {
            if (excelVersion == 2003) {
                book = new HSSFWorkbook(inStream);
            }
            else {  // 当 excel 是 2007 时
                book = new XSSFWorkbook(inStream);
            }
        } catch (Exception e) {
            log.error("fail", e);
            return R.error("导入文件格式错误,请使用xls后缀的文件!");
        }
        Sheet sheet = book.getSheetAt(0);
        int totalRows = sheet.getLastRowNum() + 1;    // 总
        DataFormatter dataFormatter = new DataFormatter();
        List<String> strs = new ArrayList<>();
        for (int i = 1; i < totalRows; i++) {
            Row row = sheet.getRow(i);
            //单据类型
            String docName =  dataFormatter.formatCellValue(row.getCell(0));
            //单据编号
            String uuid = dataFormatter.formatCellValue(row.getCell(1));
            //物料号
            String matnr = dataFormatter.formatCellValue(row.getCell(2));
            Mat mat = matService.selectByMatnr(matnr);
            if (null == mat) {
                strs.add(matnr);
//                throw new CoolException(matnr + "商品编码的商品不存在,请检查!");
            }
        }
        return R.ok("导入成功").add(strs);
    }
}