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,7 +1,5 @@
package com.xzzn.ems.domain.vo;
import java.util.List;
import javax.validation.constraints.NotBlank;
/**
@ -24,10 +22,6 @@ public class DeviceUpdateRequest {
/** 设备类型 */
private String deviceCategory;
/** 设备点位数据匹配表字段 */
private List<String> matchFields;
public String getSiteId() {
return siteId;
}
@ -60,11 +54,4 @@ public class DeviceUpdateRequest {
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;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
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.enums.DeviceCategory;
import com.xzzn.common.enums.DeviceRunningStatus;
import com.xzzn.common.enums.PcsControlCommand;
import com.xzzn.common.enums.PointType;
import com.xzzn.common.enums.SiteEnum;
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.ems.domain.EmsDevicesSetting;
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.DevicesSettingVo;
import com.xzzn.ems.domain.vo.PointDataRequest;
@ -45,7 +44,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 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
private EmsDevicesSettingMapper emsDevicesMapper;
@Autowired
@ -528,13 +523,10 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
if (device == null) {
throw new ServiceException("未找到对应设备配置信息");
}
// 查询设备配置的设备状态对应点位
CLUSTER_ACTIVE_POWER_FIELDS.add(DEVICE_STATUS_FIELD);
request.setMatchFields(CLUSTER_ACTIVE_POWER_FIELDS);
request.setDeviceCategory(DeviceCategory.PCS.getCode());
List<EmsPointMatch> pointMatchList = emsPointMatchMapper.selectDeviceStatusPoint(request);
if (CollectionUtils.isEmpty(pointMatchList) || pointMatchList.stream().noneMatch(point -> DEVICE_STATUS_FIELD.equals(point.getMatchField()))) {
throw new ServiceException("未找到对应设备状态点位");
// 查询设备的开关机配置
EmsPcsSetting pcsSetting = emsPcsSettingMapper.selectEmsPcsSettingByDeviceId(device.getId());
if (pcsSetting == null) {
throw new ServiceException("未找到对应PCS配置信息");
}
if (DeviceRunningStatus.getShutdownCodeList().contains(request.getDeviceStatus())) {
// 开机逻辑
@ -545,14 +537,9 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
} else {
return false;
}
// 根据设备类型和请求状态确定控制命令
PcsControlCommand command = PcsControlCommand.fromDeviceStatus(device.getDeviceStatus());
if (command == null) {
throw new ServiceException("不支持的设备状态操作");
}
// 调用Modbus向设备发送指令
DeviceConfig deviceConfig = getDeviceConfig(device);
deviceConfig.setWriteTags(getWriteTags(device, pointMatchList, command));
deviceConfig.setWriteTags(getWriteTags(device.getDeviceStatus(), pcsSetting));
log.info("设备控制指令发送数据: {}", JSON.toJSONString(deviceConfig));
boolean result = modbusProcessor.writeDataToDevice(deviceConfig);
if (!result) {
@ -576,18 +563,32 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
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<>();
for (EmsPointMatch pointMatch : pointMatchList) {
WriteTagConfig writeTag = new WriteTagConfig();
writeTag.setAddress(pointMatch.getIpAddress());
if (DEVICE_STATUS_FIELD.equals(pointMatch.getMatchField())) {
writeTag.setValue(command.getCode());
} else {
// 电池簇PCS有功功率给定置0
writeTag.setValue(0);
BigDecimal power;
WriteTagConfig writeTag = new WriteTagConfig();
writeTag.setAddress(pcsSetting.getPointAddress());
if (DeviceRunningStatus.RUNNING.getCode().equals(deviceStatus)) {
// 开机
writeTag.setValue(pcsSetting.getStartCommand());
power = pcsSetting.getStartPower();
} 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;
}