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 王仕龙 * 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), @JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE), }) @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_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE"; /* 点表类型:KNPCV1 end */ private String code; private Long deviceId; public Collection 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 builderModbusCommand(); }