新增运行策略轮询功能
This commit is contained in:
32
ems-common/src/main/java/com/xzzn/common/enums/SocLimit.java
Normal file
32
ems-common/src/main/java/com/xzzn/common/enums/SocLimit.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.xzzn.common.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SOC限制 (%) 1 = 开,0 = 关
|
||||||
|
*
|
||||||
|
* @author xzzn
|
||||||
|
*/
|
||||||
|
public enum SocLimit
|
||||||
|
{
|
||||||
|
OFF(0, "关"),
|
||||||
|
ON(1, "开"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
SocLimit(Integer code, String info)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo()
|
||||||
|
{
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
ems-common/src/main/java/com/xzzn/common/enums/YesOrNo.java
Normal file
33
ems-common/src/main/java/com/xzzn/common/enums/YesOrNo.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.xzzn.common.enums;
|
||||||
|
|
||||||
|
public enum YesOrNo
|
||||||
|
{
|
||||||
|
YES(1, "是", "Y"),
|
||||||
|
NO(0, "否", "N");
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String info;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
YesOrNo(Integer code, String info, String value)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode()
|
||||||
|
{
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo()
|
||||||
|
{
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue()
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,5 @@
|
|||||||
package com.xzzn.common.utils;
|
package com.xzzn.common.utils;
|
||||||
|
|
||||||
import com.xzzn.common.annotation.Log;
|
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@ -161,6 +159,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
|||||||
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
|
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算相差分钟
|
||||||
|
*/
|
||||||
|
public static int differentMinutesByMillisecond(Date date1, Date date2)
|
||||||
|
{
|
||||||
|
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 60)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算时间差
|
* 计算时间差
|
||||||
*
|
*
|
||||||
|
|||||||
@ -12,29 +12,45 @@ import com.xzzn.common.enums.AlarmStatus;
|
|||||||
import com.xzzn.common.enums.ProtPlanStatus;
|
import com.xzzn.common.enums.ProtPlanStatus;
|
||||||
import com.xzzn.common.enums.StrategyStatus;
|
import com.xzzn.common.enums.StrategyStatus;
|
||||||
import com.xzzn.common.utils.StringUtils;
|
import com.xzzn.common.utils.StringUtils;
|
||||||
import com.xzzn.ems.domain.*;
|
import com.xzzn.ems.domain.EmsAlarmRecords;
|
||||||
|
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||||
|
import com.xzzn.ems.domain.EmsFaultIssueLog;
|
||||||
|
import com.xzzn.ems.domain.EmsFaultProtectionPlan;
|
||||||
|
import com.xzzn.ems.domain.EmsStrategyRunning;
|
||||||
import com.xzzn.ems.domain.vo.ProtectionPlanVo;
|
import com.xzzn.ems.domain.vo.ProtectionPlanVo;
|
||||||
import com.xzzn.ems.domain.vo.ProtectionSettingVo;
|
import com.xzzn.ems.domain.vo.ProtectionSettingVo;
|
||||||
import com.xzzn.ems.mapper.*;
|
import com.xzzn.ems.mapper.EmsAlarmRecordsMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsFaultIssueLogMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsFaultProtectionPlanMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsStrategyRunningMapper;
|
||||||
import com.xzzn.ems.service.IEmsFaultProtectionPlanService;
|
import com.xzzn.ems.service.IEmsFaultProtectionPlanService;
|
||||||
import com.xzzn.framework.manager.ModbusConnectionManager;
|
import com.xzzn.framework.manager.ModbusConnectionManager;
|
||||||
import com.xzzn.framework.manager.ModbusConnectionWrapper;
|
import com.xzzn.framework.manager.ModbusConnectionWrapper;
|
||||||
import com.xzzn.framework.web.service.ModbusService;
|
import com.xzzn.framework.web.service.ModbusService;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 告警保护方案轮询
|
* 告警保护方案轮询
|
||||||
*
|
*
|
||||||
@ -113,7 +129,7 @@ public class ProtectionPlanTask {
|
|||||||
final Integer isAlertAlarm = plan.getIsAlert();
|
final Integer isAlertAlarm = plan.getIsAlert();
|
||||||
final Long status = plan.getStatus();
|
final Long status = plan.getStatus();
|
||||||
// 看方案是否启用,走不同判断
|
// 看方案是否启用,走不同判断
|
||||||
if (status == ProtPlanStatus.STOP.getCode()) {
|
if (Objects.equals(status, ProtPlanStatus.STOP.getCode())) {
|
||||||
// 未启用,获取方案的故障值与最新数据判断是否需要下发方案
|
// 未启用,获取方案的故障值与最新数据判断是否需要下发方案
|
||||||
if(checkIsNeedIssuedPlan(protSettings, siteId)){
|
if(checkIsNeedIssuedPlan(protSettings, siteId)){
|
||||||
if("3".equals(plan.getFaultLevel())){
|
if("3".equals(plan.getFaultLevel())){
|
||||||
@ -143,6 +159,9 @@ public class ProtectionPlanTask {
|
|||||||
logger.info("<方案已启用> 方案ID:{}", plan.getId());
|
logger.info("<方案已启用> 方案ID:{}", plan.getId());
|
||||||
plan.setStatus(ProtPlanStatus.RUNNING.getCode());
|
plan.setStatus(ProtPlanStatus.RUNNING.getCode());
|
||||||
emsFaultProtectionPlanMapper.updateEmsFaultProtectionPlan(plan);
|
emsFaultProtectionPlanMapper.updateEmsFaultProtectionPlan(plan);
|
||||||
|
|
||||||
|
// 更新该站点策略为暂停状态
|
||||||
|
updateStrategyRunningStatus(siteId, StrategyStatus.SUSPENDED.getCode());
|
||||||
}
|
}
|
||||||
}, faultDelay, TimeUnit.SECONDS);
|
}, faultDelay, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
@ -167,8 +186,8 @@ public class ProtectionPlanTask {
|
|||||||
plan.setStatus(ProtPlanStatus.STOP.getCode());
|
plan.setStatus(ProtPlanStatus.STOP.getCode());
|
||||||
plan.setUpdateBy("system");
|
plan.setUpdateBy("system");
|
||||||
emsFaultProtectionPlanMapper.updateEmsFaultProtectionPlan(plan);
|
emsFaultProtectionPlanMapper.updateEmsFaultProtectionPlan(plan);
|
||||||
// 更新该站点策略为启用
|
// 更新该站点策略为启用状态
|
||||||
updateStrategyRunning(siteId);
|
updateStrategyRunningStatus(siteId, StrategyStatus.RUNNING.getCode());
|
||||||
}, releaseDelay, TimeUnit.SECONDS);
|
}, releaseDelay, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,6 +345,22 @@ public class ProtectionPlanTask {
|
|||||||
return StringUtils.getBigDecimal(obj.get(point));
|
return StringUtils.getBigDecimal(obj.get(point));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新站点策略为启用
|
||||||
|
private void updateStrategyRunningStatus(String siteId, String status) {
|
||||||
|
// 获取是否有正在运行的策略,如果有则不更改
|
||||||
|
EmsStrategyRunning query = new EmsStrategyRunning();
|
||||||
|
query.setSiteId(siteId);
|
||||||
|
query.setStatus(StrategyStatus.RUNNING.getCode().equals(status) ? StrategyStatus.SUSPENDED.getCode() : StrategyStatus.RUNNING.getCode());
|
||||||
|
List<EmsStrategyRunning> strategyRunningList = emsStrategyRunningMapper.selectEmsStrategyRunningList(query);
|
||||||
|
if (CollectionUtils.isNotEmpty(strategyRunningList)) {
|
||||||
|
// 获取已存在并且状态为:未启用和已暂停的最晚一条策略,更新为已启用
|
||||||
|
strategyRunningList.forEach(emsStrategyRunning -> {
|
||||||
|
emsStrategyRunning.setStatus(status);
|
||||||
|
emsStrategyRunningMapper.updateEmsStrategyRunning(emsStrategyRunning);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 更新站点策略为启用
|
// 更新站点策略为启用
|
||||||
private void updateStrategyRunning(String siteId) {
|
private void updateStrategyRunning(String siteId) {
|
||||||
// 获取是否有正在运行的策略,如果有则不更改
|
// 获取是否有正在运行的策略,如果有则不更改
|
||||||
|
|||||||
@ -1,44 +1,67 @@
|
|||||||
package com.xzzn.quartz.task;
|
package com.xzzn.quartz.task;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.xzzn.common.core.modbus.ModbusProcessor;
|
||||||
|
import com.xzzn.common.core.modbus.domain.DeviceConfig;
|
||||||
|
import com.xzzn.common.core.modbus.domain.WriteTagConfig;
|
||||||
|
import com.xzzn.common.enums.ChargeStatus;
|
||||||
|
import com.xzzn.common.enums.DeviceCategory;
|
||||||
|
import com.xzzn.common.enums.SiteDevice;
|
||||||
|
import com.xzzn.common.enums.SocLimit;
|
||||||
import com.xzzn.common.utils.DateUtils;
|
import com.xzzn.common.utils.DateUtils;
|
||||||
import com.xzzn.common.utils.StringUtils;
|
import com.xzzn.common.utils.StringUtils;
|
||||||
import com.xzzn.ems.domain.EmsStrategyCurve;
|
import com.xzzn.ems.domain.EmsAmmeterData;
|
||||||
|
import com.xzzn.ems.domain.EmsBatteryStack;
|
||||||
|
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||||
|
import com.xzzn.ems.domain.EmsPcsData;
|
||||||
|
import com.xzzn.ems.domain.EmsPointMatch;
|
||||||
|
import com.xzzn.ems.domain.EmsStrategyLog;
|
||||||
import com.xzzn.ems.domain.EmsStrategyTemp;
|
import com.xzzn.ems.domain.EmsStrategyTemp;
|
||||||
import com.xzzn.ems.domain.EmsStrategyTimeConfig;
|
import com.xzzn.ems.domain.EmsStrategyTimeConfig;
|
||||||
import com.xzzn.ems.domain.vo.StrategyPowerDataVo;
|
import com.xzzn.ems.domain.vo.DeviceUpdateRequest;
|
||||||
import com.xzzn.ems.domain.vo.StrategyRunningVo;
|
import com.xzzn.ems.domain.vo.StrategyRunningVo;
|
||||||
import com.xzzn.ems.mapper.*;
|
import com.xzzn.ems.mapper.EmsAmmeterDataMapper;
|
||||||
import com.xzzn.framework.manager.ModbusConnectionManager;
|
import com.xzzn.ems.mapper.EmsBatteryStackMapper;
|
||||||
import com.xzzn.framework.manager.MqttLifecycleManager;
|
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
||||||
import com.xzzn.framework.web.service.ModbusService;
|
import com.xzzn.ems.mapper.EmsPcsDataMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsStrategyLogMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsStrategyRunningMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsStrategyTempMapper;
|
||||||
|
import com.xzzn.ems.mapper.EmsStrategyTimeConfigMapper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.YearMonth;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
@Component("strategyPoller")
|
@Component("strategyPoller")
|
||||||
public class StrategyPoller {
|
public class StrategyPoller {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StrategyPoller.class);
|
private static final Logger logger = LoggerFactory.getLogger(StrategyPoller.class);
|
||||||
|
|
||||||
private final MqttLifecycleManager mqttLifecycleManager;
|
// SOC 上下限值,默认为0%-100%
|
||||||
|
private static final BigDecimal SOC_DOWN = new BigDecimal(0);
|
||||||
|
private static final BigDecimal SOC_UP = new BigDecimal(100);
|
||||||
|
// 逆变器功率下限值,默认为30kW
|
||||||
|
private static final BigDecimal ANTI_REVERSE_THRESHOLD = new BigDecimal(30);
|
||||||
|
// 逆变器下限值范围,默认为20%
|
||||||
|
private static final BigDecimal ANTI_REVERSE_RANGE_PERCENT = new BigDecimal(20);
|
||||||
|
// PCS功率降幅,默认为10%
|
||||||
|
private static final BigDecimal ANTI_REVERSE_POWER_DOWN_PERCENT = new BigDecimal(10);
|
||||||
|
private final Map<String, BigDecimal> sitePcsPowerDown = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ModbusConnectionManager connectionManager;
|
|
||||||
@Autowired
|
|
||||||
private ModbusService modbusService;
|
|
||||||
@Autowired
|
|
||||||
private EmsDevicesSettingMapper deviceRepo;
|
|
||||||
@Autowired
|
|
||||||
private EmsMqttMessageMapper emsMqttMessageMapper;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmsStrategyRunningMapper emsStrategyRunningMapper;
|
private EmsStrategyRunningMapper emsStrategyRunningMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -46,15 +69,22 @@ public class StrategyPoller {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmsStrategyTimeConfigMapper emsStrategyTimeConfigMapper;
|
private EmsStrategyTimeConfigMapper emsStrategyTimeConfigMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmsStrategyCurveMapper emsStrategyCurveMapper;
|
private EmsBatteryStackMapper emsBatteryStackMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public StrategyPoller(MqttLifecycleManager mqttLifecycleManager) {
|
private EmsPcsDataMapper emsPcsDataMapper;
|
||||||
this.mqttLifecycleManager = mqttLifecycleManager;
|
@Autowired
|
||||||
}
|
private EmsDevicesSettingMapper emsDevicesMapper;
|
||||||
|
@Autowired
|
||||||
|
private EmsPointMatchMapper emsPointMatchMapper;
|
||||||
|
@Autowired
|
||||||
|
private EmsAmmeterDataMapper emsAmmeterDataMapper;
|
||||||
|
@Autowired
|
||||||
|
private EmsStrategyLogMapper emsStrategyLogMapper;
|
||||||
|
@Autowired
|
||||||
|
private ModbusProcessor modbusProcessor;
|
||||||
|
|
||||||
public void pollAllDevices() {
|
public void pollAllDevices() {
|
||||||
logger.info("开始执行策略数据轮询...");
|
logger.info("开始执行运行策略数据轮询...");
|
||||||
List<StrategyRunningVo> strategyRunningVoList = emsStrategyRunningMapper.getPendingPollerStrategy(null);
|
List<StrategyRunningVo> strategyRunningVoList = emsStrategyRunningMapper.getPendingPollerStrategy(null);
|
||||||
strategyRunningVoList.forEach(strategyVo -> {
|
strategyRunningVoList.forEach(strategyVo -> {
|
||||||
try {
|
try {
|
||||||
@ -62,17 +92,17 @@ public class StrategyPoller {
|
|||||||
processData(strategyVo);
|
processData(strategyVo);
|
||||||
})
|
})
|
||||||
.exceptionally(e -> {
|
.exceptionally(e -> {
|
||||||
logger.error("策略{}轮询异常", strategyVo.getId(), e);
|
logger.error("运行策略{}轮询异常", strategyVo.getId(), e);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("策略下方{}任务失败", strategyVo.getId(), e);
|
logger.error("运行策略{}任务失败", strategyVo.getId(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 处理获取到的数据,发到mqtt服务上
|
// 处理获取到的运行策略数据,modbus发送指定的命令控制设备
|
||||||
private void processData(StrategyRunningVo strategyVo) {
|
private void processData(StrategyRunningVo strategyVo) {
|
||||||
logger.info("策略下发数据处理开始");
|
logger.info("运行策略数据处理开始");
|
||||||
// 根据运行策略获取主副策略的模板数据
|
// 根据运行策略获取主副策略的模板数据
|
||||||
Long mainStrategyId = strategyVo.getMainStrategyId();
|
Long mainStrategyId = strategyVo.getMainStrategyId();
|
||||||
Long auxStrategyId = strategyVo.getAuxStrategyId();
|
Long auxStrategyId = strategyVo.getAuxStrategyId();
|
||||||
@ -86,78 +116,249 @@ public class StrategyPoller {
|
|||||||
dealStrategyCurveData(auxStrategyId, siteId);
|
dealStrategyCurveData(auxStrategyId, siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 策略数据下发-下方格式暂无
|
logger.info("运行策略轮询处理结束");
|
||||||
logger.info("策略下发结束");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealStrategyCurveData(Long mainStrategyId, String siteId) {
|
private void dealStrategyCurveData(Long strategyId, String siteId) {
|
||||||
// 获取当前策略的所有模板
|
// 1.获取当前策略的所有模板
|
||||||
List<Map<String, String>> temps = emsStrategyTempMapper.getTempNameList(mainStrategyId,siteId);
|
List<Map<String, String>> temps = emsStrategyTempMapper.getTempNameList(strategyId, siteId);
|
||||||
if (temps != null && temps.size() > 0) {
|
if (CollectionUtils.isEmpty(temps)) {
|
||||||
for (Map<String, String> temp : temps) {
|
logger.info("当前站点: {}, 策略: {} 没有模板数据", siteId, strategyId);
|
||||||
String tempId = temp.get("templateId");
|
return;
|
||||||
List<EmsStrategyTimeConfig> timeConfigs = emsStrategyTimeConfigMapper.getAllTimeConfigByTempId(tempId);
|
}
|
||||||
if (timeConfigs != null && timeConfigs.size() > 0) {
|
for (Map<String, String> temp : temps) {
|
||||||
for (EmsStrategyTimeConfig timeConfig : timeConfigs) {
|
// 2.查询当月配置的运行策略
|
||||||
EmsStrategyCurve curve = new EmsStrategyCurve();
|
String tempId = temp.get("templateId");
|
||||||
curve.setStrategyId(mainStrategyId);
|
int month = LocalDateTime.now().getMonthValue();
|
||||||
curve.setSiteId(siteId);
|
List<EmsStrategyTimeConfig> timeConfigs = emsStrategyTimeConfigMapper.getTimeConfigByTempIdAndMonth(tempId, month);
|
||||||
curve.setTemplateId(tempId);
|
if (CollectionUtils.isEmpty(timeConfigs)) {
|
||||||
curve.setCreateBy("system");
|
continue;
|
||||||
curve.setCreateTime(DateUtils.getNowDate());
|
}
|
||||||
curve.setUpdateBy("system");
|
logger.info("当前站点: {}, 策略: {}, {}月配置模版:{}", siteId, strategyId, month, tempId);
|
||||||
curve.setUpdateTime(DateUtils.getNowDate());
|
// 3.查询当月配置的运行策略时间阶段数据
|
||||||
// 时间设置
|
List<EmsStrategyTemp> powerConfig = emsStrategyTempMapper.selectStrategyTempByTempId(tempId);
|
||||||
int month = Integer.parseInt(timeConfig.getMonth().toString());
|
if (CollectionUtils.isEmpty(powerConfig)) {
|
||||||
String[] dateList= dealWithMonth(month);
|
logger.info("当前站点: {}, 策略: {}, 模版:{} 未配置数据", siteId, strategyId, tempId);
|
||||||
curve.setMonth(Long.valueOf(month));
|
continue;
|
||||||
curve.setStartDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD,dateList[0]));
|
}
|
||||||
curve.setEndDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD,dateList[1]));
|
// 4.遍历时间段数据,判断当前时间是否在时间段内,在时间段内的进行处理
|
||||||
// powerData-存json格式
|
for (EmsStrategyTemp emsStrategyTemp : powerConfig) {
|
||||||
List<EmsStrategyTemp> powerConfig = emsStrategyTempMapper.selectStrategyTempByTempId(tempId);
|
if (emsStrategyTemp.getStartTime() == null || emsStrategyTemp.getEndTime() == null) {
|
||||||
List<StrategyPowerDataVo> powerDataVoList = new ArrayList<>();
|
logger.info("当前站点: {}, 策略: {}, 模版:{} 未配置时间阶段数据", siteId, strategyId, tempId);
|
||||||
for (int i = 0; i < powerConfig.size(); i++) {
|
continue;
|
||||||
EmsStrategyTemp powerTemp = powerConfig.get(i);
|
}
|
||||||
StrategyPowerDataVo powerDataVo = new StrategyPowerDataVo();
|
// 判断当前时间是否在时间段内
|
||||||
powerDataVo.setPowerData(powerTemp.getChargeDischargePower());
|
if (!isTimeInRange(LocalTime.now(), emsStrategyTemp.getStartTime(), emsStrategyTemp.getEndTime())) {
|
||||||
powerDataVo.setEndTime(DateUtils.parseDateToStr("HH:mm:ss",powerTemp.getEndTime()));
|
continue;
|
||||||
powerDataVo.setStartTime(DateUtils.parseDateToStr("HH:mm:ss",powerTemp.getStartTime()));
|
}
|
||||||
powerDataVoList.add(powerDataVo);
|
// 查询PCS设备信息
|
||||||
|
List<EmsPcsData> pcsDataList = emsPcsDataMapper.getSitePcsDataInfo(siteId);
|
||||||
|
if (CollectionUtils.isEmpty(pcsDataList)) {
|
||||||
|
logger.info("当前站点: {} 未配置PCS设备", siteId);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 判断SOC上限和下限是否在范围内
|
||||||
|
if (isSocInRange(emsStrategyTemp)) {
|
||||||
|
BigDecimal avgChargeDischargePower = emsStrategyTemp.getChargeDischargePower().divide(new BigDecimal(pcsDataList.size()));
|
||||||
|
for (EmsPcsData pcsData : pcsDataList) {
|
||||||
|
if (pcsData.getClusterNum() == null || pcsData.getClusterNum() < 1) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} 未获取电池簇数量", siteId, pcsData.getDeviceId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 平均功率值,根据电池簇数量进行平均分配
|
||||||
|
avgChargeDischargePower = avgChargeDischargePower.divide(new BigDecimal(pcsData.getClusterNum()));
|
||||||
|
// 根据充电状态,处理数据
|
||||||
|
if (ChargeStatus.CHARGING.getCode().equals(emsStrategyTemp.getChargeStatus())) {
|
||||||
|
// 发送Modbus命令控制设备-充电
|
||||||
|
sendModbusCommand(Collections.singletonList(pcsData), ChargeStatus.CHARGING, avgChargeDischargePower, emsStrategyTemp, false);
|
||||||
|
} else if (ChargeStatus.DISCHARGING.getCode().equals(emsStrategyTemp.getChargeStatus())) {
|
||||||
|
// 判断是否需要防逆流,PCS降功率运行
|
||||||
|
boolean needAntiReverseFlow = isNeedAntiReverseFlow(emsStrategyTemp);
|
||||||
|
if (needAntiReverseFlow) {
|
||||||
|
BigDecimal powerDown = ANTI_REVERSE_POWER_DOWN_PERCENT;
|
||||||
|
// 查询站点PCS功率降幅记录,如果有则累加增幅
|
||||||
|
List<EmsStrategyLog> strategyLogList = getStrategyLog(pcsData.getDeviceId(), emsStrategyTemp.getChargeStatus(), emsStrategyTemp, needAntiReverseFlow);
|
||||||
|
if (CollectionUtils.isNotEmpty(strategyLogList)) {
|
||||||
|
// 判断上次防逆流时间是否已经过了15分钟
|
||||||
|
if (DateUtils.differentMinutesByMillisecond(strategyLogList.get(0).getExecutionDate(), new Date()) < 15) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
powerDown = powerDown.multiply(new BigDecimal(strategyLogList.size() + 1));
|
||||||
|
}
|
||||||
|
avgChargeDischargePower = avgChargeDischargePower.subtract(avgChargeDischargePower.multiply(powerDown).divide(new BigDecimal(100)));
|
||||||
|
}
|
||||||
|
if (BigDecimal.ZERO.compareTo(avgChargeDischargePower) == 0) {
|
||||||
|
// 如果已经降功率到0,则设备直接待机
|
||||||
|
// 发送Modbus命令控制设备-待机
|
||||||
|
sendModbusCommand(Collections.singletonList(pcsData), ChargeStatus.STANDBY, BigDecimal.ZERO, emsStrategyTemp, needAntiReverseFlow);
|
||||||
|
} else {
|
||||||
|
// 发送Modbus命令控制设备-放电
|
||||||
|
sendModbusCommand(Collections.singletonList(pcsData), ChargeStatus.DISCHARGING, avgChargeDischargePower, emsStrategyTemp, needAntiReverseFlow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 发送Modbus命令控制设备-待机
|
||||||
|
sendModbusCommand(Collections.singletonList(pcsData), ChargeStatus.STANDBY, BigDecimal.ZERO, emsStrategyTemp, false);
|
||||||
}
|
}
|
||||||
curve.setPowerData(powerDataVoList !=null ? JSON.toJSON(powerDataVoList).toString() : "");
|
|
||||||
|
|
||||||
// 记录推送记录
|
|
||||||
emsStrategyCurveMapper.insertEmsStrategyCurve(curve);
|
|
||||||
|
|
||||||
// 设置已下发
|
|
||||||
timeConfig.setIsPost(0);
|
|
||||||
emsStrategyTimeConfigMapper.updateEmsStrategyTimeConfig(timeConfig);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 发送Modbus命令控制设备-待机
|
||||||
|
sendModbusCommand(pcsDataList, ChargeStatus.STANDBY, BigDecimal.ZERO, emsStrategyTemp, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] dealWithMonth(int month) {
|
private void saveStrategyLog(String deviceId, BigDecimal chargeDischargePower, String chargeStatus,
|
||||||
// 获取当前年份
|
EmsStrategyTemp strategyTemp, boolean needAntiReverseFlow) {
|
||||||
int currentYear = LocalDate.now().getYear();
|
EmsStrategyLog log = new EmsStrategyLog();
|
||||||
|
log.setStrategyId(strategyTemp.getStrategyId());
|
||||||
|
log.setTemplateId(strategyTemp.getTemplateId());
|
||||||
|
log.setSiteId(strategyTemp.getSiteId());
|
||||||
|
log.setDeviceId(deviceId);
|
||||||
|
log.setStartTime(strategyTemp.getStartTime());
|
||||||
|
log.setEndTime(strategyTemp.getEndTime());
|
||||||
|
log.setChargeDischargePower(chargeDischargePower);
|
||||||
|
log.setChargeStatus(chargeStatus);
|
||||||
|
log.setExecutionDate(DateUtils.toDate(LocalDateTime.now()));
|
||||||
|
log.setAntiReverse(needAntiReverseFlow ? 1 : 0);
|
||||||
|
emsStrategyLogMapper.insertEmsStrategyLog(log);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建YearMonth对象表示当年指定的月份
|
private List<EmsStrategyLog> getStrategyLog(String deviceId, String chargeStatus,
|
||||||
YearMonth yearMonth = YearMonth.of(currentYear, month);
|
EmsStrategyTemp strategyTemp, boolean needAntiReverseFlow) {
|
||||||
|
EmsStrategyLog query = new EmsStrategyLog();
|
||||||
|
query.setStrategyId(strategyTemp.getStrategyId());
|
||||||
|
query.setTemplateId(strategyTemp.getTemplateId());
|
||||||
|
query.setSiteId(strategyTemp.getSiteId());
|
||||||
|
query.setDeviceId(deviceId);
|
||||||
|
query.setStartTime(strategyTemp.getStartTime());
|
||||||
|
query.setEndTime(strategyTemp.getEndTime());
|
||||||
|
query.setChargeStatus(chargeStatus);
|
||||||
|
query.setExecutionDate(DateUtils.toDate(LocalDateTime.now()));
|
||||||
|
query.setAntiReverse(needAntiReverseFlow ? 1 : 0);
|
||||||
|
return emsStrategyLogMapper.selectEmsStrategyLogList(query);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取当月的第一天和最后一天
|
private boolean isNeedAntiReverseFlow(EmsStrategyTemp emsStrategyTemp) {
|
||||||
LocalDate firstDay = yearMonth.atDay(1);
|
EmsAmmeterData emsAmmeterData = emsAmmeterDataMapper.getLastData(emsStrategyTemp.getSiteId(), SiteDevice.LOAD.name());
|
||||||
LocalDate lastDay = yearMonth.atEndOfMonth();
|
if (emsAmmeterData == null || emsAmmeterData.getTotalActivePower() == null) {
|
||||||
|
logger.info("当前站点: {}, 未获取到最新电表数据", emsStrategyTemp.getSiteId());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// 获取当前设定的防逆流阈值(30kW)
|
||||||
|
BigDecimal threshold = ANTI_REVERSE_THRESHOLD;
|
||||||
|
// 计算20%范围的上限(36kW)
|
||||||
|
BigDecimal upperLimit = threshold.multiply(ANTI_REVERSE_RANGE_PERCENT).divide(new BigDecimal(100)).add(threshold);
|
||||||
|
|
||||||
// 定义日期格式(年月日)
|
// 判断电网电表正向有功功率是否小于36kW(接近30kW的20%范围)
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
return emsAmmeterData.getTotalActivePower().compareTo(upperLimit) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
// 格式化日期
|
public List<WriteTagConfig> getWriteTags(List<EmsPointMatch> pointMatchList,
|
||||||
return new String[]{
|
ChargeStatus chargeStatus, BigDecimal chargeDischargePower) {
|
||||||
firstDay.format(formatter),
|
List<WriteTagConfig> writeTags = new ArrayList<>();
|
||||||
lastDay.format(formatter)
|
for (EmsPointMatch pointMatch : pointMatchList) {
|
||||||
};
|
WriteTagConfig writeTag = new WriteTagConfig();
|
||||||
|
writeTag.setAddress(pointMatch.getIpAddress());
|
||||||
|
if (ChargeStatus.CHARGING.equals(chargeStatus)) {
|
||||||
|
writeTag.setValue(chargeDischargePower);
|
||||||
|
} else if (ChargeStatus.DISCHARGING.equals(chargeStatus)) {
|
||||||
|
writeTag.setValue(chargeDischargePower.negate());
|
||||||
|
} else {
|
||||||
|
// 待机状态-电池簇PCS有功功率给定置0
|
||||||
|
writeTag.setValue(chargeDischargePower);
|
||||||
|
}
|
||||||
|
writeTags.add(writeTag);
|
||||||
|
}
|
||||||
|
return writeTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getMatchFields(Integer clusterNum) {
|
||||||
|
List<String> matchFields = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= clusterNum; i++) {
|
||||||
|
//电池簇PCS有功功率给定
|
||||||
|
matchFields.add("cluster"+ i +"_active_power");
|
||||||
|
}
|
||||||
|
return matchFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceConfig getDeviceConfig(EmsPcsData pcsData, ChargeStatus chargeStatus, BigDecimal chargeDischargePower) {
|
||||||
|
EmsDevicesSetting device = emsDevicesMapper.getDeviceBySiteAndDeviceId(pcsData.getDeviceId(), pcsData.getSiteId());
|
||||||
|
if (device == null) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} 未找到对应设备配置信息", pcsData.getSiteId(), pcsData.getDeviceId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DeviceUpdateRequest query = new DeviceUpdateRequest();
|
||||||
|
query.setSiteId(device.getSiteId());
|
||||||
|
query.setDeviceId(device.getDeviceId());
|
||||||
|
query.setMatchFields(getMatchFields(pcsData.getClusterNum()));
|
||||||
|
query.setDeviceCategory(DeviceCategory.PCS.getCode());
|
||||||
|
List<EmsPointMatch> pointMatchList = emsPointMatchMapper.selectDeviceStatusPoint(query);
|
||||||
|
if (CollectionUtils.isEmpty(pointMatchList)) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} 未找到对应设备点位字段配置", pcsData.getSiteId(), pcsData.getDeviceId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (pointMatchList.size() != pcsData.getClusterNum()) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} 设备点位字段配置数量与电池簇数不一致", pcsData.getSiteId(), pcsData.getDeviceId());
|
||||||
|
}
|
||||||
|
DeviceConfig deviceConfig = new DeviceConfig();
|
||||||
|
deviceConfig.setDeviceNumber(device.getDeviceId());
|
||||||
|
deviceConfig.setDeviceName(device.getDeviceName());
|
||||||
|
deviceConfig.setSlaveId(device.getSlaveId().intValue());
|
||||||
|
deviceConfig.setHost(device.getIpAddress());
|
||||||
|
deviceConfig.setPort(device.getIpPort().intValue());
|
||||||
|
deviceConfig.setWriteTags(getWriteTags(pointMatchList, chargeStatus, chargeDischargePower));
|
||||||
|
return deviceConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendModbusCommand(List<EmsPcsData> pcsDataList, ChargeStatus chargeStatus, BigDecimal chargeDischargePower,
|
||||||
|
EmsStrategyTemp emsStrategyTemp, boolean needAntiReverseFlow) {
|
||||||
|
for (EmsPcsData pcsData : pcsDataList) {
|
||||||
|
List<EmsStrategyLog> strategyLogList = getStrategyLog(pcsData.getDeviceId(), chargeStatus.getCode(), emsStrategyTemp, needAntiReverseFlow);
|
||||||
|
if (CollectionUtils.isNotEmpty(strategyLogList) && !ChargeStatus.DISCHARGING.equals(chargeStatus) && !needAntiReverseFlow) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} 当前时间段已存在策略执行记录,不再重复执行", pcsData.getSiteId(), pcsData.getDeviceId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DeviceConfig deviceConfig = getDeviceConfig(pcsData, chargeStatus, chargeDischargePower);
|
||||||
|
if (deviceConfig == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean result = modbusProcessor.writeDataToDevice(deviceConfig);
|
||||||
|
if (!result) {
|
||||||
|
logger.info("当前站点: {}, PCS设备: {} modbus控制设备{}指令发送失败", pcsData.getSiteId(), pcsData.getDeviceId(), chargeStatus.getInfo());
|
||||||
|
}
|
||||||
|
// 记录策略执行日志
|
||||||
|
saveStrategyLog(pcsData.getDeviceId(), chargeDischargePower, chargeStatus.getCode(), emsStrategyTemp, needAntiReverseFlow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断当前时间是否在时间范围内
|
||||||
|
private static boolean isTimeInRange(LocalTime now, Date startTime, Date endTime) {
|
||||||
|
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
|
||||||
|
LocalTime startLocalTime = startTime.toInstant()
|
||||||
|
.atZone(zoneId)
|
||||||
|
.toLocalTime();
|
||||||
|
LocalTime endLocalTime = endTime.toInstant()
|
||||||
|
.atZone(zoneId)
|
||||||
|
.toLocalTime();
|
||||||
|
return now.equals(startLocalTime) || (now.isAfter(startLocalTime) && now.isBefore(endLocalTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断SOC上限和下限是否在范围内
|
||||||
|
private boolean isSocInRange(EmsStrategyTemp emsStrategyTemp) {
|
||||||
|
BigDecimal socDown = SOC_DOWN;
|
||||||
|
BigDecimal socUp = SOC_UP;
|
||||||
|
if (SocLimit.ON.getCode().equals(emsStrategyTemp.getSdcLimit())) {
|
||||||
|
socDown = emsStrategyTemp.getSdcDown();
|
||||||
|
socUp = emsStrategyTemp.getSdcUp();
|
||||||
|
}
|
||||||
|
// 查询电池堆(BMSD) SOC
|
||||||
|
EmsBatteryStack emsBatteryStack = emsBatteryStackMapper.getSiteSumStackInfo(emsStrategyTemp.getSiteId());
|
||||||
|
if (emsBatteryStack != null && emsBatteryStack.getStackSoc() != null) {
|
||||||
|
return emsBatteryStack.getStackSoc().compareTo(socDown) > 0 && emsBatteryStack.getStackSoc().compareTo(socUp) < 0;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
197
ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategyLog.java
Normal file
197
ems-system/src/main/java/com/xzzn/ems/domain/EmsStrategyLog.java
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
package com.xzzn.ems.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.xzzn.common.annotation.Excel;
|
||||||
|
import com.xzzn.common.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 策略运行日志对象 ems_strategy_log
|
||||||
|
*
|
||||||
|
* @author xzzn
|
||||||
|
* @date 2025-12-26
|
||||||
|
*/
|
||||||
|
public class EmsStrategyLog extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** $column.columnComment */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 策略ID */
|
||||||
|
@Excel(name = "策略ID")
|
||||||
|
private Long strategyId;
|
||||||
|
|
||||||
|
/** 模版id */
|
||||||
|
@Excel(name = "模版id")
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
|
/** 站点id */
|
||||||
|
@Excel(name = "站点id")
|
||||||
|
private String siteId;
|
||||||
|
|
||||||
|
/** 设备唯一标识符 */
|
||||||
|
@Excel(name = "设备唯一标识符")
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/** 开始时间 */
|
||||||
|
@JsonFormat(pattern = "HH:mm")
|
||||||
|
@Excel(name = "开始时间", width = 30, dateFormat = "HH:mm")
|
||||||
|
private Date startTime;
|
||||||
|
|
||||||
|
/** 结束时间 */
|
||||||
|
@JsonFormat(pattern = "HH:mm")
|
||||||
|
@Excel(name = "结束时间", width = 30, dateFormat = "HH:mm")
|
||||||
|
private Date endTime;
|
||||||
|
|
||||||
|
/** 功率 (kW) */
|
||||||
|
@Excel(name = "功率 (kW)")
|
||||||
|
private BigDecimal chargeDischargePower;
|
||||||
|
|
||||||
|
/** 充电状态,如“1-充电”、“2-待机”、“3-放电” */
|
||||||
|
@Excel(name = "充电状态,如“1-充电”、“2-待机”、“3-放电”")
|
||||||
|
private String chargeStatus;
|
||||||
|
|
||||||
|
/** 执行时间 */
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@Excel(name = "执行时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
|
private Date executionDate;
|
||||||
|
|
||||||
|
/** 防逆流, 1-是、0-否 */
|
||||||
|
@Excel(name = "防逆流, 1-是、0-否")
|
||||||
|
private Integer antiReverse;
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStrategyId(Long strategyId)
|
||||||
|
{
|
||||||
|
this.strategyId = strategyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getStrategyId()
|
||||||
|
{
|
||||||
|
return strategyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemplateId(String templateId)
|
||||||
|
{
|
||||||
|
this.templateId = templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTemplateId()
|
||||||
|
{
|
||||||
|
return templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSiteId(String siteId)
|
||||||
|
{
|
||||||
|
this.siteId = siteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSiteId()
|
||||||
|
{
|
||||||
|
return siteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceId(String deviceId) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(Date startTime)
|
||||||
|
{
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getStartTime()
|
||||||
|
{
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(Date endTime)
|
||||||
|
{
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getEndTime()
|
||||||
|
{
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChargeDischargePower(BigDecimal chargeDischargePower)
|
||||||
|
{
|
||||||
|
this.chargeDischargePower = chargeDischargePower;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getChargeDischargePower()
|
||||||
|
{
|
||||||
|
return chargeDischargePower;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChargeStatus(String chargeStatus)
|
||||||
|
{
|
||||||
|
this.chargeStatus = chargeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChargeStatus()
|
||||||
|
{
|
||||||
|
return chargeStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutionDate(Date executionDate)
|
||||||
|
{
|
||||||
|
this.executionDate = executionDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getExecutionDate()
|
||||||
|
{
|
||||||
|
return executionDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAntiReverse() {
|
||||||
|
return antiReverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAntiReverse(Integer antiReverse) {
|
||||||
|
this.antiReverse = antiReverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("id", getId())
|
||||||
|
.append("strategyId", getStrategyId())
|
||||||
|
.append("templateId", getTemplateId())
|
||||||
|
.append("siteId", getSiteId())
|
||||||
|
.append("deviceId", getDeviceId())
|
||||||
|
.append("antiReverse", getAntiReverse())
|
||||||
|
.append("startTime", getStartTime())
|
||||||
|
.append("endTime", getEndTime())
|
||||||
|
.append("chargeDischargePower", getChargeDischargePower())
|
||||||
|
.append("chargeStatus", getChargeStatus())
|
||||||
|
.append("executionDate", getExecutionDate())
|
||||||
|
.append("antiReverse", getAntiReverse())
|
||||||
|
.append("createBy", getCreateBy())
|
||||||
|
.append("createTime", getCreateTime())
|
||||||
|
.append("updateBy", getUpdateBy())
|
||||||
|
.append("updateTime", getUpdateTime())
|
||||||
|
.append("remark", getRemark())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,18 @@
|
|||||||
package com.xzzn.ems.mapper;
|
package com.xzzn.ems.mapper;
|
||||||
|
|
||||||
|
import com.xzzn.ems.domain.EmsPcsData;
|
||||||
|
import com.xzzn.ems.domain.vo.DateSearchRequest;
|
||||||
|
import com.xzzn.ems.domain.vo.ElectricIndexList;
|
||||||
|
import com.xzzn.ems.domain.vo.EnergyStoragePowVo;
|
||||||
|
import com.xzzn.ems.domain.vo.PcsDetailInfoVo;
|
||||||
|
import com.xzzn.ems.domain.vo.PcsMaxTempVo;
|
||||||
|
import com.xzzn.ems.domain.vo.PcsStatisListVo;
|
||||||
|
import com.xzzn.ems.domain.vo.SiteMonitorDataVo;
|
||||||
|
import com.xzzn.ems.domain.vo.SiteMonitorRunningHeadInfoVo;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.xzzn.ems.domain.EmsPcsData;
|
|
||||||
import com.xzzn.ems.domain.vo.*;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,4 +140,6 @@ public interface EmsPcsDataMapper
|
|||||||
public List<PcsMaxTempVo> getFXMaxTemp(@Param("siteId")String siteId, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
public List<PcsMaxTempVo> getFXMaxTemp(@Param("siteId")String siteId, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
||||||
// 实时运行-dds-pcs最高温度
|
// 实时运行-dds-pcs最高温度
|
||||||
public List<PcsMaxTempVo> getDDSMaxTemp(@Param("siteId")String siteId, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
public List<PcsMaxTempVo> getDDSMaxTemp(@Param("siteId")String siteId, @Param("startDate")Date startDate, @Param("endDate")Date endDate);
|
||||||
|
|
||||||
|
List<EmsPcsData> getSitePcsDataInfo(@Param("siteId") String siteId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
package com.xzzn.ems.mapper;
|
||||||
|
|
||||||
|
import com.xzzn.ems.domain.EmsStrategyLog;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 策略运行日志Mapper接口
|
||||||
|
*
|
||||||
|
* @author xzzn
|
||||||
|
* @date 2025-12-26
|
||||||
|
*/
|
||||||
|
public interface EmsStrategyLogMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询策略运行日志
|
||||||
|
*
|
||||||
|
* @param id 策略运行日志主键
|
||||||
|
* @return 策略运行日志
|
||||||
|
*/
|
||||||
|
public EmsStrategyLog selectEmsStrategyLogById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询策略运行日志列表
|
||||||
|
*
|
||||||
|
* @param emsStrategyLog 策略运行日志
|
||||||
|
* @return 策略运行日志集合
|
||||||
|
*/
|
||||||
|
public List<EmsStrategyLog> selectEmsStrategyLogList(EmsStrategyLog emsStrategyLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增策略运行日志
|
||||||
|
*
|
||||||
|
* @param emsStrategyLog 策略运行日志
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertEmsStrategyLog(EmsStrategyLog emsStrategyLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改策略运行日志
|
||||||
|
*
|
||||||
|
* @param emsStrategyLog 策略运行日志
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateEmsStrategyLog(EmsStrategyLog emsStrategyLog);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除策略运行日志
|
||||||
|
*
|
||||||
|
* @param id 策略运行日志主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEmsStrategyLogById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除策略运行日志
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteEmsStrategyLogByIds(Long[] ids);
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package com.xzzn.ems.mapper;
|
package com.xzzn.ems.mapper;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import com.xzzn.ems.domain.EmsStrategyTimeConfig;
|
import com.xzzn.ems.domain.EmsStrategyTimeConfig;
|
||||||
import com.xzzn.ems.domain.vo.StrategyTimeConfigVo;
|
import com.xzzn.ems.domain.vo.StrategyTimeConfigVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,6 +72,9 @@ public interface EmsStrategyTimeConfigMapper
|
|||||||
// 获取该策略下的时间配置
|
// 获取该策略下的时间配置
|
||||||
List<EmsStrategyTimeConfig> getAllTimeConfigByTempId(String templateId);
|
List<EmsStrategyTimeConfig> getAllTimeConfigByTempId(String templateId);
|
||||||
|
|
||||||
|
// 获取指定月份和策略下的时间配置
|
||||||
|
List<EmsStrategyTimeConfig> getTimeConfigByTempIdAndMonth(@Param("templateId") String templateId, @Param("month") int month);
|
||||||
|
|
||||||
// 设置该模版的时间配置为待下发
|
// 设置该模版的时间配置为待下发
|
||||||
public void updateTimeConfigWaitingPost(String templateId);
|
public void updateTimeConfigWaitingPost(String templateId);
|
||||||
|
|
||||||
|
|||||||
@ -1054,6 +1054,7 @@
|
|||||||
t.site_id,
|
t.site_id,
|
||||||
t.device_id,
|
t.device_id,
|
||||||
t.data_update_time,
|
t.data_update_time,
|
||||||
|
t.total_active_power,
|
||||||
t.current_forward_active_total,
|
t.current_forward_active_total,
|
||||||
t.current_reverse_active_total
|
t.current_reverse_active_total
|
||||||
FROM ems_ammeter_data t
|
FROM ems_ammeter_data t
|
||||||
|
|||||||
@ -655,4 +655,20 @@
|
|||||||
group by deviceId,dateDay,createDate,temp
|
group by deviceId,dateDay,createDate,temp
|
||||||
order by dateDay,createDate
|
order by dateDay,createDate
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getSitePcsDataInfo" resultType="com.xzzn.ems.domain.EmsPcsData">
|
||||||
|
select
|
||||||
|
t.device_id as deviceId,
|
||||||
|
t.site_id as siteId,
|
||||||
|
t.cluster_num as clusterNum
|
||||||
|
from ems_pcs_data t
|
||||||
|
INNER JOIN (
|
||||||
|
select p.site_id, p.device_id, MAX(p.create_time) as max_time
|
||||||
|
from ems_pcs_data p
|
||||||
|
where p.site_id = #{siteId}
|
||||||
|
group by p.site_id, p.device_id
|
||||||
|
) latest on t.site_id = latest.site_id
|
||||||
|
and t.device_id = latest.device_id
|
||||||
|
and t.create_time = latest.max_time
|
||||||
|
where t.site_id = #{siteId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@ -0,0 +1,122 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xzzn.ems.mapper.EmsStrategyLogMapper">
|
||||||
|
|
||||||
|
<resultMap type="EmsStrategyLog" id="EmsStrategyLogResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="strategyId" column="strategy_id" />
|
||||||
|
<result property="templateId" column="template_id" />
|
||||||
|
<result property="siteId" column="site_id" />
|
||||||
|
<result property="deviceId" column="device_id" />
|
||||||
|
<result property="startTime" column="start_time" />
|
||||||
|
<result property="endTime" column="end_time" />
|
||||||
|
<result property="chargeDischargePower" column="charge_discharge_power" />
|
||||||
|
<result property="chargeStatus" column="charge_status" />
|
||||||
|
<result property="executionDate" column="execution_date" />
|
||||||
|
<result property="antiReverse" column="anti_reverse" />
|
||||||
|
<result property="createBy" column="create_by" />
|
||||||
|
<result property="createTime" column="create_time" />
|
||||||
|
<result property="updateBy" column="update_by" />
|
||||||
|
<result property="updateTime" column="update_time" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectEmsStrategyLogVo">
|
||||||
|
select id, strategy_id, template_id, site_id, device_id, start_time, end_time, charge_discharge_power, charge_status, execution_date, anti_reverse, create_by, create_time, update_by, update_time, remark from ems_strategy_log
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectEmsStrategyLogList" parameterType="EmsStrategyLog" resultMap="EmsStrategyLogResult">
|
||||||
|
<include refid="selectEmsStrategyLogVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="strategyId != null "> and strategy_id = #{strategyId}</if>
|
||||||
|
<if test="templateId != null and templateId != ''"> and template_id = #{templateId}</if>
|
||||||
|
<if test="siteId != null and siteId != ''"> and site_id = #{siteId}</if>
|
||||||
|
<if test="deviceId != null and deviceId != ''"> and device_id = #{deviceId}</if>
|
||||||
|
<if test="startTime != null "> and start_time = #{startTime}</if>
|
||||||
|
<if test="endTime != null "> and end_time = #{endTime}</if>
|
||||||
|
<if test="chargeDischargePower != null "> and charge_discharge_power = #{chargeDischargePower}</if>
|
||||||
|
<if test="chargeStatus != null and chargeStatus != ''"> and charge_status = #{chargeStatus}</if>
|
||||||
|
<if test="executionDate != null "> and execution_date = #{executionDate}</if>
|
||||||
|
<if test="antiReverse != null "> and anti_reverse = #{antiReverse}</if>
|
||||||
|
</where>
|
||||||
|
order by create_time desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectEmsStrategyLogById" parameterType="Long" resultMap="EmsStrategyLogResult">
|
||||||
|
<include refid="selectEmsStrategyLogVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertEmsStrategyLog" parameterType="EmsStrategyLog" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into ems_strategy_log
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="strategyId != null">strategy_id,</if>
|
||||||
|
<if test="templateId != null">template_id,</if>
|
||||||
|
<if test="siteId != null">site_id,</if>
|
||||||
|
<if test="deviceId != null">device_id,</if>
|
||||||
|
<if test="startTime != null">start_time,</if>
|
||||||
|
<if test="endTime != null">end_time,</if>
|
||||||
|
<if test="chargeDischargePower != null">charge_discharge_power,</if>
|
||||||
|
<if test="chargeStatus != null">charge_status,</if>
|
||||||
|
<if test="executionDate != null">execution_date,</if>
|
||||||
|
<if test="antiReverse != null">anti_reverse,</if>
|
||||||
|
<if test="createBy != null">create_by,</if>
|
||||||
|
<if test="createTime != null">create_time,</if>
|
||||||
|
<if test="updateBy != null">update_by,</if>
|
||||||
|
<if test="updateTime != null">update_time,</if>
|
||||||
|
<if test="remark != null">remark,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="strategyId != null">#{strategyId},</if>
|
||||||
|
<if test="templateId != null">#{templateId},</if>
|
||||||
|
<if test="siteId != null">#{siteId},</if>
|
||||||
|
<if test="deviceId != null">#{deviceId},</if>
|
||||||
|
<if test="startTime != null">#{startTime},</if>
|
||||||
|
<if test="endTime != null">#{endTime},</if>
|
||||||
|
<if test="chargeDischargePower != null">#{chargeDischargePower},</if>
|
||||||
|
<if test="chargeStatus != null">#{chargeStatus},</if>
|
||||||
|
<if test="executionDate != null">#{executionDate},</if>
|
||||||
|
<if test="antiReverse != null">#{antiReverse},</if>
|
||||||
|
<if test="createBy != null">#{createBy},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
<if test="remark != null">#{remark},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateEmsStrategyLog" parameterType="EmsStrategyLog">
|
||||||
|
update ems_strategy_log
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="strategyId != null">strategy_id = #{strategyId},</if>
|
||||||
|
<if test="templateId != null">template_id = #{templateId},</if>
|
||||||
|
<if test="siteId != null">site_id = #{siteId},</if>
|
||||||
|
<if test="deviceId != null">device_id = #{deviceId},</if>
|
||||||
|
<if test="startTime != null">start_time = #{startTime},</if>
|
||||||
|
<if test="endTime != null">end_time = #{endTime},</if>
|
||||||
|
<if test="chargeDischargePower != null">charge_discharge_power = #{chargeDischargePower},</if>
|
||||||
|
<if test="chargeStatus != null">charge_status = #{chargeStatus},</if>
|
||||||
|
<if test="executionDate != null">execution_date = #{executionDate},</if>
|
||||||
|
<if test="antiReverse != null">anti_reverse = #{antiReverse},</if>
|
||||||
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteEmsStrategyLogById" parameterType="Long">
|
||||||
|
delete from ems_strategy_log where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteEmsStrategyLogByIds" parameterType="String">
|
||||||
|
delete from ems_strategy_log where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
@ -134,4 +134,10 @@
|
|||||||
and strategy_id = #{strategyId}
|
and strategy_id = #{strategyId}
|
||||||
and month = #{month}
|
and month = #{month}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getTimeConfigByTempIdAndMonth" resultType="com.xzzn.ems.domain.EmsStrategyTimeConfig">
|
||||||
|
<include refid="selectEmsStrategyTimeConfigVo"/>
|
||||||
|
where template_id = #{templateId}
|
||||||
|
and month = #{month}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user