package com.doumee.core.haikang.isapi;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.doumee.core.haikang.isapi.model.DockDeviceDTO;
|
import com.doumee.core.haikang.isapi.model.DockStationBasicInfoDTO;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* ISAPI JSON 响应解析(采集站 dockStation 接口)
|
*/
|
public final class IsapiJsonParser {
|
|
private IsapiJsonParser() {
|
}
|
|
public static DockStationBasicInfoDTO parseDockBasicInfo(String json) {
|
if (json == null || json.isEmpty()) {
|
return null;
|
}
|
try {
|
JSONObject root = JSONObject.parseObject(json);
|
JSONObject basic = root.getJSONObject("BasicInfo");
|
if (basic == null) {
|
return null;
|
}
|
DockStationBasicInfoDTO dto = new DockStationBasicInfoDTO();
|
dto.setDockStationId(basic.getString("dockStationID"));
|
dto.setDockStationType(basic.getString("dockStationType"));
|
return dto;
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
public static List<DockDeviceDTO> parseDockDeviceList(String json) {
|
List<DockDeviceDTO> list = new ArrayList<>();
|
if (json == null || json.isEmpty()) {
|
return list;
|
}
|
try {
|
JSONObject root = JSONObject.parseObject(json);
|
JSONArray deviceInfoList = root.getJSONArray("DeviceInfoList");
|
if (deviceInfoList == null) {
|
return list;
|
}
|
for (int i = 0; i < deviceInfoList.size(); i++) {
|
JSONObject item = deviceInfoList.getJSONObject(i);
|
if (item == null) {
|
continue;
|
}
|
JSONObject info = item.getJSONObject("DeviceInfo");
|
if (info == null) {
|
continue;
|
}
|
DockDeviceDTO dto = new DockDeviceDTO();
|
dto.setDeviceId(info.getString("deviceId"));
|
dto.setDeviceName(info.getString("deviceName"));
|
dto.setShortSerialNumber(info.getString("shortSerialNumber"));
|
dto.setAccessDeviceId(info.getString("accessDeviceID"));
|
dto.setNetworkedDevice(info.getBoolean("isNetworkedDevice"));
|
list.add(dto);
|
}
|
} catch (Exception ignored) {
|
}
|
return list;
|
}
|
}
|