From 692c1a185d768a18c2007348806d775b2fbdeaa7 Mon Sep 17 00:00:00 2001 From: wuyouming666 <2265557248@qq.com> Date: 星期五, 23 二月 2024 09:45:19 +0800 Subject: [PATCH] 增加MQ 示例 --- springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java b/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java index 20ed8a4..d8311d6 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java +++ b/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java @@ -18,15 +18,15 @@ public class ExcelToJsonConverter { public static void main(String[] args) { - String excelFilePath = "JsonFile/state.xlsx"; + String excelFilePath = "src/main/resources/JsonFile/alarm.xlsx"; String sheetName = "Sheet1"; int addressColumnIndex = 0; int nameColumnIndex = 1; - int unitColumnIndex = 2; - String outputFilePath = "JsonFile/state.json"; + //int unitColumnIndex = 2; + String outputFilePath = "src/main/resources/JsonFile/PlcAlarm.json"; - try (Workbook workbook = new HSSFWorkbook(new FileInputStream(excelFilePath))) { + try (Workbook workbook = new XSSFWorkbook(new FileInputStream(excelFilePath))) { Sheet sheet = workbook.getSheet(sheetName); List<LinkedHashMap<String, Object>> jsonList = new ArrayList<>(); @@ -38,19 +38,19 @@ } int plcAddressLength = 0; // 璁板綍鎵�鏈� addressLenght 鐨勫拰 - + int addressIndex = 0; // 鑷鐨勫湴鍧�绱㈠紩 while (rowIterator.hasNext()) { Row row = rowIterator.next(); Cell nameCell = row.getCell(nameColumnIndex); Cell addressCell = row.getCell(addressColumnIndex); - Cell unitCell = row.getCell(unitColumnIndex); + // Cell unitCell = row.getCell(unitColumnIndex); String name = nameCell.getStringCellValue(); String address = addressCell.getStringCellValue(); - String unit = unitCell.getStringCellValue(); + // String unit = unitCell.getStringCellValue(); - String addressIndex = extractAddressIndex(address); + // String addressIndex = extractAddressIndex(address); LinkedHashMap<String, Object> jsonObject = new LinkedHashMap<>(); jsonObject.put("codeId", name); @@ -62,19 +62,21 @@ } else { addressLength = 2; } - jsonObject.put("addressLenght", String.valueOf(addressLength)); + // jsonObject.put("addressLenght", String.valueOf(addressLength)); - jsonObject.put("unit", unit); + //jsonObject.put("unit", unit); plcAddressLength += addressLength; jsonList.add(jsonObject); + addressIndex++; } LinkedHashMap<String, Object> resultObject = new LinkedHashMap<>(); resultObject.put("plcAddressBegin", "DB100.0"); resultObject.put("plcAddressLenght", String.valueOf(plcAddressLength)); - resultObject.put("dataType", "word"); + // resultObject.put("dataType", "word"); + resultObject.put("dataType", "bit"); resultObject.put("parameteInfor", jsonList); Gson gson = new Gson(); @@ -88,6 +90,8 @@ } } + + private static String extractAddressIndex(String address) { // Assuming the address format is "DB103.DBW0" or "DB103.DBB100~DBB113" if (address.startsWith("DB") && address.contains(".DBW")) { -- Gitblit v1.8.0