平台修改意见20251120-点位上传根据设备ID区分
This commit is contained in:
@ -87,6 +87,11 @@ public class RedisKeyConstants
|
||||
*/
|
||||
public static final String ORIGINAL_MQTT_DATA = "MQTT_";
|
||||
|
||||
/**
|
||||
* 存放单个设备同步过来的告警点位原始数据-最晚一次数据
|
||||
*/
|
||||
public static final String ORIGINAL_MQTT_DATA_ALARM = "MQTT_ALARM_";
|
||||
|
||||
/** 存放订阅失败告警信息 */
|
||||
public static final String TOPIC_FAILED_ALRAM_RECORD = "topic_failed_";
|
||||
/** topic 内没有数据设备维度告警 */
|
||||
@ -110,4 +115,7 @@ public class RedisKeyConstants
|
||||
|
||||
/** 每个设备最新数据-设置失效时间-判断是否正常同步数据 */
|
||||
public static final String SYNC_DATA= "SYNC_DATA_";
|
||||
|
||||
/** 每个设备最新数据-设置失效时间-判断是否正常同步数据 */
|
||||
public static final String SYNC_DATA_ALARM = "SYNC_DATA_ALARM_";
|
||||
}
|
||||
|
||||
@ -74,6 +74,10 @@ public class EmsPointMatch extends BaseEntity
|
||||
@Excel(name = "是否告警点位", readConverterExp = "0=否,1=是")
|
||||
private Integer isAlarm;
|
||||
|
||||
/** 设备唯一标识符 */
|
||||
@Excel(name = "设备唯一标识符")
|
||||
private String deviceId;
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
@ -220,6 +224,14 @@ public class EmsPointMatch extends BaseEntity
|
||||
this.isAlarm = isAlarm;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
@ -243,6 +255,7 @@ public class EmsPointMatch extends BaseEntity
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.append("isAlarm", getIsAlarm())
|
||||
.append("deviceId", getDeviceId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,9 @@ public class ImportPointDataRequest {
|
||||
/** 站点id */
|
||||
@NotBlank(message = "站点ID不能为空")
|
||||
private String siteId;
|
||||
/** 设备id */
|
||||
@NotBlank(message = "设备ID不能为空")
|
||||
private String deviceId;
|
||||
/** 设备类型 */
|
||||
@NotBlank(message = "设备类型不能为空")
|
||||
private String deviceCategory;
|
||||
@ -32,6 +35,14 @@ public class ImportPointDataRequest {
|
||||
this.siteId = siteId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceCategory() {
|
||||
return deviceCategory;
|
||||
}
|
||||
|
||||
@ -141,6 +141,7 @@ public interface EmsPointMatchMapper
|
||||
|
||||
// 单个站点单个设备点位查询-除了电池簇其他设备使用
|
||||
public List<PointQueryResponse> getSingleSiteDevicePoints(@Param("siteId")String siteId,
|
||||
@Param("deviceId")String deviceId,
|
||||
@Param("deviceCategory")String deviceCategory,
|
||||
@Param("pointName")String pointName,
|
||||
@Param("dataPoint")String dataPoint,
|
||||
@ -161,9 +162,9 @@ public interface EmsPointMatchMapper
|
||||
// 根据站点,设备类别,点位,获取唯一数据
|
||||
public EmsPointMatch getUniquePoint(@Param("siteId")String siteId, @Param("deviceCategory")String deviceCategory, @Param("dataPoint")String dataPoint);
|
||||
|
||||
EmsPointMatch getOnePointMatch(@Param("siteId") String siteId, @Param("deviceCategory") String deviceCategory, @Param("dataPoint") String dataPoint);
|
||||
EmsPointMatch getOnePointMatch(@Param("siteId") String siteId, @Param("deviceId") String deviceId, @Param("deviceCategory") String deviceCategory, @Param("dataPoint") String dataPoint);
|
||||
|
||||
List<EmsPointMatch> getDevicePointMatchList(@Param("siteId") String siteId, @Param("deviceCategory") String deviceCategory);
|
||||
List<EmsPointMatch> getDevicePointMatchList(@Param("siteId") String siteId, @Param("deviceId") String deviceId, @Param("deviceCategory") String deviceCategory);
|
||||
|
||||
List<DevicePointMatchExportVo> selectEmsPointMatchExportList(EmsPointMatch emsPointMatch);
|
||||
|
||||
|
||||
@ -1405,6 +1405,12 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
|
||||
Date dataUpdateTime = DateUtils.convertUpdateTime(timestamp);
|
||||
|
||||
log.info("deviceId:" + deviceId);
|
||||
|
||||
// 存放mqtt原始每个设备最晚一次数据,便于后面点位获取数据
|
||||
redisCache.setCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA_ALARM + siteId + "_" + deviceId, obj);
|
||||
// 存放每次同步数据,失效时间(同同步时间)-用于判断是否正常同步数据
|
||||
redisCache.setCacheObject(RedisKeyConstants.SYNC_DATA_ALARM + siteId + "_" + deviceId, obj, 1, TimeUnit.MINUTES);
|
||||
|
||||
String deviceCategory = "";
|
||||
if (deviceId.contains(SiteDevice.ZSLQ.name())) {
|
||||
coolingAlarmDataProcess(siteId, deviceId, jsonData, dataUpdateTime);
|
||||
|
||||
@ -152,9 +152,13 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
||||
dataPointName,dataPoint,parentDeviceId,ipAddress,ipPort,isAlarm);
|
||||
} else {
|
||||
response = emsPointMatchMapper.getSingleSiteDevicePoints(
|
||||
siteId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
|
||||
siteId,deviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
|
||||
String redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA;
|
||||
if (PointType.YES.getCode().equals(isAlarm)) {
|
||||
redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA_ALARM;
|
||||
}
|
||||
// 从redis取最新数据
|
||||
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
||||
JSONObject mqttJson = redisCache.getCacheObject(redisDataKey + siteId + "_" + deviceId);
|
||||
if(mqttJson == null){
|
||||
return response;
|
||||
}
|
||||
@ -239,11 +243,15 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
||||
private List<PointQueryResponse> specialDealWithBattery(String siteId, String deviceId, String deviceCategory,
|
||||
String dataPointName, String dataPoint, String parentDeviceId,
|
||||
String ipAddress, Integer ipPort, Integer isAlarm) {
|
||||
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
|
||||
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceId,deviceCategory,
|
||||
dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
|
||||
|
||||
// 获取redis同步最新数据
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA;
|
||||
if (PointType.YES.getCode().equals(isAlarm)) {
|
||||
redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA_ALARM;
|
||||
}
|
||||
if (SiteEnum.DDS.getCode().equals(siteId)) {
|
||||
// dds单体电池数据来源于BMSD
|
||||
EmsDevicesSetting clusterDevice = emsDevicesMapper.getDeviceBySiteAndDeviceId(parentDeviceId,siteId);
|
||||
@ -251,10 +259,10 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
||||
if (StringUtils.isEmpty(bmsdDeviceId)) {
|
||||
return response;
|
||||
}
|
||||
jsonObject = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + bmsdDeviceId);
|
||||
jsonObject = redisCache.getCacheObject(redisDataKey + siteId + "_" + bmsdDeviceId);
|
||||
} else if (SiteEnum.FX.getCode().equals(siteId)) {
|
||||
// fx单体电池数据来源于父类簇BMSC
|
||||
jsonObject = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + parentDeviceId);
|
||||
jsonObject = redisCache.getCacheObject(redisDataKey + siteId + "_" + parentDeviceId);
|
||||
}
|
||||
if (jsonObject != null) {
|
||||
// 填充数据
|
||||
@ -329,15 +337,19 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
||||
|
||||
|
||||
JSONObject mergedData = new JSONObject();
|
||||
String redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA;
|
||||
if (PointType.YES.getCode().equals(isAlarm)) {
|
||||
redisDataKey = RedisKeyConstants.ORIGINAL_MQTT_DATA_ALARM;
|
||||
}
|
||||
|
||||
// 数据来源pcs
|
||||
JSONObject pcsJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_PCS");
|
||||
JSONObject pcsJson = redisCache.getCacheObject(redisDataKey + siteId + "_PCS");
|
||||
if (pcsJson != null) {
|
||||
JSONObject data = pcsJson.getJSONObject("Data");
|
||||
mergedData.putAll(data);
|
||||
}
|
||||
// 根据deviceId获取父类bmsd
|
||||
JSONObject bmsdJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + bmsdDeviceId);
|
||||
JSONObject bmsdJson = redisCache.getCacheObject(redisDataKey + siteId + "_" + bmsdDeviceId);
|
||||
if (bmsdJson != null) {
|
||||
JSONObject data = bmsdJson.getJSONObject("Data");
|
||||
mergedData.putAll(data);
|
||||
|
||||
@ -51,6 +51,8 @@ import javax.validation.Validator;
|
||||
public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
private static final Logger log = LoggerFactory.getLogger(EmsPointMatchServiceImpl.class);
|
||||
private static final String SEPARATOR = "#";
|
||||
|
||||
private static final String SITE_ID = "DEFAULT";
|
||||
@Autowired
|
||||
private EmsPointMatchMapper emsPointMatchMapper;
|
||||
@Autowired
|
||||
@ -68,6 +70,9 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
*/
|
||||
@Override
|
||||
public List<DevicePointMatchExportVo> selectEmsPointMatchList(EmsPointMatch emsPointMatch) {
|
||||
if (StringUtils.isBlank(emsPointMatch.getDeviceId())) {
|
||||
emsPointMatch.setSiteId(SITE_ID);
|
||||
}
|
||||
List<DevicePointMatchExportVo> devicePointMatchExportVos = emsPointMatchMapper.selectEmsPointMatchExportList(emsPointMatch);
|
||||
if (CollectionUtils.isEmpty(devicePointMatchExportVos)) {
|
||||
return devicePointMatchExportVos;
|
||||
@ -171,6 +176,7 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
}
|
||||
|
||||
String siteId = request.getSiteId();
|
||||
String deviceId = request.getDeviceId();
|
||||
String deviceCategory = request.getDeviceCategory();
|
||||
List<DevicePointMatchVo> errorList = new ArrayList<>();
|
||||
for (DevicePointMatchVo pointMatch : pointMatchList) {
|
||||
@ -193,7 +199,7 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
savePoint.setCreateBy(operName);
|
||||
savePoint.setUpdateBy(operName);
|
||||
// 验证点位是否存在
|
||||
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceCategory, pointMatch.getDataPoint());
|
||||
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceId, deviceCategory, pointMatch.getDataPoint());
|
||||
if (Objects.isNull(dbPoint)) {
|
||||
emsPointMatchMapper.insertEmsPointMatch(savePoint);
|
||||
} else {
|
||||
@ -209,7 +215,7 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
}
|
||||
}
|
||||
// 同步到Redis
|
||||
syncToRedis(siteId, deviceCategory);
|
||||
syncToRedis(siteId, deviceId, deviceCategory);
|
||||
return errorList;
|
||||
}
|
||||
|
||||
@ -232,10 +238,10 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void syncToRedis(String siteId, String deviceCategory) {
|
||||
private void syncToRedis(String siteId, String deviceId, String deviceCategory) {
|
||||
// 点位匹配数据同步到Redis
|
||||
String pointMatchKey = DevicePointMatchDataProcessor.getPointMacthCacheKey(siteId, deviceCategory);
|
||||
List<EmsPointMatch> pointMatchData = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceCategory);
|
||||
String pointMatchKey = DevicePointMatchDataProcessor.getPointMacthCacheKey(siteId, deviceId, deviceCategory);
|
||||
List<EmsPointMatch> pointMatchData = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceId, deviceCategory);
|
||||
// log.info("同步点位匹配数据到Redis key:{} data:{}", pointMatchKey, pointMatchData);
|
||||
if (redisCache.hasKey(pointMatchKey)) {
|
||||
redisCache.deleteObject(pointMatchKey);
|
||||
|
||||
@ -104,9 +104,9 @@ public class DevicePointMatchDataProcessor {
|
||||
// log.info("未找到设备配置信息,siteId: " + siteId + ", deviceId: "+ deviceId);
|
||||
// return pointMatchList;
|
||||
// }
|
||||
List<EmsPointMatch> pointMatchList = redisCache.getCacheList(getPointMacthCacheKey(siteId, deviceCategory));
|
||||
List<EmsPointMatch> pointMatchList = redisCache.getCacheList(getPointMacthCacheKey(siteId, deviceId, deviceCategory));
|
||||
if (CollectionUtils.isEmpty(pointMatchList)) {
|
||||
pointMatchList = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceCategory);
|
||||
pointMatchList = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceId, deviceCategory);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(pointMatchList)) {
|
||||
Map<Integer, List<EmsPointMatch>> map = pointMatchList.stream().collect(Collectors.groupingBy(EmsPointMatch::getIsAlarm));
|
||||
@ -154,7 +154,7 @@ public class DevicePointMatchDataProcessor {
|
||||
try {
|
||||
devicePintointMtachInfo.forEach((key, value) -> {
|
||||
// 查询点位是否存在
|
||||
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceCategory, value);
|
||||
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceId, deviceCategory, value);
|
||||
if (!Objects.isNull(dbPoint)) {
|
||||
return;
|
||||
}
|
||||
@ -214,9 +214,9 @@ public class DevicePointMatchDataProcessor {
|
||||
* @param deviceCategory
|
||||
* @return 点位缓存key
|
||||
*/
|
||||
public static String getPointMacthCacheKey(String siteId, String deviceCategory)
|
||||
public static String getPointMacthCacheKey(String siteId, String deviceId, String deviceCategory)
|
||||
{
|
||||
return RedisKeyConstants.POINT_MATCH + deviceCategory + "_" + siteId;
|
||||
return RedisKeyConstants.POINT_MATCH + deviceCategory + "_" + siteId + "_" + deviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -25,10 +25,11 @@
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="isAlarm" column="is_alarm" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmsPointMatchVo">
|
||||
select id, point_name, match_table, match_field, site_id, device_category, data_point, data_point_name, data_device, data_unit, ip_address, ip_port, data_type, need_diff_device_id, create_by, create_time, update_by, update_time, remark, is_alarm from ems_point_match
|
||||
select id, point_name, match_table, match_field, site_id, device_category, data_point, data_point_name, data_device, data_unit, ip_address, ip_port, data_type, need_diff_device_id, create_by, create_time, update_by, update_time, remark, is_alarm, device_id from ems_point_match
|
||||
</sql>
|
||||
|
||||
<select id="selectEmsPointMatchList" parameterType="EmsPointMatch" resultMap="EmsPointMatchResult">
|
||||
@ -77,6 +78,7 @@
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="isAlarm != null">is_alarm,</if>
|
||||
<if test="deviceId != null">device_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="pointName != null">#{pointName},</if>
|
||||
@ -123,6 +125,7 @@
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="isAlarm != null">is_alarm = #{isAlarm},</if>
|
||||
<if test="deviceId != null">device_id = #{deviceId},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
@ -434,6 +437,9 @@
|
||||
<if test="isAlarm != null">
|
||||
and t.is_alarm = #{isAlarm}
|
||||
</if>
|
||||
<if test="deviceId != null">
|
||||
and t.device_id = #{deviceId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getClusterDevicePoints" resultType="com.xzzn.ems.domain.vo.PointQueryResponse">
|
||||
@ -465,6 +471,9 @@
|
||||
<if test="isAlarm != null">
|
||||
and t.is_alarm = #{isAlarm}
|
||||
</if>
|
||||
<if test="deviceId != null">
|
||||
and t.device_id = #{deviceId}
|
||||
</if>
|
||||
) as tmp
|
||||
where 1=1
|
||||
<if test="pointName != null and pointName != ''">
|
||||
@ -490,6 +499,7 @@
|
||||
<select id="getOnePointMatch" resultMap="EmsPointMatchResult">
|
||||
<include refid="selectEmsPointMatchVo"/>
|
||||
where site_id = #{siteId}
|
||||
and device_id = #{deviceId}
|
||||
and device_category = #{deviceCategory}
|
||||
and data_point = #{dataPoint}
|
||||
order by update_time desc
|
||||
@ -499,6 +509,7 @@
|
||||
<select id="getDevicePointMatchList" resultMap="EmsPointMatchResult">
|
||||
<include refid="selectEmsPointMatchVo"/>
|
||||
where site_id = #{siteId}
|
||||
and device_id = #{deviceId}
|
||||
and device_category = #{deviceCategory}
|
||||
</select>
|
||||
|
||||
@ -515,6 +526,7 @@
|
||||
ems_point_match
|
||||
<where>
|
||||
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
||||
<if test="deviceCategory != null and deviceCategory != ''"> and device_category = #{deviceCategory}</if>
|
||||
</where>
|
||||
</select>
|
||||
@ -525,6 +537,7 @@
|
||||
ems_point_match
|
||||
where is_alarm = 1
|
||||
and site_id = #{siteId}
|
||||
and device_id = #{deviceId}
|
||||
and device_category = #{deviceCategory}
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user