Browse Source

feat:定量排空

master
白凤吉 3 days ago
parent
commit
defeda86f9
  1. 9
      src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStartCommand.java
  2. 96
      src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStopCommand.java
  3. 4
      src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java
  4. 5
      src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java
  5. 9
      src/main/resources/sql/init.sql

9
src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStartCommand.java

@ -2,6 +2,7 @@ package com.iflytop.handacid.app.command.control;
import com.iflytop.handacid.app.common.annotation.CommandMapping;
import com.iflytop.handacid.app.common.enums.ChannelStateCode;
import com.iflytop.handacid.app.common.enums.SystemConfigKey;
import com.iflytop.handacid.app.common.utils.CommandUtil;
import com.iflytop.handacid.app.core.command.BaseCommandHandler;
import com.iflytop.handacid.app.core.command.CommandFuture;
@ -11,6 +12,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.common.service.SystemConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -30,6 +32,7 @@ public class SolutionDrainStartCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
private final SystemConfigService systemConfigService;
@Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) {
@ -38,10 +41,14 @@ public class SolutionDrainStartCommand extends BaseCommandHandler {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
channelState.setStateCode(ChannelStateCode.DRAIN);
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelState.getChannelCode());
Double drainRevolutions = systemConfigService.getValueByKeyToDouble(SystemConfigKey.DRAIN_REVOLUTIONS);
DeviceCommand deviceCommand = channelCtrlService.getPumpMoveByCommandByChannel(channelState.getChannelCode(), -drainRevolutions);
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
for (ChannelState channelState : channelCodeList) {
channelState.setStateCode(ChannelStateCode.IDLE);
}
});
}
}

96
src/main/java/com/iflytop/handacid/app/command/control/SolutionDrainStopCommand.java

@ -1,48 +1,48 @@
package com.iflytop.handacid.app.command.control;
import com.iflytop.handacid.app.common.annotation.CommandMapping;
import com.iflytop.handacid.app.common.enums.ChannelStateCode;
import com.iflytop.handacid.app.common.utils.CommandUtil;
import com.iflytop.handacid.app.core.command.BaseCommandHandler;
import com.iflytop.handacid.app.core.command.CommandFuture;
import com.iflytop.handacid.app.core.command.DeviceCommand;
import com.iflytop.handacid.app.core.state.ChannelState;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 停止排空
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("solution_drain_stop")
public class SolutionDrainStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
@Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) {
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.DRAIN);
return runAsync(() -> {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
channelState.setStateCode(ChannelStateCode.DRAIN);
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
});
}
}
//package com.iflytop.handacid.app.command.control;
//
//import com.iflytop.handacid.app.common.annotation.CommandMapping;
//import com.iflytop.handacid.app.common.enums.ChannelStateCode;
//import com.iflytop.handacid.app.common.utils.CommandUtil;
//import com.iflytop.handacid.app.core.command.BaseCommandHandler;
//import com.iflytop.handacid.app.core.command.CommandFuture;
//import com.iflytop.handacid.app.core.command.DeviceCommand;
//import com.iflytop.handacid.app.core.state.ChannelState;
//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 lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.CompletableFuture;
//
///**
// * 停止排空
// */
//@Slf4j
//@Component
//@RequiredArgsConstructor
//@CommandMapping("solution_drain_stop")
//public class SolutionDrainStopCommand extends BaseCommandHandler {
// private final DeviceCommandService deviceCommandService;
// private final ChannelCtrlService channelCtrlService;
// private final DeviceState deviceState;
//
// @Override
// public CompletableFuture<Void> handle(CommandDTO commandDTO) {
// List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.DRAIN);
// return runAsync(() -> {
// List<CommandFuture> commandFutureList = new ArrayList<>();
// for (ChannelState channelState : channelCodeList) {
// channelState.setStateCode(ChannelStateCode.DRAIN);
// DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode());
// commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
// }
// CommandUtil.wait(commandFutureList);
// });
// }
//}
//

4
src/main/java/com/iflytop/handacid/app/common/enums/SystemConfigKey.java

@ -17,4 +17,8 @@ public enum SystemConfigKey {
* 设备SN码
*/
DEVICE_SN,
/**
* 排空转数
*/
DRAIN_REVOLUTIONS,
}

5
src/main/java/com/iflytop/handacid/common/service/SystemConfigService.java

@ -26,6 +26,11 @@ public class SystemConfigService extends ServiceImpl<SystemConfigMapper, SystemC
return systemConfig != null ? Integer.parseInt(systemConfig.getValue()) : null;
}
public Double getValueByKeyToDouble(SystemConfigKey key){
SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key));
return systemConfig != null ? Double.parseDouble(systemConfig.getValue()) : null;
}
public boolean updateValueByKey(SystemConfigKey key, String value){
SystemConfig systemConfig = this.getOne(new LambdaQueryWrapper<>(SystemConfig.class).eq(SystemConfig::getKey, key));
systemConfig.setValue(value);

9
src/main/resources/sql/init.sql

@ -86,10 +86,11 @@ CREATE TABLE IF NOT EXISTS system_config (
);
INSERT OR IGNORE INTO system_config (id, key, value, description) VALUES
(1, 'SOLUTION_ADD_MODE','AUTO', '加液模式'),
(2, 'SOLUTION_ADD_DELAY','3', '自动加液间隔'),
(3, 'PUMP_CONVERSION_FACTOR','100', '蠕动泵转数与泵位置换算系数'),
(4, 'DEVICE_SN','ABCDEFG202507312000000001', '设备SN码');
(1, 'SOLUTION_ADD_MODE', 'AUTO', '加液模式'),
(2, 'SOLUTION_ADD_DELAY', '3', '自动加液间隔'),
(3, 'PUMP_CONVERSION_FACTOR', '100', '蠕动泵转数与泵位置换算系数'),
(4, 'DEVICE_SN', 'ABCDEFG202507312000000001', '设备SN码'),
(5, 'DRAIN_REVOLUTIONS', '50', '排空转数');
-- 系统日志
CREATE TABLE IF NOT EXISTS system_log (

Loading…
Cancel
Save