Browse Source

Merge remote-tracking branch 'origin/master'

master
HSZ_HeSongZhen 4 days ago
parent
commit
fa4c8a3846
  1. 18
      src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java
  2. 6
      src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java
  3. 28
      src/main/java/com/iflytop/handacid/app/controller/FormulationController.java
  4. 20
      src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java
  5. 22
      src/main/java/com/iflytop/handacid/app/controller/TestController.java
  6. 28
      src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java
  7. 14
      src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java
  8. 18
      src/main/java/com/iflytop/handacid/app/core/listener/CommandFeedbackListener.java
  9. 6
      src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
  10. 18
      src/main/java/com/iflytop/handacid/app/model/dto/FormulationListDTO.java
  11. 24
      src/main/java/com/iflytop/handacid/app/model/vo/FormulationListVO.java
  12. 25
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
  13. 8
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
  14. 38
      src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java
  15. 16
      src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java
  16. 4
      src/main/java/com/iflytop/handacid/common/model/entity/AuditRecord.java
  17. 6
      src/main/java/com/iflytop/handacid/common/model/entity/Channel.java
  18. 2
      src/main/java/com/iflytop/handacid/common/model/entity/Formulation.java
  19. 5
      src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java
  20. 2
      src/main/java/com/iflytop/handacid/common/model/vo/FormulationVO.java
  21. 25
      src/main/java/com/iflytop/handacid/common/service/FormulationService.java
  22. 34
      src/main/java/com/iflytop/handacid/common/service/ReceiveRecordService.java
  23. 20
      src/main/resources/sql/init.sql

18
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<Void> 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);

6
src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java

@ -59,14 +59,14 @@ public class AuditRecordController {
@Operation(summary = "增加记录")
public Result<String> 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<String> 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")

28
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<FormulationVO> getPage(BasePageQuery query) {
public PageResult<FormulationVO> getPage(@RequestBody BasePageQuery query) {
return PageResult.success(formulationService.getPage(query));
}
/* @GetMapping("/list")
@PostMapping("/list")
@Operation(summary = "获取List数据")
public Result<List<Formulation>> getList( @RequestParam Integer solutionId, @RequestParam String concentration) {
List<Formulation> formulations=formulationService.list(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, solutionId).eq(Formulation::getConcentration,concentration));
return Result.success(formulations);
}*/
public Result<List<FormulationListVO>> 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<String> 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<String> 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}")

20
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<ReceiveRecord> getById(@PathVariable Integer id) {
return Result.success(receiveRecordService.getById(id));
}
@PostMapping
@Operation(summary = "领取溶液")
public Result<String> create(@RequestBody ReceiveRecord receiveRecord) {
boolean flag = receiveRecordService.save(receiveRecord);
return flag? Result.success("添加成功") : Result.failed("添加失败");
public Result<String> receive(@RequestBody ReceiveRecord receiveRecord) {
return receiveRecordService.receive(receiveRecord) ? Result.success() : Result.failed();
}
@PutMapping
@Operation(summary = "修改记录")
public Result<String> update(@RequestBody ReceiveRecord receiveRecord) {
boolean flag = receiveRecordService.updateById(receiveRecord);
return flag? Result.success("修改成功") : Result.failed("修改失败");
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() : "");

22
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();
}
}

28
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);
}
//=========================================== 私有方法 ============================================================
/**

14
src/main/java/com/iflytop/handacid/app/core/event/StateChangeEvent.java

@ -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;
}

18
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());
}
}

6
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;

18
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;
}

24
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;
}

25
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) {

8
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)));

38
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";
}

16
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);
}*/
}

4
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;
}

6
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;

2
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;

5
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;
}

2
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;

25
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<FormulationMapper, Formulati
});
}
public List<FormulationListVO> getList(FormulationListDTO dto) {
LambdaQueryWrapper<Formulation> qw = null;
if (dto != null) {
qw = Wrappers.<Formulation>lambdaQuery()
.eq(dto.getSolutionId() != null, Formulation::getSolutionId, dto.getSolutionId())
.eq(dto.getConcentration() != null, Formulation::getConcentration, dto.getConcentration());
}
List<Formulation> formulations = this.list(qw);
List<FormulationListVO> 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;
}
}

34
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<ReceiveRecordMapper, ReceiveRecord> {
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;
}
}

20
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

Loading…
Cancel
Save