Browse Source

KingIoServer 增加新的Bacnet数据格式解析

zhczh_c
zhczyx@163.com 3 weeks ago
parent
commit
9054141457
  1. 36
      src/main/java/com/techsor/datacenter/sender/dao/TypeDAO.java
  2. 32
      src/main/java/com/techsor/datacenter/sender/entitiy/TypeEntity.java
  3. 191
      src/main/java/com/techsor/datacenter/sender/service/KingIOServerService.java

36
src/main/java/com/techsor/datacenter/sender/dao/TypeDAO.java

@ -0,0 +1,36 @@
package com.techsor.datacenter.sender.dao;
import com.techsor.datacenter.sender.entitiy.DeviceEntity;
import com.techsor.datacenter.sender.entitiy.TypeEntity;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class TypeDAO {
@Resource
private JdbcTemplate jdbcTemplate ;
//Get Wsclient info by deviceId
@Cacheable(value = "typeDAO::queryCategoryIdByTypeId", key = "#typeId")
public Long queryCategoryIdByTypeId(Integer typeId) {
String sql = "SELECT id,device_category_id FROM type WHERE id="+typeId+" and flag!=1";
List<TypeEntity> dataList = jdbcTemplate.query(sql,
(rs, rowNum) -> {
TypeEntity item = new TypeEntity();
item.setId(rs.getInt("id"));
item.setDeviceCategoryId(rs.getLong("device_category_id"));
return item;
});
if (dataList.size()==0){
return null;
}else{
return dataList.get(dataList.size()-1).getDeviceCategoryId();
}
}
}

32
src/main/java/com/techsor/datacenter/sender/entitiy/TypeEntity.java

@ -0,0 +1,32 @@
package com.techsor.datacenter.sender.entitiy;
import lombok.Data;
import java.io.Serializable;
@Data
public class TypeEntity implements Serializable {
private Integer id;
private String name;
private String description;
private String deviceType; // 设备类别
private String deviceDataSrc; // 设备数据来源
private String originJsonFormat; // 原始数据来源
private String expressionMap; // 表达式映射
private String expressionVariableMap; // 表达式变量map
private String targetJsonFormat; // 转发数据格式
private Long targetForwardId; // 转发目标ID
private String targetForwardCode; // 转发识别代码 (修正了原表中的拼写错误)
private Long createdBy; // 创建人
private Long updatedBy; // 更新人
private Long companyId; // 公司ID
private Long spaceId; // 空间ID
private Integer flag; // 标志位:0:正常;1:删除
private String dbmId; // dbmId,{"[deviceId][dbm_id]":value}
private String nameZh; // name中文
private String nameEn; // name英文
private Long deviceCategoryId; // 设备大类ID
private String unit; // 单位信息
}

191
src/main/java/com/techsor/datacenter/sender/service/KingIOServerService.java

@ -6,6 +6,7 @@ import com.google.gson.Gson;
import com.techsor.datacenter.sender.components.CommonOpt; import com.techsor.datacenter.sender.components.CommonOpt;
import com.techsor.datacenter.sender.config.DataSourceContextHolder; import com.techsor.datacenter.sender.config.DataSourceContextHolder;
import com.techsor.datacenter.sender.dao.KingIOServerDAO; import com.techsor.datacenter.sender.dao.KingIOServerDAO;
import com.techsor.datacenter.sender.dao.TypeDAO;
import com.techsor.datacenter.sender.entitiy.DeviceEntity; import com.techsor.datacenter.sender.entitiy.DeviceEntity;
import com.techsor.datacenter.sender.entitiy.kingio.KingIODataModel; import com.techsor.datacenter.sender.entitiy.kingio.KingIODataModel;
import com.techsor.datacenter.sender.entitiy.kingio.KingIODataItemEntity; import com.techsor.datacenter.sender.entitiy.kingio.KingIODataItemEntity;
@ -35,6 +36,8 @@ import java.util.Map;
@Component("kingIOServerService") @Component("kingIOServerService")
public class KingIOServerService { public class KingIOServerService {
@Resource
TypeDAO typeDAO;
@Resource @Resource
KingIOServerDAO kingIOServerDAO; KingIOServerDAO kingIOServerDAO;
@Autowired @Autowired
@ -182,6 +185,7 @@ public class KingIOServerService {
private String generateDBMStr(DeviceEntity deviceItem,KingIODataItemEntity dataItem){ private String generateDBMStr(DeviceEntity deviceItem,KingIODataItemEntity dataItem){
String finalStr = ""; String finalStr = "";
String tempKey; String tempKey;
switch (deviceItem.getTypeId()){ switch (deviceItem.getTypeId()){
case 80: case 80:
finalStr = String.format("{\"onoffmonitor_ios_%s\":%s",dataItem.getDeviceName(),dataItem.getValue().toString()+"}"); finalStr = String.format("{\"onoffmonitor_ios_%s\":%s",dataItem.getDeviceName(),dataItem.getValue().toString()+"}");
@ -215,6 +219,193 @@ public class KingIOServerService {
tempKey = "delta_status"; tempKey = "delta_status";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}"); finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break; break;
//Present_Value == 85
case 100101:
case 100201:
case 100301:
case 100321:
case 100401:
case 100421:
case 100441:
case 100461:
tempKey = "85";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Status_Flags == 111
case 100102:
case 100202:
case 100302:
case 100322:
case 100402:
case 100422:
case 100442:
case 100462:
tempKey = "111";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Event_State == 36
case 100103:
case 100203:
case 100303:
case 100323:
case 100403:
case 100423:
case 100443:
case 100463:
tempKey = "36";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//High_Limit == 45
case 100304:
tempKey = "45";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Low_Limit == 59
case 100305:
tempKey = "59";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Deadband == 25
case 100306:
tempKey = "25";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Limit_Enable == 52
case 100307:
tempKey = "52";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Event_Timestamp == 250.1
case 100108:
case 100308:
case 100325:
case 100408:
case 100428:
case 100446:
case 100467:
tempKey = "250.1";
finalStr = String.format("{\"%s_"+tempKey+"\":\"%s\"",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Event_Type == 250.2
case 100109:
case 100309:
case 100326:
case 100409:
case 100429:
case 100447:
case 100468:
tempKey = "250.2";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Nofity_Type == 250.3
case 100110:
case 100310:
case 100327:
case 100410:
case 100430:
case 100448:
case 100469:
tempKey = "250.3";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//From_State == 250.4
case 100111:
case 100311:
case 100328:
case 100411:
case 100431:
case 100449:
case 100470:
tempKey = "250.4";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//To_State == 250.5
case 100112:
case 100312:
case 100329:
case 100412:
case 100432:
case 100450:
case 100471:
tempKey = "250.5";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Event_Value == 250.6
case 100113:
case 100313:
case 100330:
case 100413:
case 100433:
case 100451:
case 100472:
tempKey = "250.6";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Reliability == 103
case 100104:
case 100204:
case 100324:
case 100404:
case 100424:
case 100444:
case 100464:
tempKey = "103";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Out_Of_Service == 81
case 100105:
case 100206:
case 100405:
case 100425:
case 100445:
case 100465:
tempKey = "81";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Change_Of_State_Count == 15
case 100106:
case 100426:
tempKey = "15";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Elapsed_Active_Time == 33
case 100107:
case 100427:
tempKey = "33";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Polaroty == 84
case 100406:
tempKey = "84";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Feedback_Value == 40
case 100407:
case 100466:
tempKey = "40";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Buffer_Size == 126
case 100601:
tempKey = "126";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Log_Buffer == 131
case 100602:
tempKey = "131";
finalStr = String.format("{\"%s_"+tempKey+"\":\"%s\"",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Record_Count == 141
case 100603:
tempKey = "141";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
//Total_Record_Count == 145
case 100604:
tempKey = "141";
finalStr = String.format("{\"%s_"+tempKey+"\":%s",deviceItem.getDeviceSN(),dataItem.getValue().toString()+"}");
break;
default: default:
log.error("Unsupported typeId: " + deviceItem.getTypeId()); log.error("Unsupported typeId: " + deviceItem.getTypeId());
return ""; return "";

Loading…
Cancel
Save