diff --git a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java index bb9a378..0de86cd 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java @@ -11,6 +11,7 @@ import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.app.model.dto.CommandDTO; import com.iflytop.handacid.app.service.ChannelCtrlService; import com.iflytop.handacid.app.service.DeviceCommandService; +import com.iflytop.handacid.app.websocket.server.WebSocketSender; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -27,6 +28,7 @@ import java.util.concurrent.CompletableFuture; public class PumpRotateStartCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; private final ChannelCtrlService channelCtrlService; + private final WebSocketSender webSocketSender; @Override public CompletableFuture handle(CommandDTO commandDTO) { @@ -38,12 +40,22 @@ public class PumpRotateStartCommand extends BaseCommandHandler { if (direction == null) { throw new IllegalArgumentException("参数 direction 不能为空"); } + Double position = commandDTO.getDoubleParam("position"); + if (position == null) { + throw new IllegalArgumentException("参数 position 不能为空"); + } return runAsync(() -> { - if(Direction.FORWARD.equals(direction)) { - DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); + if (Direction.FORWARD.equals(direction)) { + DeviceCommand getPositionDeviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); + CommandFuture positionCommandFuture = deviceCommandService.sendCommand(getPositionDeviceCommand); + CommandUtil.wait(positionCommandFuture); + Integer currentPosition = (Integer) positionCommandFuture.getResponseResult().get("position"); + DeviceCommand deviceCommand = channelCtrlService.getPumpMoveCommandByChannel(channelCode, position); CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); CommandUtil.wait(commandFuture); - }else{ + Integer newPosition = (Integer) commandFuture.getResponseResult().get("position"); + webSocketSender.pushPumpPosition(newPosition - currentPosition); + } else { DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); CommandUtil.wait(commandFuture); diff --git a/src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java b/src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java index 5baacac..61ac55c 100644 --- a/src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java +++ b/src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java @@ -59,14 +59,14 @@ public class AuditRecordController { @Operation(summary = "增加记录") public Result create(@RequestBody AuditRecord auditRecord) { boolean flag = auditRecordService.save(auditRecord); - return flag ? Result.success("添加成功") : Result.failed("添加失败"); + return flag ? Result.success() : Result.failed(); } @PutMapping @Operation(summary = "修改记录") public Result update(@RequestBody AuditRecord auditRecord) { boolean flag = auditRecordService.updateById(auditRecord); - return flag ? Result.success("修改成功") : Result.failed("修改失败"); + return flag ? Result.success() : Result.failed(); } @DeleteMapping("/{ids}") @@ -75,7 +75,7 @@ public class AuditRecordController { boolean success = auditRecordService.removeBatchByIds( Arrays.stream(ids.split(",")).map(Long::valueOf).toList() ); - return success ? Result.success("删除成功") : Result.failed("删除失败"); + return success ? Result.success() : Result.failed(); } @GetMapping("/export") diff --git a/src/main/java/com/iflytop/handacid/app/controller/FormulationController.java b/src/main/java/com/iflytop/handacid/app/controller/FormulationController.java index bfc9f5d..b5f6c48 100644 --- a/src/main/java/com/iflytop/handacid/app/controller/FormulationController.java +++ b/src/main/java/com/iflytop/handacid/app/controller/FormulationController.java @@ -1,6 +1,7 @@ package com.iflytop.handacid.app.controller; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.iflytop.handacid.app.model.dto.FormulationListDTO; +import com.iflytop.handacid.app.model.vo.FormulationListVO; import com.iflytop.handacid.common.base.BasePageQuery; import com.iflytop.handacid.common.model.entity.Formulation; import com.iflytop.handacid.common.model.vo.FormulationVO; @@ -12,10 +13,10 @@ 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.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Arrays; +import java.util.List; /** * 配方 @@ -26,23 +27,20 @@ import java.util.Arrays; @RequiredArgsConstructor @Slf4j public class FormulationController { - @Autowired - private FormulationService formulationService; - @Autowired - private SolutionService solutionService; + private final FormulationService formulationService; + private final SolutionService solutionService; @PostMapping("/page") @Operation(summary = "获取分页数据") - public PageResult getPage(BasePageQuery query) { + public PageResult getPage(@RequestBody BasePageQuery query) { return PageResult.success(formulationService.getPage(query)); } -/* @GetMapping("/list") + @PostMapping("/list") @Operation(summary = "获取List数据") - public Result> getList( @RequestParam Integer solutionId, @RequestParam String concentration) { - List formulations=formulationService.list(new LambdaQueryWrapper().eq(Formulation::getSolutionId, solutionId).eq(Formulation::getConcentration,concentration)); - return Result.success(formulations); - }*/ + public Result> getList(@RequestBody(required = false) FormulationListDTO dto) { + return Result.success(formulationService.getList(dto)); + } @GetMapping("/{id}") @Operation(summary = "根据ID获取") @@ -54,14 +52,14 @@ public class FormulationController { @Operation(summary = "创建配方") public Result create(@RequestBody Formulation formulation) { boolean flag = formulationService.save(formulation); - return flag ? Result.success("添加成功") : Result.failed("添加失败"); + return flag ? Result.success() : Result.failed(); } @PutMapping @Operation(summary = "修改配方") public Result update(@RequestBody Formulation formulation) { boolean flag = formulationService.saveOrUpdate(formulation); - return flag ? Result.success("修改成功") : Result.failed("修改失败"); + return flag ? Result.success() : Result.failed(); } @DeleteMapping("/{ids}") @@ -70,7 +68,7 @@ public class FormulationController { boolean success = formulationService.removeBatchByIds( Arrays.stream(ids.split(",")).map(Long::valueOf).toList() ); - return success ? Result.success("删除成功") : Result.failed("删除失败"); + return success ? Result.success() : Result.failed(); } /* @GetMapping("/concentration/{id}") diff --git a/src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java b/src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java index b1446b5..1a70744 100644 --- a/src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java +++ b/src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java @@ -3,7 +3,6 @@ package com.iflytop.handacid.app.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.iflytop.handacid.app.common.utils.UsbDriverUtil; import com.iflytop.handacid.common.base.BasePageQuery; -import com.iflytop.handacid.common.model.entity.AuditRecord; import com.iflytop.handacid.common.model.entity.ReceiveRecord; import com.iflytop.handacid.common.result.PageResult; import com.iflytop.handacid.common.result.Result; @@ -12,13 +11,11 @@ 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.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.File; @@ -26,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; + /** * 领取 */ @@ -35,8 +33,7 @@ import java.util.List; @RequiredArgsConstructor @Slf4j public class ReceiveRecordController { - @Autowired - private ReceiveRecordService receiveRecordService; + private final ReceiveRecordService receiveRecordService; @GetMapping("/list") @Operation(summary = "获取List数据") @@ -51,23 +48,22 @@ public class ReceiveRecordController { } @GetMapping("/{id}") - @Operation(summary = "根据ID获取") + @Operation(summary = "根据ID获取领取记录") public Result getById(@PathVariable Integer id) { return Result.success(receiveRecordService.getById(id)); } @PostMapping @Operation(summary = "领取溶液") - public Result create(@RequestBody ReceiveRecord receiveRecord) { - boolean flag = receiveRecordService.save(receiveRecord); - return flag? Result.success("添加成功") : Result.failed("添加失败"); + public Result receive(@RequestBody ReceiveRecord receiveRecord) { + return receiveRecordService.receive(receiveRecord) ? Result.success() : Result.failed(); } @PutMapping @Operation(summary = "修改记录") public Result update(@RequestBody ReceiveRecord receiveRecord) { - boolean flag = receiveRecordService.updateById(receiveRecord); - return flag? Result.success("修改成功") : Result.failed("修改失败"); + boolean flag = receiveRecordService.updateById(receiveRecord); + return flag ? Result.success() : Result.failed(); } @DeleteMapping("/{ids}") @@ -76,7 +72,7 @@ public class ReceiveRecordController { boolean success = receiveRecordService.removeBatchByIds( Arrays.stream(ids.split(",")).map(Long::valueOf).toList() ); - return success? Result.success("删除成功") : Result.failed("删除失败"); + return success ? Result.success() : Result.failed(); } @GetMapping("/export") @@ -107,7 +103,7 @@ public class ReceiveRecordController { row.createCell(2).setCellValue(record.getReceiverNickname()); row.createCell(3).setCellValue(record.getSolutionName()); row.createCell(4).setCellValue(record.getConcentration()); - row.createCell(5).setCellValue(record.getChannelCode()); + row.createCell(5).setCellValue(record.getChannelCode().toString()); row.createCell(6).setCellValue(record.getReceivedVolume()); row.createCell(7).setCellValue(record.getCreateTime() != null ? record.getCreateTime().toString() : ""); row.createCell(8).setCellValue(record.getUpdateTime() != null ? record.getUpdateTime().toString() : ""); diff --git a/src/main/java/com/iflytop/handacid/app/controller/TestController.java b/src/main/java/com/iflytop/handacid/app/controller/TestController.java index ba4a003..40c7566 100644 --- a/src/main/java/com/iflytop/handacid/app/controller/TestController.java +++ b/src/main/java/com/iflytop/handacid/app/controller/TestController.java @@ -3,6 +3,10 @@ package com.iflytop.handacid.app.controller; import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.common.result.Result; +import com.iflytop.handacid.hardware.service.AppEventBusService; +import com.iflytop.handacid.hardware.type.A8kPacket; +import com.iflytop.handacid.hardware.type.CmdId; +import com.iflytop.handacid.hardware.type.appevent.A8kHardwareReport; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -21,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j public class TestController { private final DeviceState deviceState; + private final AppEventBusService eventBus; @Operation(summary = "启动虚拟模式") @PostMapping("/virtual") @@ -36,9 +41,20 @@ public class TestController { return Result.success(); } - @Operation(summary = "设置模拟环境湿度") - @PostMapping("/set-humidity") - public Result setHumidity(ChannelCode heatModule, double humidity) { + @Operation(summary = "模拟点击手柄加液按钮") + @PostMapping("/click-add") + public Result clickAdd() { + A8kPacket packet = A8kPacket.createPacket(0, A8kPacket.PACKET_TYPE_EVENT, CmdId.event_ble_gamepad_liquid_acid.index, new Integer[]{}); + eventBus.pushEvent(new A8kHardwareReport(packet)); return Result.success(); } + + @Operation(summary = "模拟点击手柄预充按钮") + @PostMapping("/click-pre") + public Result clickPre() { + A8kPacket packet = A8kPacket.createPacket(0, A8kPacket.PACKET_TYPE_EVENT, CmdId.event_ble_gamepad_liquid_acid_prefilling.index, new Integer[]{}); + eventBus.pushEvent(new A8kHardwareReport(packet)); + return Result.success(); + } + } diff --git a/src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java b/src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java index 609691f..c33eeed 100644 --- a/src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java +++ b/src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java @@ -64,6 +64,13 @@ public class DeviceCommandGenerator { } /** + * 泵 1当前转数 + */ + public static DeviceCommand pump1GetPosition() { + return controlCmd(Device.PUMP_1, Action.GET, null); + } + + /** * 泵 2 设置速度 */ public static DeviceCommand pump2SetSpeed(double speed) { @@ -114,6 +121,13 @@ public class DeviceCommandGenerator { } /** + * 泵 2当前转数 + */ + public static DeviceCommand pump2GetPosition() { + return controlCmd(Device.PUMP_2, Action.GET, null); + } + + /** * 泵 3 设置速度 */ public static DeviceCommand pump3SetSpeed(double speed) { @@ -164,6 +178,13 @@ public class DeviceCommandGenerator { } /** + * 泵 3当前转数 + */ + public static DeviceCommand pump3GetPosition() { + return controlCmd(Device.PUMP_3, Action.GET, null); + } + + /** * 泵 4 设置速度 */ public static DeviceCommand pump4SetSpeed(double speed) { @@ -212,6 +233,13 @@ public class DeviceCommandGenerator { public static DeviceCommand pump4Enable() { return controlCmd(Device.PUMP_4, Action.ENABLE, null); } + + /** + * 泵 4当前转数 + */ + public static DeviceCommand pump4GetPosition() { + return controlCmd(Device.PUMP_4, Action.GET, null); + } //=========================================== 私有方法 ============================================================ /** diff --git a/src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java b/src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java deleted file mode 100644 index df8ab75..0000000 --- a/src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.iflytop.handacid.app.core.event; -import lombok.AllArgsConstructor; -import lombok.Data; - -/** - * 状态变更事件 - */ -@Data -@AllArgsConstructor -public class StateChangeEvent { - private String fieldPath; - private Object oldValue; - private Object newValue; -} diff --git a/src/main/java/com/iflytop/handacid/app/core/listener/CommandFeedbackListener.java b/src/main/java/com/iflytop/handacid/app/core/listener/CommandFeedbackListener.java new file mode 100644 index 0000000..ebca7eb --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/core/listener/CommandFeedbackListener.java @@ -0,0 +1,18 @@ +package com.iflytop.handacid.app.core.listener; + +import com.iflytop.handacid.app.core.event.CommandFeedbackEvent; +import com.iflytop.handacid.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()); + } +} diff --git a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java index bfcf915..2960545 100644 --- a/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java +++ b/src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java @@ -32,7 +32,7 @@ public class ChannelState { private volatile String solutionName; @Schema(description = "溶液浓度") - private volatile Integer concentration; + private volatile Double concentration; @Schema(description = "是否选中") private volatile boolean selected = false; @@ -46,10 +46,8 @@ public class ChannelState { @Schema(description = "领取溶液量(单位:mL)") private volatile Double receivedVolume; - public ChannelState(ChannelCode channelCode, Long solutionId, String solutionName, Integer concentration, Double targetVolume, Double receivedVolume, Double currentVolume) { + public ChannelState(ChannelCode channelCode, Double concentration, Double targetVolume, Double receivedVolume, Double currentVolume) { this.channelCode = channelCode; - this.solutionId = solutionId; - this.solutionName = solutionName; this.concentration = concentration; this.targetVolume = targetVolume; this.receivedVolume = receivedVolume; diff --git a/src/main/java/com/iflytop/handacid/app/model/dto/FormulationListDTO.java b/src/main/java/com/iflytop/handacid/app/model/dto/FormulationListDTO.java new file mode 100644 index 0000000..c2226b4 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/model/dto/FormulationListDTO.java @@ -0,0 +1,18 @@ +package com.iflytop.handacid.app.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class FormulationListDTO { + + @NotNull + @Schema(description = "溶液id") + private Long solutionId; + + @NotNull + @Schema(description = "浓度") + private Double concentration; + +} diff --git a/src/main/java/com/iflytop/handacid/app/model/vo/FormulationListVO.java b/src/main/java/com/iflytop/handacid/app/model/vo/FormulationListVO.java new file mode 100644 index 0000000..2648337 --- /dev/null +++ b/src/main/java/com/iflytop/handacid/app/model/vo/FormulationListVO.java @@ -0,0 +1,24 @@ +package com.iflytop.handacid.app.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class FormulationListVO { + + private Long id; + + @Schema(description = "加液量(mL)") + private Double volume; + + @Schema(description = "溶液ID") + private Long solutionId; + + @Schema(description = "溶液名称") + private String solutionName; + + @Schema(description = "溶液浓度") + private Double concentration; + +} diff --git a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java index 03346d3..ecfe275 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -166,6 +166,31 @@ public class ChannelCtrlService { } /** + * 根据通道code获取泵移动指令 + */ + public DeviceCommand getPumpMoveCommandByChannel(ChannelCode channelCode, Double position) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.pump1MoveBy(position); + case CHANNEL_2 -> DeviceCommandGenerator.pump2MoveBy(position); + case CHANNEL_3 -> DeviceCommandGenerator.pump3MoveBy(position); + case CHANNEL_4 -> DeviceCommandGenerator.pump4MoveBy(position); + }; + } + + + /** + * 根据通道code获取泵转数指令 + */ + public DeviceCommand getPumpPositionCommandByChannel(ChannelCode channelCode) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.pump1GetPosition(); + case CHANNEL_2 -> DeviceCommandGenerator.pump2GetPosition(); + case CHANNEL_3 -> DeviceCommandGenerator.pump3GetPosition(); + case CHANNEL_4 -> DeviceCommandGenerator.pump4GetPosition(); + }; + } + + /** * 根据通道code获取泵反转指令 */ public DeviceCommand getPumpBackwardRotateCommandByChannel(ChannelCode channelCode) { diff --git a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 9f23c48..78247c4 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -74,7 +74,7 @@ public class DeviceInitService { /** * 初始化所有设备使能 */ - public void initEnable() throws Exception { + public void initEnable() { DeviceCommand pump1Enable = DeviceCommandGenerator.pump1Enable(); deviceCommandService.sendCommand(pump1Enable); @@ -96,8 +96,12 @@ public class DeviceInitService { for (ChannelCode code : ChannelCode.values()) { //初始化通道 Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code)); + ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); Solution solution = solutionService.getById(channel.getSolutionId()); - ChannelState channelState = channelStateObjectProvider.getObject(code, solution.getId(), solution.getName(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume()); + if(solution != null) { + channelState.setSolutionId(solution.getId()); + channelState.setSolutionName(solution.getName()); + } deviceState.getChannelStateMap().put(code, channelState); } deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKey(SystemConfigKey.SOLUTION_ADD_MODE))); diff --git a/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java b/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java index 235af6f..0165acf 100644 --- a/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java +++ b/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java @@ -6,54 +6,24 @@ public class WebSocketMessageType { */ public static final String STATUS = "status"; /** - * 设备报警 - */ - public static final String ALARM = "alarm"; - /** * 滴定日志 */ public static final String LOG = "log"; - /** - * 自检移动电机测试 - */ - public static final String SELF_MOVE_TEST = "self_move_test"; + /** * 指令反馈 */ public static final String CMD_RESPONSE = "cmd_response"; /** - * 工艺执行步骤反馈 - */ - public static final String CRAFTS_STEP = "crafts_step"; - - /** - * 工艺执行状态反馈 - */ - public static final String CRAFTS_STATE = "crafts_state"; - - /** - * 工艺DEBUG - */ - public static final String CRAFTS_DEBUG = "crafts_debug"; - - /** - * 容器剩余状态 - */ - public static final String CONTAINER = "container"; - - /** * DEBUG消息推送 */ public static final String CMD_DEBUG = "cmd_debug"; /** - * 加热倒计时 + * 泵转数统计推送 */ - public static final String HEAT_COUNTDOWN = "heat_countdown"; - /** - * 照片 - */ - public static final String PHOTO = "photo"; + public static final String PUMP_POSITION = "pump_position"; + } diff --git a/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java b/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java index e0aa3fb..675508a 100644 --- a/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java +++ b/src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java @@ -19,12 +19,8 @@ public class WebSocketSender { websocketResult.setData(data); websocketResult.setTimestamp(Instant.now().toEpochMilli()); WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); -// log.info("WS::{}", JSONUtil.toJsonStr(websocketResult)); } - public void pushCraftsDebug(Object data) { - push(WebSocketMessageType.CRAFTS_DEBUG, data); - } public void pushDebug(Object data) { push(WebSocketMessageType.CMD_DEBUG, data); @@ -44,16 +40,8 @@ public class WebSocketSender { push(WebSocketMessageType.CMD_RESPONSE, data); } - public void pushSelfMoveTest(Object data) { - push(WebSocketMessageType.SELF_MOVE_TEST, data); - } - - public void pushHeatCountdown(Object data) { - push(WebSocketMessageType.HEAT_COUNTDOWN, data); + public void pushPumpPosition(Object data) { + push(WebSocketMessageType.PUMP_POSITION, data); } - /* public void pushNotification(Notification notification) { - push("notification", notification); - }*/ - } diff --git a/src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java b/src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java index 25b3567..85747b8 100644 --- a/src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java +++ b/src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java @@ -25,12 +25,12 @@ public class AuditRecord extends BaseEntity { private String solutionName; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "通道Code") private String channelCode; @Schema(description = "使用溶液量") - private String usedVolume; + private Double usedVolume; } diff --git a/src/main/java/com/iflytop/handacid/common/model/entity/Channel.java b/src/main/java/com/iflytop/handacid/common/model/entity/Channel.java index 7bd2249..8a7d9f0 100644 --- a/src/main/java/com/iflytop/handacid/common/model/entity/Channel.java +++ b/src/main/java/com/iflytop/handacid/common/model/entity/Channel.java @@ -1,7 +1,7 @@ package com.iflytop.handacid.common.model.entity; -import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.common.base.BaseEntity; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -17,13 +17,13 @@ public class Channel extends BaseEntity { private String name; @Schema(description = "通道Code") - private String code; + private ChannelCode code; @Schema(description = "绑定的溶液ID") private Long solutionId; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "添加溶液量") private Double targetVolume; diff --git a/src/main/java/com/iflytop/handacid/common/model/entity/Formulation.java b/src/main/java/com/iflytop/handacid/common/model/entity/Formulation.java index 42737f5..cf3d8f8 100644 --- a/src/main/java/com/iflytop/handacid/common/model/entity/Formulation.java +++ b/src/main/java/com/iflytop/handacid/common/model/entity/Formulation.java @@ -19,7 +19,7 @@ public class Formulation extends BaseEntity { private Long solutionId; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "对应转数") private Double revolutions; diff --git a/src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java b/src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java index a53fdfb..a09c2ee 100644 --- a/src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java +++ b/src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java @@ -2,6 +2,7 @@ package com.iflytop.handacid.common.model.entity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.iflytop.handacid.app.common.enums.ChannelCode; import com.iflytop.handacid.common.base.BaseEntity; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -35,11 +36,11 @@ public class ReceiveRecord extends BaseEntity { private String solutionName; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "领取溶液量") private Double receivedVolume; @Schema(description = "通道Code") - private String channelCode; + private ChannelCode channelCode; } diff --git a/src/main/java/com/iflytop/handacid/common/model/vo/FormulationVO.java b/src/main/java/com/iflytop/handacid/common/model/vo/FormulationVO.java index 150bbe5..ec4faaf 100644 --- a/src/main/java/com/iflytop/handacid/common/model/vo/FormulationVO.java +++ b/src/main/java/com/iflytop/handacid/common/model/vo/FormulationVO.java @@ -24,7 +24,7 @@ public class FormulationVO{ private String solutionName; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "对应转数") private Double revolutions; diff --git a/src/main/java/com/iflytop/handacid/common/service/FormulationService.java b/src/main/java/com/iflytop/handacid/common/service/FormulationService.java index fc0064e..fab7475 100644 --- a/src/main/java/com/iflytop/handacid/common/service/FormulationService.java +++ b/src/main/java/com/iflytop/handacid/common/service/FormulationService.java @@ -1,8 +1,12 @@ package com.iflytop.handacid.common.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.iflytop.handacid.app.model.dto.FormulationListDTO; +import com.iflytop.handacid.app.model.vo.FormulationListVO; import com.iflytop.handacid.common.base.BasePageQuery; import com.iflytop.handacid.common.mapper.FormulationMapper; import com.iflytop.handacid.common.model.entity.Formulation; @@ -12,6 +16,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -47,4 +52,24 @@ public class FormulationService extends ServiceImpl getList(FormulationListDTO dto) { + LambdaQueryWrapper qw = null; + if (dto != null) { + qw = Wrappers.lambdaQuery() + .eq(dto.getSolutionId() != null, Formulation::getSolutionId, dto.getSolutionId()) + .eq(dto.getConcentration() != null, Formulation::getConcentration, dto.getConcentration()); + } + + List formulations = this.list(qw); + List formulationListVOList = new ArrayList<>(); + for (Formulation formulation : formulations) { + FormulationListVO formulationListVO = new FormulationListVO(); + BeanUtils.copyProperties(formulation, formulationListVO); + Solution solution = solutionService.getById(formulation.getSolutionId()); + formulationListVO.setSolutionName(solution.getName()); + formulationListVOList.add(formulationListVO); + } + return formulationListVOList; + } + } diff --git a/src/main/java/com/iflytop/handacid/common/service/ReceiveRecordService.java b/src/main/java/com/iflytop/handacid/common/service/ReceiveRecordService.java index d29daa1..6dd87a6 100644 --- a/src/main/java/com/iflytop/handacid/common/service/ReceiveRecordService.java +++ b/src/main/java/com/iflytop/handacid/common/service/ReceiveRecordService.java @@ -1,14 +1,48 @@ package com.iflytop.handacid.common.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.iflytop.handacid.app.core.state.ChannelState; +import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.common.mapper.ReceiveRecordMapper; +import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.model.entity.ReceiveRecord; +import com.iflytop.handacid.common.model.entity.Solution; +import com.iflytop.handacid.common.model.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; + /** * 领取记录接口服务 */ @Service @RequiredArgsConstructor public class ReceiveRecordService extends ServiceImpl { + private final UserService userService; + private final SolutionService solutionService; + private final ChannelService channelService; + private final DeviceState deviceState; + + public boolean receive(ReceiveRecord receiveRecord) { + User issuer = userService.getById(receiveRecord.getIssuerId()); + receiveRecord.setIssuerNickname(issuer.getNickname()); + User receiver = userService.getById(receiveRecord.getReceiverId()); + receiveRecord.setReceiverNickname(receiver.getNickname()); + Solution solution = solutionService.getById(receiveRecord.getSolutionId()); + receiveRecord.setSolutionName(solution.getName()); + this.save(receiveRecord); + + Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, receiveRecord.getChannelCode())); + channel.setCurrentVolume(receiveRecord.getReceivedVolume()); + channel.setReceivedVolume(receiveRecord.getReceivedVolume()); + channel.setConcentration(receiveRecord.getConcentration()); + channelService.updateById(channel); + + ChannelState channelState = deviceState.getChannelStateMap().get(receiveRecord.getChannelCode()); + channelState.setCurrentVolume(receiveRecord.getReceivedVolume()); + channelState.setReceivedVolume(receiveRecord.getReceivedVolume()); + channelState.setConcentration(receiveRecord.getConcentration()); + + return true; + } } diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 7886565..605bd35 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -5,9 +5,9 @@ CREATE TABLE IF NOT EXISTS audit_record( user_nickname TEXT,--用户昵称 solution_id INTEGER,--溶液id solution_name TEXT,--溶液名称 - concentration INTEGER,--溶液浓度 + concentration REAL,--溶液浓度 channel_code TEXT,--通道code - used_volume TEXT,--使用溶液量 + used_volume REAL,--使用溶液量 create_time TEXT DEFAULT CURRENT_TIMESTAMP, update_time TEXT DEFAULT CURRENT_TIMESTAMP ); @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS receive_record ( receiver_nickname TEXT,--领取人昵称 solution_id INTEGER,--溶液id solution_name TEXT,--溶液名称 - concentration INTEGER,--溶液浓度 + concentration REAL,--溶液浓度 received_volume REAL,--领取溶液量 channel_code TEXT,--通道code create_time TEXT DEFAULT CURRENT_TIMESTAMP, @@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS channel ( name TEXT,--通道名称 code TEXT,--通道code solution_id INTEGER,--绑定的溶液id - concentration INTEGER,--溶液浓度 + concentration REAL,--溶液浓度 target_volume REAL,--添加溶液量 current_volume REAL,--当前溶液量 received_volume REAL,--领取溶液量 @@ -43,19 +43,19 @@ CREATE TABLE IF NOT EXISTS channel ( ); INSERT OR IGNORE INTO channel ( - id, name, code, solution_id,concentration, current_volume, received_volume + id, name, code ) VALUES - (1, '通道一', 'CHANNEL_1',1, '10', 5000, 5000), - (2, '通道二', 'CHANNEL_2',2, '10', 5000, 5000), - (3, '通道三', 'CHANNEL_3',3, '10', 5000, 5000), - (4, '通道四', 'CHANNEL_4',4, '10', 5000, 5000); + (1, '通道一', 'CHANNEL_1'), + (2, '通道二', 'CHANNEL_2'), + (3, '通道三', 'CHANNEL_3'), + (4, '通道四', 'CHANNEL_4'); -- 配方 CREATE TABLE IF NOT EXISTS formulation ( id INTEGER PRIMARY KEY AUTOINCREMENT, volume REAL,--加液量 solution_id INTEGER,--溶液id - concentration INTEGER,--溶液浓度 + concentration REAL,--溶液浓度 revolutions REAL,--对应转数 create_time TEXT DEFAULT CURRENT_TIMESTAMP, update_time TEXT DEFAULT CURRENT_TIMESTAMP