diff --git a/src/main/java/com/iflytop/colortitration/ColorTitrationApplication.java b/src/main/java/com/iflytop/colortitration/ColorTitrationApplication.java index 2c6c0df..b047780 100644 --- a/src/main/java/com/iflytop/colortitration/ColorTitrationApplication.java +++ b/src/main/java/com/iflytop/colortitration/ColorTitrationApplication.java @@ -2,12 +2,20 @@ package com.iflytop.colortitration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; @SpringBootApplication public class ColorTitrationApplication { public static void main(String[] args) { - SpringApplication.run(ColorTitrationApplication.class, args); + SpringApplication app = new SpringApplication(ColorTitrationApplication.class); + ConfigurableApplicationContext ctx = app.run(args); + ConfigurableEnvironment env = ctx.getEnvironment(); + String port = env.getProperty("local.server.port", env.getProperty("server.port", "8080")); + System.out.println("应用已启动"); + System.out.println("访问地址 → http://localhost:" + port + "/"); + System.out.println("文档地址 → http://localhost:" + port + "/doc.html"); } } diff --git a/src/main/java/com/iflytop/colortitration/common/enums/Device.java b/src/main/java/com/iflytop/colortitration/common/enums/Device.java index 494e1da..a406ce5 100644 --- a/src/main/java/com/iflytop/colortitration/common/enums/Device.java +++ b/src/main/java/com/iflytop/colortitration/common/enums/Device.java @@ -1,50 +1,51 @@ package com.iflytop.colortitration.common.enums; +import lombok.Getter; + public enum Device { - door_motor, - shake_motor, - cap_motor, - dual_robot, - gantry_x, - gantry_y, - gantry_z, - heater_motor_1, - heater_motor_2, - heater_motor_3, - heater_motor_4, - heater_motor_5, - heater_motor_6, - acid_pump_1, - acid_pump_2, - acid_pump_3, - acid_pump_4, - acid_pump_5, - acid_pump_6, - acid_pump_7, - acid_pump_8, - claw, - fan_1, - fan_2, - fan_3, - fan_4, - fan_5, - fan_6, - water_pump_power, - ventilator_power, - heat_rod_1, - heat_rod_2, - heat_rod_3, - heat_rod_4, - heat_rod_5, - heat_rod_6, - vacuum_pump_valve_1, - vacuum_pump_valve_2, - vacuum_pump_valve_3, - vacuum_pump_valve_4, - vacuum_pump_valve_5, - vacuum_pump_valve_6, - tricolor_light, - fill_light, - cold_trap, - photo + Z_MOTOR(HardwareType.STEPPER_MOTOR, "Z 轴升降电机"), + CERAMIC_PUMP_1(HardwareType.STEPPER_MOTOR, "陶瓷泵 1"), + CERAMIC_PUMP_2(HardwareType.STEPPER_MOTOR, "陶瓷泵 2"), + BRUSHLESS_PUMP_1(HardwareType.STEPPER_MOTOR, "无刷泵 1"), + BRUSHLESS_PUMP_2(HardwareType.STEPPER_MOTOR, "无刷泵 2"), + BRUSHLESS_PUMP_3(HardwareType.STEPPER_MOTOR, "无刷泵 3"), + BRUSHLESS_PUMP_4(HardwareType.STEPPER_MOTOR, "无刷泵 4"), + BRUSHLESS_PUMP_5(HardwareType.STEPPER_MOTOR, "无刷泵 5"), + BRUSHLESS_PUMP_6(HardwareType.STEPPER_MOTOR, "无刷泵 6"), + BRUSHLESS_PUMP_7(HardwareType.STEPPER_MOTOR, "无刷泵 7"), + BRUSHLESS_PUMP_8(HardwareType.STEPPER_MOTOR, "无刷泵 8"), + BRUSHLESS_PUMP_9(HardwareType.STEPPER_MOTOR, "无刷泵 9"), + BRUSHLESS_PUMP_10(HardwareType.STEPPER_MOTOR, "无刷泵 10"), + STEP_PUMP_1(HardwareType.STEPPER_MOTOR, "步进泵 1"), + STEP_PUMP_2(HardwareType.STEPPER_MOTOR, "步进泵 2"), + STEP_PUMP_3(HardwareType.STEPPER_MOTOR, "步进泵 3"), + STIR_MOTOR_1(HardwareType.STEPPER_MOTOR, "搅拌电机 1"), + STIR_MOTOR_2(HardwareType.STEPPER_MOTOR, "搅拌电机 2"), + CLAW(HardwareType.SERVO_MOTOR, "夹爪"), + DUAL_ROBOT(HardwareType.STEPPER_MOTOR, "双轴机械臂"), + HEAT_ROD_1(HardwareType.IO_DEVICE, "加热棒 1"), + HEAT_ROD_2(HardwareType.IO_DEVICE, "加热棒 2"), + TRICOLOR_LIGHT(HardwareType.IO_DEVICE, "三色灯"); + + + /** + * 设备所属硬件类型 + */ + @Getter + private final HardwareType type; + /** + * 设备中文描述或显示名 + */ + @Getter + private final String description; + + Device(HardwareType type, String description) { + this.type = type; + this.description = description; + } + + @Override + public String toString() { + return this.name(); + } } diff --git a/src/main/java/com/iflytop/colortitration/common/enums/HardwareType.java b/src/main/java/com/iflytop/colortitration/common/enums/HardwareType.java new file mode 100644 index 0000000..da01c59 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/common/enums/HardwareType.java @@ -0,0 +1,25 @@ +package com.iflytop.colortitration.common.enums; + +public enum HardwareType { + /** + * 步进电机 + */ + STEPPER_MOTOR, + /** + * 伺服电机 + */ + SERVO_MOTOR, + /** + * 通用传感器(温度、湿度等) + */ + SENSOR, + /** + * IO 控制(阀门、风扇、加热器等) + */ + IO_DEVICE, + /** + * 相机 + */ + CAMERA; + +} diff --git a/src/main/java/com/iflytop/colortitration/common/handler/DeviceTypeHandler.java b/src/main/java/com/iflytop/colortitration/common/handler/DeviceTypeHandler.java new file mode 100644 index 0000000..bc61ca2 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/common/handler/DeviceTypeHandler.java @@ -0,0 +1,40 @@ +package com.iflytop.colortitration.common.handler; + +import com.iflytop.colortitration.common.enums.Device; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +@MappedJdbcTypes(JdbcType.VARCHAR) +@MappedTypes(Device.class) +public class DeviceTypeHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Device parameter, JdbcType jdbcType) throws SQLException { + ps.setString(i, parameter.name()); + } + + @Override + public Device getNullableResult(ResultSet rs, String columnName) throws SQLException { + String name = rs.getString(columnName); + return name == null ? null : Device.valueOf(name); + } + + @Override + public Device getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String name = rs.getString(columnIndex); + return name == null ? null : Device.valueOf(name); + } + + @Override + public Device getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String name = cs.getString(columnIndex); + return name == null ? null : Device.valueOf(name); + } +} \ No newline at end of file