dev #2

Merged
dashixiong merged 349 commits from dev into main 2026-02-11 01:55:46 +00:00
373 changed files with 55312 additions and 1120 deletions
Showing only changes of commit f24072f248 - Show all commits

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;
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) {
BigDecimal power;
WriteTagConfig writeTag = new WriteTagConfig();
writeTag.setAddress(pointMatch.getIpAddress());
if (DEVICE_STATUS_FIELD.equals(pointMatch.getMatchField())) {
writeTag.setValue(command.getCode());
writeTag.setAddress(pcsSetting.getPointAddress());
if (DeviceRunningStatus.RUNNING.getCode().equals(deviceStatus)) {
// 开机
writeTag.setValue(pcsSetting.getStartCommand());
power = pcsSetting.getStartPower();
} else {
// 电池簇PCS有功功率给定置0
writeTag.setValue(0);
// 关机
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;
}
clusterWriteTag.setValue(power);
writeTags.add(clusterWriteTag);
}
return writeTags;
}