2024-11-27 02:00:58 +08:00
|
|
|
|
package com.isu.gaswellwatch.vo.command;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
|
|
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
|
|
|
|
import com.isu.gaswellwatch.vo.command.knpcv1.TurnOff;
|
|
|
|
|
import com.isu.gaswellwatch.vo.command.knpcv1.TurnOn;
|
|
|
|
|
import com.isu.gaswellwatch.vo.command.knpcv1.mode.*;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
import lombok.Setter;
|
|
|
|
|
import lombok.experimental.SuperBuilder;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.Serial;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.security.InvalidParameterException;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author <a href="mailto:scwsl@foxmail.com">王仕龙</a>
|
|
|
|
|
* 2024/11/26 19:59
|
|
|
|
|
*/
|
|
|
|
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "code")
|
|
|
|
|
@JsonSubTypes(value = {
|
|
|
|
|
@JsonSubTypes.Type(value = TurnOn.class, name = Command.KNPCV1_TURN_ON_THE_WELL),
|
|
|
|
|
@JsonSubTypes.Type(value = TurnOff.class, name = Command.KNPCV1_TURN_OFF_THE_WELL),
|
|
|
|
|
@JsonSubTypes.Type(value = TimerMode.class, name = Command.KNPCV1_RUN_TIMER),
|
|
|
|
|
@JsonSubTypes.Type(value = TimingMode.class, name = Command.KNPCV1_RUN_TIMING),
|
|
|
|
|
@JsonSubTypes.Type(value = ManualMode.class, name = Command.KNPCV1_RUN_MANUAL),
|
|
|
|
|
@JsonSubTypes.Type(value = PlungerMode.class, name = Command.KNPCV1_RUN_PLUNGER),
|
2024-11-27 14:12:46 +08:00
|
|
|
|
@JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_PRESSURE),
|
|
|
|
|
@JsonSubTypes.Type(value = TimePressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE),
|
2024-11-27 02:00:58 +08:00
|
|
|
|
})
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
@SuperBuilder
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public abstract class Command implements Serializable {
|
|
|
|
|
|
|
|
|
|
@Serial
|
|
|
|
|
private static final long serialVersionUID = -2590497444442160271L;
|
|
|
|
|
|
|
|
|
|
/* 点表类型:KNPCV1 start */
|
|
|
|
|
/* 开关井 */
|
|
|
|
|
public static final String KNPCV1_TURN_ON_THE_WELL = "KNPCV1.TURN_ON_THE_WELL";
|
|
|
|
|
public static final String KNPCV1_TURN_OFF_THE_WELL = "KNPCV1.TURN_OFF_THE_WELL";
|
|
|
|
|
/* 运行模式*/
|
|
|
|
|
public static final String KNPCV1_RUN_TIMER = "KNPCV1.RUN.TIMER";
|
|
|
|
|
public static final String KNPCV1_RUN_TIMING = "KNPCV1.RUN.TIMING";
|
|
|
|
|
public static final String KNPCV1_RUN_MANUAL = "KNPCV1.RUN.MANUAL";
|
|
|
|
|
public static final String KNPCV1_RUN_PLUNGER = "KNPCV1.RUN.PLUNGER";
|
2024-11-27 14:12:46 +08:00
|
|
|
|
public static final String KNPCV1_RUN_PRESSURE = "KNPCV1.RUN.PRESSURE";
|
2024-11-27 02:00:58 +08:00
|
|
|
|
public static final String KNPCV1_RUN_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE";
|
|
|
|
|
/* 点表类型:KNPCV1 end */
|
|
|
|
|
|
|
|
|
|
private String code;
|
|
|
|
|
|
|
|
|
|
private Long deviceId;
|
|
|
|
|
|
|
|
|
|
public Collection<ModbusCommandDto> buildModbusCommand() {
|
2024-11-27 14:12:46 +08:00
|
|
|
|
if (!this.validate()) {
|
2024-11-27 02:00:58 +08:00
|
|
|
|
throw new InvalidParameterException("Invalid command");
|
|
|
|
|
}
|
|
|
|
|
return this.builderModbusCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean validate() {
|
|
|
|
|
return Objects.nonNull(this.deviceId) && StringUtils.isNotBlank(this.code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract Collection<ModbusCommandDto> builderModbusCommand();
|
|
|
|
|
|
|
|
|
|
}
|