|
@@ -1,46 +1,127 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
+import cn.hutool.json.JSONString;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.persagy.ibms.core.data.SceneDataObject;
|
|
|
+import com.persagy.ibms.core.data.SceneDataSet;
|
|
|
+import com.persagy.ibms.core.data.SceneDataValue;
|
|
|
+import com.persagy.ibms.core.util.ExamineUtil;
|
|
|
+import com.persagy.ibms.core.util.ExceptionItem;
|
|
|
+import com.persagy.ibms.core.util.QueryAssist;
|
|
|
+import com.persagy.ibms.core.util.QueryUtil;
|
|
|
+import com.persagy.ibms.data.sdk.service.rest.RestUtil;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.springframework.core.serializer.Serializer;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.io.ObjectInputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class ExeclReadEquipStaticInfoUtil {
|
|
|
|
|
|
- public static JSONObject ReadEquipStaticInfo(String firstName, String sheetName) throws Exception {
|
|
|
- FileInputStream fis = new FileInputStream(FileUtil.file(firstName + ".xlsx"));
|
|
|
- Workbook workbook = WorkbookFactory.create(new BufferedInputStream(fis));
|
|
|
- Sheet sheet = workbook.getSheet(sheetName);
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
- // 获取合并单元格的值
|
|
|
- CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
- int firstRow = ca.getFirstRow();
|
|
|
- Row fRow = sheet.getRow(firstRow);
|
|
|
- Cell fCell = fRow.getCell(0);
|
|
|
- String caVal = getCellValue(fCell);
|
|
|
- // 获取合并单元格之后的值,形成树形结构
|
|
|
- JSONArray dic = new JSONArray();
|
|
|
- for (int j = firstRow; j <= ca.getLastRow(); j++) {
|
|
|
- Row row = sheet.getRow(j);
|
|
|
- JSONObject obj = new JSONObject();
|
|
|
- obj.put("name", getCellValue(row.getCell(1)));
|
|
|
- obj.put("code", getCellValue(row.getCell(2)));
|
|
|
- obj.put("enable", row.getCell(3).getBooleanCellValue());
|
|
|
- dic.add(obj);
|
|
|
- }
|
|
|
- object.put(caVal, dic);
|
|
|
- }
|
|
|
- fis.close();
|
|
|
- return object;
|
|
|
- }
|
|
|
+ public static JSONObject ReadEquipStaticInfo(String firstName, String sheetName) throws Exception {
|
|
|
+ FileInputStream fis = new FileInputStream(FileUtil.file(firstName + ".xlsx"));
|
|
|
+ Workbook workbook = WorkbookFactory.create(new BufferedInputStream(fis));
|
|
|
+ Sheet sheet = workbook.getSheet(sheetName);
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
+ // 获取合并单元格的值
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
+ int firstRow = ca.getFirstRow();
|
|
|
+ Row fRow = sheet.getRow(firstRow);
|
|
|
+ Cell fCell = fRow.getCell(0);
|
|
|
+ String caVal = getCellValue(fCell);
|
|
|
+ // 获取合并单元格之后的值,形成树形结构
|
|
|
+ JSONArray dic = new JSONArray();
|
|
|
+ for (int j = firstRow; j <= ca.getLastRow(); j++) {
|
|
|
+ Row row = sheet.getRow(j);
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("name", getCellValue(row.getCell(1)));
|
|
|
+ obj.put("code", getCellValue(row.getCell(2)));
|
|
|
+ obj.put("enable", row.getCell(3).getBooleanCellValue());
|
|
|
+ dic.add(obj);
|
|
|
+ }
|
|
|
+ object.put(caVal, dic);
|
|
|
+ }
|
|
|
+ fis.close();
|
|
|
+ return object;
|
|
|
+ }
|
|
|
|
|
|
- public static String getCellValue(Cell cell) {
|
|
|
- if (cell == null)
|
|
|
- return "";
|
|
|
- return cell.getStringCellValue();
|
|
|
- }
|
|
|
+ public static JSONObject ReadEquipStaticInfoById(String objId) throws Exception {
|
|
|
+ RepositoryImpl Repository = RepositoryContainer.instance;
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ String code = "classCode";
|
|
|
+ //获取此设备的对象数据
|
|
|
+ JSONObject eqObj= Repository.id2object.get(objId);
|
|
|
+ //获取classCode的值
|
|
|
+ String pointString = eqObj.getString(code);
|
|
|
+ //获取管理范围的classArray
|
|
|
+ SceneDataSet zktClassArray = Repository.ZKTClassArray;
|
|
|
+ String ibmsSceneCode = null;
|
|
|
+ String ibmsClassCode = null;
|
|
|
+ String classCode = "";
|
|
|
+ for (int i = 0; i < zktClassArray.set.size(); i++) {
|
|
|
+ SceneDataObject classObj = zktClassArray.set.get(i);
|
|
|
+ String codeVal = classObj.get("code").value_prim.toString();
|
|
|
+ //遍历查询classCode对应的ibmsSceneCode和ibmsClassCode
|
|
|
+ if (codeVal.equals(pointString)) {
|
|
|
+ classCode = codeVal;
|
|
|
+ ibmsSceneCode = classObj.get("ibmsSceneCode").value_prim.toString();
|
|
|
+ ibmsClassCode = classObj.get("ibmsClassCode").value_prim.toString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //如果ibmsClassCode和ibmsSceneCode为空则返回,意味着查询失败
|
|
|
+ if (ibmsSceneCode.isEmpty() && ibmsClassCode.isEmpty()) {
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+ //根据ibmsSceneCode和ibmsClassCode查询对应的excel获取台账信息点
|
|
|
+ FileInputStream fis = new FileInputStream(FileUtil.file(ibmsSceneCode + ".xlsx"));
|
|
|
+ Workbook workbook = WorkbookFactory.create(new BufferedInputStream(fis));
|
|
|
+ Sheet sheet = workbook.getSheet(ibmsClassCode);
|
|
|
+ for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
|
|
+ // 获取合并单元格的值
|
|
|
+ CellRangeAddress ca = sheet.getMergedRegion(i);
|
|
|
+ int firstRow = ca.getFirstRow();
|
|
|
+ Row fRow = sheet.getRow(firstRow);
|
|
|
+ Cell fCell = fRow.getCell(0);
|
|
|
+ String caVal = getCellValue(fCell);
|
|
|
+ // 获取合并单元格之后的值,形成树形结构
|
|
|
+ JSONArray dic = new JSONArray();
|
|
|
+ //获取这个设备类的信息点列表
|
|
|
+ JSONArray array = Repository.infoArrayJson.get(classCode);
|
|
|
+ for (int j = firstRow; j <= ca.getLastRow(); j++) {
|
|
|
+ Row row = sheet.getRow(j);
|
|
|
+ String codeInfo = getCellValue(row.getCell(1));
|
|
|
+ for (int z = 0; z < array.size(); z++) {
|
|
|
+ JSONObject obj= (JSONObject) array.get(z);
|
|
|
+ String codeVal=obj.get("code").toString();
|
|
|
+ if(codeVal.equals(codeInfo))
|
|
|
+ {
|
|
|
+ obj.put("data",eqObj.get(codeInfo));
|
|
|
+ obj.put("enable",row.getCell(2).getBooleanCellValue());
|
|
|
+ dic.add(obj);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ object.put(caVal, dic);
|
|
|
+ }
|
|
|
+ fis.close();
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getCellValue(Cell cell) {
|
|
|
+ if (cell == null)
|
|
|
+ return "";
|
|
|
+ return cell.getStringCellValue();
|
|
|
+ }
|
|
|
}
|