优化
This commit is contained in:
@@ -94,12 +94,6 @@
|
||||
<version>1.12.780</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fazecast</groupId>
|
||||
<artifactId>jSerialComm</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- WebSocket API -->
|
||||
<dependency>
|
||||
<groupId>jakarta.websocket</groupId>
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
package top.wms.admin.controller.light;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
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.*;
|
||||
import top.continew.starter.log.annotation.Log;
|
||||
import top.continew.starter.web.model.R;
|
||||
import top.wms.admin.light.LightService;
|
||||
import top.wms.admin.material.service.MaterialInfoService;
|
||||
|
||||
/**
|
||||
* 灯光控制器 API
|
||||
* 提供前端页面调用的接口
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/light")
|
||||
@Log(ignore = true)
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "灯光控制器", description = "灯光控制器相关接口")
|
||||
public class LightController {
|
||||
|
||||
private final LightService lightService;
|
||||
|
||||
private final MaterialInfoService materialInfoService;
|
||||
|
||||
/**
|
||||
* 连接控制器
|
||||
* 前端页面进入"称重管理"页面时调用
|
||||
*/
|
||||
@PostMapping("/connect")
|
||||
@Operation(summary = "连接控制器", description = "前端页面进入'称重管理'页面时调用")
|
||||
public R connect() {
|
||||
boolean connected = lightService.connect();
|
||||
if (connected) {
|
||||
return R.ok();
|
||||
} else {
|
||||
return R.fail("500","灯光连接失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开连接
|
||||
* 前端页面离开"称重管理"页面时调用
|
||||
*/
|
||||
@PostMapping("/disconnect")
|
||||
@Operation(summary = "断开连接", description = "前端页面离开'称重管理'页面时调用")
|
||||
public R disconnect() {
|
||||
lightService.disconnect();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查连接状态
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@Operation(summary = "检查连接状态", description = "检查控制器是否已连接")
|
||||
public R<Boolean> status() {
|
||||
boolean connected = lightService.isConnected();
|
||||
return R.ok(connected);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置通道亮度
|
||||
*
|
||||
*/
|
||||
@PostMapping("/brightness")
|
||||
@Operation(summary = "设置通道亮度", description = "设置指定通道的亮度")
|
||||
public R setBrightness(@RequestBody JSONObject js) {
|
||||
Long materialId = js.getLong("materialId");
|
||||
Integer brightness = materialInfoService.getBrightness(materialId);
|
||||
if (brightness == null) {
|
||||
return R.ok();
|
||||
}
|
||||
boolean success = lightService.setBrightness(1, brightness);
|
||||
if (success) {
|
||||
return R.ok();
|
||||
} else {
|
||||
return R.fail("500","设置灯光亮度失败,请检查连接状态");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取通道亮度
|
||||
* @param channel 通道号 (1-2)
|
||||
*/
|
||||
@GetMapping("/brightness")
|
||||
@Operation(summary = "读取通道亮度", description = "读取指定通道的当前亮度")
|
||||
public R<Integer> getBrightness(@RequestParam int channel) {
|
||||
int brightness = lightService.getBrightness(channel);
|
||||
return R.ok(brightness);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开指定通道
|
||||
* @param channel 通道号 (1-2)
|
||||
*/
|
||||
@PostMapping("/turn-on")
|
||||
@Operation(summary = "打开通道", description = "打开指定通道")
|
||||
public R<Boolean> turnOn(@RequestParam int channel) {
|
||||
boolean success = lightService.turnOn(channel);
|
||||
return R.ok(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭指定通道
|
||||
* @param channel 通道号 (1-2)
|
||||
*/
|
||||
@PostMapping("/turn-off")
|
||||
@Operation(summary = "关闭通道", description = "关闭指定通道")
|
||||
public R<Boolean> turnOff(@RequestParam int channel) {
|
||||
boolean success = lightService.turnOff(channel);
|
||||
return R.ok(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所有通道亮度
|
||||
* @param brightness 亮度等级 (0-255)
|
||||
*/
|
||||
@PostMapping("/all-brightness")
|
||||
@Operation(summary = "设置所有通道亮度", description = "设置所有通道的亮度")
|
||||
public R<Void> setAllBrightness(@RequestParam int brightness) {
|
||||
lightService.setAllBrightness(brightness);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开所有通道
|
||||
*/
|
||||
@PostMapping("/all-turn-on")
|
||||
@Operation(summary = "打开所有通道", description = "打开所有通道")
|
||||
public R<Void> turnAllOn() {
|
||||
lightService.turnAllOn();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭所有通道
|
||||
*/
|
||||
@PostMapping("/all-turn-off")
|
||||
@Operation(summary = "关闭所有通道", description = "关闭所有通道")
|
||||
public R<Void> turnAllOff() {
|
||||
lightService.turnAllOff();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user