修正部分参数
This commit is contained in:
@ -1,14 +1,8 @@
|
||||
package com.xzzn.web.controller.ems;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.xzzn.common.enums.*;
|
||||
import com.xzzn.common.utils.DateUtils;
|
||||
import com.xzzn.common.utils.StringUtils;
|
||||
import com.xzzn.ems.domain.*;
|
||||
import com.xzzn.ems.service.*;
|
||||
import com.xzzn.ems.domain.EmsMqttMessage;
|
||||
import com.xzzn.ems.service.IEmsMqttMessageService;
|
||||
import com.xzzn.ems.service.IFXXDataProcessService;
|
||||
import com.xzzn.framework.manager.MqttLifecycleManager;
|
||||
import com.xzzn.framework.web.service.MqttPublisher;
|
||||
import com.xzzn.framework.web.service.MqttSubscriber;
|
||||
@ -21,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class MqttMessageController implements MqttPublisher, MqttSubscriber {
|
||||
@ -37,21 +29,7 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
|
||||
private IEmsMqttMessageService emsMqttMessageService;
|
||||
|
||||
@Autowired
|
||||
private IEmsBatteryDataService emsBatteryDataService;
|
||||
|
||||
@Autowired
|
||||
private IEmsPcsDataService emsPcsDataService;
|
||||
|
||||
@Autowired
|
||||
private IEmsPcsBranchDataService emsPcsBranchDataService;
|
||||
|
||||
@Autowired
|
||||
private IEmsBatteryClusterService emsBatteryClusterService;
|
||||
|
||||
@Autowired
|
||||
private IEmsBatteryStackService emsBatteryStackService;
|
||||
|
||||
|
||||
private IFXXDataProcessService fXXDataProcessService;
|
||||
|
||||
@Autowired
|
||||
public MqttMessageController(MqttLifecycleManager mqttLifecycleManager) {
|
||||
@ -94,7 +72,7 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
|
||||
System.out.println("[DEVICE] data: " + payload);
|
||||
try {
|
||||
// 业务处理逻辑
|
||||
handleFxData(payload);
|
||||
fXXDataProcessService.handleFxData(payload);
|
||||
|
||||
|
||||
EmsMqttMessage mqttMessage = new EmsMqttMessage();
|
||||
@ -139,360 +117,5 @@ public class MqttMessageController implements MqttPublisher, MqttSubscriber {
|
||||
}
|
||||
|
||||
|
||||
private void handleFxData(String message) {
|
||||
JSONArray arraylist = JSONArray.parseArray(message);
|
||||
|
||||
for (int i = 0; i < arraylist.size(); i++) {
|
||||
JSONObject obj = JSONObject.parseObject(arraylist.get(i).toString());
|
||||
|
||||
String deviceId = obj.get("Device").toString();
|
||||
String jsonData = obj.get("Data").toString();
|
||||
|
||||
log.info("deviceId:" + deviceId);
|
||||
if (deviceId.contains("BMSD")) {
|
||||
|
||||
|
||||
//电池堆
|
||||
//BMS 电池簇
|
||||
EmsBatteryStack dataStack = new EmsBatteryStack();
|
||||
// 设置所有 BigDecimal 类型字段为 ZERO
|
||||
dataStack.setChargeableCapacity(BigDecimal.ZERO);
|
||||
dataStack.setTotalChargedCapacity(BigDecimal.ZERO);
|
||||
dataStack.setDischargeableCapacity(BigDecimal.ZERO);
|
||||
dataStack.setTotalDischargedCapacity(BigDecimal.ZERO);
|
||||
dataStack.setSoh(BigDecimal.ZERO);
|
||||
dataStack.setAverageTemperature(BigDecimal.ZERO);
|
||||
dataStack.setInsulationResistance(BigDecimal.ZERO);
|
||||
dataStack.setCurrentSoc(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedChargePower(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedDischargePower(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedChargeVoltage(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedDischargeVoltage(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedChargeCurrent(BigDecimal.ZERO);
|
||||
dataStack.setMaxAllowedDischargeCurrent(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackVoltage(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackCurrent(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackTemp(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackSoc(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackSoh(BigDecimal.ZERO);
|
||||
dataStack.setBatteryPackInsulationResistance(BigDecimal.ZERO);
|
||||
dataStack.setAvgCellVoltage(BigDecimal.ZERO);
|
||||
dataStack.setAvgCellTemp(BigDecimal.ZERO);
|
||||
dataStack.setMaxCellVoltage(BigDecimal.ZERO);
|
||||
dataStack.setMinCellVoltage(BigDecimal.ZERO);
|
||||
dataStack.setMaxCellTemp(BigDecimal.ZERO);
|
||||
dataStack.setMinCellTemp(BigDecimal.ZERO);
|
||||
dataStack.setMaxCellSoc(BigDecimal.ZERO);
|
||||
dataStack.setMinCellSoc(BigDecimal.ZERO);
|
||||
dataStack.setMaxCellSoh(BigDecimal.ZERO);
|
||||
dataStack.setMinCellSoh(BigDecimal.ZERO);
|
||||
dataStack.setTotalChargeEnergy(BigDecimal.ZERO);
|
||||
dataStack.setTotalDischargeEnergy(BigDecimal.ZERO);
|
||||
|
||||
// 其他非 BigDecimal 字段
|
||||
dataStack.setWorkStatus(WorkStatus.NORMAL.getCode()); // 或其他默认值
|
||||
dataStack.setPcsCommunicationStatus(CommunicationStatus.OK.getCode());
|
||||
dataStack.setEmsCommunicationStatus(CommunicationStatus.OK.getCode());
|
||||
dataStack.setCreateBy("system");
|
||||
dataStack.setCreateTime(DateUtils.getNowDate());
|
||||
dataStack.setUpdateBy("system");
|
||||
dataStack.setUpdateTime(DateUtils.getNowDate());
|
||||
dataStack.setSiteId("021_FXX_01");
|
||||
dataStack.setDeviceId(deviceId);
|
||||
dataStack.setMaxCellVoltageId(Long.parseLong("1"));
|
||||
dataStack.setMinCellVoltageId(Long.parseLong("1"));
|
||||
dataStack.setMaxCellTempId(Long.parseLong("1"));
|
||||
dataStack.setMinCellTempId(Long.parseLong("1"));
|
||||
dataStack.setMaxCellSocId(Long.parseLong("1"));
|
||||
dataStack.setMinCellSocId(Long.parseLong("1"));
|
||||
dataStack.setMaxCellSohId(Long.parseLong("1"));
|
||||
dataStack.setMinCellSohId(Long.parseLong("1"));
|
||||
|
||||
emsBatteryStackService.insertEmsBatteryStack(dataStack);
|
||||
|
||||
|
||||
//单体电池
|
||||
Map<String, Map<String, Object>> records = processData(JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {}));
|
||||
List<EmsBatteryData> list = new ArrayList<>();
|
||||
//单体电池
|
||||
for (Map.Entry<String, Map<String, Object>> record : records.entrySet()) {
|
||||
String recordId = record.getKey();
|
||||
Map<String, Object> fields = record.getValue();
|
||||
|
||||
EmsBatteryData batteryData = new EmsBatteryData();
|
||||
batteryData.setDeviceId(recordId);
|
||||
batteryData.setBatteryCellId(recordId);
|
||||
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(deviceId);
|
||||
|
||||
// 时间戳
|
||||
batteryData.setDataTimestamp(new Date());
|
||||
|
||||
// ID字段
|
||||
batteryData.setSiteId(("021_FXX_01"));
|
||||
batteryData.setClusterDeviceId(("021"));
|
||||
|
||||
list.add(batteryData);
|
||||
}
|
||||
if (list.size() > 0 ) {
|
||||
emsBatteryDataService.insertEmsBatteryDataList(list);
|
||||
}
|
||||
} else if (deviceId.contains("BMSC")) {
|
||||
log.info("====================");
|
||||
log.info("BMSC data:"+ jsonData);
|
||||
//BMS 电池簇
|
||||
EmsBatteryCluster data = new EmsBatteryCluster();
|
||||
// 设置所有 BigDecimal 类型字段为 ZERO
|
||||
data.setChargeableCapacity(BigDecimal.ZERO);
|
||||
data.setTotalChargedCapacity(BigDecimal.ZERO);
|
||||
data.setDischargeableCapacity(BigDecimal.ZERO);
|
||||
data.setTotalDischargedCapacity(BigDecimal.ZERO);
|
||||
data.setSoh(BigDecimal.ZERO);
|
||||
data.setAverageTemperature(BigDecimal.ZERO);
|
||||
data.setInsulationResistance(BigDecimal.ZERO);
|
||||
data.setCurrentSoc(BigDecimal.ZERO);
|
||||
data.setMaxAllowedChargePower(BigDecimal.ZERO);
|
||||
data.setMaxAllowedDischargePower(BigDecimal.ZERO);
|
||||
data.setMaxAllowedChargeVoltage(BigDecimal.ZERO);
|
||||
data.setMaxAllowedDischargeVoltage(BigDecimal.ZERO);
|
||||
data.setMaxAllowedChargeCurrent(BigDecimal.ZERO);
|
||||
data.setMaxAllowedDischargeCurrent(BigDecimal.ZERO);
|
||||
data.setBatteryPackVoltage(BigDecimal.ZERO);
|
||||
data.setBatteryPackCurrent(BigDecimal.ZERO);
|
||||
data.setBatteryPackTemp(BigDecimal.ZERO);
|
||||
data.setBatteryPackSoc(BigDecimal.ZERO);
|
||||
data.setBatteryPackSoh(BigDecimal.ZERO);
|
||||
data.setBatteryPackInsulationResistance(BigDecimal.ZERO);
|
||||
data.setAvgCellVoltage(BigDecimal.ZERO);
|
||||
data.setAvgCellTemp(BigDecimal.ZERO);
|
||||
data.setMaxCellVoltage(BigDecimal.ZERO);
|
||||
data.setMinCellVoltage(BigDecimal.ZERO);
|
||||
data.setMaxCellTemp(BigDecimal.ZERO);
|
||||
data.setMinCellTemp(BigDecimal.ZERO);
|
||||
data.setMaxCellSoc(BigDecimal.ZERO);
|
||||
data.setMinCellSoc(BigDecimal.ZERO);
|
||||
data.setMaxCellSoh(BigDecimal.ZERO);
|
||||
data.setMinCellSoh(BigDecimal.ZERO);
|
||||
data.setTotalChargeEnergy(BigDecimal.ZERO);
|
||||
data.setTotalDischargeEnergy(BigDecimal.ZERO);
|
||||
|
||||
// 其他非 BigDecimal 字段
|
||||
data.setWorkStatus(WorkStatus.NORMAL.getCode()); // 或其他默认值
|
||||
data.setPcsCommunicationStatus(CommunicationStatus.OK.getCode());
|
||||
data.setEmsCommunicationStatus(CommunicationStatus.OK.getCode());
|
||||
data.setCreateBy("system");
|
||||
data.setCreateTime(DateUtils.getNowDate());
|
||||
data.setUpdateBy("system");
|
||||
data.setUpdateTime(DateUtils.getNowDate());
|
||||
data.setSiteId("021_FXX_01");
|
||||
data.setDeviceId(deviceId);
|
||||
data.setMaxCellVoltageId(Long.parseLong("1"));
|
||||
data.setMinCellVoltageId(Long.parseLong("1"));
|
||||
data.setMaxCellTempId(Long.parseLong("1"));
|
||||
data.setMinCellTempId(Long.parseLong("1"));
|
||||
data.setMaxCellSocId(Long.parseLong("1"));
|
||||
data.setMinCellSocId(Long.parseLong("1"));
|
||||
data.setMaxCellSohId(Long.parseLong("1"));
|
||||
data.setMinCellSohId(Long.parseLong("1"));
|
||||
data.setStackDeviceId("1");
|
||||
emsBatteryClusterService.insertEmsBatteryCluster(data);
|
||||
|
||||
|
||||
//单体电池
|
||||
Map<String, Map<String, Object>> records = processData(JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {}));
|
||||
List<EmsBatteryData> list = new ArrayList<>();
|
||||
//单体电池
|
||||
for (Map.Entry<String, Map<String, Object>> record : records.entrySet()) {
|
||||
String recordId = record.getKey();
|
||||
Map<String, Object> fields = record.getValue();
|
||||
|
||||
EmsBatteryData batteryData = new EmsBatteryData();
|
||||
batteryData.setDeviceId(recordId);
|
||||
batteryData.setBatteryCellId(recordId);
|
||||
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(deviceId);
|
||||
|
||||
// 时间戳
|
||||
batteryData.setDataTimestamp(new Date());
|
||||
|
||||
// ID字段
|
||||
batteryData.setSiteId(("021_FXX_01"));
|
||||
batteryData.setClusterDeviceId(deviceId);
|
||||
|
||||
list.add(batteryData);
|
||||
}
|
||||
if (list.size() > 0 ) {
|
||||
emsBatteryDataService.insertEmsBatteryDataList(list);
|
||||
}
|
||||
} else if (deviceId.contains("PCS")) {
|
||||
log.info("====================");
|
||||
|
||||
log.info("PCS data:"+ jsonData);
|
||||
|
||||
|
||||
//pcs
|
||||
EmsPcsData pcsData = new EmsPcsData();
|
||||
// 时间与状态类字段
|
||||
pcsData.setDataUpdateTime(new Date());
|
||||
pcsData.setWorkStatus(WorkStatus.NORMAL.getCode());
|
||||
pcsData.setGridStatus(GridStatus.GRID.getCode());
|
||||
pcsData.setDeviceStatus(DeviceStatus.ONLINE.getCode());
|
||||
pcsData.setControlMode(ControlModeStatus.REMOTE.getCode());
|
||||
|
||||
// 功率与能量类字段
|
||||
pcsData.setTotalActivePower(BigDecimal.ZERO);
|
||||
pcsData.setDailyAcChargeEnergy(BigDecimal.ZERO);
|
||||
pcsData.setTotalReactivePower(BigDecimal.ZERO);
|
||||
pcsData.setDailyAcDischargeEnergy(BigDecimal.ZERO);
|
||||
pcsData.setTotalApparentPower(BigDecimal.ZERO);
|
||||
pcsData.setTotalPowerFactor(BigDecimal.ZERO);
|
||||
pcsData.setDcPower(BigDecimal.ZERO);
|
||||
pcsData.setTotalAcChargeEnergy(BigDecimal.ZERO);
|
||||
pcsData.setTotalAcDischargeEnergy(BigDecimal.ZERO);
|
||||
pcsData.setAcChargeActivePower(BigDecimal.ZERO);
|
||||
pcsData.setAcCapacitiveReactivePower(BigDecimal.ZERO);
|
||||
pcsData.setAcDischargeActivePower(BigDecimal.ZERO);
|
||||
pcsData.setAcInductiveReactivePower(BigDecimal.ZERO);
|
||||
pcsData.setMaxCapacitivePowerCapacity(BigDecimal.ZERO);
|
||||
pcsData.setMaxInductivePowerCapacity(BigDecimal.ZERO);
|
||||
pcsData.setMaxChargePowerCapacity(BigDecimal.ZERO);
|
||||
pcsData.setMaxDischargePowerCapacity(BigDecimal.ZERO);
|
||||
|
||||
|
||||
// 温度与环境参数
|
||||
pcsData.setPcsModuleTemperature(BigDecimal.ZERO);
|
||||
pcsData.setPcsEnvironmentTemperature(BigDecimal.ZERO);
|
||||
pcsData.setAcFrequency(BigDecimal.ZERO);
|
||||
|
||||
// 状态指示类
|
||||
pcsData.setBranchStatus(BranchStatus.NORMAL.getCode());
|
||||
pcsData.setDischargeStatus(ChargeStatus.CHARGING.getCode());
|
||||
pcsData.setAcSwitchStatus(SwitchStatus.CLOSED.getCode());
|
||||
pcsData.setDcSwitchStatus(SwitchStatus.CLOSED.getCode());
|
||||
pcsData.setRemoteControlStatus(ControlModeStatus.REMOTE.getCode());
|
||||
|
||||
// 直流参数
|
||||
pcsData.setDcVoltage(BigDecimal.ZERO);
|
||||
pcsData.setDcCurrent(BigDecimal.ZERO);
|
||||
|
||||
// 系统管理字段
|
||||
// data.setCreateBy(BigDecimal.ZERO);
|
||||
// data.setCreateTime(BigDecimal.ZERO);
|
||||
// data.setUpdateBy(BigDecimal.ZERO);
|
||||
// data.setUpdateTime(BigDecimal.ZERO);
|
||||
// data.setRemark(BigDecimal.ZERO);
|
||||
pcsData.setSiteId("021_FXX_01");
|
||||
pcsData.setDeviceId(deviceId);
|
||||
pcsData.setDateMonth(DateUtils.getNowMonthLong());
|
||||
pcsData.setDateDay(DateUtils.getNowDayLong());
|
||||
|
||||
emsPcsDataService.insertEmsPcsData(pcsData);
|
||||
|
||||
Map<String, Map<String, Object>> records = processDataPrefix(JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {}));
|
||||
List<EmsPcsBranchData> list = new ArrayList<>();
|
||||
|
||||
//PCS支路
|
||||
for (Map.Entry<String, Map<String, Object>> record : records.entrySet()) {
|
||||
String recordId = record.getKey();
|
||||
Map<String, Object> fields = record.getValue();
|
||||
|
||||
EmsPcsBranchData data = new EmsPcsBranchData();
|
||||
data.setDeviceId(recordId);
|
||||
data.setDcPower(BigDecimal.ZERO);
|
||||
data.setDcVoltage(BigDecimal.ZERO);
|
||||
data.setDcCurrent(BigDecimal.ZERO);
|
||||
data.setGridUVoltage(BigDecimal.ZERO);
|
||||
data.setGridVVoltage(BigDecimal.ZERO);
|
||||
data.setGridWVoltage(BigDecimal.ZERO);
|
||||
data.setOutputUCurrent(BigDecimal.ZERO);
|
||||
data.setOutputVCurrent(BigDecimal.ZERO);
|
||||
data.setOutputWCurrent(BigDecimal.ZERO);
|
||||
data.setApparentPower(BigDecimal.ZERO);
|
||||
data.setActivePower(BigDecimal.ZERO);
|
||||
data.setReactivePower(BigDecimal.ZERO);
|
||||
data.setPowerFactor(BigDecimal.ZERO);
|
||||
data.setFrequency(BigDecimal.ZERO);
|
||||
data.setInternalTemp(BigDecimal.ZERO);
|
||||
data.setuIgbtTemp(BigDecimal.ZERO);
|
||||
data.setvIgbtTemp(BigDecimal.ZERO);
|
||||
data.setwIgbtTemp(BigDecimal.ZERO);
|
||||
data.setAvailablePower(BigDecimal.ZERO);
|
||||
data.setTotalLoadRatio(BigDecimal.ZERO);
|
||||
data.setAcLeakageCurrent(BigDecimal.ZERO);
|
||||
data.setInsulationResistance(BigDecimal.ZERO);
|
||||
data.setBranchId(Long.parseLong("1"));
|
||||
list.add(data);
|
||||
}
|
||||
if (list.size() > 0 ) {
|
||||
emsPcsBranchDataService.insertEmsPcsBranchDataList(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 数据分组处理
|
||||
private static Map<String, Map<String, Object>> processData(Map<String, Object> rawData) {
|
||||
Map<String, Map<String, Object>> records = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Object> entry : rawData.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
// 提取记录ID(最后3位)
|
||||
String recordId = key.substring(key.length() - 3);
|
||||
try {
|
||||
Long.parseLong(recordId);
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 提取字段类型(前缀)
|
||||
String fieldType = key.substring(0, key.length() - 3);
|
||||
|
||||
// 初始化记录
|
||||
records.putIfAbsent(recordId, new HashMap<>());
|
||||
// 存入字段值
|
||||
records.get(recordId).put(fieldType, entry.getValue());
|
||||
}
|
||||
return records;
|
||||
}
|
||||
|
||||
private static Map<String, Map<String, Object>> processDataPrefix(Map<String, Object> rawData) {
|
||||
Map<String, Map<String, Object>> records = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Object> entry : rawData.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
// 确保键长度足够
|
||||
if (key.length() < 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 提取记录ID(前3位)
|
||||
String recordId = key.substring(0, 3);
|
||||
if (!recordId.startsWith("DY")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 提取字段类型(剩余部分)
|
||||
String fieldType = key.substring(3);
|
||||
|
||||
// 初始化记录
|
||||
records.putIfAbsent(recordId, new HashMap<>());
|
||||
// 存入字段值
|
||||
records.get(recordId).put(fieldType, entry.getValue());
|
||||
}
|
||||
return records;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user