Browse Source

设备批量导入的时候,针对永旺ioserver的设备,如果不设置类别,也可以自动导入

zhc
zhczyx@163.com 2 weeks ago
parent
commit
dd492aab71
  1. 2
      data-center-business-dao/src/main/java/com/techsor/datacenter/business/dao/ex/DeviceConfigInfoExtMapper.java
  2. 11
      data-center-business-dao/src/main/resources/mappers/ex/DeviceConfigInfoExtMapper.xml
  3. 110
      data-center-business-model/src/main/java/com/techsor/datacenter/business/entity/ioserver/IoserverDeviceIdEntity.java
  4. 3
      data-center-business-model/src/main/java/com/techsor/datacenter/business/vo/device/DeviceVO.java
  5. 46
      data-center-business-service/src/main/java/com/techsor/datacenter/business/service/impl/DeviceServiceImpl.java

2
data-center-business-dao/src/main/java/com/techsor/datacenter/business/dao/ex/DeviceConfigInfoExtMapper.java

@ -14,6 +14,8 @@ public interface DeviceConfigInfoExtMapper extends DeviceConfigInfoMapper {
List<DeviceConfigVO> getListPage(DeviceConfigSearchParams pageSearchParam); List<DeviceConfigVO> getListPage(DeviceConfigSearchParams pageSearchParam);
List<DeviceConfigVO> getAll();
List<DeviceTypeVO> getDeviceCategoryListByTypeName(String deviceTypeName, Long companyId); List<DeviceTypeVO> getDeviceCategoryListByTypeName(String deviceTypeName, Long companyId);
DeviceConfigVO selectByDeviceId(String deviceId); DeviceConfigVO selectByDeviceId(String deviceId);

11
data-center-business-dao/src/main/resources/mappers/ex/DeviceConfigInfoExtMapper.xml

@ -48,4 +48,15 @@
<select id="selectByDeviceId" resultType="com.techsor.datacenter.business.vo.device.DeviceConfigVO"> <select id="selectByDeviceId" resultType="com.techsor.datacenter.business.vo.device.DeviceConfigVO">
select * from type,device_info where type.id=device_info.type_id and device_info.device_id=#{deviceId} and device_info.flag!=1 select * from type,device_info where type.id=device_info.type_id and device_info.device_id=#{deviceId} and device_info.flag!=1
</select> </select>
<select id="getAll" resultType="com.techsor.datacenter.business.vo.device.DeviceConfigVO" >
select
id, `name`, description, device_type, device_data_src, origin_json_format, expression_map,
expression_variable_map, target_json_format, target_forward_id, target_foward_code, company_id,dbm_id,name_zh,name_en,
device_category_id,`unit`
from `type`
<where>
and flag = 0
</where>
</select>
</mapper> </mapper>

110
data-center-business-model/src/main/java/com/techsor/datacenter/business/entity/ioserver/IoserverDeviceIdEntity.java

@ -0,0 +1,110 @@
package com.techsor.datacenter.business.entity.ioserver;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IoserverDeviceIdEntity {
// 定义正则表达式模式
private static final String DEVICE_ID_PATTERN = "^([A-Z]+)_([A-Z]+)_(\\d{4})_(\\w+)_(\\d+)(?:_S)?$";
private static final Pattern PATTERN = Pattern.compile(DEVICE_ID_PATTERN);
/**
* 解析设备ID格式
* 格式: [物件Initial]_[设备分类]_[BA Device Instance]_[ObjectType, Instance]_[Property][_S(sub, 备份用)]
*/
public static DeviceInfo parseDeviceId(String deviceId) {
if (deviceId == null) {
return null;
}
Matcher matcher = PATTERN.matcher(deviceId);
if (!matcher.matches()) {
return null;
}
String[] groups = new String[matcher.groupCount()];
for (int i = 0; i < groups.length; i++) {
groups[i] = matcher.group(i + 1);
}
DeviceInfo info = new DeviceInfo();
info.setObjectInitial(groups[0]);
info.setDeviceCategory(groups[1]);
info.setBaDeviceInstance(groups[2]);
info.setObjectTypeInstance(groups[3]);
info.setProperty(groups[4]);
info.setHasBackup(deviceId.endsWith("_S"));
return info;
}
/**
* 验证设备ID格式是否正确
*/
public static boolean isValidFormat(String deviceId) {
if (deviceId == null) {
return false;
}
return PATTERN.matcher(deviceId).matches();
}
/**
* 批量验证和解析设备ID
*/
public static void validateAndParse(String[] deviceIds) {
System.out.println("设备ID格式验证结果:");
System.out.println("=" + "=".repeat(80));
for (String deviceId : deviceIds) {
DeviceInfo info = parseDeviceId(deviceId);
if (info != null) {
System.out.printf("✓ %-30s - 格式正确\n", deviceId);
System.out.println(" - 物件Initial: " + info.getObjectInitial());
System.out.println(" - 设备分类: " + info.getDeviceCategory());
System.out.println(" - BA Device Instance: " + info.getBaDeviceInstance());
System.out.println(" - ObjectType, Instance: " + info.getObjectTypeInstance());
System.out.println(" - Property: " + info.getProperty());
System.out.println(" - 是否备份: " + (info.isHasBackup() ? "是" : "否"));
System.out.println();
} else {
System.out.printf("✗ %-30s - 格式错误\n", deviceId);
System.out.println();
}
}
}
// 设备信息类
public static class DeviceInfo {
private String objectInitial;
private String deviceCategory;
private String baDeviceInstance;
private String objectTypeInstance;
private String property;
private boolean hasBackup;
// Getters and Setters
public String getObjectInitial() { return objectInitial; }
public void setObjectInitial(String objectInitial) { this.objectInitial = objectInitial; }
public String getDeviceCategory() { return deviceCategory; }
public void setDeviceCategory(String deviceCategory) { this.deviceCategory = deviceCategory; }
public String getBaDeviceInstance() { return baDeviceInstance; }
public void setBaDeviceInstance(String baDeviceInstance) { this.baDeviceInstance = baDeviceInstance; }
public String getObjectTypeInstance() { return objectTypeInstance; }
public void setObjectTypeInstance(String objectTypeInstance) { this.objectTypeInstance = objectTypeInstance; }
public String getProperty() { return property; }
public void setProperty(String property) { this.property = property; }
public boolean isHasBackup() { return hasBackup; }
public void setHasBackup(boolean hasBackup) { this.hasBackup = hasBackup; }
@Override
public String toString() {
return String.format("DeviceInfo{物件Initial='%s', 设备分类='%s', BA Device Instance='%s', ObjectType_Instance='%s', Property='%s', 备份=%s}",
objectInitial, deviceCategory, baDeviceInstance, objectTypeInstance, property, hasBackup);
}
}
}

3
data-center-business-model/src/main/java/com/techsor/datacenter/business/vo/device/DeviceVO.java

@ -44,7 +44,8 @@ public class DeviceVO {
private Long typeId; private Long typeId;
private Long categoryId; private Long categoryId;
private Long categoryName;
private String categoryName;
private String typeName; private String typeName;

46
data-center-business-service/src/main/java/com/techsor/datacenter/business/service/impl/DeviceServiceImpl.java

@ -37,6 +37,7 @@ import com.techsor.datacenter.business.dto.device.forward.DeviceForwardBatchPara
import com.techsor.datacenter.business.dto.device.forward.DeviceForwardQueryParams; import com.techsor.datacenter.business.dto.device.forward.DeviceForwardQueryParams;
import com.techsor.datacenter.business.dto.device.forward.DeviceForwardRemoveParmas; import com.techsor.datacenter.business.dto.device.forward.DeviceForwardRemoveParmas;
import com.techsor.datacenter.business.dto.devicegroup.DeviceGroupSearchParams; import com.techsor.datacenter.business.dto.devicegroup.DeviceGroupSearchParams;
import com.techsor.datacenter.business.entity.ioserver.IoserverDeviceIdEntity;
import com.techsor.datacenter.business.importexcel.deviceAlertInfo.DeviceAlertInfoExcel; import com.techsor.datacenter.business.importexcel.deviceAlertInfo.DeviceAlertInfoExcel;
import com.techsor.datacenter.business.importexcel.deviceinfo.AlarmLevelMapping; import com.techsor.datacenter.business.importexcel.deviceinfo.AlarmLevelMapping;
import com.techsor.datacenter.business.importexcel.deviceinfo.DeviceGroupRelationExcel; import com.techsor.datacenter.business.importexcel.deviceinfo.DeviceGroupRelationExcel;
@ -57,11 +58,7 @@ import com.techsor.datacenter.business.util.entity.AlertContentExtractParams;
import com.techsor.datacenter.business.util.redis.RedisUtil; import com.techsor.datacenter.business.util.redis.RedisUtil;
import com.techsor.datacenter.business.vo.company.ApikeyInfo2; import com.techsor.datacenter.business.vo.company.ApikeyInfo2;
import com.techsor.datacenter.business.vo.data.AuroraDataVO; import com.techsor.datacenter.business.vo.data.AuroraDataVO;
import com.techsor.datacenter.business.vo.device.DeviceAlertCsvVO; import com.techsor.datacenter.business.vo.device.*;
import com.techsor.datacenter.business.vo.device.DeviceInfoCsvVO;
import com.techsor.datacenter.business.vo.device.DeviceVO;
import com.techsor.datacenter.business.vo.device.LambdaEmailResult;
import com.techsor.datacenter.business.vo.device.MonitoringPointCategoryVO;
import com.techsor.datacenter.business.vo.device.alert.DeviceAlertConfigVO; import com.techsor.datacenter.business.vo.device.alert.DeviceAlertConfigVO;
import com.techsor.datacenter.business.vo.device.forward.DeviceForwardConfigVO; import com.techsor.datacenter.business.vo.device.forward.DeviceForwardConfigVO;
import com.techsor.datacenter.business.vo.devicegroup.DeviceGroupPageVO; import com.techsor.datacenter.business.vo.devicegroup.DeviceGroupPageVO;
@ -141,6 +138,9 @@ public class DeviceServiceImpl implements IDeviceService {
@Resource @Resource
private BasicFloorMapperExt basicFloorMapperExt; private BasicFloorMapperExt basicFloorMapperExt;
@Resource
private DeviceConfigInfoExtMapper deviceTypeExtMapper;
@Resource @Resource
private BasicSpaceMapperExt basicSpaceMapperExt; private BasicSpaceMapperExt basicSpaceMapperExt;
@ -804,6 +804,8 @@ public class DeviceServiceImpl implements IDeviceService {
Map<String, DeviceGroup> deviceGroupMapping = deviceGroupList.stream() Map<String, DeviceGroup> deviceGroupMapping = deviceGroupList.stream()
.collect(Collectors.toMap(DeviceGroup::getName, item -> item)); .collect(Collectors.toMap(DeviceGroup::getName, item -> item));
//Prepare all device type list for futher checks
List<DeviceConfigVO> allDeviceTypeList = deviceTypeExtMapper.getAll();
List<Long> targetFowardCodeIdListCache = new ArrayList<>(); List<Long> targetFowardCodeIdListCache = new ArrayList<>();
for (int dataIndex=0; dataIndex<dataSize; dataIndex++) { for (int dataIndex=0; dataIndex<dataSize; dataIndex++) {
@ -854,7 +856,7 @@ public class DeviceServiceImpl implements IDeviceService {
} }
// Device Type Check // Device Type Check
boolean deviceExists = checkDeviceType(deviceInfoExcel.getDeviceType(), companyId); boolean deviceExists = checkDeviceType(allDeviceTypeList,deviceInfoExcel,deviceInfoExcel.getDeviceType(), companyId);
if (!deviceExists) { if (!deviceExists) {
errorList.add(msgLanguageChange.getParameterMapByCode(languageType, "deviceTypeNotExist")); errorList.add(msgLanguageChange.getParameterMapByCode(languageType, "deviceTypeNotExist"));
} }
@ -2115,19 +2117,31 @@ public class DeviceServiceImpl implements IDeviceService {
private boolean checkDeviceType(String deviceType, long companyId) { private boolean checkDeviceType(List<DeviceConfigVO> allDeviceTypeList, DeviceInfoExcel deviceInfoExcel,String deviceType, long companyId) {
if (StringUtils.isBlank(deviceType)) { IoserverDeviceIdEntity.DeviceInfo baseDeviceInfo = IoserverDeviceIdEntity.parseDeviceId(deviceInfoExcel.getDeviceId());
// Return false if not enter type and deviceInfo is null(Means it's not valid eaon's ioserver device, so we cannot auto fill the type)
if (StringUtils.isBlank(deviceType) && baseDeviceInfo == null) {
return false;
}else if (StringUtils.isBlank(deviceType)){
// If DeviceType is blank but device is eaon's ioserver device,auto fill the type
for (DeviceConfigVO deviceConfigInfo : allDeviceTypeList) {
if (deviceConfigInfo.getName().contains(baseDeviceInfo.getProperty()) && deviceConfigInfo.getName().contains(baseDeviceInfo.getDeviceCategory())) {
deviceInfoExcel.setDeviceType(deviceConfigInfo.getName());
return true;
}
}
}
//If deviceType not blank, check if it exists in the database
DeviceConfigInfoExample deviceConfigInfoExample = new DeviceConfigInfoExample();
deviceConfigInfoExample.createCriteria().andNameEqualTo(deviceType);
List deviceConfigInfoList = this.deviceConfigInfoExtMapper.selectByExample(deviceConfigInfoExample);
if (CollectionUtils.isEmpty(deviceConfigInfoList)) {
return false; return false;
} else { } else {
DeviceConfigInfoExample deviceConfigInfoExample = new DeviceConfigInfoExample(); return true;
deviceConfigInfoExample.createCriteria().andNameEqualTo(deviceType);
List deviceConfigInfoList = this.deviceConfigInfoExtMapper.selectByExample(deviceConfigInfoExample);
if (CollectionUtils.isEmpty(deviceConfigInfoList)) {
return false;
} else {
return true;
}
} }
} }
private Integer checkWsClientId(String wsClientId, long companyId) { private Integer checkWsClientId(String wsClientId, long companyId) {

Loading…
Cancel
Save