|
|
@@ -0,0 +1,98 @@
|
|
|
+package top.haijunit.train.device.entity;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.annotation.JsonCreator;
|
|
|
+import jakarta.persistence.*;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.Getter;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import top.haijunit.train.domain.constant.DirectionEnum;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zhanghaijun
|
|
|
+ * @date 2023/12/19 16:36
|
|
|
+ * @description AFC闸机信息
|
|
|
+ */
|
|
|
+@Data
|
|
|
+@Entity(name = "device_afc_gate")
|
|
|
+public class StationAfcGate implements Serializable {
|
|
|
+
|
|
|
+ @Id
|
|
|
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
|
+ private Long id;
|
|
|
+
|
|
|
+ // 闸机编号
|
|
|
+ private String gateMachineNo;
|
|
|
+ // 闸机状态
|
|
|
+ private GateStatusEnum state;
|
|
|
+ // 闸机方向状态
|
|
|
+ private DirectionEnum direction;
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @RequiredArgsConstructor
|
|
|
+ public static enum GateStatusEnum {
|
|
|
+ CLOSE(0, "关闭"), OPEN(1, "开启"), PAUSE(2, "暂停服务"), FAULT(3, "故障");
|
|
|
+
|
|
|
+ private final Integer code;
|
|
|
+ private final String describe;
|
|
|
+
|
|
|
+ @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
|
|
+ public static GateStatusEnum getByCode(Integer code) {
|
|
|
+ for (GateStatusEnum genderEnum : values()) {
|
|
|
+ if (Objects.equals(genderEnum.getCode(), code)) {
|
|
|
+ return genderEnum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Converter(autoApply = true)
|
|
|
+ public static class GateStatusConvert implements AttributeConverter<GateStatusEnum, Integer> {
|
|
|
+ @Override
|
|
|
+ public Integer convertToDatabaseColumn(GateStatusEnum status) {
|
|
|
+ return Optional.of(status).map(GateStatusEnum::getCode).orElse(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GateStatusEnum convertToEntityAttribute(Integer code) {
|
|
|
+ return GateStatusEnum.getByCode(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Getter
|
|
|
+ @RequiredArgsConstructor
|
|
|
+ public static enum GateDirectionEnum {
|
|
|
+ JOIN(0, "进站"), LEAVE(1, "出站");
|
|
|
+
|
|
|
+ private final Integer code;
|
|
|
+ private final String describe;
|
|
|
+
|
|
|
+ @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
|
|
+ public static GateDirectionEnum getByCode(Integer code) {
|
|
|
+ for (GateDirectionEnum genderEnum : values()) {
|
|
|
+ if (Objects.equals(genderEnum.getCode(), code)) {
|
|
|
+ return genderEnum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Converter(autoApply = true)
|
|
|
+ public static class DirectionConvert implements AttributeConverter<GateDirectionEnum, Integer> {
|
|
|
+ @Override
|
|
|
+ public Integer convertToDatabaseColumn(GateDirectionEnum status) {
|
|
|
+ return Optional.of(status).map(GateDirectionEnum::getCode).orElse(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GateDirectionEnum convertToEntityAttribute(Integer code) {
|
|
|
+ return GateDirectionEnum.getByCode(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|