diff --git a/src/main/java/com/qyft/ms/app/common/constant/FrontSendStatus.java b/src/main/java/com/qyft/ms/app/common/constant/FrontSendStatus.java index d8f6be7..364b459 100644 --- a/src/main/java/com/qyft/ms/app/common/constant/FrontSendStatus.java +++ b/src/main/java/com/qyft/ms/app/common/constant/FrontSendStatus.java @@ -9,6 +9,7 @@ public class FrontSendStatus { * 错误 */ public static final String ERROR = "error"; + private FrontSendStatus() { } diff --git a/src/main/java/com/qyft/ms/app/controller/DeviceStatusController.java b/src/main/java/com/qyft/ms/app/controller/DeviceStatusController.java index d55443a..32ab055 100644 --- a/src/main/java/com/qyft/ms/app/controller/DeviceStatusController.java +++ b/src/main/java/com/qyft/ms/app/controller/DeviceStatusController.java @@ -2,8 +2,6 @@ package com.qyft.ms.app.controller; import cn.hutool.json.JSONObject; import com.qyft.ms.app.device.status.DeviceStatus; -import com.qyft.ms.app.model.vo.SelfTestVO; -import com.qyft.ms.app.service.SelfTestService; import com.qyft.ms.system.common.result.Result; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/src/main/java/com/qyft/ms/app/controller/SelfTestController.java b/src/main/java/com/qyft/ms/app/controller/SelfTestController.java index ef2eb1c..85adee6 100644 --- a/src/main/java/com/qyft/ms/app/controller/SelfTestController.java +++ b/src/main/java/com/qyft/ms/app/controller/SelfTestController.java @@ -10,10 +10,12 @@ import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.service.device.DeviceCommandService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -47,7 +49,7 @@ public class SelfTestController { @Operation(summary = "自检完毕") @PostMapping("/finish") - public Result selfTestFinish(){ + public Result selfTestFinish() { deviceStatus.setSelfTestCompleted(true); return Result.success(); } diff --git a/src/main/java/com/qyft/ms/app/controller/SystemController.java b/src/main/java/com/qyft/ms/app/controller/SystemController.java index ccfe14a..2cc9ebb 100644 --- a/src/main/java/com/qyft/ms/app/controller/SystemController.java +++ b/src/main/java/com/qyft/ms/app/controller/SystemController.java @@ -7,7 +7,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,7 +21,7 @@ public class SystemController { private final SysSettingsService sysSettingsService; @Operation(summary = "还原出厂配置") - @PostMapping("/reset") + @GetMapping("/reset") public Result resetFactorySettings() { try { positionService.resetToFactorySettings(); diff --git a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java index 6828d8b..003a609 100644 --- a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java +++ b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskPointCollector.java @@ -1,20 +1,10 @@ package com.qyft.ms.app.device.spray; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.qyft.ms.app.common.constant.WebSocketMessageType; -import com.qyft.ms.app.device.status.SprayTask; -import com.qyft.ms.app.model.bo.Point2D; -import com.qyft.ms.app.model.bo.SprayTaskPointCollectorPushBO; import com.qyft.ms.app.model.entity.Position; import com.qyft.ms.app.service.PositionService; -import com.qyft.ms.system.common.device.command.CommandFuture; -import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; -import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.service.WebSocketService; import com.qyft.ms.system.service.device.DeviceCommandService; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.TaskScheduler; @@ -40,7 +30,7 @@ public class SprayTaskPointCollector { private Double[][] slideArr; -// @PostConstruct + // @PostConstruct private void init() { Position slidePosition1 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position1")); Position slidePosition2 = positionService.getOne(new LambdaQueryWrapper().eq(Position::getPointCode, "slide_position2")); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java b/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java index 937596b..aa7f1ea 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java @@ -1,11 +1,8 @@ package com.qyft.ms.app.front.cmd; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; -import com.qyft.ms.system.common.constant.CommandStatus; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; -import com.qyft.ms.system.common.device.command.FrontResponseGenerator; import com.qyft.ms.system.core.handler.BaseCommandHandler; import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.model.form.FrontCmdControlForm; diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java b/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java index b2772f9..b0d30f1 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java @@ -3,10 +3,7 @@ package com.qyft.ms.app.front.cmd.business; import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.service.SelfTestService; import com.qyft.ms.system.common.annotation.CommandMapping; -import com.qyft.ms.system.common.device.command.CommandFuture; -import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.core.handler.BaseCommandHandler; -import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java index 5045806..6c1a0a5 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java @@ -88,7 +88,7 @@ public class MatrixSprayChangeParam extends BaseCommandHandler { DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume);//注射泵流速设置 CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand); - commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture,smotorZPositionSetCommandFuture,syringePumpVolumeSetCommandFuture); + commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture, smotorZPositionSetCommandFuture, syringePumpVolumeSetCommandFuture); }); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java index 14feaa5..9972798 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java @@ -9,7 +9,6 @@ import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.core.handler.BaseCommandHandler; import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.model.form.FrontCmdControlForm; -import com.qyft.ms.system.service.WebSocketService; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java index 1fce9f8..b194540 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java @@ -10,7 +10,6 @@ import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.core.handler.BaseCommandHandler; import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.model.form.FrontCmdControlForm; -import com.qyft.ms.system.service.WebSocketService; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java index f0b6a09..9f8d905 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java @@ -17,8 +17,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -42,14 +40,14 @@ public class MatrixSprayStop extends BaseCommandHandler { if (!sprayTask.isSpraying()) { throw new RuntimeException("设备没有正在喷涂"); } - if(sprayTask.isClosing()){ + if (sprayTask.isClosing()) { throw new RuntimeException("正在结束喷涂,请稍后"); } webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); return runAsync(() -> { sprayTask.setClosing(true); - try{ + try { sprayTaskExecutor.stopTask();//终止喷涂任务线程 DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵 @@ -81,7 +79,7 @@ public class MatrixSprayStop extends BaseCommandHandler { deviceStatus.setSpraying(false); deviceStatus.setPaused(false); deviceStatus.setSuspendable(false); - }finally { + } finally { sprayTask.setClosing(false); } diff --git a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java index 3f9fb1c..adf9345 100644 --- a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java +++ b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java @@ -7,11 +7,6 @@ import lombok.Data; @Schema(description = "喷涂任务已喷涂记录") public class SprayTaskSprayed { /** - * 玻片序号 - */ - @Schema(description = "玻片序号") - private Integer index; - /** * 当前玻片是第几次喷涂 */ Integer number; @@ -20,6 +15,11 @@ public class SprayTaskSprayed { */ Integer sprayCount; /** + * 玻片序号 + */ + @Schema(description = "玻片序号") + private Integer index; + /** * 已喷涂点位 */ private volatile Point2D sprayedPoints; diff --git a/src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java b/src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java index f44b8ce..75fefb8 100644 --- a/src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java +++ b/src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.model.vo; -import com.qyft.ms.app.model.bo.SprayParams; import com.qyft.ms.app.model.bo.SprayTaskSprayed; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -31,7 +30,7 @@ public class SprayTaskStatusVO { * 喷涂参数 */ @Schema(description = "喷涂参数") - private Map sprayParams; + private Map sprayParams; } diff --git a/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java b/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java index ec20f17..7ec02fd 100644 --- a/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java +++ b/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java @@ -29,13 +29,12 @@ import java.util.concurrent.CompletableFuture; @RequiredArgsConstructor @Slf4j public class FrontCmdController { + private static final Set NO_SELF_TEST_CMDS = + new HashSet<>(Arrays.asList("device_self_test", "motor_x_to_home", "motor_y_to_home", "motor_z_to_home")); private final CommandHandlerRegistry registry; private final WebSocketService webSocketService; private final DeviceStatus deviceStatus; - private static final Set NO_SELF_TEST_CMDS = - new HashSet<>(Arrays.asList("device_self_test", "motor_x_to_home", "motor_y_to_home", "motor_z_to_home")); - @Operation(summary = "前端统一调用一个接口") @PostMapping public Result controlMethod(@RequestBody FrontCmdControlForm form) { @@ -46,7 +45,7 @@ public class FrontCmdController { log.error("未进行自检,无法执行业务指令"); return Result.failed("未进行自检,无法执行业务指令"); } - if(deviceStatus.isStopPressed()){ + if (deviceStatus.isStopPressed()) { log.error("设备急停中"); return Result.failed("设备急停中"); } diff --git a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java index 495463b..1d7db9c 100644 --- a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java +++ b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java @@ -71,13 +71,13 @@ public class DeviceCommandService { future.setEndSendTime(System.currentTimeMillis()); Boolean success = deviceResult.getBool("success"); //数据验证 if (success == null || !success) { //response失败 - if(future.getCmdId() != null) { + if (future.getCmdId() != null) { webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(future.getCmdId(), future.getCmdCode(), CommandStatus.DEVICE_ERROR, future.getDeviceCommand().getCmdName() + "指令,设备response错误,耗时:" + (future.getEndSendTime() - future.getStartSendTime()), deviceResult)); } future.completeResponseExceptionally(new RuntimeException("response失败:" + deviceResult)); } else { - if(future.getCmdId() != null) { + if (future.getCmdId() != null) { webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(future.getCmdId(), future.getCmdCode(), CommandStatus.DEVICE_RESULT, future.getDeviceCommand().getCmdName() + "指令,设备response正常,耗时:" + (future.getEndSendTime() - future.getStartSendTime()), deviceResult)); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 65c7997..c8363ab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -40,10 +40,10 @@ jwt: tcp: enable: true # 是否开启 TCP 连接 server-enable: true # 是否开启 TCP 连接 -# host: 127.0.0.1 -# host: 192.168.1.106 + # host: 127.0.0.1 + # host: 192.168.1.106 host: 192.168.1.140 -# host: 192.168.100.168 + # host: 192.168.100.168 port: 9080 reconnect: 5000 # 断线重连间隔(单位:毫秒) timeout: 10000 # 连接超时时间(单位:毫秒) diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index f93ccac..360d1fb 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -1,62 +1,130 @@ -- 创建 matrix 基质类型表 CREATE TABLE IF NOT EXISTS matrix ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id + INTEGER + PRIMARY + KEY + AUTOINCREMENT, + name + TEXT + NOT + NULL, + create_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP, + update_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP ); -- 插入 matrix 表数据 -INSERT OR IGNORE INTO matrix (id, name, create_time, update_time) +INSERT +OR IGNORE INTO matrix (id, name, create_time, update_time) VALUES (1, 'DHB', null, null); -- 创建 matrix_craft 基质工艺表 CREATE TABLE IF NOT EXISTS matrix_craft ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - name TEXT NOT NULL, - matrix_id INTEGER NOT NULL, - matrix_path_type TEXT NOT NULL, - motor_z_height INTEGER, - gas_pressure INTEGER, - volume INTEGER, - matrix_flow_velocity INTEGER, - high_voltage BOOLEAN, - high_voltage_value INTEGER, - spacing INTEGER, - moving_speed INTEGER, - times INTEGER, - create_user INTEGER, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id + INTEGER + PRIMARY + KEY + AUTOINCREMENT, + name + TEXT + NOT + NULL, + matrix_id + INTEGER + NOT + NULL, + matrix_path_type + TEXT + NOT + NULL, + motor_z_height + INTEGER, + gas_pressure + INTEGER, + volume + INTEGER, + matrix_flow_velocity + INTEGER, + high_voltage + BOOLEAN, + high_voltage_value + INTEGER, + spacing + INTEGER, + moving_speed + INTEGER, + times + INTEGER, + create_user + INTEGER, + create_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP, + update_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP ); -- 创建 operation_log 操作记录表 CREATE TABLE IF NOT EXISTS operation_log ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - matrix_id INTEGER, - matrix_info TEXT, - status INTEGER, - create_user INTEGER, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id + INTEGER + PRIMARY + KEY + AUTOINCREMENT, + matrix_id + INTEGER, + matrix_info + TEXT, + status + INTEGER, + create_user + INTEGER, + create_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP, + update_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP ); -- 创建 sys_settings 系统配置表 CREATE TABLE IF NOT EXISTS sys_settings ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - parent_id INTEGER, - name TEXT NOT NULL, - code TEXT, - value TEXT + id + INTEGER + PRIMARY + KEY + AUTOINCREMENT, + parent_id + INTEGER, + name + TEXT + NOT + NULL, + code + TEXT, + value + TEXT ); -- 插入 sys_settings 表数据 -INSERT OR IGNORE INTO sys_settings (id, parent_id, name, code, value) +INSERT +OR IGNORE INTO sys_settings (id, parent_id, name, code, value) VALUES (1, NULL, '玻片高度', 'slide_height', 101.2), (2, NULL, 'z轴安全高度', 'safe_z_height', 80); @@ -65,17 +133,43 @@ VALUES (1, NULL, '玻片高度', 'slide_height', 101.2), -- 位置表,用来存储设备固定点位 CREATE TABLE IF NOT EXISTS position ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - point_name TEXT NOT NULL, - point_code TEXT NOT NULL, - x REAL NOT NULL, - y REAL NOT NULL, - z REAL NOT NULL, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + id + INTEGER + PRIMARY + KEY + AUTOINCREMENT, + point_name + TEXT + NOT + NULL, + point_code + TEXT + NOT + NULL, + x + REAL + NOT + NULL, + y + REAL + NOT + NULL, + z + REAL + NOT + NULL, + create_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP, + update_time + TIMESTAMP + DEFAULT + CURRENT_TIMESTAMP ); - INSERT OR IGNORE INTO position (id, point_name, point_code, x, y, z) +INSERT +OR IGNORE INTO position (id, point_name, point_code, x, y, z) VALUES (1,'玻片1位置', 'slide_position1', 18.08, 0, 101.2), (2,'玻片2位置', 'slide_position2', 45.08, 0, 101.2), (3,'玻片3位置', 'slide_position3', 72.08, 0, 101.2),