gasWellWatch/src/main/java/com/isu/gaswellwatch/vo/command/Command.java

123 lines
5.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.etc.PlungerTimer;
import com.isu.gaswellwatch.vo.command.etc.SensorDelay;
import com.isu.gaswellwatch.vo.command.knpcv1.mode.*;
import com.isu.gaswellwatch.vo.command.scss.ControlMode;
import com.isu.gaswellwatch.vo.command.scss.PlungerLogicMode;
import com.isu.gaswellwatch.vo.command.scss.SimpleLogicMode;
import com.isu.gaswellwatch.vo.command.scss.SystemInfo;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
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.math.BigDecimal;
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 = 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),
@JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_PRESSURE),
@JsonSubTypes.Type(value = TimePressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE),
@JsonSubTypes.Type(value = SensorDelay.class, name = Command.ETC_SENSOR_DELAY),
@JsonSubTypes.Type(value = PlungerTimer.class, name = Command.ETC_PLUNGER_TIMER),
@JsonSubTypes.Type(value = SystemInfo.class, name = Command.SCSS_SYSTEM_INFO),
@JsonSubTypes.Type(value = ControlMode.class, name = Command.SCSS_CONTROL_MODE),
@JsonSubTypes.Type(value = SimpleLogicMode.class, name = Command.SCSS_SIMPLE_LOGIC_MODE),
@JsonSubTypes.Type(value = PlungerLogicMode.class, name = Command.SCSS_PLUNGER_LOGIC_MODE),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOn.class, name = Command.ETC_TURN_ON_THE_WELL),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOff.class, name = Command.ETC_TURN_OFF_THE_WELL),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.scss.TurnOn.class, name = Command.SCSS_TURN_ON_THE_WELL),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.scss.TurnOff.class, name = Command.SCSS_TURN_OFF_THE_WELL),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.knpcv1.TurnOn.class, name = Command.KNPCV1_TURN_ON_THE_WELL),
@JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.knpcv1.TurnOff.class, name = Command.KNPCV1_TURN_OFF_THE_WELL),
})
@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";
public static final String KNPCV1_RUN_PRESSURE = "KNPCV1.RUN.PRESSURE";
public static final String KNPCV1_RUN_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE";
/* 点表类型KNPCV1 end */
/* 点表类型SCSS start */
/* 系统基本信息 */
public static final String SCSS_SYSTEM_INFO = "SCSS.SYSTEM_INFO";
/* 开关井 */
public static final String SCSS_TURN_ON_THE_WELL = "SCSS.TURN_ON_THE_WELL";
public static final String SCSS_TURN_OFF_THE_WELL = "SCSS.TURN_OFF_THE_WELL";
/* 模式指令 */
public static final String SCSS_CONTROL_MODE = "SCSS.CONTROL_MODE";
public static final String SCSS_SIMPLE_LOGIC_MODE = "SCSS.SIMPLE_LOGIC_MODE";
public static final String SCSS_PLUNGER_LOGIC_MODE = "SCSS.PLUNGER_LOGIC_MODE";
/* 点表类型SCSS end */
/* 点表类型ETC start */
/* 开关井 */
public static final String ETC_TURN_ON_THE_WELL = "ETC.TURN_ON_THE_WELL";
public static final String ETC_TURN_OFF_THE_WELL = "ETC.TURN_OFF_THE_WELL";
/* 模式指令*/
public static final String ETC_SENSOR_DELAY = "ETC.SENSOR_DELAY";
public static final String ETC_PLUNGER_TIMER = "ETC.PLUNGER_TIMER";
/* 点表类型ETC end */
public static final BigDecimal ONE_HUNDRED = BigDecimal.valueOf(100);
public static final BigDecimal ONE_THOUSAND = BigDecimal.valueOf(1000);
@NotBlank(message = "指令编码不能为空")
private String code;
@NotNull(message = "下发设备标识不能为空")
private Long deviceId;
public final Collection<ModbusCommandDto> buildModbusCommand() {
if (!this.validate()) {
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();
}