Ver código fonte

fix 调试修复

zhanghaijun 2 anos atrás
pai
commit
e42fec1332

+ 23 - 12
train-server/src/main/java/top/haijunit/train/controller/DeviceController.java

@@ -4,9 +4,12 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import top.haijunit.common.domain.ResultData;
+import top.haijunit.common.utils.JsonUtils;
 import top.haijunit.train.device.domain.CommandEnum;
+import top.haijunit.train.device.domain.SituationVo;
 import top.haijunit.train.device.entity.DeviceEntity;
 import top.haijunit.train.device.service.DeviceService;
+import top.haijunit.train.utils.TrainWebSocketUtils;
 
 import java.util.List;
 
@@ -28,7 +31,7 @@ public class DeviceController {
     }
 
     @PostMapping("/add")
-    public ResultData<DeviceEntity> addDevice(@RequestBody @Validated DeviceEntity entity){
+    public ResultData<DeviceEntity> addDevice(@RequestBody @Validated DeviceEntity entity) {
         return ResultData.success(deviceService.addDevice(entity));
     }
 
@@ -37,18 +40,26 @@ public class DeviceController {
         return ResultData.success(deviceService.getDeviceByCommand(CommandEnum.ELEVATOR_HAND_COMMAND));
     }
 
-    @GetMapping("/platform/door")
-    public ResultData<String> door() {
-        return ResultData.success("");
+    /**
+     * 客流进站速度
+     * @param speed 客流进站速度 单位:人/分钟
+     * @return 执行结果
+     */
+    @GetMapping("/situation/client/{speed}")
+    public ResultData<String> clientControl(@PathVariable Double speed) {
+        TrainWebSocketUtils.sendMessage(CommandEnum.SITUATION_CLIENT_SPEED, new SituationVo.ClientVo(speed));
+        return ResultData.success("客流进站速度");
     }
 
-    @GetMapping("/water")
-    public ResultData<String> water() {
-        return ResultData.success("");
-    }
-
-    @GetMapping("/situation")
-    public ResultData<String> situation() {
-        return ResultData.success("");
+    /**
+     * 水灾强度控制
+     * @param isOpen 开启/关闭
+     * @param strength 强度 取值范围:0-1
+     * @return 执行结果
+     */
+    @GetMapping("/situation/water/{isOpen}/{strength}")
+    public ResultData<String> waterControl(@PathVariable Boolean isOpen, @PathVariable Double strength) {
+        TrainWebSocketUtils.sendMessage(CommandEnum.SITUATION_WATER_CONTROL, new SituationVo.WaterVo(isOpen, strength));
+        return ResultData.success("水灾控制");
     }
 }

+ 12 - 1
train-server/src/main/java/top/haijunit/train/device/domain/CommandEnum.java

@@ -70,7 +70,18 @@ public enum CommandEnum {
     // 垂直电梯操作指令 | 垂直电梯编号 | 状态 (0运行 1停止 2禁用)
     ELEVATOR_VERTICAL_COMMAND(20401, "verticalElevatorNo", "state", "垂直电梯操作指令"),
     // 电扶梯操作指令 | 电扶梯编号 | 状态 (0上行 1下行 2停止 3禁用)
-    ELEVATOR_HAND_COMMAND(20402, "elevatorNo", "state", "电扶梯操作指令");
+    ELEVATOR_HAND_COMMAND(20402, "elevatorNo", "state", "电扶梯操作指令"),
+    // 客流进站速度
+    SITUATION_CLIENT_SPEED(10501, "speedOfEntry", "", "客流进站速度"),
+    // 客流信息
+    SITUATION_CLIENT_INFO(20501, "kvp", "", "客流信息"),
+    // 水灾控制
+    SITUATION_WATER_CONTROL(10601, "isTurnOn", "strength", "水灾控制"),
+    // 水灾水位信息
+    SITUATION_WATER_LEVEL(20601, "kvp", "", "水灾水位信息"),
+    ;
+
+
 
     @JsonValue
     private final Integer code;

+ 24 - 0
train-server/src/main/java/top/haijunit/train/device/domain/SituationVo.java

@@ -0,0 +1,24 @@
+package top.haijunit.train.device.domain;
+
+import lombok.Data;
+
+/**
+ * @author zhanghaijun
+ * @date 2024/2/25 20:44
+ * @description 态势相关的vo
+ */
+public class SituationVo {
+
+    /**
+     * @param speedOfEntry  客流进站速度
+     */
+    public record ClientVo(Double speedOfEntry) {
+    }
+
+    /**
+     * @param isTurnOn 开启|关闭
+     * @param strength 强度 取值 0-1
+     */
+    public record WaterVo(Boolean isTurnOn, Double strength) {
+    }
+}

+ 3 - 2
train-server/src/main/java/top/haijunit/train/device/entity/DeviceEntity.java

@@ -29,7 +29,7 @@ public class DeviceEntity implements Serializable {
     @NotNull(message = "资源类型不能为空")
     private CommandEnum command;
     /** 标识编码 */
-    @NotEmpty(message="设备标识不能为空")
+    @NotEmpty(message = "设备标识不能为空")
     private String code;
     /** 状态 */
     @NotNull(message = "资源状态不能为空")
@@ -39,5 +39,6 @@ public class DeviceEntity implements Serializable {
     // 所属站台
     @NotNull(message = "所属站台不能为空")
     private Long stationId;
-
+    // 消息内容
+    private String message;
 }

+ 0 - 68
train-server/src/main/java/top/haijunit/train/device/entity/PlatformStopEntity.java

@@ -1,68 +0,0 @@
-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:15
- * @description 站台紧急停车按钮
- */
-@Data
-@Entity(name = "device_train_stop_button")
-public class PlatformStopEntity implements Serializable {
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Long id;
-
-    // 站台编号
-    private String platformNo;
-    // 运行方向
-    private DirectionEnum direction;
-    // 按下/弹起指令
-    private PlatformStopStatus status;
-    // 所属站台
-    private Long stationId;
-
-
-    @Getter
-    @RequiredArgsConstructor
-    public static enum PlatformStopStatus {
-        UP(0, "弹起/复位"), DOWN(1, "按下");
-
-        private final Integer code;
-        private final String describe;
-
-        @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
-        public static PlatformStopStatus getByCode(Integer code) {
-            for (PlatformStopStatus genderEnum : values()) {
-                if (Objects.equals(genderEnum.getCode(), code)) {
-                    return genderEnum;
-                }
-            }
-            return PlatformStopStatus.DOWN;
-        }
-    }
-
-    @Converter(autoApply = true)
-    public static class PlatformStopStatusConvert implements AttributeConverter<PlatformStopStatus, Integer> {
-        @Override
-        public Integer convertToDatabaseColumn(PlatformStopStatus status) {
-            return Optional.of(status).map(PlatformStopStatus::getCode).orElse(PlatformStopStatus.DOWN.getCode());
-        }
-
-        @Override
-        public PlatformStopStatus convertToEntityAttribute(Integer code) {
-            return PlatformStopStatus.getByCode(code);
-        }
-    }
-}

+ 0 - 99
train-server/src/main/java/top/haijunit/train/device/entity/StationAfcGateEntity.java

@@ -1,99 +0,0 @@
-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 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 StationAfcGateEntity implements Serializable {
-
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    private Long id;
-
-    // 闸机编号
-    private String gateMachineNo;
-    // 闸机状态
-    private GateStatusEnum state;
-    // 闸机方向状态
-    private GateDirectionEnum direction;
-    // 所属站台
-    private Long stationId;
-
-    @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);
-        }
-    }
-
-}

+ 0 - 17
train-server/src/main/java/top/haijunit/train/device/repository/DevicePlatformStopRepository.java

@@ -1,17 +0,0 @@
-package top.haijunit.train.device.repository;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-import top.haijunit.train.device.entity.PlatformStopEntity;
-
-/**
- * @author zhanghaijun
- * @date 2023/11/24 11:36
- * @description [一句话描述该类的功能]
- */
-@Repository
-public interface DevicePlatformStopRepository extends JpaRepository<PlatformStopEntity, Long> {
-
-    PlatformStopEntity findByPlatformNo(String platformNo);
-
-}

+ 0 - 17
train-server/src/main/java/top/haijunit/train/device/repository/DeviceStationAfcGateRepository.java

@@ -1,17 +0,0 @@
-package top.haijunit.train.device.repository;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-import top.haijunit.train.device.entity.StationAfcGateEntity;
-
-/**
- * @author zhanghaijun
- * @date 2023/11/24 11:36
- * @description [一句话描述该类的功能]
- */
-@Repository
-public interface DeviceStationAfcGateRepository extends JpaRepository<StationAfcGateEntity, Long> {
-
-    StationAfcGateEntity findByGateMachineNo(String gateMachineNo);
-
-}

+ 27 - 1
train-server/src/main/java/top/haijunit/train/device/service/DeviceService.java

@@ -3,6 +3,7 @@ package top.haijunit.train.device.service;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpStatus;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import lombok.RequiredArgsConstructor;
@@ -65,6 +66,24 @@ public class DeviceService {
     }
 
     public DeviceEntity saveDevice(CommandEnum command, JSONObject data) {
+        switch (command) {
+            case SITUATION_CLIENT_INFO:
+            case SITUATION_WATER_LEVEL:
+                JSONArray array = JSONUtil.parseArray(data.get(command.getNameStr()));
+                if (null == array || array.isEmpty()) {
+                    return null;
+                }
+                List<DeviceEntity> entityList = deviceRepository.findByCommand(command);
+                deviceRepository.deleteAll(entityList);
+                DeviceEntity entity = new DeviceEntity();
+                entity.setCommand(command);
+                entity.setCode(command.getDescribe());
+                entity.setStatus(0);
+                entity.setStationId(104002L);
+                entity.setMessage(array.toString());
+                deviceRepository.save(entity);
+                return entity;
+        }
         if (StrUtil.isBlank(command.getNameStr()) || StrUtil.isBlank(command.getStatusStr())) {
             throw new ServiceException(500, String.format("无法获取对应的参数,cmd: %s, data: %s", command.getCode(), data));
         }
@@ -73,7 +92,13 @@ public class DeviceService {
         if (StrUtil.isBlank(code) || null == status) {
             throw new ServiceException(500, String.format("参数值为空,cmd: %s, data: %s", command.getCode(), data));
         }
-        DeviceEntity device = deviceRepository.findByCommandAndCode(command, code);
+        DeviceEntity device;
+        try {
+            Long deviceId = Convert.toLong(code);
+            device = deviceRepository.findById(deviceId).orElse(null);
+        } catch (Exception exception) {
+            device = deviceRepository.findByCommandAndCode(command, code);
+        }
         if (null == device) {
             device = new DeviceEntity();
             device.setCode(code);
@@ -82,6 +107,7 @@ public class DeviceService {
             device.setStationId(104002L);
         }
         device.setStatus(status);
+        device.setMessage(data.toString());
         device.setJsonStr(getJsonStr(command, device.getJsonStr(), data));
         return deviceRepository.save(device);
     }

+ 11 - 3
train-server/src/main/java/top/haijunit/train/listener/MessageEventListener.java

@@ -46,28 +46,36 @@ public class MessageEventListener implements ApplicationListener<MessageEvent> {
             if (entity == null) {
                 return;
             }
-            log.info("设备信息更新成功: {}, message: {}", entity.getCode(), message);
             switch (entity.getCommand()) {
                 case AFC_GATE_MACHINE_STATUS:
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
                     TrainWebSocketUtils.sendMessage(CommandEnum.AFC_GATE_MACHINE, getMessage(CommandEnum.AFC_GATE_MACHINE, entity));
                     break;
                 case AFC_TICKETING_AUTO_STATUS:
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
                     TrainWebSocketUtils.sendMessage(CommandEnum.AFC_TICKETING_AUTO, getMessage(CommandEnum.AFC_TICKETING_AUTO, entity));
                     break;
                 case ELEVATOR_VERTICAL_COMMAND:
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
                     TrainWebSocketUtils.sendMessage(CommandEnum.ELEVATOR_VERTICAL, getMessage(CommandEnum.ELEVATOR_VERTICAL, entity));
                     break;
                 case ELEVATOR_HAND_COMMAND:
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
                     TrainWebSocketUtils.sendMessage(CommandEnum.ELEVATOR_HAND, getMessage(CommandEnum.ELEVATOR_HAND, entity));
                     break;
                 case PLATFORM_DOOR_LCW:
                 case AFC_IBP, IBP_CONTROL, IBP_DOOR_OPEN, IBP_DOOR_CLOSE:
                 case PSL_LOCK, PSL_CONTROL, PSL_DOOR_OPEN, PSL_DOOR_CLOSE:
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
                     // 屏蔽门控制指令
                     doorService.updateIbpControl(entity);
                     break;
+                case SITUATION_CLIENT_INFO:
+                case SITUATION_WATER_LEVEL:
+                    break;
                 default:
-                    log.warn("未处理返回的消息:{}", message);
+                    log.info("接受消息: {}, message: {}", entity.getCode(), message);
+                    // log.warn("未处理返回的消息:{}", message);
             }
         } catch (RuntimeException exception) {
             log.error("消息处理异常: {},消息: {}", exception.getMessage(), message);
@@ -81,7 +89,7 @@ public class MessageEventListener implements ApplicationListener<MessageEvent> {
         } else {
             data = JSONUtil.createObj();
         }
-        data.set(command.getNameStr(), device.getCode());
+        data.set(command.getNameStr(), Convert.toStr(device.getId(),""));
         data.set(command.getStatusStr(), device.getStatus());
         data.set("stationId", Convert.toLong(device.getStationId(), 104002L));
         return data;

+ 1 - 0
train-server/src/main/resources/db/changelog/device/db-server-device.xml

@@ -12,6 +12,7 @@
             <column name="status" type="${number.type}" defaultValueNumeric="0" remarks="设备状态"/>
             <column name="station_id" type="${autoing.type}" defaultValueNumeric="0" remarks="所属站台"/>
             <column name="json_str" type="VARCHAR(254)" defaultValue="" remarks="其他信息"/>
+            <column name="message" type="VARCHAR(254)" defaultValue="" remarks="消息内容"/>
         </createTable>
     </changeSet>
     <changeSet id="load-db_device-data" author="zhanghaijun" failOnError="false" runOnChange="true">

+ 10 - 0
train-web/src/api/device.ts

@@ -9,3 +9,13 @@ export function deviceAll(): AxiosPromise<Array<DeviceItem>> {
 export function addDevice(data: DeviceItem): AxiosPromise<any> {
   return request({ url: '/device/add', method: 'post', data })
 }
+
+// 客流进站速度控制
+export function situationClientControl(speed: number): AxiosPromise<any> {
+  return request({ url: '/device/situation/client/' + speed, method: 'get' })
+}
+
+// 水灾强度控制
+export function situationWaterControl(isOpen: boolean, strength: number): AxiosPromise<any> {
+  return request({ url: '/device/situation/water/' + isOpen + '/' + strength, method: 'get' })
+}

+ 1 - 0
train-web/src/pages/device/DeviceTestItem.vue

@@ -24,6 +24,7 @@
       <el-table class="device-table" :data="deviceList" style="width: 100%;height: 100%;">
         <el-table-column prop="stationId" label="所属站台" width="100px"></el-table-column>
         <el-table-column prop="command" label="指令" width="100px"></el-table-column>
+        <el-table-column prop="id" label="设备ID" width="120px"></el-table-column>
         <el-table-column prop="code" label="标识编码" width="120px"></el-table-column>
         <!-- <el-table-column prop="jsonStr" label="其他信息"></el-table-column> -->
         <el-table-column label="状态">

+ 2 - 0
train-web/src/types/auto-imports.d.ts

@@ -309,6 +309,7 @@ import { UnwrapRef } from 'vue'
 declare module 'vue' {
   interface ComponentCustomProperties {
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
+    readonly ElNotification: UnwrapRef<typeof import('element-plus/es')['ElNotification']>
     readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
     readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
     readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>
@@ -604,6 +605,7 @@ declare module 'vue' {
 declare module '@vue/runtime-core' {
   interface ComponentCustomProperties {
     readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
+    readonly ElNotification: UnwrapRef<typeof import('element-plus/es')['ElNotification']>
     readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
     readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
     readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>