Browse Source

通道加排序

master
王梦远 3 days ago
parent
commit
3909fe23c5
  1. 14
      src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java
  2. 13
      src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java
  3. 4
      src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
  4. 6
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  5. 7
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
  6. 8
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

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

@ -117,6 +117,20 @@ public class AuditRecordController {
String fileName = "审计记录_" + System.currentTimeMillis() + ".xlsx"; String fileName = "审计记录_" + System.currentTimeMillis() + ".xlsx";
// 尝试保存到U盘 // 尝试保存到U盘
String filePath = usbPath + File.separator + fileName; String filePath = usbPath + File.separator + fileName;
log.info("导出审计记录到:" + filePath);
// 显式创建文件
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
if (!file.createNewFile()) {
return Result.failed("文件创建失败");
}
} catch (IOException e) {
log.error(e.getMessage());
return Result.failed("导出失败" + e.getMessage());
}
try (FileOutputStream fileOut = new FileOutputStream(filePath)) { try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
workbook.write(fileOut); workbook.write(fileOut);
workbook.close(); workbook.close();

13
src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java

@ -116,6 +116,19 @@ public class ReceiveRecordController {
String fileName = "领取记录_" + System.currentTimeMillis() + ".xlsx"; String fileName = "领取记录_" + System.currentTimeMillis() + ".xlsx";
// 尝试保存到U盘 // 尝试保存到U盘
String filePath = usbPath + File.separator + fileName; String filePath = usbPath + File.separator + fileName;
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
try {
if (!file.createNewFile()) {
return Result.failed("文件创建失败");
}
} catch (IOException e) {
log.error(e.getMessage());
return Result.failed("导出失败" + e.getMessage());
}
log.info("导出领取记录到:" + filePath);
try (FileOutputStream fileOut = new FileOutputStream(filePath)) { try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
workbook.write(fileOut); workbook.write(fileOut);
workbook.close(); workbook.close();

4
src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java

@ -50,9 +50,9 @@ public class BleGamepadEventListener {
} else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) { } else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) {
log.info("蓝牙手柄 预充按钮 按下"); log.info("蓝牙手柄 预充按钮 按下");
if (deviceState.isSolutionPreFillStart()) { if (deviceState.isSolutionPreFillStart()) {
channelCtrlService.solutionPreFillStart();
} else {
channelCtrlService.solutionPreFillStop(); channelCtrlService.solutionPreFillStop();
} else {
channelCtrlService.solutionPreFillStart();
} }
} else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) { } else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) {
log.info("蓝牙手柄 连接成功"); log.info("蓝牙手柄 连接成功");

6
src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java

@ -52,7 +52,9 @@ public class DeviceState {
*/ */
public synchronized JSONObject toJSON() { public synchronized JSONObject toJSON() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.putOnce("channelState", new ArrayList<>(channelStateMap.values()));
List<ChannelState> channelList = new ArrayList<>(channelStateMap.values());
channelList.sort(Comparator.comparingInt(a -> a.getChannelCode().ordinal()));
json.putOnce("channelState", channelList);
json.putOnce("mode", mode); json.putOnce("mode", mode);
json.putOnce("delay", delay); json.putOnce("delay", delay);
json.putOnce("virtual", virtual); json.putOnce("virtual", virtual);
@ -106,7 +108,7 @@ public class DeviceState {
*/ */
public boolean isSolutionPreFillStart() { public boolean isSolutionPreFillStart() {
return channelStateMap.values().stream() return channelStateMap.values().stream()
.anyMatch(cs -> cs.getStateCode() == ChannelStateCode.ADD);
.anyMatch(cs -> cs.getStateCode() == ChannelStateCode.PRE);
} }
/** /**

7
src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

@ -53,8 +53,8 @@ public class ChannelCtrlService {
CommandUtil.wait(currentPositionCommandFuture); CommandUtil.wait(currentPositionCommandFuture);
Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position");
channelState.setPumpPositionCache(currentPosition); channelState.setPumpPositionCache(currentPosition);
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()));
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId())
.eq(Formulation::getConcentration, channelState.getConcentration()).eq(Formulation::getVolume, channelState.getTargetVolume()).last("limit 1"));
DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(),
@ -75,7 +75,8 @@ public class ChannelCtrlService {
} else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式 } else if (SolutionAddMode.CLICK.equals(deviceState.getMode())) {//点动模式
List<CommandFuture> commandFutureList = new ArrayList<>(); List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) { for (ChannelState channelState : channelStateList) {
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()));
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId())
.eq(Formulation::getConcentration, channelState.getConcentration()).eq(Formulation::getVolume, channelState.getTargetVolume()).last("limit 1"));
DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(),

8
src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

@ -98,16 +98,16 @@ public class DeviceInitService {
*/ */
public void initDeviceState() { public void initDeviceState() {
log.info("初始化 initDeviceState"); log.info("初始化 initDeviceState");
for (ChannelCode code : ChannelCode.values()) {
List<Channel> channels = channelService.list(new LambdaQueryWrapper<>(new Channel()).orderByAsc(Channel::getId));
for (Channel channel : channels) {
//初始化通道 //初始化通道
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());
ChannelState channelState = channelStateObjectProvider.getObject(channel.getCode(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume());
Solution solution = solutionService.getById(channel.getSolutionId()); Solution solution = solutionService.getById(channel.getSolutionId());
if (solution != null) { if (solution != null) {
channelState.setSolutionId(solution.getId()); channelState.setSolutionId(solution.getId());
channelState.setSolutionName(solution.getName()); channelState.setSolutionName(solution.getName());
} }
deviceState.getChannelStateMap().put(code, channelState);
deviceState.getChannelStateMap().put(channel.getCode(), channelState);
} }
deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKeyToString(SystemConfigKey.SOLUTION_ADD_MODE))); deviceState.setMode(SolutionAddMode.valueOf(systemConfigService.getValueByKeyToString(SystemConfigKey.SOLUTION_ADD_MODE)));
deviceState.setDelay(systemConfigService.getValueByKeyToInteger(SystemConfigKey.SOLUTION_ADD_DELAY)); deviceState.setDelay(systemConfigService.getValueByKeyToInteger(SystemConfigKey.SOLUTION_ADD_DELAY));

Loading…
Cancel
Save