PCS设备开关机逻辑修改

This commit is contained in:
zq
2026-01-04 10:40:38 +08:00
parent 041c41822e
commit f24072f248
3 changed files with 30 additions and 87 deletions

View File

@ -1,45 +0,0 @@
package com.xzzn.common.enums;
public enum PcsControlCommand {
TOTAL_START(0x0004, "总运行"),
TOTAL_STOP(0x0010, "总停机"),
TOTAL_RESET(0x0080, "总复位"),
// CLUSTER1_START(0x1004, "电池簇1运行"),
// CLUSTER1_STOP(0x1010, "电池簇1停机"),
// CLUSTER1_RESET(0x1080, "电池簇1复位"),
// CLUSTER2_START(0x2004, "电池簇2运行"),
// CLUSTER2_STOP(0x2010, "电池簇2停机"),
// CLUSTER2_RESET(0x2080, "电池簇2复位"),
// CLUSTER3_START(0x3004, "电池簇3运行"),
// CLUSTER3_STOP(0x3010, "电池簇3停机"),
// CLUSTER3_RESET(0x3080, "电池簇3复位"),
// CLUSTER4_START(0x4004, "电池簇4运行"),
// CLUSTER4_STOP(0x4010, "电池簇4停机"),
// CLUSTER4_RESET(0x4080, "电池簇4复位"),
;
private final int code;
private final String description;
PcsControlCommand(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static PcsControlCommand fromDeviceStatus(String deviceStatus) {
if (DeviceRunningStatus.RUNNING.getCode().equals(deviceStatus)) {
return PcsControlCommand.TOTAL_START;
} else if (DeviceRunningStatus.SHUTDOWN.getCode().equals(deviceStatus) ) {
return PcsControlCommand.TOTAL_STOP;
}
return null;
}
}

View File

@ -1,7 +1,5 @@
package com.xzzn.ems.domain.vo; package com.xzzn.ems.domain.vo;
import java.util.List;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
/** /**
@ -24,10 +22,6 @@ public class DeviceUpdateRequest {
/** 设备类型 */ /** 设备类型 */
private String deviceCategory; private String deviceCategory;
/** 设备点位数据匹配表字段 */
private List<String> matchFields;
public String getSiteId() { public String getSiteId() {
return siteId; return siteId;
} }
@ -60,11 +54,4 @@ public class DeviceUpdateRequest {
this.deviceCategory = deviceCategory; this.deviceCategory = deviceCategory;
} }
public List<String> getMatchFields() {
return matchFields;
}
public void setMatchFields(List<String> matchFields) {
this.matchFields = matchFields;
}
} }

View File

@ -1,6 +1,7 @@
package com.xzzn.ems.service.impl; package com.xzzn.ems.service.impl;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference; import com.alibaba.fastjson2.TypeReference;
import com.xzzn.common.constant.RedisKeyConstants; import com.xzzn.common.constant.RedisKeyConstants;
@ -10,7 +11,6 @@ import com.xzzn.common.core.modbus.domain.WriteTagConfig;
import com.xzzn.common.core.redis.RedisCache; import com.xzzn.common.core.redis.RedisCache;
import com.xzzn.common.enums.DeviceCategory; import com.xzzn.common.enums.DeviceCategory;
import com.xzzn.common.enums.DeviceRunningStatus; import com.xzzn.common.enums.DeviceRunningStatus;
import com.xzzn.common.enums.PcsControlCommand;
import com.xzzn.common.enums.PointType; import com.xzzn.common.enums.PointType;
import com.xzzn.common.enums.SiteEnum; import com.xzzn.common.enums.SiteEnum;
import com.xzzn.common.exception.ServiceException; import com.xzzn.common.exception.ServiceException;
@ -18,7 +18,6 @@ import com.xzzn.common.utils.DateUtils;
import com.xzzn.common.utils.StringUtils; import com.xzzn.common.utils.StringUtils;
import com.xzzn.ems.domain.EmsDevicesSetting; import com.xzzn.ems.domain.EmsDevicesSetting;
import com.xzzn.ems.domain.EmsPcsSetting; import com.xzzn.ems.domain.EmsPcsSetting;
import com.xzzn.ems.domain.EmsPointMatch;
import com.xzzn.ems.domain.vo.DeviceUpdateRequest; import com.xzzn.ems.domain.vo.DeviceUpdateRequest;
import com.xzzn.ems.domain.vo.DevicesSettingVo; import com.xzzn.ems.domain.vo.DevicesSettingVo;
import com.xzzn.ems.domain.vo.PointDataRequest; import com.xzzn.ems.domain.vo.PointDataRequest;
@ -45,7 +44,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
/** /**
* 站点信息 服务层实现 * 站点信息 服务层实现
@ -57,9 +55,6 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
private static final Logger log = LoggerFactory.getLogger(EmsDeviceSettingServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(EmsDeviceSettingServiceImpl.class);
private static final String DDS_SITE_ID = "021_DDS_01"; private static final String DDS_SITE_ID = "021_DDS_01";
private static final String DEVICE_STATUS_FIELD = "device_status";
private static final List<String> CLUSTER_ACTIVE_POWER_FIELDS = Arrays.asList("cluster1_active_power", "cluster2_active_power", "cluster3_active_power", "cluster4_active_power");
@Autowired @Autowired
private EmsDevicesSettingMapper emsDevicesMapper; private EmsDevicesSettingMapper emsDevicesMapper;
@Autowired @Autowired
@ -528,13 +523,10 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
if (device == null) { if (device == null) {
throw new ServiceException("未找到对应设备配置信息"); throw new ServiceException("未找到对应设备配置信息");
} }
// 查询设备配置的设备状态对应点位 // 查询设备的开关机配置
CLUSTER_ACTIVE_POWER_FIELDS.add(DEVICE_STATUS_FIELD); EmsPcsSetting pcsSetting = emsPcsSettingMapper.selectEmsPcsSettingByDeviceId(device.getId());
request.setMatchFields(CLUSTER_ACTIVE_POWER_FIELDS); if (pcsSetting == null) {
request.setDeviceCategory(DeviceCategory.PCS.getCode()); throw new ServiceException("未找到对应PCS配置信息");
List<EmsPointMatch> pointMatchList = emsPointMatchMapper.selectDeviceStatusPoint(request);
if (CollectionUtils.isEmpty(pointMatchList) || pointMatchList.stream().noneMatch(point -> DEVICE_STATUS_FIELD.equals(point.getMatchField()))) {
throw new ServiceException("未找到对应设备状态点位");
} }
if (DeviceRunningStatus.getShutdownCodeList().contains(request.getDeviceStatus())) { if (DeviceRunningStatus.getShutdownCodeList().contains(request.getDeviceStatus())) {
// 开机逻辑 // 开机逻辑
@ -545,14 +537,9 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
} else { } else {
return false; return false;
} }
// 根据设备类型和请求状态确定控制命令
PcsControlCommand command = PcsControlCommand.fromDeviceStatus(device.getDeviceStatus());
if (command == null) {
throw new ServiceException("不支持的设备状态操作");
}
// 调用Modbus向设备发送指令 // 调用Modbus向设备发送指令
DeviceConfig deviceConfig = getDeviceConfig(device); DeviceConfig deviceConfig = getDeviceConfig(device);
deviceConfig.setWriteTags(getWriteTags(device, pointMatchList, command)); deviceConfig.setWriteTags(getWriteTags(device.getDeviceStatus(), pcsSetting));
log.info("设备控制指令发送数据: {}", JSON.toJSONString(deviceConfig)); log.info("设备控制指令发送数据: {}", JSON.toJSONString(deviceConfig));
boolean result = modbusProcessor.writeDataToDevice(deviceConfig); boolean result = modbusProcessor.writeDataToDevice(deviceConfig);
if (!result) { if (!result) {
@ -576,18 +563,32 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
return deviceConfig; return deviceConfig;
} }
public List<WriteTagConfig> getWriteTags(EmsDevicesSetting device, List<EmsPointMatch> pointMatchList, PcsControlCommand command) { public List<WriteTagConfig> getWriteTags(String deviceStatus, EmsPcsSetting pcsSetting) {
List<WriteTagConfig> writeTags = new ArrayList<>(); List<WriteTagConfig> writeTags = new ArrayList<>();
for (EmsPointMatch pointMatch : pointMatchList) { BigDecimal power;
WriteTagConfig writeTag = new WriteTagConfig(); WriteTagConfig writeTag = new WriteTagConfig();
writeTag.setAddress(pointMatch.getIpAddress()); writeTag.setAddress(pcsSetting.getPointAddress());
if (DEVICE_STATUS_FIELD.equals(pointMatch.getMatchField())) { if (DeviceRunningStatus.RUNNING.getCode().equals(deviceStatus)) {
writeTag.setValue(command.getCode()); // 开机
} else { writeTag.setValue(pcsSetting.getStartCommand());
// 电池簇PCS有功功率给定置0 power = pcsSetting.getStartPower();
writeTag.setValue(0); } else {
// 关机
writeTag.setValue(pcsSetting.getStopCommand());
power = pcsSetting.getStopPower();
}
writeTags.add(writeTag);
JSONArray array = JSON.parseArray(pcsSetting.getClusterPointAddress());
for (int i = 0; i < pcsSetting.getClusterNum(); i++) {
Object clusterPointAddress = array.get(i);
WriteTagConfig clusterWriteTag = new WriteTagConfig();
clusterWriteTag.setAddress(String.valueOf(clusterPointAddress));
// 电池簇PCS有功功率给定置0
if (power == null) {
power = BigDecimal.ZERO;
} }
writeTags.add(writeTag); clusterWriteTag.setValue(power);
writeTags.add(clusterWriteTag);
} }
return writeTags; return writeTags;
} }