平台修改意见20251120-设备点位匹配解析;上传点位清单修改;

This commit is contained in:
zq
2025-12-05 08:46:19 +08:00
parent c068e7d4ab
commit 3735c4f4d8
28 changed files with 2441 additions and 452 deletions

View File

@ -118,6 +118,17 @@ public class EmsStatisticalReportController extends BaseController
return getDataTable(dataList);
}
/**
* 概率统计-电表收益报表
*/
@GetMapping("/getAmmeterRevenueData")
public TableDataInfo getAmmeterRevenueData(StatisAmmeterDateRequest requestVo)
{
startPage();
List<AmmeterRevenueStatisListVo> dataList = ieEmsStatsReportService.getAmmeterRevenueDataResult(requestVo);
return getDataTable(dataList);
}
/**
* 概率统计-功率曲线
*/

View File

@ -1,6 +1,9 @@
package com.xzzn.web.controller.ems;
import com.alibaba.fastjson2.JSON;
import com.xzzn.common.constant.RedisKeyConstants;
import com.xzzn.common.core.redis.RedisCache;
import com.xzzn.common.enums.TopicHandleType;
import com.xzzn.common.utils.StringUtils;
import com.xzzn.ems.domain.EmsMqttTopicConfig;
import com.xzzn.ems.domain.MqttSyncLog;
@ -39,6 +42,9 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
@Autowired
private IDDSDataProcessService dDSDataProcessService;
@Autowired
private IDeviceDataProcessService deviceDataProcessService;
@Autowired
private IFXXAlarmDataProcessService fXXAlarmDataProcessService;
@Autowired
@ -48,6 +54,9 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
@Autowired
private IMqttSyncLogService iMqttSyncLogService;
@Autowired
private RedisCache redisCache;
@Autowired
public MqttMessageController(MqttLifecycleManager mqttLifecycleManager) {
this.mqttLifecycleManager = mqttLifecycleManager;
@ -75,7 +84,7 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
qos = 1;
}
IMqttMessageListener listener = getMqttListenerByTopic(topic, topicConfig.getId());
IMqttMessageListener listener = getMqttListenerByTopic(topic, topicConfig.getHandleType());
subscribe(topic, qos, listener);
}
// 订阅奉贤系统状态主题
@ -93,14 +102,15 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
}
private IMqttMessageListener getMqttListenerByTopic(String topic, Long id) {
if (topic.contains("ALARM_UP")) {
private IMqttMessageListener getMqttListenerByTopic(String topic, String handleType) {
TopicHandleType topicHandleType = TopicHandleType.getEnumByCode(handleType);
switch (topicHandleType) {
case DEVICE:
return this::handleDeviceData;
case DEVICE_ALARM:
return this::handleAlarmData;
} else if (topic.endsWith("_01")) {
return this::handleSystemStatus;
} else if (topic.contains("STRATEGY")) {
return this::handleStrategyData;
} else if (topic.equals("FAULT_PROTECTION_PLAN_UP")) {
case STRATEGY:
if (topic.equals("FAULT_PROTECTION_PLAN_UP")) {
return this::handleFaultProtPlanData;
} else if (topic.equals("FAULT_ALARM_RECORD_UP")) {
return this::handleFaultAlarmData;
@ -109,7 +119,11 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
} else if (topic.equals("DEVICE_CHANGE_LOG_UP")) {
return this::handleDeviceChangeLogData;
} else {
return this::handleDeviceData;
return this::handleStrategyData;
}
default:
log.warn("Unknown handle type: " + handleType + ", using default handler");
return this::handleSystemStatus;
}
}
@ -129,18 +143,19 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
// 处理设备数据
private void handleDeviceData(String topic, MqttMessage message) {
String payload = new String(message.getPayload());
System.out.println("[DEVICE] data: " + payload);
log.info("[DEVICE] data: " + payload);
try {
// 业务处理逻辑
if (topic.startsWith("021_DDS")) {
dDSDataProcessService.handleDdsData(payload);
} else if (topic.startsWith("021_FXX")) {
fXXDataProcessService.handleFxData(payload);
}
// if (topic.startsWith("021_DDS")) {
// dDSDataProcessService.handleDdsData(payload);
// } else if (topic.startsWith("021_FXX")) {
// fXXDataProcessService.handleFxData(payload);
// }
deviceDataProcessService.handleDeviceData(payload, getSiteIdByTopic(topic));
emsMqttMessageService.insertMqttOriginalMessage(topic, payload);
} catch (Exception e) {
log.error("Failed to process system status message: " + e.getMessage(), e);
log.error("Failed to process device data message: " + e.getMessage(), e);
}
}
@ -151,17 +166,29 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
System.out.println("[DEVICE] data: " + payload);
try {
// 业务处理逻辑
if (topic.startsWith("021_FXX")) {
fXXAlarmDataProcessService.handleFxAlarmData(payload);
}
// if (topic.startsWith("021_FXX")) {
// fXXAlarmDataProcessService.handleFxAlarmData(payload);
// }
deviceDataProcessService.handleAlarmData(payload, getSiteIdByTopic(topic));
emsMqttMessageService.insertMqttOriginalMessage(topic, payload);
} catch (Exception e) {
log.error("Failed to process alarm data message: " + e.getMessage(), e);
log.error("Failed to process device alarm data message: " + e.getMessage(), e);
}
}
private String getSiteIdByTopic(String topic) {
String siteId = redisCache.getCacheObject(RedisKeyConstants.SITE_ID + topic);
if (StringUtils.isEmpty(siteId)) {
EmsMqttTopicConfig topicConfig = emsMqttTopicConfigMapper.selectOneByTopic(topic);
siteId = topicConfig.getSiteId();
redisCache.setCacheObject(RedisKeyConstants.SITE_ID + topic, siteId);
}
log.info("当前处理数据站点:" + siteId + ",topic: " + topic);
return siteId;
}
// 处理运行策略数据:云端-本地
private void handleStrategyData(String topic, MqttMessage message) {
String payload = new String(message.getPayload());

View File

@ -67,6 +67,11 @@ public class RedisKeyConstants
*/
public static final String POINT_MATCH = "POINT_MATCH_";
/**
* topic对应站点ID redis key
*/
public static final String SITE_ID = "SITE_ID_";
/**
* 存放单个设备同步过来的原始数据-最晚一次数据
*/

View File

@ -0,0 +1,45 @@
package com.xzzn.common.enums;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* 设备点位类型
*/
public enum PointType
{
YES(1, ""),
NO(0, "");
private final Integer code;
private final String info;
private static final Map<Integer, String> CODE_NAME_MAP = new HashMap<>(PointType.values().length);
static {
Arrays.stream(PointType.values()).forEach(record -> {
CODE_NAME_MAP.put(record.code, record.info);
});
}
PointType(Integer code, String info)
{
this.code = code;
this.info = info;
}
public String getInfoByCode(Integer code) {
return CODE_NAME_MAP.get(code);
}
public Integer getCode()
{
return code;
}
public String getInfo()
{
return info;
}
}

View File

@ -0,0 +1,57 @@
package com.xzzn.common.enums;
/**
*
*/
public enum SiteDevice
{
/**
* 电池堆
*/
BMSD,
/**
* 电池簇
*/
BMSC,
/**
* PCS设备
*/
PCS,
/**
* 电表-总表
*/
LOAD,
/**
* 电表-光伏电表
*/
METEGF,
/**
* 电表-储能电表
*/
METE,
/**
* 电表-储能电表
*/
METE0,
/**
* 动环
*/
donghuan,
/**
* 动环
*/
DH,
/**
* 中水冷却
*/
ZSLQ
}

View File

@ -0,0 +1,39 @@
package com.xzzn.common.enums;
/**
* MQTT主题处理类型未知类型
*/
public enum TopicHandleType {
DEVICE("DEVICE", "设备数据"),
DEVICE_ALARM("DEVICE_ALARM", "设备告警数据"),
STRATEGY("STRATEGY", "策略数据"),
SYSTEM("SYSTEM", "系统数据"),
;
private final String code;
private final String info;
TopicHandleType(String code, String info) {
this.code = code;
this.info = info;
}
public String getName() {
return code;
}
public String getInfo() {
return info;
}
// 根据名称查找枚举
public static TopicHandleType getEnumByCode(String code) {
for (TopicHandleType type : values()) {
if (type.getName().equals(code)) {
return type;
}
}
// 默认返回SYSTEM
return SYSTEM;
}
}

View File

@ -33,8 +33,8 @@ public class EmsMqttTopicConfig extends BaseEntity
@Excel(name = "对应方法")
private String handleMethod;
/** 处理器类型:(device=设备数据system=系统状态,alarm=告警数据等) */
@Excel(name = "处理器类型:(device=设备数据system=系统状态,alarm=告警数据等)")
/** 处理器类型:(DEVICE=设备数据SYSTEM=系统状态,ALARM=告警数据等) */
@Excel(name = "处理器类型:(DEVICE=设备数据SYSTEM=系统状态,ALARM=告警数据等)")
private String handleType;
/** 站点id */

View File

@ -70,9 +70,9 @@ public class EmsPointMatch extends BaseEntity
@Excel(name = "点位是否需要区分多设备0-不需要 1-需要")
private Long needDiffDeviceId;
/** 设备唯一标识符 */
@Excel(name = "设备唯一标识符")
private String deviceId;
/** 是否告警点位 */
@Excel(name = "是否告警点位", readConverterExp = "0=否,1=是")
private Integer isAlarm;
public void setId(Long id)
{
@ -212,12 +212,12 @@ public class EmsPointMatch extends BaseEntity
return needDiffDeviceId;
}
public String getDeviceId() {
return deviceId;
public Integer getIsAlarm() {
return isAlarm;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
public void setIsAlarm(Integer isAlarm) {
this.isAlarm = isAlarm;
}
@Override
@ -242,7 +242,7 @@ public class EmsPointMatch extends BaseEntity
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("deviceId", getDeviceId())
.append("isAlarm", getIsAlarm())
.toString();
}
}

View File

@ -0,0 +1,131 @@
package com.xzzn.ems.domain.vo;
import java.math.BigDecimal;
/**
* 电表收益数据
*/
public class AmmeterRevenueStatisListVo {
/** 类别 */
private String dataTime;
/** 组合有功-总 */
private BigDecimal activeTotalPrice = BigDecimal.ZERO;
/** 组合有功-尖 */
private BigDecimal activePeakPrice = BigDecimal.ZERO;
/** 组合有功-峰 */
private BigDecimal activeHighPrice = BigDecimal.ZERO;
/** 组合有功-平 */
private BigDecimal activeFlatPrice = BigDecimal.ZERO;
/** 组合有功-谷 */
private BigDecimal activeValleyPrice = BigDecimal.ZERO;
/** 组合无功-总 */
private BigDecimal reActiveTotalPrice = BigDecimal.ZERO;
/** 组合无功-尖 */
private BigDecimal reActivePeakPrice = BigDecimal.ZERO;
/** 组合无功-峰 */
private BigDecimal reActiveHighPrice = BigDecimal.ZERO;
/** 组合无功-平 */
private BigDecimal reActiveFlatPrice = BigDecimal.ZERO;
/** 组合无功-谷 */
private BigDecimal reActiveValleyPrice = BigDecimal.ZERO;
public String getDataTime() {
return dataTime;
}
public void setDataTime(String dataTime) {
this.dataTime = dataTime;
}
public BigDecimal getActiveTotalPrice() {
return activeTotalPrice;
}
public void setActiveTotalPrice(BigDecimal activeTotalPrice) {
this.activeTotalPrice = activeTotalPrice;
}
public BigDecimal getActivePeakPrice() {
return activePeakPrice;
}
public void setActivePeakPrice(BigDecimal activePeakPrice) {
this.activePeakPrice = activePeakPrice;
}
public BigDecimal getActiveHighPrice() {
return activeHighPrice;
}
public void setActiveHighPrice(BigDecimal activeHighPrice) {
this.activeHighPrice = activeHighPrice;
}
public BigDecimal getActiveFlatPrice() {
return activeFlatPrice;
}
public void setActiveFlatPrice(BigDecimal activeFlatPrice) {
this.activeFlatPrice = activeFlatPrice;
}
public BigDecimal getActiveValleyPrice() {
return activeValleyPrice;
}
public void setActiveValleyPrice(BigDecimal activeValleyPrice) {
this.activeValleyPrice = activeValleyPrice;
}
public BigDecimal getReActiveTotalPrice() {
return reActiveTotalPrice;
}
public void setReActiveTotalPrice(BigDecimal reActiveTotalPrice) {
this.reActiveTotalPrice = reActiveTotalPrice;
}
public BigDecimal getReActivePeakPrice() {
return reActivePeakPrice;
}
public void setReActivePeakPrice(BigDecimal reActivePeakPrice) {
this.reActivePeakPrice = reActivePeakPrice;
}
public BigDecimal getReActiveHighPrice() {
return reActiveHighPrice;
}
public void setReActiveHighPrice(BigDecimal reActiveHighPrice) {
this.reActiveHighPrice = reActiveHighPrice;
}
public BigDecimal getReActiveFlatPrice() {
return reActiveFlatPrice;
}
public void setReActiveFlatPrice(BigDecimal reActiveFlatPrice) {
this.reActiveFlatPrice = reActiveFlatPrice;
}
public BigDecimal getReActiveValleyPrice() {
return reActiveValleyPrice;
}
public void setReActiveValleyPrice(BigDecimal reActiveValleyPrice) {
this.reActiveValleyPrice = reActiveValleyPrice;
}
}

View File

@ -25,6 +25,10 @@ public class DevicePointMatchVo implements Serializable {
/** 数据单位 */
@Excel(name = "数据单位")
private String dataUnit;
/** 是否告警点位 */
@Excel(name = "是否告警点位", readConverterExp = "0=否,1=是")
private String isAlarm;
//
// /** 数据点位来源设备 */
// @Excel(name = "数据点位来源设备")
@ -78,6 +82,15 @@ public class DevicePointMatchVo implements Serializable {
// this.dataDevice = dataDevice;
// }
public String getIsAlarm() {
return isAlarm;
}
public void setIsAlarm(String isAlarm) {
this.isAlarm = isAlarm;
}
public String getIpAddress() {
return ipAddress;
}

View File

@ -17,9 +17,6 @@ public class ImportPointDataRequest {
/** 站点id */
@NotBlank(message = "站点ID不能为空")
private String siteId;
/** 设备id */
@NotBlank(message = "设备ID不能为空")
private String deviceId;
/** 设备类型 */
@NotBlank(message = "设备类型不能为空")
private String deviceCategory;
@ -35,14 +32,6 @@ public class ImportPointDataRequest {
this.siteId = siteId;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getDeviceCategory() {
return deviceCategory;
}

View File

@ -35,6 +35,16 @@ public class PointDataRequest {
private String ipAddress;
/** modbus端口 */
private Integer ipPort;
/** 是否告警点位 */
private Integer isAlarm;
public Integer getIsAlarm() {
return isAlarm;
}
public void setIsAlarm(Integer isAlarm) {
this.isAlarm = isAlarm;
}
public String getIpAddress() {
return ipAddress;

View File

@ -43,7 +43,7 @@ public class PointQueryResponse
private String dataUnit;
/** 地址 */
@Excel(name = "地址")
@Excel(name = "寄存器地址")
private String ipAddress;
/** 端口 */

View File

@ -5,10 +5,14 @@ import com.xzzn.ems.domain.EmsBatteryCluster;
import com.xzzn.ems.domain.EmsBatteryData;
import com.xzzn.ems.domain.EmsBatteryGroup;
import com.xzzn.ems.domain.EmsBatteryStack;
import com.xzzn.ems.domain.EmsClusterAlarmData;
import com.xzzn.ems.domain.EmsCoolingAlarmData;
import com.xzzn.ems.domain.EmsCoolingData;
import com.xzzn.ems.domain.EmsDhData;
import com.xzzn.ems.domain.EmsPcsAlarmData;
import com.xzzn.ems.domain.EmsPcsBranchData;
import com.xzzn.ems.domain.EmsPcsData;
import com.xzzn.ems.domain.EmsStackAlarmData;
import com.xzzn.ems.domain.EmsXfData;
import java.util.HashMap;
@ -28,7 +32,14 @@ public enum DeviceMatchTable
COOLING("COOLING", "ems_cooling_data", EmsCoolingData.class),
DH("DH", "ems_dh_data", EmsDhData.class),
XF("XF", "ems_xf_data", EmsXfData.class),
BATTERY_GROUP("BATTERY_GROUP", "ems_battery_group", EmsBatteryGroup.class);
BATTERY_GROUP("BATTERY_GROUP", "ems_battery_group", EmsBatteryGroup.class),
/** 告警点位 */
COOLING_ALARM("COOLING_ALARM", "ems_cooling_alarm_data", EmsCoolingAlarmData.class),
STACK_ALARM("STACK_ALARM", "ems_stack_alarm_data", EmsStackAlarmData.class),
CLUSTER_ALARM("CLUSTER_ALARM", "ems_cluster_alarm_data", EmsClusterAlarmData.class),
PCS_ALARM("PCS_ALARM", "ems_pcs_alarm_data", EmsPcsAlarmData.class),
;
private final String code;
private final String matchTable;
@ -80,4 +91,8 @@ public enum DeviceMatchTable
return TABLE_TO_CLASS_MAP.get(matchTable); // 从缓存中直接获取,效率高
}
public static String getAlarmMatchTableByCode(String code) {
return DEVICE_MATCH_TABLE_MAP.get(code + "_ALARM"); // 从缓存中直接获取,效率高
}
}

View File

@ -76,4 +76,8 @@ public interface EmsEnergyPriceConfigMapper
// 获取所有有效站点的电价配置
public List<EmsEnergyPriceConfig> getAllSitePriceConfig( @Param("currentYear")int currentYear,
@Param("currentMonth")int currentMonth);
// 查询指定时间范围的电价配置列表
public List<EmsEnergyPriceConfig> getConfigListByTimeFrame(@Param("siteId")String siteId,
@Param("startTime")String startTime,
@Param("endTime")String endTime);
}

View File

@ -61,4 +61,6 @@ public interface EmsMqttTopicConfigMapper
// 判断topic是否存在
public String checkTopicIsExist(String strategyTopic);
EmsMqttTopicConfig selectOneByTopic(String topic);
}

View File

@ -127,7 +127,8 @@ public interface EmsPointMatchMapper
@Param("pointName")String pointName,
@Param("dataPoint")String dataPoint,
@Param("ipAddress")String ipAddress,
@Param("ipPort")Integer ipPort);
@Param("ipPort")Integer ipPort,
@Param("isAlarm")Integer isAlarm);
// 单个站点单个设备点位查询-电池簇使用
public List<PointQueryResponse> getClusterDevicePoints(@Param("siteId")String siteId,
@Param("deviceId")String deviceId,
@ -136,12 +137,13 @@ public interface EmsPointMatchMapper
@Param("pointName")String pointName,
@Param("dataPoint")String dataPoint,
@Param("ipAddress")String ipAddress,
@Param("ipPort")Integer ipPort);
@Param("ipPort")Integer ipPort,
@Param("isAlarm")Integer isAlarm);
// 根据站点,设备类别,点位,获取唯一数据
public EmsPointMatch getUniquePoint(@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);
EmsPointMatch getOnePointMatch(@Param("siteId") String siteId, @Param("deviceCategory") String deviceCategory, @Param("dataPoint") String dataPoint);
List<EmsPointMatch> getDevicePointMatchList(@Param("siteId") String siteId, @Param("deviceId") String deviceId, @Param("deviceCategory") String deviceCategory);
List<EmsPointMatch> getDevicePointMatchList(@Param("siteId") String siteId, @Param("deviceCategory") String deviceCategory);
}

View File

@ -0,0 +1,8 @@
package com.xzzn.ems.service;
public interface IDeviceDataProcessService {
public void handleDeviceData(String message, String siteId);
public void handleAlarmData(String message, String siteId);
}

View File

@ -26,6 +26,8 @@ public interface IEmsStatsReportService
public List<AmmeterStatisListVo> getAmmeterDataResult(StatisAmmeterDateRequest requestVo);
List<AmmeterRevenueStatisListVo> getAmmeterRevenueDataResult(StatisAmmeterDateRequest requestVo);
public List<PowerStatisListVo> getPowerDataList(DateSearchRequest requestVo);
public List<BatteryDataStatsListVo> getSingleBatteryData(DateSearchRequest requestVo);

View File

@ -6,6 +6,7 @@ import com.alibaba.fastjson2.TypeReference;
import com.xzzn.common.constant.RedisKeyConstants;
import com.xzzn.common.core.redis.RedisCache;
import com.xzzn.common.enums.DeviceCategory;
import com.xzzn.common.enums.PointType;
import com.xzzn.common.enums.SiteEnum;
import com.xzzn.common.utils.DateUtils;
import com.xzzn.common.utils.StringUtils;
@ -142,15 +143,16 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
String parentDeviceId = request.getParentId();
String ipAddress = request.getIpAddress();
Integer ipPort = request.getIpPort();
Integer isAlarm = request.getIsAlarm() == null ? PointType.YES.getCode() : request.getIsAlarm();
// 电动所的电池簇特殊处理-来源pcs+bmsd
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort);
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
} else if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
response = specialDealWithBattery(siteId,deviceId,deviceCategory,
dataPointName,dataPoint,parentDeviceId,ipAddress,ipPort);
dataPointName,dataPoint,parentDeviceId,ipAddress,ipPort,isAlarm);
} else {
response = emsPointMatchMapper.getSingleSiteDevicePoints(
siteId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort);
siteId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
// 从redis取最新数据
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
if(mqttJson == null){
@ -235,9 +237,10 @@ 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) {
String dataPointName, String dataPoint, String parentDeviceId,
String ipAddress, Integer ipPort, Integer isAlarm) {
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
dataPointName,dataPoint,ipAddress,ipPort);
dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
// 获取redis同步最新数据
JSONObject jsonObject = new JSONObject();
@ -316,12 +319,13 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
// 对于dds的电池簇点位最新数据获取特殊处理
private List<PointQueryResponse> specialDealWithDDSCluster(String siteId, String deviceId, String deviceCategory,
String dataPointName, String dataPoint, String ipAddress, Integer ipPort) {
String dataPointName, String dataPoint, String ipAddress,
Integer ipPort, Integer isAlarm) {
// 替换为对应的父类id
String bmsdDeviceId = deviceId.replace("BMSC","BMSD");
List<PointQueryResponse> response = emsPointMatchMapper
.getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort);
.getClusterDevicePoints(siteId,deviceId,bmsdDeviceId,deviceCategory,dataPointName,dataPoint,ipAddress,ipPort,isAlarm);
JSONObject mergedData = new JSONObject();

View File

@ -2,16 +2,22 @@ package com.xzzn.ems.service.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.alibaba.fastjson2.JSON;
import com.xzzn.common.constant.RedisKeyConstants;
import com.xzzn.common.core.redis.RedisCache;
import com.xzzn.common.enums.PointType;
import com.xzzn.common.exception.ServiceException;
import com.xzzn.common.utils.StringUtils;
import com.xzzn.common.utils.bean.BeanValidators;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@ -140,7 +146,6 @@ 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) {
@ -152,17 +157,22 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService
EmsPointMatch savePoint = new EmsPointMatch();
BeanUtils.copyProperties(pointMatch, savePoint);
savePoint.setSiteId(siteId);
savePoint.setDeviceId(deviceId);
savePoint.setDeviceCategory(deviceCategory);
if (StringUtils.isNotBlank(pointMatch.getIsAlarm()) && String.valueOf(PointType.YES.getCode()).equals(pointMatch.getIsAlarm())) {
savePoint.setMatchTable(DeviceMatchTable.getAlarmMatchTableByCode(deviceCategory));
savePoint.setIsAlarm(PointType.YES.getCode());
} else {
savePoint.setMatchTable(DeviceMatchTable.getMatchTableByCode(deviceCategory));
}
savePoint.setPointName(DevicePointMatchDataProcessor.getFieldAnnotation(DeviceMatchTable.getClassByTable(savePoint.getMatchTable()), StringUtils.toCamelCase(savePoint.getMatchField())));
savePoint.setCreateBy(operName);
savePoint.setUpdateBy(operName);
// 验证点位是否存在
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceId, deviceCategory, pointMatch.getDataPoint());
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceCategory, pointMatch.getDataPoint());
if (Objects.isNull(dbPoint)) {
emsPointMatchMapper.insertEmsPointMatch(savePoint);
} else {
savePoint.setId(dbPoint.getId());
emsPointMatchMapper.updateEmsPointMatch(savePoint);
}
} catch (Exception e) {
@ -171,7 +181,7 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService
}
}
// 同步到Redis
syncToRedis(siteId, deviceId, deviceCategory);
syncToRedis(siteId, deviceCategory);
return errorList;
}
@ -197,10 +207,10 @@ public class EmsPointMatchServiceImpl implements IEmsPointMatchService
return false;
}
private void syncToRedis(String siteId, String deviceId, String deviceCategory) {
private void syncToRedis(String siteId, String deviceCategory) {
// 同步到Redis
String pointMatchKey = RedisKeyConstants.POINT_MATCH + deviceCategory + "_" + siteId + "_" + deviceId;
List<EmsPointMatch> pointMatchData = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceId, deviceCategory);
String pointMatchKey = DevicePointMatchDataProcessor.getPointMacthCacheKey(siteId, deviceCategory);
List<EmsPointMatch> pointMatchData = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceCategory);
// log.info("同步点位匹配数据到Redis key:{} data:{}", pointMatchKey, pointMatchData);
redisCache.setCacheObject(pointMatchKey, pointMatchData);
log.info("点位匹配数据同步完成 data:{}", JSON.toJSONString(redisCache.getCacheObject(pointMatchKey)));

View File

@ -3,10 +3,12 @@ package com.xzzn.ems.service.impl;
import com.xzzn.common.enums.SiteEnum;
import com.xzzn.common.utils.DateUtils;
import com.xzzn.ems.domain.EmsAmmeterData;
import com.xzzn.ems.domain.EmsEnergyPriceConfig;
import com.xzzn.ems.domain.vo.*;
import com.xzzn.ems.mapper.*;
import com.xzzn.ems.service.IEmsStatsReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -16,6 +18,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -43,6 +46,8 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService
private EmsDailyChargeDataMapper emsDailyChargeDataMapper;
@Autowired
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper;
@Autowired
private EmsEnergyPriceConfigMapper emsEnergyPriceConfigMapper;
// 电量指标
@Override
@ -305,6 +310,40 @@ public class EmsStatsReportServiceImpl implements IEmsStatsReportService
return dataList;
}
@Override
public List<AmmeterRevenueStatisListVo> getAmmeterRevenueDataResult(StatisAmmeterDateRequest requestVo) {
//查询电表数据
List<AmmeterStatisListVo> dataList = emsDailyEnergyDataMapper.getDataBySiteId(requestVo.getSiteId(), requestVo.getStartTime(), requestVo.getEndTime());
if (CollectionUtils.isEmpty(dataList)){
return null;
}
//查询电价配置
List<EmsEnergyPriceConfig> priceConfigList = emsEnergyPriceConfigMapper.getConfigListByTimeFrame(requestVo.getSiteId(), requestVo.getStartTime(), requestVo.getEndTime());
if (CollectionUtils.isEmpty(priceConfigList)){
return null;
}
Map<String, EmsEnergyPriceConfig> priceConfigMap = priceConfigList.stream().collect(Collectors.toMap(data -> data.getYear() + "-" + String.format("%02d", Integer.parseInt(data.getMonth())), Function.identity()));
List<AmmeterRevenueStatisListVo> resultList = new ArrayList<>();
dataList.forEach(ammeter -> {
EmsEnergyPriceConfig price = priceConfigMap.get(ammeter.getDataTime().substring(0, 7));
resultList.add(calculateDailyBill(ammeter, price));
});
return resultList;
}
public static AmmeterRevenueStatisListVo calculateDailyBill(AmmeterStatisListVo ammeter, EmsEnergyPriceConfig price) {
AmmeterRevenueStatisListVo ammeterRevenue = new AmmeterRevenueStatisListVo();
ammeterRevenue.setDataTime(ammeter.getDataTime());
if (price != null) {
// BigDecimal activeTotalPrice = ammeter.getActiveTotalKwh().multiply(new BigDecimal(price.getPeak()));
// BigDecimal activePeakPrice = ammeter.getActivePeakKwh().multiply(new BigDecimal(price.getPeak()));
// BigDecimal activeHighPrice = ammeter.getActiveHighKwh().multiply(new BigDecimal(price.getHigh()));
// BigDecimal activeFlatPrice = ammeter.getActiveFlatKwh().multiply(new BigDecimal(price.getFlat()));
}
return ammeterRevenue;
}
private void dealWithAmmeterTotalDate(AmmeterStatisListVo ammeterStatisListVo, AmmeterStatisListVo totalVo) {
// 有功
totalVo.setActiveTotalKwh(totalVo.getActiveTotalKwh().add(ammeterStatisListVo.getActiveTotalKwh()));

View File

@ -155,11 +155,7 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
});
EmsCoolingData coolingData = new EmsCoolingData();
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.COOLING.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, coolingData);
} else {
coolingData.setGsTemp(StringUtils.getBigDecimal(obj.get("GSWD")));
coolingData.setHsTemp(StringUtils.getBigDecimal(obj.get("HSWD")));
coolingData.setGsPressure(StringUtils.getBigDecimal(obj.get("GSYL")));
@ -167,7 +163,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
coolingData.setLysTemp(StringUtils.getBigDecimal(obj.get("LYSWD")));
coolingData.setVb01Kd(StringUtils.getBigDecimal(obj.get("VB1KD")));
coolingData.setVb02Kd(StringUtils.getBigDecimal(obj.get("VB2KD")));
}
coolingData.setCreateBy("system");
coolingData.setCreateTime(DateUtils.getNowDate());
@ -180,7 +175,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.COOLING + SITE_ID + "_" +deviceId, coolingData);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.COOLING, "ZSLQ");
}
private void dhDataProcess(String deviceId, String dataJson) {
@ -190,14 +184,8 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
//DH
EmsDhData dhData = new EmsDhData();
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.DH.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, dhData);
} else {
dhData.setHumidity(StringUtils.getBigDecimal(obj.get("SD3")));
dhData.setTemperature(StringUtils.getBigDecimal(obj.get("WD3")));
}
dhData.setCreateBy("system");
dhData.setCreateTime(DateUtils.getNowDate());
@ -209,7 +197,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.DH + SITE_ID + "_" +deviceId, dhData);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.DH, "donghuan");
}
private void batteryStackDataProcess(String deviceId, String dataJson) {
@ -226,12 +213,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
dataStack.setPcsCommunicationStatus(CommunicationStatus.OK.getCode());
dataStack.setEmsCommunicationStatus(CommunicationStatus.OK.getCode());
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.STACK.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, dataStack);
} else {
// 电池堆状态数据设置
dataStack.setOperationStatus(StringUtils.getString(obj.get("DCZT")));
dataStack.setStackVoltage(StringUtils.getBigDecimal(obj.get("DCDDY")));
@ -285,8 +266,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
dataStack.setBmsChargeStatus(StringUtils.getString(obj.get("BMSCFDZT")));
dataStack.setStackInsulationResistance(StringUtils.getBigDecimal(obj.get("DCDJYDZ")));
}
dataStack.setCreateBy("system");
dataStack.setCreateTime(DateUtils.getNowDate());
@ -299,7 +278,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.STACK + SITE_ID + "_" +deviceId, dataStack);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.STACK, "BMSD");
}
private void saveDeviceData(List<EmsPointMatch> pointMatchList, Map<String, Object> obj, Object entity) {
@ -350,12 +328,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
}
//BMS 电池簇
EmsBatteryCluster data = new EmsBatteryCluster();
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.CLUSTER.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, data);
} else {
// 设置所有 BigDecimal 类型字段为 ZERO
data.setChargeableCapacity(StringUtils.getBigDecimal(obj.get("KCDL")));
data.setClusterVoltage(StringUtils.getBigDecimal(obj.get("ZDY")));
@ -401,7 +373,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
data.setMinCellSocId(StringUtils.getString(obj.get("ZDDTSOCDYD")));
data.setMaxCellSohId(StringUtils.getString(obj.get("ZGDTSOHDYD")));
data.setMinCellSohId(StringUtils.getString(obj.get("ZDDTSOHDYD")));
}
data.setWorkStatus(WorkStatus.NORMAL.getCode()); // 或其他默认值
data.setPcsCommunicationStatus(CommunicationStatus.OK.getCode());
@ -421,7 +392,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.CLUSTER + SITE_ID + "_" +deviceId, data);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.CLUSTER, "BMSC");
}
private void batteryDataProcess(String deviceId, String dataJson, Date dataUpdateTime) {
@ -444,8 +414,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
LocalDateTime oneHourAgo = LocalDateTime.now().minus(1, ChronoUnit.HOURS);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String oneHourAgoStr = oneHourAgo.format(formatter);
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.BATTERY.getCode());
//单体电池
for (Map.Entry<String, Map<String, Object>> record : records.entrySet()) {
String recordId = record.getKey();
@ -455,14 +423,10 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
batteryData.setDeviceId(recordId);
batteryData.setBatteryCellId(recordId);
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, fields, batteryData);
} else {
batteryData.setSoc(StringUtils.getBigDecimal(fields.get("DTSOC")));
batteryData.setSoh(StringUtils.getBigDecimal(fields.get("DTSOH")));
batteryData.setTemperature(StringUtils.getBigDecimal(fields.get("DTWD")));
batteryData.setVoltage(StringUtils.getBigDecimal(fields.get("DTDY")));
}
batteryData.setBatteryCluster(deviceId);
batteryData.setBatteryPack(stackDeviceId);
@ -496,7 +460,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.deleteList(RedisKeyConstants.BATTERY + SITE_ID + "_" + deviceId);
redisCache.setCacheList(RedisKeyConstants.BATTERY + SITE_ID + "_" + deviceId, list);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.BATTERY, "BMSC");
}
// 批量处理每日最新数据
@ -523,12 +486,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
//pcs
EmsPcsData pcsData = new EmsPcsData();
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.PCS.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, pcsData);
} else {
// 功率与能量类字段
pcsData.setTotalActivePower(StringUtils.getBigDecimal(obj.get("YGGL")));
pcsData.setDailyAcChargeEnergy(StringUtils.getBigDecimal(obj.get("RCDL")));
@ -578,8 +535,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
pcsData.setvTemperature(StringUtils.getBigDecimal(obj.get("DY1VXIGBTWD")));
pcsData.setwTemperature(StringUtils.getBigDecimal(obj.get("DY1WXIGBTWD")));
}
// 时间与状态类字段
pcsData.setDataUpdateTime(dataUpdateTime);
pcsData.setWorkStatus(WorkStatus.NORMAL.getCode());
@ -599,15 +554,13 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
emsPcsDataMapper.insertEmsPcsData(pcsData);
redisCache.setCacheObject(RedisKeyConstants.PCS + SITE_ID + "_" +deviceId, pcsData);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.PCS, "PCS");
}
private void pcsBranchDataProcess(String deviceId, String dataJson) {
Map<String, Map<String, Object>> records = processDataPrefix(JSON.parseObject(dataJson, new TypeReference<Map<String, Object>>() {}));
List<EmsPcsBranchData> list = new ArrayList<>();
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.BRANCH.getCode());
//PCS支路
for (Map.Entry<String, Map<String, Object>> record : records.entrySet()) {
@ -618,9 +571,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
data.setDeviceId(deviceId);
data.setSiteId(SITE_ID);
data.setGridStatus(GridStatus.GRID.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, fields, data);
} else {
data.setDcPower(StringUtils.getBigDecimal(fields.get("ZLGL")));
data.setDcVoltage(StringUtils.getBigDecimal(fields.get("ZLDY")));
data.setDcCurrent(StringUtils.getBigDecimal(fields.get("ZLDL")));
@ -643,7 +593,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
data.setTotalLoadRatio(StringUtils.getBigDecimal(fields.get("ZFZB")));
data.setAcLeakageCurrent(StringUtils.getBigDecimal(fields.get("JLLDL")));
data.setInsulationResistance(StringUtils.getBigDecimal(fields.get("JYZK")));
}
data.setBranchId(recordId);
data.setCreateBy("system");
data.setCreateTime(DateUtils.getNowDate());
@ -656,7 +605,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.BRANCH + SITE_ID + "_" +deviceId, list);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.BRANCH, "PCS");
}
}
@ -671,12 +619,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
// 更新时间
dataLoad.setDataUpdateTime(dataUpdateTime);
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.AMMETER.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, dataLoad);
} else {
// 电能设置-组合有功
dataLoad.setCurrentCombActiveTotal(StringUtils.getBigDecimal(obj.get("DQZHYGZDN")));
dataLoad.setCurrentCombActivePeak(StringUtils.getBigDecimal(obj.get("DQZHYGJDN")));
@ -754,7 +696,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
dataLoad.setReverseAcMaxDemand(StringUtils.getBigDecimal(obj.get("FXYGZDXL")));
dataLoad.setDailyForwardMaxDemand(StringUtils.getBigDecimal(obj.get("DRZXYGZDXL")));
}
dataLoad.setCreateBy("system");
dataLoad.setCreateTime(DateUtils.getNowDate());
dataLoad.setUpdateBy("system");
@ -766,7 +707,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.AMMETER + SITE_ID + "_" +deviceId, dataLoad);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.AMMETER, "LOAD");
}
private void dealFXXDailyChargeDate(String deviceId, String dataJson) {
@ -805,11 +745,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
EmsAmmeterData dataLoad = new EmsAmmeterData();
// 更新时间
dataLoad.setDataUpdateTime(dataUpdateTime);
// 点位匹配数据
List<EmsPointMatch> pointMatchList = devicePointMatchDataProcessor.getDevicePointMatch(SITE_ID, deviceId, DeviceMatchTable.AMMETER.getCode());
if (CollectionUtils.isNotEmpty(pointMatchList)) {
saveDeviceData(pointMatchList, obj, dataLoad);
} else {
// 电压+电流
dataLoad.setPhaseAVoltage(StringUtils.getBigDecimal(obj.get("AXDY")));
dataLoad.setPhaseBVoltage(StringUtils.getBigDecimal(obj.get("BXDY")));
@ -882,7 +817,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
dataLoad.setCurrentForwardReactiveTotal(StringUtils.getBigDecimal(obj.get("ZXWGDN")));
dataLoad.setCurrentReverseReactiveTotal(StringUtils.getBigDecimal(obj.get("FXWGDN")));
}
dataLoad.setCreateBy("system");
dataLoad.setCreateTime(DateUtils.getNowDate());
dataLoad.setUpdateBy("system");
@ -894,8 +828,6 @@ public class FXXDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache.setCacheObject(RedisKeyConstants.AMMETER + SITE_ID + "_" +deviceId, dataLoad);
saveDevicePointMatchData(pointMatchList, deviceId, DeviceMatchTable.AMMETER, "METE");
// 处理电表每日充放电数据
dealAmmeterDailyDate(obj, dataUpdateTime, lastAmmeterData);
}

View File

@ -7,11 +7,13 @@ import com.xzzn.common.annotation.Excel;
import com.xzzn.common.constant.RedisKeyConstants;
import com.xzzn.common.core.redis.RedisCache;
import com.xzzn.common.enums.DeviceCategory;
import com.xzzn.common.enums.PointType;
import com.xzzn.common.utils.DataUtils;
import com.xzzn.common.utils.StringUtils;
import com.xzzn.ems.domain.EmsDevicesSetting;
import com.xzzn.ems.domain.EmsPointMatch;
import com.xzzn.ems.domain.vo.DevicePointMatchInfo;
import com.xzzn.ems.domain.vo.StackStatisListVo;
import com.xzzn.ems.enums.DeviceMatchTable;
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
import com.xzzn.ems.mapper.EmsPointMatchMapper;
@ -23,6 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
@ -82,15 +85,31 @@ public class DevicePointMatchDataProcessor {
}
public List<EmsPointMatch> getDevicePointMatch(String siteId, String deviceId, String deviceCategory) {
return getDevicePointMatch(siteId, deviceId, deviceCategory, false);
}
public List<EmsPointMatch> getDeviceAlarmPointMatch(String siteId, String deviceId, String deviceCategory) {
return getDevicePointMatch(siteId, deviceId, deviceCategory, true);
}
private List<EmsPointMatch> getDevicePointMatch(String siteId, String deviceId, String deviceCategory, boolean isAlarm) {
// List<EmsPointMatch> pointMatchList = new ArrayList<>();
// EmsDevicesSetting devicesSetting = emsDevicesSettingMapper.getDeviceBySiteAndDeviceId(deviceId, siteId);
// if (devicesSetting == null) {
// log.info("未找到设备配置信息siteId: " + siteId + ", deviceId: "+ deviceId);
// return pointMatchList;
// }
List<EmsPointMatch> pointMatchList = redisCache.getCacheList(getPointTacthCacheKey(siteId, deviceId, deviceCategory));
List<EmsPointMatch> pointMatchList = redisCache.getCacheList(getPointMacthCacheKey(siteId, deviceCategory));
if (CollectionUtils.isEmpty(pointMatchList)) {
pointMatchList = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceId, deviceCategory);
pointMatchList = emsPointMatchMapper.getDevicePointMatchList(siteId, deviceCategory);
}
if (CollectionUtils.isNotEmpty(pointMatchList)) {
Map<Integer, List<EmsPointMatch>> map = pointMatchList.stream().collect(Collectors.groupingBy(EmsPointMatch::getIsAlarm));
if (isAlarm) {
pointMatchList = map.get(PointType.YES.getCode());
} else {
pointMatchList = map.get(PointType.NO.getCode());
}
}
return pointMatchList;
@ -111,13 +130,12 @@ public class DevicePointMatchDataProcessor {
try {
devicePintointMtachInfo.forEach((key, value) -> {
// 查询点位是否存在
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceId, deviceCategory, value);
EmsPointMatch dbPoint = emsPointMatchMapper.getOnePointMatch(siteId, deviceCategory, value);
if (!Objects.isNull(dbPoint)) {
return;
}
EmsPointMatch pointMatch = new EmsPointMatch();
pointMatch.setSiteId(siteId);
pointMatch.setDeviceId(deviceId);
pointMatch.setDeviceCategory(deviceCategory);
pointMatch.setMatchTable(DeviceMatchTable.getMatchTableByCode(deviceCategory));
pointMatch.setMatchField(StringUtils.toUnderScoreCase(key));
@ -169,12 +187,11 @@ public class DevicePointMatchDataProcessor {
/**
* 设置点位缓存key
* @param siteId
* @param deviceId
* @param deviceCategory
* @return 点位缓存key
*/
public static String getPointTacthCacheKey(String siteId, String deviceId, String deviceCategory)
public static String getPointMacthCacheKey(String siteId, String deviceCategory)
{
return RedisKeyConstants.POINT_MATCH + deviceCategory + "_" + siteId + "_" + deviceId;
return RedisKeyConstants.POINT_MATCH + deviceCategory + "_" + siteId;
}
}

View File

@ -177,4 +177,18 @@
where t.`year` = #{currentYear}
and t.`month` = #{currentMonth}
</select>
<select id="getConfigListByTimeFrame" resultType="com.xzzn.ems.domain.EmsEnergyPriceConfig">
<include refid="selectEmsEnergyPriceConfigVo"/>
<where>
<if test="siteId != null and siteId != ''">
and site_id = #{siteId}
</if>
<if test="startTime != null and endTime != null">
and STR_TO_DATE(CONCAT(year, '-', month, '-01'), '%Y-%m-%d') between #{startTime} and #{endTime}
</if>
</where>
order by
`year` asc,
`month` desc;
</select>
</mapper>

View File

@ -100,4 +100,9 @@
from ems_mqtt_topic_config
where mqtt_topic = #{strategyTopic}
</select>
<select id="selectOneByTopic" parameterType="String" resultMap="EmsMqttTopicConfigResult">
<include refid="selectEmsMqttTopicConfigVo"/>
where mqtt_topic = #{topic}
</select>
</mapper>

View File

@ -24,11 +24,11 @@
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="deviceId" column="device_id" />
<result property="isAlarm" column="is_alarm" />
</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, device_id 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 from ems_point_match
</sql>
<select id="selectEmsPointMatchList" parameterType="EmsPointMatch" resultMap="EmsPointMatchResult">
@ -76,7 +76,7 @@
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="deviceId != null">device_id,</if>
<if test="isAlarm != null">is_alarm,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="pointName != null">#{pointName},</if>
@ -97,7 +97,7 @@
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="deviceId != null">#{deviceId},</if>
<if test="isAlarm != null">#{isAlarm},</if>
</trim>
</insert>
@ -122,7 +122,7 @@
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="isAlarm != null">is_alarm = #{isAlarm},</if>
</trim>
where id = #{id}
</update>
@ -380,6 +380,9 @@
<if test="ipPort != null">
and t.ip_port = #{ipPort}
</if>
<if test="isAlarm != null">
and t.is_alarm = #{isAlarm}
</if>
</select>
<select id="getClusterDevicePoints" resultType="com.xzzn.ems.domain.vo.PointQueryResponse">
@ -408,6 +411,9 @@
<if test="deviceCategory != null and deviceCategory != ''">
and t.device_category = #{deviceCategory}
</if>
<if test="isAlarm != null">
and t.is_alarm = #{isAlarm}
</if>
) as tmp
where 1=1
<if test="pointName != null and pointName != ''">
@ -434,7 +440,6 @@
<include refid="selectEmsPointMatchVo"/>
where site_id = #{siteId}
and device_category = #{deviceCategory}
and device_id = #{deviceId}
and data_point = #{dataPoint}
order by update_time desc
limit 1
@ -444,6 +449,5 @@
<include refid="selectEmsPointMatchVo"/>
where site_id = #{siteId}
and device_category = #{deviceCategory}
and device_id = #{deviceId}
</select>
</mapper>