Browse Source

first commit!

master
王梦远 2 months ago
parent
commit
9c9d54b0f1
  1. 56
      build.gradle
  2. 28
      build.gradle.kts
  3. BIN
      lib/modbus4j-3.1.0.jar
  4. 50
      src/main/java/com/iflytop/sgs/app/cmd/AnnealStartCommand.java
  5. 42
      src/main/java/com/iflytop/sgs/app/cmd/AnnealStopCommand.java
  6. 44
      src/main/java/com/iflytop/sgs/app/cmd/CleanStartCommand.java
  7. 44
      src/main/java/com/iflytop/sgs/app/cmd/CleanStopCommand.java
  8. 35
      src/main/java/com/iflytop/sgs/app/cmd/DoorCloseCommand.java
  9. 40
      src/main/java/com/iflytop/sgs/app/cmd/DoorOpenCommand.java
  10. 38
      src/main/java/com/iflytop/sgs/app/cmd/DoorOriginCommand.java
  11. 50
      src/main/java/com/iflytop/sgs/app/cmd/DryStartCommand.java
  12. 43
      src/main/java/com/iflytop/sgs/app/cmd/DryStopCommand.java
  13. 40
      src/main/java/com/iflytop/sgs/app/cmd/FanStartCommand.java
  14. 40
      src/main/java/com/iflytop/sgs/app/cmd/FanStopCommand.java
  15. 33
      src/main/java/com/iflytop/sgs/app/cmd/GantryXOriginCommand.java
  16. 33
      src/main/java/com/iflytop/sgs/app/cmd/GantryZOriginCommand.java
  17. 50
      src/main/java/com/iflytop/sgs/app/cmd/HeatStartCommand.java
  18. 41
      src/main/java/com/iflytop/sgs/app/cmd/HeatStopCommand.java
  19. 77
      src/main/java/com/iflytop/sgs/app/cmd/MoveToHeatAreaCommand.java
  20. 81
      src/main/java/com/iflytop/sgs/app/cmd/MoveToSolutionAreaCommand.java
  21. 66
      src/main/java/com/iflytop/sgs/app/cmd/SolutionAddCommand.java
  22. 67
      src/main/java/com/iflytop/sgs/app/cmd/SolutionReduceCommand.java
  23. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorCloseCommand.java
  24. 40
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorOpenCommand.java
  25. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorStopCommand.java
  26. 45
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStartCommand.java
  27. 45
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java
  28. 46
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java
  29. 45
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java
  30. 46
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java
  31. 41
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStopCommand.java
  32. 75
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidMoveByCommand.java
  33. 37
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidMoveToCommand.java
  34. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidResetCommand.java
  35. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidStopCommand.java
  36. 78
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveByCommand.java
  37. 41
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveToCommand.java
  38. 39
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXOriginCommand.java
  39. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXStopCommand.java
  40. 76
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveByCommand.java
  41. 37
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveToCommand.java
  42. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZOriginCommand.java
  43. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZStopCommand.java
  44. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenThickWayCommand.java
  45. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenThinWayCommand.java
  46. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenVacantWayCommand.java
  47. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenWasteWayCommand.java
  48. 35
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenWaterWayCommand.java
  49. 31
      src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java
  50. 31
      src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java
  51. 30
      src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java
  52. 32
      src/main/java/com/iflytop/sgs/app/config/A8kCanBusConnectionConfig.java
  53. 21
      src/main/java/com/iflytop/sgs/app/config/AsyncConfig.java
  54. 76
      src/main/java/com/iflytop/sgs/app/config/CraftsStateMachineConfig.java
  55. 61
      src/main/java/com/iflytop/sgs/app/config/MybatisPlusConfig.java
  56. 68
      src/main/java/com/iflytop/sgs/app/config/SwaggerConfig.java
  57. 16
      src/main/java/com/iflytop/sgs/app/config/WebConfig.java
  58. 57
      src/main/java/com/iflytop/sgs/app/controller/AuthController.java
  59. 74
      src/main/java/com/iflytop/sgs/app/controller/CmdController.java
  60. 67
      src/main/java/com/iflytop/sgs/app/controller/CmdDebugController.java
  61. 34
      src/main/java/com/iflytop/sgs/app/controller/ContainerController.java
  62. 112
      src/main/java/com/iflytop/sgs/app/controller/CraftsController.java
  63. 121
      src/main/java/com/iflytop/sgs/app/controller/DeviceParamController.java
  64. 59
      src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java
  65. 33
      src/main/java/com/iflytop/sgs/app/controller/HeatModuleController.java
  66. 74
      src/main/java/com/iflytop/sgs/app/controller/OresController.java
  67. 59
      src/main/java/com/iflytop/sgs/app/controller/SelfTestController.java
  68. 74
      src/main/java/com/iflytop/sgs/app/controller/SolutionsController.java
  69. 72
      src/main/java/com/iflytop/sgs/app/controller/StepCommandController.java
  70. 51
      src/main/java/com/iflytop/sgs/app/controller/SystemController.java
  71. 48
      src/main/java/com/iflytop/sgs/app/controller/SystemLogController.java
  72. 83
      src/main/java/com/iflytop/sgs/app/controller/TasksController.java
  73. 47
      src/main/java/com/iflytop/sgs/app/controller/TrayController.java
  74. 72
      src/main/java/com/iflytop/sgs/app/controller/UserController.java
  75. 33
      src/main/java/com/iflytop/sgs/app/core/BaseCommandHandler.java
  76. 58
      src/main/java/com/iflytop/sgs/app/core/CommandHandlerRegistry.java
  77. 31
      src/main/java/com/iflytop/sgs/app/core/CommandPoolManager.java
  78. 151
      src/main/java/com/iflytop/sgs/app/core/CraftsContext.java
  79. 15
      src/main/java/com/iflytop/sgs/app/core/CraftsDebugGenerator.java
  80. 22
      src/main/java/com/iflytop/sgs/app/core/DebugGenerator.java
  81. 35
      src/main/java/com/iflytop/sgs/app/core/device/CommandState.java
  82. 23
      src/main/java/com/iflytop/sgs/app/core/device/CraftsState.java
  83. 36
      src/main/java/com/iflytop/sgs/app/core/device/DeviceState.java
  84. 11
      src/main/java/com/iflytop/sgs/app/core/device/DoorState.java
  85. 11
      src/main/java/com/iflytop/sgs/app/core/device/GantryArmState.java
  86. 47
      src/main/java/com/iflytop/sgs/app/core/device/HeatModuleState.java
  87. 49
      src/main/java/com/iflytop/sgs/app/core/device/SelfTestState.java
  88. 34
      src/main/java/com/iflytop/sgs/app/core/device/SolutionContainerState.java
  89. 23
      src/main/java/com/iflytop/sgs/app/core/device/SolutionModuleState.java
  90. 37
      src/main/java/com/iflytop/sgs/app/core/device/TrayState.java
  91. 17
      src/main/java/com/iflytop/sgs/app/core/device/TubeState.java
  92. 16
      src/main/java/com/iflytop/sgs/app/core/event/CommandFeedbackEvent.java
  93. 18
      src/main/java/com/iflytop/sgs/app/core/listener/CommandFeedbackListener.java
  94. 33
      src/main/java/com/iflytop/sgs/app/core/listener/DeviceStateListener.java
  95. 15
      src/main/java/com/iflytop/sgs/app/mapper/ContainerMapper.java
  96. 19
      src/main/java/com/iflytop/sgs/app/mapper/CraftsMapper.java
  97. 12
      src/main/java/com/iflytop/sgs/app/mapper/DeviceParamConfigMapper.java
  98. 12
      src/main/java/com/iflytop/sgs/app/mapper/DevicePositionMapper.java
  99. 15
      src/main/java/com/iflytop/sgs/app/mapper/OresMapper.java
  100. 13
      src/main/java/com/iflytop/sgs/app/mapper/SolutionsMapper.java

56
build.gradle

@ -0,0 +1,56 @@
// build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.5'
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.iflytop'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/spring' }
}
dependencies {
implementation files('lib/modbus4j-3.1.0.jar')
implementation 'ch.qos.logback:logback-core:1.5.16'
implementation 'cn.hutool:hutool-all:5.8.35'
implementation 'com.baomidou:mybatis-plus-boot-starter:3.5.10.1'
implementation 'com.baomidou:mybatis-plus-generator:3.5.10.1'
implementation 'com.baomidou:mybatis-plus-jsqlparser:3.5.10.1'
implementation 'com.github.xiaoymin:knife4j-openapi3-jakarta-spring-boot-starter:4.5.0'
implementation 'jakarta.annotation:jakarta.annotation-api:3.0.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6'
implementation 'org.freemarker:freemarker:2.3.34'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.4'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket:3.4.2'
implementation 'org.springframework.statemachine:spring-statemachine-core:4.0.0'
implementation 'org.xerial:sqlite-jdbc:3.48.0.0'
implementation 'org.springframework.boot:spring-boot-starter-validation:3.4.5'
implementation 'org.java-websocket:Java-WebSocket:1.6.0'
implementation 'com.fazecast:jSerialComm:2.11.0'
implementation 'com.opencsv:opencsv:5.11'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.named('test') {
enabled = false
useJUnitPlatform()
}

28
build.gradle.kts

@ -1,28 +0,0 @@
plugins {
java
id("org.springframework.boot") version "3.4.6"
id("io.spring.dependency-management") version "1.1.7"
}
group = "com.iflytop"
version = "0.0.1-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.withType<Test> {
useJUnitPlatform()
}

BIN
lib/modbus4j-3.1.0.jar

50
src/main/java/com/iflytop/sgs/app/cmd/AnnealStartCommand.java

@ -0,0 +1,50 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.core.device.HeatModuleState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 开始退火
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class AnnealStartCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
//获取当前加热区
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
HeatModuleState heatModuleState = deviceStateService.getHeatModuleState(heatModuleId);
//设置加热区目标温度
deviceStateService.setHeatModuleStateTargetTemperature(heatModuleId,heatModuleState.getAnnealTemperature());
//从系统状态中获取指定加热区设定的退火温度数值
double temperature = deviceStateService.getHeatModuleState(heatModuleId).getAnnealTemperature();
//开启退火
deviceCommandUtilService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, temperature);
//设置加热区状态 正在退火
deviceStateService.setHeatModuleStateAnnealing(heatModuleId,true);
}
});
}
}

42
src/main/java/com/iflytop/sgs/app/cmd/AnnealStopCommand.java

@ -0,0 +1,42 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 结束退火
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class AnnealStopCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//关闭加热
deviceCommandUtilService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);
//设置加热区状态 退火结束
deviceStateService.setHeatModuleStateAnnealing(heatModuleId,false);
}
});
}
}

44
src/main/java/com/iflytop/sgs/app/cmd/CleanStartCommand.java

@ -0,0 +1,44 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 开始清洗 todo wmy 需要改
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class CleanStartCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//从系统状态中获取指定加热区设定的温度数值
double temperature = deviceStateService.getHeatModuleState(heatModuleId).getTemperature();
//开启加热
deviceCommandUtilService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, temperature);
deviceStateService.setHeatModuleStateHeating(heatModuleId, true);//设置状态加热中
}
});
}
}

44
src/main/java/com/iflytop/sgs/app/cmd/CleanStopCommand.java

@ -0,0 +1,44 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 结束清洗 todo wmy 需要改
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class CleanStopCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//从系统状态中获取指定加热区设定的温度数值
double temperature = deviceStateService.getHeatModuleState(heatModuleId).getTemperature();
//开启加热
deviceCommandUtilService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, temperature);
deviceStateService.setHeatModuleStateHeating(heatModuleId, true);//设置状态加热中
}
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/DoorCloseCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 关门
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_close")//业务指令注解
public class DoorCloseCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
//门电机回原点
deviceCommandUtilService.doorOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());
//将门状态设置为false
deviceStateService.setDoorStatus(false);
});
}
}

40
src/main/java/com/iflytop/sgs/app/cmd/DoorOpenCommand.java

@ -0,0 +1,40 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DevicePositionService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 开门
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_open")//业务指令注解
public class DoorOpenCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DevicePositionService devicePositionService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
//从数据库获取开门距离
Double doorOpenDistance = devicePositionService.getPosition(DevicePositionCode.doorOpen).getDistance();
//门电机移动开门距离
deviceCommandUtilService.doorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), doorOpenDistance);
//将门状态设置为true
deviceStateService.setDoorStatus(true);
});
}
}

38
src/main/java/com/iflytop/sgs/app/cmd/DoorOriginCommand.java

@ -0,0 +1,38 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.SelfTestService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 门回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_origin")//业务指令注解
public class DoorOriginCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
private final SelfTestService selfTestService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
//门电机回原点
deviceCommandUtilService.doorOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());
selfTestService.getSelfTestState().setDoorOrigin(true);//设置是否在原点状态
//将门状态设置为false
deviceStateService.setDoorStatus(false);
});
}
}

50
src/main/java/com/iflytop/sgs/app/cmd/DryStartCommand.java

@ -0,0 +1,50 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.core.device.HeatModuleState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 开始烘干
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class DryStartCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
//获取当前加热区
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
HeatModuleState heatModuleState = deviceStateService.getHeatModuleState(heatModuleId);
//设置加热区目标温度
deviceStateService.setHeatModuleStateTargetTemperature(heatModuleId,heatModuleState.getDryTemperature());
//从系统状态中获取指定加热区设定的烘干温度数值
double temperature = deviceStateService.getHeatModuleState(heatModuleId).getDryTemperature();
//开启退火
deviceCommandUtilService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, temperature);
//设置加热区状态 正在烘干
deviceStateService.setHeatModuleStateAnnealing(heatModuleId,true);
}
});
}
}

43
src/main/java/com/iflytop/sgs/app/cmd/DryStopCommand.java

@ -0,0 +1,43 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 结束烘干
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class DryStopCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//关闭加热
deviceCommandUtilService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);
//设置加热区状态 退火结束
deviceStateService.setHeatModuleStateDrying(heatModuleId,false);
}
});
}
}

40
src/main/java/com/iflytop/sgs/app/cmd/FanStartCommand.java

@ -0,0 +1,40 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 散热开
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("fan_start")
public class FanStartCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
deviceCommandUtilService.fanStart(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);
deviceStateService.setHeatModuleStateFanOpen(heatModuleId, true);
}
});
}
}

40
src/main/java/com/iflytop/sgs/app/cmd/FanStopCommand.java

@ -0,0 +1,40 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 散热关
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("fan_stop")
public class FanStopCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
deviceCommandUtilService.fanClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);
deviceStateService.setHeatModuleStateFanOpen(heatModuleId, false);
}
});
}
}

33
src/main/java/com/iflytop/sgs/app/cmd/GantryXOriginCommand.java

@ -0,0 +1,33 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.SelfTestService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 龙门架机械臂x轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_x_origin")//业务指令注解
public class GantryXOriginCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final SelfTestService selfTestService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
deviceCommandUtilService.gantryXMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());
selfTestService.getSelfTestState().setGantryXOrigin(true);//设置是否在原点状态
});
}
}

33
src/main/java/com/iflytop/sgs/app/cmd/GantryZOriginCommand.java

@ -0,0 +1,33 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.SelfTestService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 龙门架机械臂z轴回原点
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_z_origin")//业务指令注解
public class GantryZOriginCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final SelfTestService selfTestService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
deviceCommandUtilService.gantryZMoveOrigin(cmdDTO.getCommandId(), cmdDTO.getCommand());
selfTestService.getSelfTestState().setGantryZOrigin(true);//设置是否在原点状态
});
}
}

50
src/main/java/com/iflytop/sgs/app/cmd/HeatStartCommand.java

@ -0,0 +1,50 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.core.device.HeatModuleState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 开始加热
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_start")//业务指令注解
public class HeatStartCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
//获取当前加热区
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
HeatModuleState heatModuleState = deviceStateService.getHeatModuleState(heatModuleId);
//设置加热区目标温度
deviceStateService.setHeatModuleStateTargetTemperature(heatModuleId,heatModuleState.getHeatTemperature());
//从系统状态中获取指定加热区设定的烘干温度数值
double temperature = deviceStateService.getHeatModuleState(heatModuleId).getHeatTemperature();
//开启加热
deviceCommandUtilService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, temperature);
//设置加热区状态 正在加热
deviceStateService.setHeatModuleStateHeating(heatModuleId,true);
}
});
}
}

41
src/main/java/com/iflytop/sgs/app/cmd/HeatStopCommand.java

@ -0,0 +1,41 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 停止加热
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heat_stop")//业务指令注解
public class HeatStopCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId");
return runAsync(() -> {
for (int i = 0; i < heatIdJsonArray.size(); i++) {
String heatId = heatIdJsonArray.getStr(i);
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//关闭加热
deviceCommandUtilService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId);
deviceStateService.setHeatModuleStateHeating(heatModuleId, false);//设置状态停止加热
}
});
}
}

77
src/main/java/com/iflytop/sgs/app/cmd/MoveToHeatAreaCommand.java

@ -0,0 +1,77 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DevicePositionService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.GantryArmService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 移至加热 todo wmy 需要改
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("move_to_heat_area")//业务指令注解
public class MoveToHeatAreaCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DevicePositionService devicePositionService;
private final GantryArmService gantryArmService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) {
throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING);
}
if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
try {
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(true);
} catch (Exception e) {
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(false);
throw e;
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//加液电机升起的安全高度
double liquidMotorSafeDistance = devicePositionService.getPosition(DevicePositionCode.clawTrayGrip).getDistance();
//获取机械臂夹取托盘的横向距离
double clawTrayGrip = devicePositionService.getPosition(DevicePositionCode.clawTrayGrip).getDistance();
//获取机械臂夹取托盘的纵向高度
double clawTrayHeight = devicePositionService.getPosition(DevicePositionCode.clawTrayHeight).getDistance();
//获取指定加热模块上方点位
Point3D heatAreaTrayClawPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(heatModuleId);
return runAsync(() -> {
try {
//升高加液电机高度
deviceCommandUtilService.motorLiquidMove(cmdDTO.getCommandId(),cmdDTO.getCommand(),liquidMotorSafeDistance);
//移动机械臂到加热区上方 此时机械臂夹着托盘
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D); //将机械臂移动至加热模块上方
//下降z轴,夹爪脱离机械臂
deviceCommandUtilService.gantryZMove(clawTrayHeight);
//移动x轴向右脱离托盘
deviceCommandUtilService.gantryXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -clawTrayGrip);
//z轴返回原点
deviceCommandUtilService.motorLiquidMove(0);
} finally {
deviceStateService.setGantryArmStateIdle(true);
deviceStateService.getCommandState().get().setMoveToHeatAreaCommandExecuting(false);
}
});
}
}

81
src/main/java/com/iflytop/sgs/app/cmd/MoveToSolutionAreaCommand.java

@ -0,0 +1,81 @@
package com.iflytop.sgs.app.cmd;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DevicePositionService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 移至加液 todo wmy 需要改
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("move_to_solution_area")//业务指令注解
public class MoveToSolutionAreaCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final DevicePositionService devicePositionService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
if (deviceStateService.getCommandState().get().isMoveToSolutionAreaCommandExecuting()) {
throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING);
}
if (deviceStateService.getCommandState().get().isMoveToHeatAreaCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId);
//加液电机升起的安全高度
double liquidMotorSafeDistance = devicePositionService.getPosition(DevicePositionCode.clawTrayGrip).getDistance();
//获取机械臂夹取托盘的横向距离
double clawTrayGrip = devicePositionService.getPosition(DevicePositionCode.clawTrayGrip).getDistance();
//获取机械臂夹取托盘的纵向高度
double clawTrayHeight = devicePositionService.getPosition(DevicePositionCode.clawTrayHeight).getDistance();//获取z轴夹取托盘的下降高度
//获取加液模块上方点位
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();
//获取指定加热模块上方点位
Point3D heatAreaTrayPoint3D = deviceCommandUtilService.getHeatAreaTrayClawPoint3D(heatModuleId);
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(true);
} catch (Exception e) {
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(false);
throw e;
}
return runAsync(() -> {
try {
//升高加液电机高度
deviceCommandUtilService.motorLiquidMove(cmdDTO.getCommandId(),cmdDTO.getCommand(),liquidMotorSafeDistance);
//机械臂移动到加热位上方或者上料位上方
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayPoint3D);
//下降z轴
deviceCommandUtilService.gantryZMove(clawTrayHeight);
//移动x轴向左夹紧托盘
deviceCommandUtilService.gantryXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);
//z轴上升到0点
deviceCommandUtilService.gantryZMove(0);
//机械臂移动到加液区
deviceCommandUtilService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D);
} finally {
deviceStateService.setGantryArmStateIdle(true);
deviceStateService.getCommandState().get().setMoveToSolutionAreaCommandExecuting(false);
}
});
}
}

66
src/main/java/com/iflytop/sgs/app/cmd/SolutionAddCommand.java

@ -0,0 +1,66 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.ContainerService;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.AcidPumpDeviceCode;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
/**
* 添加溶液 todo wmy 需要记录托盘每一行的坐标 机械臂移动成功后 调动泵机加液
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("solution_add")//业务指令注解
public class SolutionAddCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final ContainerService containerService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
deviceStateService.setSolutionModuleStatePumping(true);
return runAsync(() -> {
JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList"));
for (int i = 0; i < dataList.size(); i++) {//遍历前端传入的加液配置
JSONObject tubeSol = dataList.getJSONObject(i);
String tubeNum = tubeSol.getStr("tubeNum");//获取试管编号
int[] tubeNums = Arrays.stream(tubeNum.split(","))
.mapToInt(s -> Integer.parseInt(s.trim()))
.toArray();
JSONArray solutionList = tubeSol.getJSONArray("solutionList");
for (int num : tubeNums) {
for (int k = 0; k < solutionList.size(); k++) {
JSONObject addSolution = solutionList.getJSONObject(k);
Long solId = addSolution.getLong("solutionId");
Double volume = addSolution.getDouble("volume");
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
if (acidPumpDevice == null) {
throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);//未找到对应溶液容器
}
deviceCommandUtilService.dualRobotMovePoint(num);//移动加液机械臂到指定试管点位
Thread.sleep(3000);
deviceCommandUtilService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
}
}
}
deviceCommandUtilService.dualRobotOrigin();
deviceStateService.setSolutionModuleStatePumping(false);
});
}
}

67
src/main/java/com/iflytop/sgs/app/cmd/SolutionReduceCommand.java

@ -0,0 +1,67 @@
package com.iflytop.sgs.app.cmd;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.ContainerService;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.AcidPumpDeviceCode;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
/**
* 抽取溶液 todo wmy 需要记录托盘每一行的坐标 机械臂移动成功后 调动泵机抽液体
*
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("solution_add")//业务指令注解
public class SolutionReduceCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final ContainerService containerService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
deviceStateService.setSolutionModuleStatePumping(true);
return runAsync(() -> {
JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList"));
for (int i = 0; i < dataList.size(); i++) {//遍历前端传入的加液配置
JSONObject tubeSol = dataList.getJSONObject(i);
String tubeNum = tubeSol.getStr("tubeNum");//获取试管编号
int[] tubeNums = Arrays.stream(tubeNum.split(","))
.mapToInt(s -> Integer.parseInt(s.trim()))
.toArray();
JSONArray solutionList = tubeSol.getJSONArray("solutionList");
for (int num : tubeNums) {
for (int k = 0; k < solutionList.size(); k++) {
JSONObject addSolution = solutionList.getJSONObject(k);
Long solId = addSolution.getLong("solutionId");
Double volume = addSolution.getDouble("volume");
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
if (acidPumpDevice == null) {
throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);//未找到对应溶液容器
}
deviceCommandUtilService.dualRobotMovePoint(num);//移动加液机械臂到指定试管点位
Thread.sleep(3000);
deviceCommandUtilService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
}
}
}
deviceCommandUtilService.dualRobotOrigin();
deviceStateService.setSolutionModuleStatePumping(false);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorCloseCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理关门指令
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_close")
public class DebugDoorCloseCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.doorOrigin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

40
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorOpenCommand.java

@ -0,0 +1,40 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.model.entity.DevicePosition;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.app.service.DevicePositionService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理开门指令
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_open")
public class DebugDoorOpenCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final DevicePositionService devicePositionService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DevicePosition devicePosition = devicePositionService.getPosition(DevicePositionCode.doorOpen);
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.doorMove(devicePosition.getDistance());
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorStopCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理停止门运动指令处理器
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("door_stop")
public class DebugDoorStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.doorStop();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

45
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStartCommand.java

@ -0,0 +1,45 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("fan_start")
public class DebugFanStartCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
String index = cmdDTO.getStringParam("index");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(index);
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
case heat_module_01 -> deviceCommand = DeviceCommandGenerator.fan1Open();
case heat_module_02 -> deviceCommand = DeviceCommandGenerator.fan2Open();
case heat_module_03 -> deviceCommand = DeviceCommandGenerator.fan3Open();
case heat_module_04 -> deviceCommand = DeviceCommandGenerator.fan4Open();
default -> throw new RuntimeException("index 未找到");
}
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

45
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java

@ -0,0 +1,45 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 关闭冷却风扇
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("fan_stop")
public class DebugFanStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
String index = cmdDTO.getStringParam("index");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(index);
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
case heat_module_01 -> deviceCommand = DeviceCommandGenerator.fan1Close();
case heat_module_02 -> deviceCommand = DeviceCommandGenerator.fan2Close();
case heat_module_03 -> deviceCommand = DeviceCommandGenerator.fan3Close();
case heat_module_04 -> deviceCommand = DeviceCommandGenerator.fan4Close();
default -> throw new RuntimeException("index 未找到");
}
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

46
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java

@ -0,0 +1,46 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理启动加热器指令
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heater_start")
public class DebugHeaterStartCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
String index = cmdDTO.getStringParam("index");
Double temperature = cmdDTO.getDoubleParam("temperature");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(index);
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
case heat_module_01 -> deviceCommand = DeviceCommandGenerator.heatRod1Open(temperature);
case heat_module_02 -> deviceCommand = DeviceCommandGenerator.heatRod2Open(temperature);
case heat_module_03 -> deviceCommand = DeviceCommandGenerator.heatRod3Open(temperature);
case heat_module_04 -> deviceCommand = DeviceCommandGenerator.heatRod4Open(temperature);
default -> throw new RuntimeException("index 未找到");
}
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

45
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java

@ -0,0 +1,45 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理停止加热器指令 todo 小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("heater_stop")
public class DebugHeaterStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
String index = cmdDTO.getStringParam("index");
HeatModuleCode heatModuleId = HeatModuleCode.valueOf(index);
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
case heat_module_01 -> deviceCommand = DeviceCommandGenerator.heatRod1Close();
case heat_module_02 -> deviceCommand = DeviceCommandGenerator.heatRod2Close();
case heat_module_03 -> deviceCommand = DeviceCommandGenerator.heatRod3Close();
case heat_module_04 -> deviceCommand = DeviceCommandGenerator.heatRod4Close();
default -> throw new RuntimeException("index 未找到");
}
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

46
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java

@ -0,0 +1,46 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.AcidPumpDeviceCode;
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.StepMotorCtrlDriver;
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理加液泵启动指令 todo 需要加正向反向
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_pump_start")
public class DebugLiquidPumpStartCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final StepMotorCtrlDriver stepMotorCtrlDriver;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
Double velocity = cmdDTO.getDoubleParam("velocity");
String direction=cmdDTO.getStringParam("direction");//front back 正转倒转
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.liquid_pump;
DeviceCommandBundle deviceCommand;
if (velocity != null) {
deviceCommand = DeviceCommandGenerator.acidPump1Set(velocity);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
stepMotorCtrlDriver.stepMotorEnable(StepMotorMId.ACID_PUMP_1_MOTOR_MID, 1);
});
}
}

41
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStopCommand.java

@ -0,0 +1,41 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.enums.AcidPumpDeviceCode;
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.StepMotorCtrlDriver;
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 处理加液泵停止指令
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_pump_stop")
public class DebugLiquidPumpStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final StepMotorCtrlDriver stepMotorCtrlDriver;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.liquid_pump;
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.liquidPumpStop();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
stepMotorCtrlDriver.stepMotorEnable(StepMotorMId.ACID_PUMP_1_MOTOR_MID, 0);
});
}
}

75
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidMoveByCommand.java

@ -0,0 +1,75 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 加液位电机相对移动
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("motor_liquid_move_by")
public class DebugMotorLiquidMoveByCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private boolean stop = false;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
this.stop = false;
return runAsync(() -> {
Double dimDistance = cmdDTO.getDoubleParam("distance");
Double dimVelocity = cmdDTO.getDoubleParam("velocity");
Integer times = cmdDTO.getIntegerParam("times");
if (dimVelocity != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidSet(dimVelocity);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (times != null) {
for (int i = 0; i < times; i++) {
if (stop) {
return;
}
if (dimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidSet(dimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (dimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidSet(-dimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
} else {
if (dimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidSet(dimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
});
}
public synchronized void stop() {
this.stop = true;
}
}

37
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidMoveToCommand.java

@ -0,0 +1,37 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 加液位电机绝对移动
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("motor_liquid_position")
public class DebugMotorLiquidMoveToCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
double position = cmdDTO.getDoubleParam("position");
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidSet(position);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidResetCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 加液位电机复位
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("motor_liquid_origin")
public class DebugMotorLiquidResetCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidOrigin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorLiquidStopCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 加液位电机停止
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("motor_liquid_stop")
public class DebugMotorLiquidStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.motorLiquidStop();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

78
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveByCommand.java

@ -0,0 +1,78 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* x轴电机相对移动
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_x_move_by")
public class DebugMotorXMoveByCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private boolean stop = false;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
this.stop = false;
return runAsync(() -> {
Double xDimDistance = cmdDTO.getDoubleParam("distance");
Double xDimVelocity = cmdDTO.getDoubleParam("velocity");
Integer times = cmdDTO.getIntegerParam("times");
if (xDimVelocity != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXSet(xDimVelocity);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (times != null) {
for (int i = 0; i < times; i++) {
if (stop) {
return;
}
if (xDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXMoveBy(xDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (xDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXMoveBy(-xDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
} else {
if (xDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXMoveBy(xDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
});
}
public synchronized void stop() {
this.stop = true;
}
}

41
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveToCommand.java

@ -0,0 +1,41 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* x轴电机绝对移动
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_x_move_to")
public class DebugMotorXMoveToCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private boolean stop = false;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
double position = cmdDTO.getDoubleParam("position");
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXMove(position);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
public synchronized void stop() {
this.stop = true;
}
}

39
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXOriginCommand.java

@ -0,0 +1,39 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
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;
/**
* 处理复位x轴电机复位
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_x_origin")
public class DebugMotorXOriginCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
List<CommandFuture> futuresList = new ArrayList<>();
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXOrigin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
futuresList.add(deviceCommandFuture);
commandWait(futuresList.toArray(new CommandFuture[0]));
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXStopCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* x轴电机停止
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_x_stop")
public class DebugMotorXStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryXStop();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

76
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveByCommand.java

@ -0,0 +1,76 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* z轴电机相对移动
*
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_z_move_by")
public class DebugMotorZMoveByCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private boolean stop = false;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
this.stop = false;
return runAsync(() -> {
Double zDimDistance = cmdDTO.getDoubleParam("distance");
Double zDimVelocity = cmdDTO.getDoubleParam("velocity");
Integer times = cmdDTO.getIntegerParam("times");
if (zDimVelocity != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZSet(zDimVelocity);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (times != null) {
for (int i = 0; i < times; i++) {
if (stop) {
return;
}
if (zDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZMoveBy(zDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (zDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZMoveBy(-zDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
} else {
if (zDimDistance != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZMoveBy(zDimDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
}
});
}
public synchronized void stop() {
this.stop = true;
}
}

37
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveToCommand.java

@ -0,0 +1,37 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* z轴电机绝对移动
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_z_position")
public class DebugMotorZMoveToCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
double position = cmdDTO.getDoubleParam("position");
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZMove(position);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZOriginCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* z轴电机复位
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_z_origin")
public class DebugMotorZOriginCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZOrigin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZStopCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* z轴电机停止
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("gantry_z_stop")
public class DebugMotorZStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.gantryZStop();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenThickWayCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇 todo 需要与小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_valve_open_thick_way")
public class DebugValveOpenThickWayCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand=DeviceCommandGenerator.valveTurn();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenThinWayCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇 todo 需要与小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_valve_open_thin_way")
public class DebugValveOpenThinWayCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand=DeviceCommandGenerator.valveTurn();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenVacantWayCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇 todo 需要与小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_valve_open_vacant_way")
public class DebugValveOpenVacantWayCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand=DeviceCommandGenerator.valveTurn();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenWasteWayCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇 todo 需要与小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_valve_open_waste_way")
public class DebugValveOpenWasteWayCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand=DeviceCommandGenerator.valveTurn();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

35
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugValveOpenWaterWayCommand.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 打开冷却风扇 todo 需要与小何确定次序
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("liquid_valve_open_water_way")
public class DebugValveOpenWaterWayCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle deviceCommand=DeviceCommandGenerator.valveTurn();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
});
}
}

31
src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java

@ -0,0 +1,31 @@
package com.iflytop.sgs.app.cmd.debug.step;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.StepCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 失能所有电机
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("debug_disabled_all_motor")
public class DebugDisabledAllMotorCommand extends BaseCommandHandler {
private final StepCommandService stepCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
return runAsync(() -> {
stepCommandService.disabilityAll();
});
}
}

31
src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java

@ -0,0 +1,31 @@
package com.iflytop.sgs.app.cmd.debug.step;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.StepCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 使能所有电机
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("debug_enable_all_motor")
public class DebugEnableAllMotorCommand extends BaseCommandHandler {
private final StepCommandService stepCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
return runAsync(() -> {
stepCommandService.enableAll();
});
}
}

30
src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java

@ -0,0 +1,30 @@
package com.iflytop.sgs.app.cmd.debug.step;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.StepCommandService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 停止所有电机
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("debug_stop_all_motor")
public class DebugStopAllMotorCommand extends BaseCommandHandler {
private final StepCommandService stepCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) throws Exception {
return runAsync(() -> {
stepCommandService.stopAll();
});
}
}

32
src/main/java/com/iflytop/sgs/app/config/A8kCanBusConnectionConfig.java

@ -0,0 +1,32 @@
package com.iflytop.sgs.app.config;
import com.iflytop.sgs.hardware.comm.can.A8kCanBusConnection;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class A8kCanBusConnectionConfig {
//协议参考 https://iflytop1.feishu.cn/wiki/QFwVwGnI8iYp0fk20W9cnpYAnkg
@Value("${iflytophald.ip}")
String ip;
@Value("${iflytophald.cmdch.port}")
Integer cmdchPort;
@Value("${iflytophald.datach.port}")
Integer datachPort;
public String getDatachUrl(String datachannel) {
return String.format("ws://%s:%d/%s", ip, datachPort, datachannel);
}
public String getCmdChBaseUrl(String cmdchannel) {
return String.format("http://%s:%d/%s", ip, cmdchPort, cmdchannel);
}
@Bean
A8kCanBusConnection a8kCanBusBaseService() {
return new A8kCanBusConnection(getCmdChBaseUrl("zexcan"), getDatachUrl("zexcan"));
}
}

21
src/main/java/com/iflytop/sgs/app/config/AsyncConfig.java

@ -0,0 +1,21 @@
package com.iflytop.sgs.app.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
public class AsyncConfig {
@Bean("commandTaskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
exec.setCorePoolSize(10);
exec.setMaxPoolSize(20);
exec.setQueueCapacity(50);
exec.setThreadNamePrefix("cmd-exec-");
exec.setWaitForTasksToCompleteOnShutdown(true);
exec.setAwaitTerminationSeconds(30);
exec.initialize();
return exec;
}
}

76
src/main/java/com/iflytop/sgs/app/config/CraftsStateMachineConfig.java

@ -0,0 +1,76 @@
package com.iflytop.sgs.app.config;
import com.iflytop.sgs.common.enums.automaton.CraftEvents;
import com.iflytop.sgs.common.enums.automaton.CraftStates;
import org.springframework.context.annotation.Configuration;
import org.springframework.statemachine.config.EnableStateMachineFactory;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
import java.util.EnumSet;
@Configuration
@EnableStateMachineFactory
public class CraftsStateMachineConfig
extends StateMachineConfigurerAdapter<CraftStates, CraftEvents> {
@Override
public void configure(StateMachineStateConfigurer<CraftStates, CraftEvents> states) throws Exception {
states
.withStates()
.initial(CraftStates.READY)
.states(EnumSet.allOf(CraftStates.class));
}
@Override
public void configure(StateMachineTransitionConfigurer<CraftStates, CraftEvents> trans) throws Exception {
trans
// 启动
.withExternal()
.source(CraftStates.READY)
.target(CraftStates.RUNNING)
.event(CraftEvents.START)
.and()
// 单步完成保持 RUNNING
.withInternal()
.source(CraftStates.RUNNING)
.event(CraftEvents.STEP_COMPLETE)
.and()
// 暂停
.withExternal()
.source(CraftStates.RUNNING)
.target(CraftStates.PAUSED)
.event(CraftEvents.PAUSE)
.and()
// 恢复
.withExternal()
.source(CraftStates.PAUSED)
.target(CraftStates.RUNNING)
.event(CraftEvents.RESUME)
.and()
// 用户手动停止RUNNING STOPPED
.withExternal()
.source(CraftStates.RUNNING)
.target(CraftStates.STOPPED)
.event(CraftEvents.STOP)
.and()
// 用户手动停止PAUSED STOPPED
.withExternal()
.source(CraftStates.PAUSED)
.target(CraftStates.STOPPED)
.event(CraftEvents.STOP)
.and()
// 出错
.withExternal()
.source(CraftStates.RUNNING)
.target(CraftStates.ERROR)
.event(CraftEvents.ERROR_OCCUR)
.and()
// 正常完成
.withExternal()
.source(CraftStates.RUNNING)
.target(CraftStates.FINISHED)
.event(CraftEvents.FINISH);
}
}

61
src/main/java/com/iflytop/sgs/app/config/MybatisPlusConfig.java

@ -0,0 +1,61 @@
package com.iflytop.sgs.app.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.iflytop.sgs.common.handler.MyMetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
*
*/
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 乐观锁插件
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
// 分页插件
interceptor.addInnerInterceptor(paginationInnerInterceptor());
return interceptor;
}
/**
* 分页插件自动识别数据库类型
* <a href="https://baomidou.com/guide/interceptor-pagination.html">...</a>
*/
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
// 设置数据库类型
paginationInnerInterceptor.setDbType(DbType.SQLITE);
// 设置最大单页限制数量默认 500 -1 不受限制
paginationInnerInterceptor.setMaxLimit(-1L);
return paginationInnerInterceptor;
}
/**
* 乐观锁插件
* <a href="https://baomidou.com/guide/interceptor-optimistic-locker.html">...</a>
*/
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
return new OptimisticLockerInnerInterceptor();
}
/**
* 自动填充数据库创建人创建时间更新人更新时间
*/
@Bean
public GlobalConfig globalConfig() {
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setMetaObjectHandler(new MyMetaObjectHandler());
return globalConfig;
}
}

68
src/main/java/com/iflytop/sgs/app/config/SwaggerConfig.java

@ -0,0 +1,68 @@
package com.iflytop.sgs.app.config;
import cn.hutool.core.util.ArrayUtil;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.util.AntPathMatcher;
import java.util.stream.Stream;
/***
* 创建Swagger配置
*/
@Configuration
public class SwaggerConfig {
@Bean
public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
return openApi -> {
// 全局添加Authorization
if (openApi.getPaths() != null) {
openApi.getPaths().forEach((path, pathItem) -> {
// 忽略认证的请求无需携带 Authorization
String[] ignoreUrls = {"/api/auth/login"};
if (ArrayUtil.isNotEmpty(ignoreUrls)) {
// Ant 匹配忽略的路径不添加Authorization
AntPathMatcher antPathMatcher = new AntPathMatcher();
if (Stream.of(ignoreUrls).anyMatch(ignoreUrl -> antPathMatcher.match(ignoreUrl, path))) {
return;
}
}
// 其他接口统一添加Authorization
// pathItem.readOperations()
// .forEach(operation ->
// operation.addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
// );
});
}
};
}
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("系统API")
.version("1.0")) // 配置全局鉴权参数-Authorize
.components(new Components()
.addSecuritySchemes(HttpHeaders.AUTHORIZATION,
new SecurityScheme()
.name(HttpHeaders.AUTHORIZATION)
.type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER)
.scheme("Bearer")
.bearerFormat("JWT")
)
);
}
}

16
src/main/java/com/iflytop/sgs/app/config/WebConfig.java

@ -0,0 +1,16 @@
package com.iflytop.sgs.app.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*");
}
}

57
src/main/java/com/iflytop/sgs/app/controller/AuthController.java

@ -0,0 +1,57 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.iflytop.sgs.app.model.dto.LoginDTO;
import com.iflytop.sgs.app.model.entity.User;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.UserService;
import com.iflytop.sgs.common.enums.data.Deleted;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
* 认证控制
*/
@Tag(name = "认证")
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
@Slf4j
public class AuthController {
private final UserService userService;
private final DeviceStateService deviceStateService;
@Operation(summary = "账号密码登录")
@PostMapping("/login")
public Result<User> login(@Valid @RequestBody LoginDTO loginDTO) {
User user = userService.getOne(new LambdaQueryWrapper<>(User.class).eq(User::getUsername, loginDTO.getUsername()));
if (user != null && !Objects.equals(user.getDeleted(), Deleted.ENABLE) && user.getPassword().equals(loginDTO.getPassword())) {
deviceStateService.setCurrentUser(user);
user.setPassword(null);
return Result.success(user);
}
return Result.failed(ResultCode.INVALID_CREDENTIALS);
}
@Operation(summary = "用户登出")
@PostMapping("/logout")
public Result<String> logout() {
deviceStateService.setCurrentUser(null);
return Result.success();
}
@Operation(summary = "获取当前登录用户")
@GetMapping("/current")
public Result<User> current() {
return Result.success(deviceStateService.getDeviceState().getCurrentUser());
}
}

74
src/main/java/com/iflytop/sgs/app/controller/CmdController.java

@ -0,0 +1,74 @@
package com.iflytop.sgs.app.controller;
import cn.hutool.json.JSONUtil;
import com.iflytop.sgs.app.core.CommandHandlerRegistry;
import com.iflytop.sgs.app.core.DebugGenerator;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.WebSocketService;
import com.iflytop.sgs.common.cmd.CommandHandler;
import com.iflytop.sgs.common.constant.CommandStatus;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
@Tag(name = "前端业务指令")
@RestController
@RequestMapping("/api/cmd")
@RequiredArgsConstructor
@Slf4j
public class CmdController {
private final CommandHandlerRegistry registry;
private final WebSocketService webSocketService;
private final DeviceStateService deviceStateService;
@Operation(summary = "前端统一调用一个接口")
@PostMapping
public Result<?> controlMethod(@Valid @RequestBody CmdDTO cmdDTO) throws Exception {
String commandId = cmdDTO.getCommandId();
String command = cmdDTO.getCommand();
try {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.RECEIVE, "已收到业务指令请求,开始处理"));
if (deviceStateService.getDeviceState().isEmergencyStop()) {
throw new AppException(ResultCode.EMERGENCY_STOP);
}
CommandHandler commandHandler = registry.getCommandHandler(command);
if (commandHandler == null) {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.DEVICE_ERROR, "未找到对应的业务指令"));
log.error("未找到对应的业务指令");
return Result.failed();
}
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.START, "业务指令开始执行"));
log.info("业务指令开始执行");
CompletableFuture<Void> future = commandHandler.handle(cmdDTO);
future.whenComplete((v, ex) -> {
if (ex != null) {
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.FAIL, "执行业务指令发生异常", ex.getMessage()));
log.error("执行业务指令发生异常: {}", JSONUtil.toJsonStr(cmdDTO), ex);
} else {
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.SUCCESS, "业务指令执行成功"));
log.info("业务指令执行成功");
}
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.FINISH, "业务指令执行结束"));
log.info("业务指令执行结束");
});
} catch (Exception e) {
log.error("执行业务指令发生异常: {}", JSONUtil.toJsonStr(cmdDTO), e);
return Result.failed(e.getMessage());
}
return Result.success();
}
}

67
src/main/java/com/iflytop/sgs/app/controller/CmdDebugController.java

@ -0,0 +1,67 @@
package com.iflytop.sgs.app.controller;
import cn.hutool.json.JSONUtil;
import com.iflytop.sgs.app.core.CommandHandlerRegistry;
import com.iflytop.sgs.app.core.DebugGenerator;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.WebSocketService;
import com.iflytop.sgs.common.cmd.CommandHandler;
import com.iflytop.sgs.common.constant.CommandStatus;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
@Tag(name = "前端调试指令")
@RestController
@RequestMapping("/api/debug/cmd")
@RequiredArgsConstructor
@Slf4j
public class CmdDebugController {
private final CommandHandlerRegistry registry;
private final WebSocketService webSocketService;
@Operation(summary = "前端调试指令")
@PostMapping
public Result<?> controlMethod(@Valid @RequestBody CmdDTO cmdDTO) {
String commandId = cmdDTO.getCommandId();
String command = cmdDTO.getCommand();
try {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.RECEIVE, "已收到调试指令请求,开始处理"));
CommandHandler commandHandler = registry.getCommandHandler(command);
if (commandHandler == null) {
webSocketService.pushDebug(DebugGenerator.generateJson(commandId, command, CommandStatus.DEVICE_ERROR, "未找到对应的调试指令"));
log.error("未找到对应的调试指令");
return Result.failed();
}
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.START, "调试指令开始执行"));
log.info("调试指令开始执行");
CompletableFuture<Void> future = commandHandler.handle(cmdDTO);
future.whenComplete((v, ex) -> {
if (ex != null) {
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.FAIL, "执行调试指令发生异常", ex.getMessage()));
log.error("执行调试指令发生异常: {}", JSONUtil.toJsonStr(cmdDTO), ex);
} else {
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.SUCCESS, "调试指令执行成功"));
log.info("调试指令执行成功");
}
webSocketService.pushCMDResponse(DebugGenerator.generateJson(commandId, command, CommandStatus.FINISH, "调试指令执行结束"));
log.info("调试指令执行结束");
});
} catch (Exception e) {
log.error("执行调试指令发生异常: {}", JSONUtil.toJsonStr(cmdDTO), e);
return Result.failed(e.getMessage());
}
return Result.success();
}
}

34
src/main/java/com/iflytop/sgs/app/controller/ContainerController.java

@ -0,0 +1,34 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.entity.Container;
import com.iflytop.sgs.app.service.ContainerService;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "容器")
@RestController
@RequestMapping("/api/container")
@RequiredArgsConstructor
@Slf4j
public class ContainerController {
private final ContainerService containerService;
@Operation(summary = "容器列表")
@GetMapping("/list")
public Result<List<Container>> getList() {
return Result.success(containerService.getList());
}
@Operation(summary = "更新容器配置")
@PutMapping("")
public Result<Boolean> update(@Valid @RequestBody Container container) {
return Result.success(containerService.updateById(container));
}
}

112
src/main/java/com/iflytop/sgs/app/controller/CraftsController.java

@ -0,0 +1,112 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.dto.*;
import com.iflytop.sgs.app.model.entity.Crafts;
import com.iflytop.sgs.app.model.vo.SetCraftsVO;
import com.iflytop.sgs.app.service.CraftsService;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Tag(name = "工艺管理")
@RestController
@RequestMapping("/api/crafts")
@RequiredArgsConstructor
@Slf4j
@Validated
public class CraftsController {
private final CraftsService craftsService;
@Operation(summary = "根据矿石id获取工艺列表")
@GetMapping("/list/{oresId}")
public Result<List<Crafts>> getList(
@NotNull(message = "矿石ID 不能为空")
@Min(value = 1, message = "矿石ID 必须大于等于 1")
@Parameter(description = "矿石ID") @PathVariable Long oresId) {
List<Crafts> craftList = craftsService.selectAllByOresId(oresId);
return Result.success(craftList);
}
@Operation(summary = "添加新工艺")
@PostMapping("")
public Result<String> add(@Valid @RequestBody Crafts crafts) {
Crafts existingCrafts = craftsService.findByName(crafts.getName());
if (existingCrafts == null) {
boolean isSuccess = craftsService.save(crafts);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "更新工艺")
@PutMapping("")
public Result<String> updateCrafts(@Valid @RequestBody Crafts crafts) {
boolean isSuccess = craftsService.updateById(crafts);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
@Operation(summary = "删除工艺")
@DeleteMapping("/{ids}")
public Result<String> delete(
@Parameter(description = "工艺ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = craftsService.deleteCrafts(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
@Operation(summary = "配置加热区工艺")
@PostMapping("/set")
public Result<SetCraftsVO> setCrafts(@Valid @RequestBody SetCraftsDTO setCraftsDTO) {
return Result.success(craftsService.setCraft(setCraftsDTO.getCraftId(), setCraftsDTO.getHeatId()));
}
@Operation(summary = "开始执行工艺")
@PostMapping("/start")
public Result<String> startCrafts(@Valid @RequestBody StartCraftsDTO startCraftsDTO) {
craftsService.startCrafts(startCraftsDTO.getHeatId());
return Result.success();
}
@Operation(summary = "暂停执行工艺")
@PostMapping("/pause")
public Result<String> pauseCrafts(@Valid @RequestBody PauseCraftsDto pauseCraftsDto) {
craftsService.pauseCrafts(pauseCraftsDto.getHeatId());
return Result.success();
}
@Operation(summary = "恢复执行工艺")
@PostMapping("/resume")
public Result<String> resumeCrafts(@Valid @RequestBody ResumeCraftsDTO resumeCraftsDto) {
craftsService.resumeCrafts(resumeCraftsDto.getHeatId());
return Result.success();
}
@Operation(summary = "停止执行工艺")
@PostMapping("/stop")
public Result<String> stopCrafts(@Valid @RequestBody StopCraftsDTO stopCraftsDto) {
craftsService.stopCrafts(stopCraftsDto.getHeatId());
return Result.success();
}
}

121
src/main/java/com/iflytop/sgs/app/controller/DeviceParamController.java

@ -0,0 +1,121 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.entity.DeviceParamConfig;
import com.iflytop.sgs.app.model.vo.DeviceParamGroupVO;
import com.iflytop.sgs.app.model.vo.ModuleIdVO;
import com.iflytop.sgs.app.model.vo.RegIndexVO;
import com.iflytop.sgs.app.service.DeviceParamConfigService;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* 设备参数配置
*/
@Tag(name = "设备参数配置")
@RestController
@RequestMapping("/api/device-param")
@RequiredArgsConstructor
@Slf4j
public class DeviceParamController {
private final DeviceParamConfigService deviceParamConfigService;
@Operation(summary = "获取所有设备配置")
@GetMapping("/list")
public Result<List<DeviceParamGroupVO>> getList() {
List<DeviceParamGroupVO> vos = deviceParamConfigService.listGroupedByModule();
return Result.success(vos);
}
@Operation(summary = "获取所有设备模块")
@GetMapping("/modules")
public Result<List<ModuleIdVO>> listAllModules() {
List<ModuleIdVO> vos = deviceParamConfigService.listAllModuleIds();
return Result.success(vos);
}
@Operation(summary = "获取所有设备模块配置项")
@GetMapping("/reg-indices")
public Result<List<RegIndexVO>> listAllRegIndices() {
List<RegIndexVO> vos = deviceParamConfigService.listAllRegIndices();
return Result.success(vos);
}
@Operation(summary = "添加新配置")
@PostMapping("")
public Result<String> add(@Valid @RequestBody DeviceParamConfig deviceParamConfig) {
deviceParamConfigService.save(deviceParamConfig);
return Result.success();
}
@Operation(summary = "修改配置")
@PutMapping("")
public Result<String> update(@Valid @RequestBody DeviceParamConfig deviceParamConfig) {
deviceParamConfigService.updateById(deviceParamConfig);
return Result.success();
}
@Operation(summary = "删除配置")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "矿石ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = deviceParamConfigService.deleteDeviceParam(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
@Operation(summary = "上传csv文件覆盖数据库配置")
@PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Result<String> uploadFile(@RequestPart("file") MultipartFile file) {
//文件后缀检查
if (!file.getOriginalFilename().endsWith(".csv")) {
return Result.failed("<UNK>.csv<UNK>");
}
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) {
String line;
//是否含有表头
boolean isHeader = true;
List<DeviceParamConfig> deviceParamConfigList = new ArrayList<>();
while ((line = reader.readLine()) != null) {
if (isHeader) {
isHeader = false;
continue; // 跳过CSV文件的标题行
}
String[] data = line.split(",");
if (data.length >= 4) { // 假设CSV文件至少包含4列
DeviceParamConfig deviceParamConfig = new DeviceParamConfig();
deviceParamConfig.setId(Long.valueOf(data[0]));
deviceParamConfig.setMid(String.valueOf(data[1]));
deviceParamConfig.setRegIndex(String.valueOf(data[2]));
deviceParamConfig.setRegVal(Integer.valueOf(data[3]));
deviceParamConfigService.save(deviceParamConfig);
deviceParamConfigList.add(deviceParamConfig);
}
}
deviceParamConfigService.saveOrUpdateBatch(deviceParamConfigList);
} catch (IOException e) {
log.error("csv文件导入数据库失败:{}", e.getMessage());
throw new RuntimeException(e);
}
return Result.success();
}
}

59
src/main/java/com/iflytop/sgs/app/controller/DevicePointController.java

@ -0,0 +1,59 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.dto.AddDevicePositionDTO;
import com.iflytop.sgs.app.model.entity.DevicePosition;
import com.iflytop.sgs.app.model.vo.DevicePositionVO;
import com.iflytop.sgs.app.service.DevicePositionService;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 设备点位接口
*/
@Tag(name = "设备位置配置")
@RestController
@RequestMapping("/api/device-point")
@RequiredArgsConstructor
@Slf4j
public class DevicePointController {
private final DevicePositionService devicePointService;
@Operation(summary = "列表")
@GetMapping("/list")
public Result<List<DevicePositionVO>> listGroupedParams() {
List<DevicePositionVO> devicePointVOList = devicePointService.getList();
return Result.success(devicePointVOList);
}
@Operation(summary = "添加")
@PostMapping("")
public Result<String> add(@Valid @RequestBody DevicePosition devicePoint) {
devicePointService.save(devicePoint);
return Result.success();
}
@Operation(summary = "修改")
@PutMapping("")
public Result<?> update(@Valid @RequestBody AddDevicePositionDTO addDevicePositionDTO) {
return Result.success(devicePointService.updatePosition(addDevicePositionDTO));
}
@Operation(summary = "删除")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "位置ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = devicePointService.deletePositon(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
}

33
src/main/java/com/iflytop/sgs/app/controller/HeatModuleController.java

@ -0,0 +1,33 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.vo.SetTargetTemperatureVO;
import com.iflytop.sgs.app.service.HeatModuleService;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 加热模块控制 todo wmy 需要和前端同步参数 加热 烘干 退火
*/
@Tag(name = "加热模块控制")
@RestController
@RequestMapping("/api/heat")
@RequiredArgsConstructor
@Slf4j
public class HeatModuleController {
private final HeatModuleService heatModuleService;
@Operation(summary = "加热模块设定目标温度")
@PostMapping("/target-temperature")
public Result<String> setTargetTemperature(@Valid @RequestBody SetTargetTemperatureVO setTargetTemperatureVO) {
heatModuleService.setTargetTemperature(setTargetTemperatureVO);
return Result.success();
}
}

74
src/main/java/com/iflytop/sgs/app/controller/OresController.java

@ -0,0 +1,74 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iflytop.sgs.app.model.entity.Ores;
import com.iflytop.sgs.app.model.vo.OresCraftsListVO;
import com.iflytop.sgs.app.service.OresService;
import com.iflytop.sgs.common.base.BasePageQuery;
import com.iflytop.sgs.common.result.PageResult;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Tag(name = "矿石管理")
@RestController
@RequestMapping("/api/ores")
@RequiredArgsConstructor
@Slf4j
public class OresController {
private final OresService oresService;
@Operation(summary = "矿石工艺列表")
@GetMapping("/list")
public PageResult<OresCraftsListVO> getList(BasePageQuery pageQuery) {
IPage<OresCraftsListVO> result = oresService.getPage(pageQuery);
return PageResult.success(result);
}
@Operation(summary = "添加新矿石")
@PostMapping("")
public Result<String> add(@Valid @RequestBody Ores ores) {
Ores existingOres = oresService.findByName(ores.getName());
if (existingOres == null) {
boolean isSuccess = oresService.addOres(ores);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "更新矿石")
@PutMapping("")
public Result<String> update(@Valid @RequestBody Ores ores) {
Ores existingOres = oresService.findByName(ores.getName());
if (existingOres == null) {
boolean isSuccess = oresService.updateOres(ores);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "删除矿石")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "矿石ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = oresService.deleteOres(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
}

59
src/main/java/com/iflytop/sgs/app/controller/SelfTestController.java

@ -0,0 +1,59 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.core.device.SelfTestState;
import com.iflytop.sgs.app.service.DeviceCommandUtilService;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.SelfTestService;
import com.iflytop.sgs.common.result.Result;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "自检")
@RestController
@RequestMapping("/api/self-test")
@RequiredArgsConstructor
@Slf4j
public class SelfTestController {
private final SelfTestService selfTestService;
private final DeviceStateService deviceStateService;
private final DeviceCommandUtilService deviceCommandUtilService;
@Operation(summary = "获取自检状态")
@GetMapping("/status")
public Result<SelfTestState> getSelfTestStatus() {
return Result.success(selfTestService.getSelfTestState());
}
@Operation(summary = "自检完毕")
@PostMapping("/finish")
public Result<?> selfTestFinish() throws Exception {
deviceStateService.setSelfTest(true);
new Thread(() -> {
try {
//deviceCommandUtilService.capMotorMove(21);
} catch (Exception e) {
log.error("拍子存放区初始化上升失败", e);
}
}).start();
return Result.success();
}
@Operation(summary = "改变自检状态")
@PostMapping("/isFinish")
public Result<?> selfTestFinish(boolean isFinish) throws Exception {
deviceStateService.setSelfTest(isFinish);
new Thread(() -> {
try {
//deviceCommandUtilService.capMotorMove(21);
} catch (Exception e) {
log.error("拍子存放区初始化上升失败", e);
}
}).start();
return Result.success();
}
}

74
src/main/java/com/iflytop/sgs/app/controller/SolutionsController.java

@ -0,0 +1,74 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytop.sgs.app.model.entity.Solutions;
import com.iflytop.sgs.app.service.SolutionsService;
import com.iflytop.sgs.common.base.BasePageQuery;
import com.iflytop.sgs.common.result.PageResult;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Tag(name = "溶液管理")
@RestController
@RequestMapping("/api/sols")
@RequiredArgsConstructor
@Slf4j
public class SolutionsController {
private final SolutionsService solutionsService;
@Operation(summary = "溶液列表")
@GetMapping("/list")
public PageResult<Solutions> getAllSols(BasePageQuery pageQuery) {
IPage<Solutions> result = solutionsService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null);
return PageResult.success(result);
}
@Operation(summary = "添加新溶液")
@PostMapping("")
public Result<String> addSolutions(@Valid @RequestBody Solutions solutions) {
Solutions existingSolutions = solutionsService.findByName(solutions.getName());
if (existingSolutions == null) {
boolean isSuccess = solutionsService.addSolutions(solutions);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "更新溶液")
@PutMapping("")
public Result<String> updateSolutions(@Valid @RequestBody Solutions solutions) {
Solutions existingSolutions = solutionsService.findByName(solutions.getName());
if (existingSolutions == null) {
boolean isSuccess = solutionsService.updateSolutions(solutions);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.DATA_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "删除溶液")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "溶液ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = solutionsService.deleteSolutions(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
}

72
src/main/java/com/iflytop/sgs/app/controller/StepCommandController.java

@ -0,0 +1,72 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.service.StepCommandService;
import com.iflytop.sgs.common.result.Result;
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.*;
@Tag(name = "单步调试")
@RestController
@RequestMapping("/api/cmd/step")
@RequiredArgsConstructor
@Slf4j
public class StepCommandController {
private final StepCommandService stepCommandService;
@Operation(summary = "获取当前龙门架机械臂坐标")
@GetMapping("/gantry-point")
public Result<String> getGantryPoint() throws Exception {
Point3D point3D = stepCommandService.getGantryPoint();
return Result.success(point3D.getX() + "," + point3D.getY() + "," + point3D.getZ());
}
@Operation(summary = "获取指定加热区升降当前位置")
@GetMapping("/heat-lifting-position/{heatId}")
public Result<String> getHeatLiftingPosition(@PathVariable String heatId) throws Exception {
double capPosition = stepCommandService.getHeatMotorPostion(heatId);
return Result.success(String.valueOf(capPosition));
}
@Operation(summary = "获取拍子存放区升降当前位置")
@GetMapping("/cap-lifting-position")
public Result<String> getHeatPosition() throws Exception {
double capPosition = stepCommandService.getCapMotorPostion();
return Result.success(String.valueOf(capPosition));
}
@Operation(summary = "使能所有电机")
@PostMapping("/enable-all")
public Result<?> enableAll() throws Exception {
stepCommandService.enableAll();
return Result.success();
}
@Operation(summary = "失能所有电机")
@PostMapping("/disability-all")
public Result<?> disabilityAll() throws Exception {
stepCommandService.disabilityAll();
return Result.success();
}
@Operation(summary = "停止所有电机")
@PostMapping("/stop-all")
public Result<?> stopAll() throws Exception {
stepCommandService.stopAll();
return Result.success();
}
@Operation(summary = "龙门架移至指定坐标")
@PostMapping("/gantry-to-point3d")
public Result<?> gantryToTray(Point3D point3D) throws Exception {
stepCommandService.gantryToPoint3D(point3D);
return Result.success();
}
//移动到指定拍子上方加热模块拍子存放
//移动至指定托盘上方加热模块加液模块
}

51
src/main/java/com/iflytop/sgs/app/controller/SystemController.java

@ -0,0 +1,51 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.core.device.DeviceState;
import com.iflytop.sgs.app.model.dto.SetSystemDatetimeDTO;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.SystemConfigService;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Tag(name = "系统")
@RestController
@RequestMapping("/api/sys")
@RequiredArgsConstructor
@Slf4j
public class SystemController {
private final SystemConfigService systemConfigService;
private final DeviceStateService deviceStateService;
@Operation(summary = "是否启动虚拟模式")
@PostMapping("/virtual")
public Result<?> changeVirtualMode(Boolean mode) {
deviceStateService.setVirtual(mode);
return Result.success();
}
@Operation(summary = "模拟向硬件写入完毕")
@PostMapping("/initComplete")
public Result<?> setInitComplete(Boolean initComplete) {
deviceStateService.setInitComplete(initComplete);
return Result.success();
}
@Operation(summary = "系统状态")
@GetMapping("/device-status")
public Result<DeviceState> getDeviceStatus() {
return Result.success(deviceStateService.getDeviceState());
}
@Operation(summary = "设置系统时间")
@PostMapping("/datetime")
public Result<?> setDatetime(@Valid @RequestBody SetSystemDatetimeDTO setSystemDatetimeDTO) {
systemConfigService.setDatetime(setSystemDatetimeDTO.getDatetime());
return Result.success();
}
}

48
src/main/java/com/iflytop/sgs/app/controller/SystemLogController.java

@ -0,0 +1,48 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytop.sgs.app.model.entity.SystemLog;
import com.iflytop.sgs.app.service.SystemLogService;
import com.iflytop.sgs.common.base.BasePageQuery;
import com.iflytop.sgs.common.result.PageResult;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Tag(name = "系统日志")
@RestController
@RequestMapping("/api/log")
@RequiredArgsConstructor
@Slf4j
public class SystemLogController {
private final SystemLogService systemLogService;
@Operation(summary = "日志列表")
@GetMapping("/list")
public PageResult<SystemLog> list(BasePageQuery pageQuery) {
IPage<SystemLog> result = systemLogService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), null);
return PageResult.success(result);
}
@Operation(summary = "日志详情")
@GetMapping("/{id}")
public Result<?> get(@PathVariable String id) {
SystemLog systemLog = systemLogService.getById(id);
return Result.success(systemLog);
}
@Operation(summary = "删除日志")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = systemLogService.deleteLog(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
}

83
src/main/java/com/iflytop/sgs/app/controller/TasksController.java

@ -0,0 +1,83 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytop.sgs.app.model.dto.GetAllTasksDTO;
import com.iflytop.sgs.app.model.dto.TaskDTO;
import com.iflytop.sgs.app.model.entity.Tasks;
import com.iflytop.sgs.app.model.vo.TaskStepsVO;
import com.iflytop.sgs.app.service.TasksService;
import com.iflytop.sgs.common.result.PageResult;
import com.iflytop.sgs.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@Tag(name = "实验")
@RestController
@RequestMapping("/api/tasks")
@RequiredArgsConstructor
@Slf4j
public class TasksController {
private final TasksService tasksService;
@Operation(summary = "实验列表")
@GetMapping("/list")
public PageResult<Tasks> list(GetAllTasksDTO getAllTasksDTO) {
LambdaQueryWrapper<Tasks> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.like(StringUtils.hasText(getAllTasksDTO.getName()), Tasks::getName, getAllTasksDTO.getName())
.orderByDesc(Tasks::getCreateTime);
IPage<Tasks> result = tasksService.page(
new Page<>(getAllTasksDTO.getPageNum(), getAllTasksDTO.getPageSize()),
queryWrapper
);
return PageResult.success(result);
}
@Operation(summary = "实验详情")
@GetMapping("/{id}")
public Result<TaskStepsVO> detail(@PathVariable Long id) {
return Result.success(tasksService.detail(id));
}
@Operation(summary = "获取正在进行的实验")
@GetMapping("/current")
public Result<Tasks> getCurrent() {
return Result.success(tasksService.getCurrent());
}
@Operation(summary = "开始新实验")
@PostMapping("/")
public Result<Tasks> start(@RequestBody TaskDTO dto) {
if (tasksService.getCurrent() != null) {
return Result.failed("存在正在运行的实验,请先终止");
}
return Result.success(tasksService.start(dto.getName()));
}
@Operation(summary = "更新实验")
@PutMapping("/")
public Result<?> updateTask(@RequestBody Tasks task) {
return Result.success(tasksService.updateById(task));
}
@Operation(summary = "删除实验")
@DeleteMapping("/{ids}")
public Result<?> deleteTask(@Parameter(description = "ID,多个以英文逗号(,)分割") @PathVariable String ids) {
return Result.success(tasksService.deleteTasks(ids));
}
@Operation(summary = "停止当前实验")
@PostMapping("/stop")
public Result<Integer> stop() {
tasksService.stop();
return Result.success();
}
}

47
src/main/java/com/iflytop/sgs/app/controller/TrayController.java

@ -0,0 +1,47 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.core.device.TrayState;
import com.iflytop.sgs.app.model.vo.SetTrayTubeVO;
import com.iflytop.sgs.app.service.TrayService;
import com.iflytop.sgs.common.result.Result;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 托盘控制
*/
@Tag(name = "托盘控制")
@RestController
@RequestMapping("/api/tray")
@RequiredArgsConstructor
@Slf4j
public class TrayController {
private final TrayService trayService;
@Operation(summary = "放入新托盘")
@PostMapping("/in")
public Result<TrayState> trayIn() {
return Result.success(trayService.trayIn());
}
@Operation(summary = "拿走托盘")
@PostMapping("/out")
public Result<?> trayOut() {
trayService.trayOut();
return Result.success();
}
@Operation(summary = "设置托盘试管")
@PostMapping("/tube")
public Result<?> setTrayTube(@RequestBody SetTrayTubeVO setTrayTubeVO) {
trayService.setTrayTube(setTrayTubeVO);
return Result.success();
}
}

72
src/main/java/com/iflytop/sgs/app/controller/UserController.java

@ -0,0 +1,72 @@
package com.iflytop.sgs.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytop.sgs.app.model.entity.User;
import com.iflytop.sgs.app.service.UserService;
import com.iflytop.sgs.common.base.BasePageQuery;
import com.iflytop.sgs.common.enums.data.Deleted;
import com.iflytop.sgs.common.result.PageResult;
import com.iflytop.sgs.common.result.Result;
import com.iflytop.sgs.common.result.ResultCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
@Tag(name = "用户接口")
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {
private final UserService userService;
@Operation(summary = "用户列表")
@GetMapping("/list")
public PageResult<User> getList(BasePageQuery pageQuery) {
IPage<User> result = userService.page(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), new LambdaQueryWrapper<User>().eq(User::getDeleted, Deleted.DISABLE));
result.getRecords().forEach(user -> user.setPassword(null));
return PageResult.success(result);
}
@Operation(summary = "添加新用户")
@PostMapping("")
public Result<String> add(@Valid @RequestBody User user) {
User existingUser = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, user.getUsername()));
if (existingUser == null) {
user.setFixedUser(null);
boolean isSuccess = userService.save(user);
if (isSuccess) {
return Result.success();
}
} else {
return Result.failed(ResultCode.USER_ALREADY_EXISTS);
}
return Result.failed();
}
@Operation(summary = "更新用户信息")
@PutMapping("")
public Result<String> update(@Valid @RequestBody User user) {
boolean isSuccess = userService.updateById(user);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
@Operation(summary = "删除用户")
@DeleteMapping("/{ids}")
public Result<String> delete(@Parameter(description = "用户ID,多个以英文逗号(,)分割") @PathVariable String ids) {
boolean isSuccess = userService.deleteUser(ids);
if (isSuccess) {
return Result.success();
}
return Result.failed();
}
}

33
src/main/java/com/iflytop/sgs/app/core/BaseCommandHandler.java

@ -0,0 +1,33 @@
package com.iflytop.sgs.app.core;
import com.iflytop.sgs.common.annotation.CheckedRunnable;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.CommandHandler;
import com.iflytop.sgs.common.utils.LambdaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
public abstract class BaseCommandHandler implements CommandHandler {
@Autowired
@Qualifier("commandTaskExecutor")
private Executor commandExecutor;
protected CompletableFuture<Void> runAsync(CheckedRunnable task) {
return CompletableFuture.runAsync(LambdaUtil.unchecked(task), commandExecutor);
}
protected void commandWait(CommandFuture... futures) throws Exception {
CompletableFuture<?>[] responseFutures = Arrays.stream(futures)
.map(CommandFuture::getResponseFuture)
.toArray(CompletableFuture[]::new);
CompletableFuture.allOf(responseFutures)
.get(120, TimeUnit.SECONDS);
}
}

58
src/main/java/com/iflytop/sgs/app/core/CommandHandlerRegistry.java

@ -0,0 +1,58 @@
package com.iflytop.sgs.app.core;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.cmd.CommandHandler;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.exception.UnSupportCommandException;
import com.iflytop.sgs.common.result.ResultCode;
import io.micrometer.common.lang.NonNull;
import jakarta.annotation.PostConstruct;
import jakarta.validation.constraints.NotNull;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class CommandHandlerRegistry implements ApplicationContextAware {
private final Map<String, CommandHandler> handlerMap = new HashMap<>();
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@PostConstruct
public void init() {
Map<String, Object> beans = applicationContext.getBeansWithAnnotation(CommandMapping.class);
for (Object bean : beans.values()) {
// 获取实际目标类而不是代理类
Class<?> targetClass = AopUtils.getTargetClass(bean);
CommandMapping mapping = targetClass.getAnnotation(CommandMapping.class);
if (mapping != null && bean instanceof CommandHandler) {
String mappingKey = mapping.value();
handlerMap.put(mappingKey, (CommandHandler) bean);
}
}
}
/**
* 通过模块名称和命令名称获取命令处理器
*
* @param commandName 命令名称
* @return 命令处理器
* @throws UnSupportCommandException
*/
public CommandHandler getCommandHandler(@NotNull String commandName) throws UnSupportCommandException {
if (!handlerMap.containsKey(commandName)) {
throw new AppException(ResultCode.COMMAND_NOT_FOUND);
}
return handlerMap.get(commandName);
}
}

31
src/main/java/com/iflytop/sgs/app/core/CommandPoolManager.java

@ -0,0 +1,31 @@
package com.iflytop.sgs.app.core;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadPoolExecutor;
@Slf4j
@Component
public class CommandPoolManager {
private final ThreadPoolTaskExecutor executor;
public CommandPoolManager(@Qualifier("commandTaskExecutor") ThreadPoolTaskExecutor executor) {
this.executor = executor;
}
/**
* 强制中断所有正在执行的任务
*/
public void forceShutdownAll() {
try {
ThreadPoolExecutor nativeExecutor = executor.getThreadPoolExecutor();
nativeExecutor.shutdownNow();
} catch (Exception e) {
log.error("强制关闭所有cmd线程失败");
}
}
}

151
src/main/java/com/iflytop/sgs/app/core/CraftsContext.java

@ -0,0 +1,151 @@
package com.iflytop.sgs.app.core;
import cn.hutool.json.JSONUtil;
import com.iflytop.sgs.app.model.bo.CraftsStep;
import com.iflytop.sgs.app.model.entity.Crafts;
import com.iflytop.sgs.app.model.entity.Ores;
import com.iflytop.sgs.app.service.CraftsStepService;
import com.iflytop.sgs.app.service.WebSocketService;
import com.iflytop.sgs.common.constant.WebSocketMessageType;
import com.iflytop.sgs.common.enums.automaton.CraftEvents;
import com.iflytop.sgs.common.enums.automaton.CraftStates;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineFactory;
import org.springframework.statemachine.listener.StateMachineListenerAdapter;
import org.springframework.statemachine.state.State;
import reactor.core.publisher.Mono;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Getter
public class CraftsContext implements Runnable {
private final String heatId;
private final Ores ores;
private final Crafts craft;
private final List<CraftsStep> craftsStepList;
private final StateMachine<CraftStates, CraftEvents> sm;
private final WebSocketService webSocketService;
private final CraftsStepService craftsStepService;
private int currentIndex = 0;
/**
* 构造方法初始化上下文并启动状态机至 READY
*/
public CraftsContext(String heatId, Ores ores,
Crafts craft,
StateMachineFactory<CraftStates, CraftEvents> factory,
WebSocketService webSocketService,
CraftsStepService craftsStepService) {
this.heatId = heatId;
this.ores = ores;
this.craft = craft;
this.craftsStepList = JSONUtil.parseArray(craft.getSteps()).toList(CraftsStep.class);
this.webSocketService = webSocketService;
this.craftsStepService = craftsStepService;
this.sm = factory.getStateMachine(heatId);
sm.addStateListener(new StateMachineListenerAdapter<>() {
@Override
public void stateEntered(State<CraftStates, CraftEvents> state) {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("heatId", heatId);
dataMap.put("state", state.getId());
dataMap.put("index", currentIndex);
webSocketService.push(WebSocketMessageType.CRAFTS_STATE, dataMap);
}
});
Mono.from(sm.startReactively()).block();
}
/**
* 执行工艺脚本遍历所有步骤并根据状态机控制流程
*/
@Override
public void run() {
try {
Message<CraftEvents> startMsg = MessageBuilder.withPayload(CraftEvents.START).build();
Mono.from(sm.sendEvent(Mono.just(startMsg))).block();
for (; currentIndex < craftsStepList.size(); currentIndex++) {
if (sm.getState().getId() == CraftStates.STOPPED) break;
CraftsStep step = craftsStepList.get(currentIndex);
boolean ok = executeStep(step);
if (!ok) {
Message<CraftEvents> errMsg = MessageBuilder.withPayload(CraftEvents.ERROR_OCCUR).build();
Mono.from(sm.sendEvent(Mono.just(errMsg))).block();
break;
}
Message<CraftEvents> compMsg = MessageBuilder.withPayload(CraftEvents.STEP_COMPLETE).build();
Mono.from(sm.sendEvent(Mono.just(compMsg))).block();
synchronized (this) {
while (sm.getState().getId() == CraftStates.PAUSED) {
this.wait();
}
}
}
if (sm.getState().getId() == CraftStates.RUNNING) {
Message<CraftEvents> finishMsg = MessageBuilder.withPayload(CraftEvents.FINISH).build();
Mono.from(sm.sendEvent(Mono.just(finishMsg))).block();
}
} catch (Exception e) {
log.error("工艺执行失败", e);
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatId, "工艺执行失败", e.getMessage()));
Message<CraftEvents> stopMsg = MessageBuilder.withPayload(CraftEvents.ERROR_OCCUR).build();
Mono.from(sm.sendEvent(Mono.just(stopMsg))).block();
}
}
/**
* 执行单个步骤并推送开始及结果
*
* @param step 当前工艺步骤
* @return 是否执行成功
* @throws InterruptedException 执行中被中断
*/
private boolean executeStep(CraftsStep step) throws Exception {
Map<String, Object> startData = new HashMap<>();
startData.put("heatId", heatId);
startData.put("currentStep", step.getMethod());
webSocketService.push(WebSocketMessageType.CRAFTS_STEP, startData);
return craftsStepService.executeStep(heatId, step);
}
/**
* 暂停执行触发 PAUSE 事件
*/
public void pause() {
Message<CraftEvents> msg = MessageBuilder.withPayload(CraftEvents.PAUSE).build();
Mono.from(sm.sendEvent(Mono.just(msg))).block();
}
/**
* 恢复执行触发 RESUME 事件并唤醒线程
*/
public void resume() {
Message<CraftEvents> msg = MessageBuilder.withPayload(CraftEvents.RESUME).build();
Mono.from(sm.sendEvent(Mono.just(msg))).block();
synchronized (this) {
this.notify();
}
}
/**
* 停止执行触发 STOP 事件并唤醒线程
*/
public void stop() {
Message<CraftEvents> msg = MessageBuilder.withPayload(CraftEvents.STOP).build();
Mono.from(sm.sendEvent(Mono.just(msg))).block();
synchronized (this) {
this.notify();
}
}
}

15
src/main/java/com/iflytop/sgs/app/core/CraftsDebugGenerator.java

@ -0,0 +1,15 @@
package com.iflytop.sgs.app.core;
import cn.hutool.json.JSONObject;
public class CraftsDebugGenerator {
public static JSONObject generateJson(String heatId, String title, Object content) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("heatId", heatId);
jsonObject.set("title", title);
jsonObject.set("content", content);
return jsonObject;
}
}

22
src/main/java/com/iflytop/sgs/app/core/DebugGenerator.java

@ -0,0 +1,22 @@
package com.iflytop.sgs.app.core;
import cn.hutool.json.JSONObject;
public class DebugGenerator {
public static JSONObject generateJson(String commandId, String command, String status, String title, Object content) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("commandId", commandId);
jsonObject.set("command", command);
jsonObject.set("status", status);
jsonObject.set("title", title);
jsonObject.set("content", content);
return jsonObject;
}
public static JSONObject generateJson(String commandId, String command, String status, String title) {
return generateJson(commandId, command, status, title, null);
}
}

35
src/main/java/com/iflytop/sgs/app/core/device/CommandState.java

@ -0,0 +1,35 @@
package com.iflytop.sgs.app.core.device;
import lombok.Data;
/**
* 指令互斥关系状态
*/
@Data
public class CommandState {
private boolean capFreeCommandExecuting = false;
private boolean capLiftingOriginCommandExecuting = false;
private boolean capUsedCommandExecuting = false;
private boolean doorCloseCommandExecuting = false;
private boolean doorOpenCommandExecuting = false;
private boolean doorOriginCommandExecuting = false;
private boolean dualRobotJointOriginCommandExecuting = false;
private boolean fanStartCommandExecuting = false;
private boolean fanStopCommandExecuting = false;
private boolean filledSolutionStartCommandExecuting = false;
private boolean filledSolutionStopCommandExecuting = false;
private boolean gantryXOriginCommandExecuting = false;
private boolean gantryYOriginCommandExecuting = false;
private boolean gantryZOriginCommandExecuting = false;
private boolean heatStartCommandExecuting = false;
private boolean heatStopCommandExecuting = false;
private boolean moveToHeatAreaCommandExecuting = false;
private boolean moveToSolutionAreaCommandExecuting = false;
private boolean shakeStartCommandExecuting = false;
private boolean shakeStopCommandExecuting = false;
private boolean solutionAddCommandExecuting = false;
private boolean takePhotoCommandExecuting = false;
private boolean trayDownCommandExecuting = false;
private boolean trayLiftingOriginCommandExecuting = false;
private boolean trayUpCommandExecuting = false;
}

23
src/main/java/com/iflytop/sgs/app/core/device/CraftsState.java

@ -0,0 +1,23 @@
package com.iflytop.sgs.app.core.device;
import com.iflytop.sgs.app.model.entity.Crafts;
import com.iflytop.sgs.app.model.entity.Ores;
import com.iflytop.sgs.common.enums.automaton.CraftStates;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "工艺")
@Data
public class CraftsState {
@Schema(description = "工艺状态")
private CraftStates state;
@Schema(description = "工艺所属矿石")
private Ores ores;
@Schema(description = "工艺")
private Crafts craft;
@Schema(description = "工艺当前步骤下标")
private int currentIndex = 0;
}

36
src/main/java/com/iflytop/sgs/app/core/device/DeviceState.java

@ -0,0 +1,36 @@
package com.iflytop.sgs.app.core.device;
import com.iflytop.sgs.app.model.entity.Tasks;
import com.iflytop.sgs.app.model.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Schema(description = "当前设备")
@Data
public class DeviceState {
@Schema(description = "门状态")
private final DoorState door = new DoorState();
@Schema(description = "龙门架机械臂状态")
private final GantryArmState gantryArm = new GantryArmState();
@Schema(description = "加液模块属性")
private final SolutionModuleState solutionModule = new SolutionModuleState();
@Schema(description = "加热模块属性")
private final List<HeatModuleState> heatModule = new ArrayList<>();
@Schema(description = "托盘")
private final List<TrayState> tray = new ArrayList<>();
@Schema(description = "虚拟模式,true为虚拟")
private boolean virtual = false;
@Schema(description = "初始化状态,true初始化完毕")
private boolean initComplete = false;
@Schema(description = "自检状态,true自检完毕")
private boolean selfTest = false;
@Schema(description = "是否是急停状态,true为急停")
private boolean emergencyStop = false;
@Schema(description = "当前登录用户")
private User currentUser;
@Schema(description = "当前实验")
private Tasks currentTasks;
}

11
src/main/java/com/iflytop/sgs/app/core/device/DoorState.java

@ -0,0 +1,11 @@
package com.iflytop.sgs.app.core.device;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "门")
@Data
public class DoorState {
@Schema(description = "是否开门,true为开启状态,false为关闭状态")
private boolean open = false;
}

11
src/main/java/com/iflytop/sgs/app/core/device/GantryArmState.java

@ -0,0 +1,11 @@
package com.iflytop.sgs.app.core.device;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "龙门架机械臂")
@Data
public class GantryArmState {
@Schema(description = "是否空闲,true为空闲,false为占用")
private boolean idle = true;
}

47
src/main/java/com/iflytop/sgs/app/core/device/HeatModuleState.java

@ -0,0 +1,47 @@
package com.iflytop.sgs.app.core.device;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "加热模块")
@Data
public class HeatModuleState {
@Schema(description = "加热模块code")
private HeatModuleCode moduleCode;
@Schema(description = "托盘升降状态,0为降下,1为抬起")
private int trayUp = 0;
@Schema(description = "托盘状态,0为无托盘,1为有托盘")
private int trayStatus = 0;
@Schema(description = "是否正在加热,true为正在加热,false为未加热")
private boolean heating = false;
@Schema(description = "是否正在烘干,true为正在烘干,false为未烘干")
private boolean drying = false;
@Schema(description = "是否正在退火,true为正在退火,false为未退火")
private boolean annealing = false;
@Schema(description = "是否启动散热,true为正在散热,false为未在散热")
private boolean fanOpen = false;
@Schema(description = "加热器目标温度")
private Double targetTemperature = null;
@Schema(description = "加热器烘干温度")
private Double dryTemperature;
@Schema(description = "加热器退火温度")
private Double annealTemperature;
@Schema(description = "加热器加热温度")
private Double heatTemperature;
@Schema(description = "加热器当前温度")
private Double temperature = null;
public HeatModuleState(HeatModuleCode moduleCode) {
this.moduleCode = moduleCode;
}
}

49
src/main/java/com/iflytop/sgs/app/core/device/SelfTestState.java

@ -0,0 +1,49 @@
package com.iflytop.sgs.app.core.device;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "自检状态")
@Data
public class SelfTestState {
@Schema(description = "门是否在原点")
private boolean doorOrigin = false;
@Schema(description = "摇匀是否在原点")
private boolean shakeOrigin = false;
@Schema(description = "龙门架机械臂x轴是否在原点")
private boolean gantryXOrigin = false;
@Schema(description = "龙门架机械臂y轴是否在原点")
private boolean gantryYOrigin = false;
@Schema(description = "龙门架机械臂z轴是否在原点")
private boolean gantryZOrigin = false;
@Schema(description = "加液机械臂是否在原点")
private boolean dualRobotOrigin = false;
@Schema(description = "拍子升降是否在原点")
private boolean capLiftingOrigin = false;
@Schema(description = "加热模块01托盘升降是否在原点")
private boolean trayLifting01Origin = false;
@Schema(description = "加热模块02托盘升降是否在原点")
private boolean trayLifting02Origin = false;
@Schema(description = "加热模块03托盘升降是否在原点")
private boolean trayLifting03Origin = false;
@Schema(description = "加热模块04托盘升降是否在原点")
private boolean trayLifting04Origin = false;
@Schema(description = "加热模块05托盘升降是否在原点")
private boolean trayLifting05Origin = false;
@Schema(description = "加热模块06托盘升降是否在原点")
private boolean trayLifting06Origin = false;
}

34
src/main/java/com/iflytop/sgs/app/core/device/SolutionContainerState.java

@ -0,0 +1,34 @@
package com.iflytop.sgs.app.core.device;
import com.iflytop.sgs.common.enums.ContainerCode;
import com.iflytop.sgs.common.enums.ContainerType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "溶液容器")
@Data
public class SolutionContainerState {
@Schema(description = "容器数据id")
private Long id;
@Schema(description = "容器code")
private ContainerCode containerCode;
@Schema(description = "容器类型 solution溶液容器 neutralization中和容器")
private ContainerType type;
@Schema(description = "容器是否为空,true为空,false不为空")
private boolean empty = false;
@Schema(description = "容器是否为满,true为满,false不满")
private boolean full = false;
@Schema(description = "是否完成预充,true为预充,false为排空")
private boolean filledSolution = false;
public SolutionContainerState(Long id, ContainerCode containerCode, ContainerType type) {
this.id = id;
this.containerCode = containerCode;
this.type = type;
}
}

23
src/main/java/com/iflytop/sgs/app/core/device/SolutionModuleState.java

@ -0,0 +1,23 @@
package com.iflytop.sgs.app.core.device;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Schema(description = "加液模块")
@Data
public class SolutionModuleState {
@Schema(description = "是否空闲,true为空闲,false为占用")
private boolean idle = true;
@Schema(description = "托盘状态,0为无托盘,1为有托盘")
private int trayStatus = 0;
@Schema(description = "溶液容器状态")
private List<SolutionContainerState> solutionContainer = new ArrayList<>();
@Schema(description = "是否正在加液,true正在加液,false未运行")
private boolean pumping = false;
}

37
src/main/java/com/iflytop/sgs/app/core/device/TrayState.java

@ -0,0 +1,37 @@
package com.iflytop.sgs.app.core.device;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.UUID;
@Schema(description = "托盘")
@Data
public class TrayState {
@Schema(description = "托盘唯一id")
private String uuid = UUID.randomUUID().toString();
@Schema(description = "所属加热模块id")
private HeatModuleCode heatModuleId;
@Schema(description = "是否在加液模块中")
private boolean inSolutionModule = false;
@Schema(description = "是否在加热模块中")
private boolean inHeatModule = false;
@Schema(description = "试管")
private TubeState[] tubes = new TubeState[40];
@Schema(description = "当前托盘的工艺")
private CraftsState crafts = null;
public TrayState() {
for (int i = 0; i < tubes.length; i++) {
TubeState tubeState = new TubeState();
tubeState.setTubeNum(i + 1);
tubes[i] = tubeState;
}
}
}

17
src/main/java/com/iflytop/sgs/app/core/device/TubeState.java

@ -0,0 +1,17 @@
package com.iflytop.sgs.app.core.device;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "试管位")
@Data
public class TubeState {
@Schema(description = "试管编号")
private int tubeNum;
@Schema(description = "是否添加过溶液 true添加过")
private boolean addSolution = false;
@Schema(description = "是否存在试管 true存在")
private boolean exists = true;
}

16
src/main/java/com/iflytop/sgs/app/core/event/CommandFeedbackEvent.java

@ -0,0 +1,16 @@
package com.iflytop.sgs.app.core.event;
import cn.hutool.json.JSONObject;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
@Getter
public class CommandFeedbackEvent extends ApplicationEvent {
private final JSONObject jsonResponse;
public CommandFeedbackEvent(Object source, JSONObject jsonResponse) {
super(source);
this.jsonResponse = jsonResponse;
}
}

18
src/main/java/com/iflytop/sgs/app/core/listener/CommandFeedbackListener.java

@ -0,0 +1,18 @@
package com.iflytop.sgs.app.core.listener;
import com.iflytop.sgs.app.core.event.CommandFeedbackEvent;
import com.iflytop.sgs.app.service.DeviceCommandService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class CommandFeedbackListener {
private final DeviceCommandService deviceCommandService;
@EventListener
public void handleCommandFeedbackEvent(CommandFeedbackEvent event) {
deviceCommandService.completeCommandResponse(event.getJsonResponse());
}
}

33
src/main/java/com/iflytop/sgs/app/core/listener/DeviceStateListener.java

@ -0,0 +1,33 @@
package com.iflytop.sgs.app.core.listener;
import com.iflytop.sgs.app.service.DeviceStateService;
import com.iflytop.sgs.app.service.WebSocketService;
import com.iflytop.sgs.common.constant.WebSocketMessageType;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@Slf4j
@Component
@RequiredArgsConstructor
public class DeviceStateListener implements PropertyChangeListener {
private final WebSocketService webSocketService;
private final DeviceStateService deviceStateService;
@PostConstruct
private void init() {
deviceStateService.addListener(this);
}
// 在此处理DeviceState的变化事件
@Override
public void propertyChange(PropertyChangeEvent event) {
log.info("设备状态发生改变,类型{} ,from {} to {}", event.getPropertyName(), event.getOldValue(), event.getNewValue());
webSocketService.push(WebSocketMessageType.STATUS, deviceStateService.getDeviceState());
}
}

15
src/main/java/com/iflytop/sgs/app/mapper/ContainerMapper.java

@ -0,0 +1,15 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.Container;
import org.apache.ibatis.annotations.Mapper;
/**
* 容器持久层接口
*/
@Mapper
public interface ContainerMapper extends BaseMapper<Container> {
}

19
src/main/java/com/iflytop/sgs/app/mapper/CraftsMapper.java

@ -0,0 +1,19 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.Crafts;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 工艺持久层接口
*/
@Mapper
public interface CraftsMapper extends BaseMapper<Crafts> {
@Select("SELECT * FROM crafts WHERE ores_id = #{oresId}")
List<Crafts> selectAllByOresId(Long oresId);
}

12
src/main/java/com/iflytop/sgs/app/mapper/DeviceParamConfigMapper.java

@ -0,0 +1,12 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.DeviceParamConfig;
import org.apache.ibatis.annotations.Mapper;
/**
* 设备参数配置持久层接口
*/
@Mapper
public interface DeviceParamConfigMapper extends BaseMapper<DeviceParamConfig> {
}

12
src/main/java/com/iflytop/sgs/app/mapper/DevicePositionMapper.java

@ -0,0 +1,12 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.DevicePosition;
import org.apache.ibatis.annotations.Mapper;
/**
* 设备位置持久层接口
*/
@Mapper
public interface DevicePositionMapper extends BaseMapper<DevicePosition> {
}

15
src/main/java/com/iflytop/sgs/app/mapper/OresMapper.java

@ -0,0 +1,15 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.Ores;
import org.apache.ibatis.annotations.Mapper;
/**
* 矿石持久层接口
*/
@Mapper
public interface OresMapper extends BaseMapper<Ores> {
Ores findByName(String name);
}

13
src/main/java/com/iflytop/sgs/app/mapper/SolutionsMapper.java

@ -0,0 +1,13 @@
package com.iflytop.sgs.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.iflytop.sgs.app.model.entity.Solutions;
import org.apache.ibatis.annotations.Mapper;
/**
* 溶液持久层接口
*/
@Mapper
public interface SolutionsMapper extends BaseMapper<Solutions> {
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save