From ea71e40b904ebafa72021d0f5fce8adfa28c0d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 11:08:58 +0800 Subject: [PATCH 01/10] =?UTF-8?q?fix:=E5=AE=8C=E5=96=84=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E6=BA=B6=E6=B6=B2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/ReceiveRecordController.java | 22 ++++++-------- .../handacid/common/model/entity/Channel.java | 4 +-- .../common/model/entity/ReceiveRecord.java | 3 +- .../common/service/ReceiveRecordService.java | 34 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 16 deletions(-) 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/common/model/entity/Channel.java b/src/main/java/com/iflytop/handacid/common/model/entity/Channel.java index 7bd2249..4c852f2 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,7 +17,7 @@ public class Channel extends BaseEntity { private String name; @Schema(description = "通道Code") - private String code; + private ChannelCode code; @Schema(description = "绑定的溶液ID") private Long solutionId; 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..275c5ce 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; @@ -41,5 +42,5 @@ public class ReceiveRecord extends BaseEntity { private Double receivedVolume; @Schema(description = "通道Code") - private String channelCode; + private ChannelCode channelCode; } 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; + } } From 271cfc6e837a138806c1e44d72477e0181cbc2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 11:18:16 +0800 Subject: [PATCH 02/10] =?UTF-8?q?fix:=E6=BA=B6=E6=B6=B2=E6=B5=93=E5=BA=A6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/iflytop/handacid/app/core/state/ChannelState.java | 4 ++-- .../com/iflytop/handacid/common/model/entity/AuditRecord.java | 2 +- .../java/com/iflytop/handacid/common/model/entity/Channel.java | 2 +- .../com/iflytop/handacid/common/model/entity/Formulation.java | 2 +- .../com/iflytop/handacid/common/model/entity/ReceiveRecord.java | 2 +- .../java/com/iflytop/handacid/common/model/vo/FormulationVO.java | 2 +- src/main/resources/sql/init.sql | 8 ++++---- 7 files changed, 11 insertions(+), 11 deletions(-) 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..4b2588e 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,7 +46,7 @@ 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, Long solutionId, String solutionName, Double concentration, Double targetVolume, Double receivedVolume, Double currentVolume) { this.channelCode = channelCode; this.solutionId = solutionId; this.solutionName = solutionName; 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..85df9c5 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,7 +25,7 @@ public class AuditRecord extends BaseEntity { private String solutionName; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "通道Code") private String channelCode; 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 4c852f2..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 @@ -23,7 +23,7 @@ public class Channel extends BaseEntity { 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 275c5ce..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 @@ -36,7 +36,7 @@ public class ReceiveRecord extends BaseEntity { private String solutionName; @Schema(description = "溶液浓度") - private Integer concentration; + private Double concentration; @Schema(description = "领取溶液量") private Double receivedVolume; 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/resources/sql/init.sql b/src/main/resources/sql/init.sql index 7886565..1bdcd5f 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -5,7 +5,7 @@ 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,--使用溶液量 create_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,--领取溶液量 @@ -55,7 +55,7 @@ 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 From 9eca7cc483a237853332b67083a33fab911c3673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 11:38:04 +0800 Subject: [PATCH 03/10] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E9=80=89=E6=8B=A9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/FormulationController.java | 28 ++++++++++------------ .../handacid/app/model/dto/FormulationListDTO.java | 18 ++++++++++++++ .../handacid/app/model/vo/FormulationListVO.java | 24 +++++++++++++++++++ .../common/service/FormulationService.java | 25 +++++++++++++++++++ 4 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/iflytop/handacid/app/model/dto/FormulationListDTO.java create mode 100644 src/main/java/com/iflytop/handacid/app/model/vo/FormulationListVO.java 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/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/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; + } + } From 1432849645f48e02b9ff67169d8b0dc611ee9dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 11:54:26 +0800 Subject: [PATCH 04/10] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=AE=A1=E8=AE=A1?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iflytop/handacid/app/controller/AuditRecordController.java | 6 +++--- .../java/com/iflytop/handacid/common/model/entity/AuditRecord.java | 2 +- src/main/resources/sql/init.sql | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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/common/model/entity/AuditRecord.java b/src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java index 85df9c5..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 @@ -31,6 +31,6 @@ public class AuditRecord extends BaseEntity { private String channelCode; @Schema(description = "使用溶液量") - private String usedVolume; + private Double usedVolume; } diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 1bdcd5f..1ad88f9 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS audit_record( solution_name TEXT,--溶液名称 concentration REAL,--溶液浓度 channel_code TEXT,--通道code - used_volume TEXT,--使用溶液量 + used_volume REAL,--使用溶液量 create_time TEXT DEFAULT CURRENT_TIMESTAMP, update_time TEXT DEFAULT CURRENT_TIMESTAMP ); From 683ba953aa666ff777965c5648056f844fd4de7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Thu, 31 Jul 2025 13:47:12 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=A7=BB=E8=87=B3commandFeedback=20?= =?UTF-8?q?=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handacid/app/core/event/StateChangeEvent.java | 14 -------------- .../app/core/listener/CommandFeedbackListener.java | 18 ++++++++++++++++++ .../handacid/app/service/DeviceInitService.java | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) delete mode 100644 src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java create mode 100644 src/main/java/com/iflytop/handacid/app/core/listener/CommandFeedbackListener.java 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/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 9f23c48..8cc7686 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); From e79d2c882de52bebc3597179ea4b3140d9fb69cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 13:57:54 +0800 Subject: [PATCH 06/10] =?UTF-8?q?fix:=E9=A6=96=E6=AC=A1=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=BB=98=E8=AE=A4=E5=80=BC=E4=B8=BAnull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/sql/init.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 1ad88f9..605bd35 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -43,12 +43,12 @@ 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 ( From 0da5f5a1329315bbf5b8d126241e58890feb09ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 14:02:28 +0800 Subject: [PATCH 07/10] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E6=B2=A1=E6=9C=89=E9=85=8D=E7=BD=AE=E6=BA=B6?= =?UTF-8?q?=E6=B6=B2=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java | 4 +--- .../java/com/iflytop/handacid/app/service/DeviceInitService.java | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) 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 4b2588e..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 @@ -46,10 +46,8 @@ public class ChannelState { @Schema(description = "领取溶液量(单位:mL)") private volatile Double receivedVolume; - public ChannelState(ChannelCode channelCode, Long solutionId, String solutionName, Double 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/service/DeviceInitService.java b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java index 8cc7686..78247c4 100644 --- a/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java +++ b/src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java @@ -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))); From fa6d1606fa9a3e33951de5794ff6d82b51ecacb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Thu, 31 Jul 2025 14:03:15 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fix:=E6=B5=8B=E8=AF=95=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A8=A1=E6=8B=9F=E7=82=B9=E5=87=BB=E6=89=8B?= =?UTF-8?q?=E6=9F=84=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handacid/app/controller/TestController.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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(); + } + } From c73df2be35a66f839996e37bf7e3232f7a44e043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Thu, 31 Jul 2025 14:20:57 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=B5=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E8=8E=B7=E5=8F=96=E5=92=8Cws=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/control/PumpRotateStartCommand.java | 12 +++++-- .../app/core/command/DeviceCommandGenerator.java | 28 ++++++++++++++++ .../handacid/app/service/ChannelCtrlService.java | 13 ++++++++ .../app/websocket/server/WebSocketMessageType.java | 38 +++------------------- .../app/websocket/server/WebSocketSender.java | 16 ++------- 5 files changed, 57 insertions(+), 50 deletions(-) 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..ea896fb 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) { @@ -39,11 +41,17 @@ public class PumpRotateStartCommand extends BaseCommandHandler { throw new IllegalArgumentException("参数 direction 不能为空"); } return runAsync(() -> { - if(Direction.FORWARD.equals(direction)) { + 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.getPumpForwardRotateCommandByChannel(channelCode); 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/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/service/ChannelCtrlService.java b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java index 03346d3..fc9adf6 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -165,6 +165,19 @@ public class ChannelCtrlService { }; } + + /** + * 根据通道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获取泵反转指令 */ 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); - }*/ - } From 02d7fc58a11c38c82b18ea13294b163bd366b428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Thu, 31 Jul 2025 14:49:00 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=B5=E6=A0=B9?= =?UTF-8?q?=E6=8D=AEcode=E7=A7=BB=E5=8A=A8=E6=8C=87=E4=BB=A4=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=AD=A3=E4=BC=A0=E4=B8=9A=E5=8A=A1=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handacid/app/command/control/PumpRotateStartCommand.java | 6 +++++- .../com/iflytop/handacid/app/service/ChannelCtrlService.java | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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 ea896fb..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 @@ -40,13 +40,17 @@ 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 getPositionDeviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); CommandFuture positionCommandFuture = deviceCommandService.sendCommand(getPositionDeviceCommand); CommandUtil.wait(positionCommandFuture); Integer currentPosition = (Integer) positionCommandFuture.getResponseResult().get("position"); - DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); + DeviceCommand deviceCommand = channelCtrlService.getPumpMoveCommandByChannel(channelCode, position); CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); CommandUtil.wait(commandFuture); Integer newPosition = (Integer) commandFuture.getResponseResult().get("position"); 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 fc9adf6..ecfe275 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -165,6 +165,18 @@ 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获取泵转数指令