石墨消解仪后端服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.5 KiB

  1. package com.iflytop.gd.app.cmd;
  2. import cn.hutool.json.JSONArray;
  3. import cn.hutool.json.JSONObject;
  4. import com.iflytop.gd.app.core.BaseCommandHandler;
  5. import com.iflytop.gd.app.model.dto.CmdDTO;
  6. import com.iflytop.gd.app.service.ContainerService;
  7. import com.iflytop.gd.app.service.DeviceCommandUtilService;
  8. import com.iflytop.gd.app.service.DeviceStateService;
  9. import com.iflytop.gd.common.annotation.CommandMapping;
  10. import com.iflytop.gd.common.enums.AcidPumpDeviceCode;
  11. import com.iflytop.gd.common.exception.AppException;
  12. import com.iflytop.gd.common.result.ResultCode;
  13. import lombok.RequiredArgsConstructor;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.springframework.stereotype.Component;
  16. import java.util.concurrent.CompletableFuture;
  17. /**
  18. * 添加溶液
  19. */
  20. @Slf4j
  21. @Component
  22. @RequiredArgsConstructor
  23. @CommandMapping("solution_add")//业务指令注解
  24. public class SolutionAddCommand extends BaseCommandHandler {
  25. private final DeviceCommandUtilService deviceCommandUtilService;
  26. private final ContainerService containerService;
  27. private final DeviceStateService deviceStateService;
  28. @Override
  29. public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
  30. deviceStateService.setSolutionModuleStatePumping(true);
  31. return runAsync(() -> {
  32. JSONArray dataList = (JSONArray) cmdDTO.getParams().get("dataList");
  33. for (int i = 0; i < dataList.size(); i++) {
  34. JSONObject tubeSol = dataList.getJSONObject(i);
  35. Integer tubeNum = tubeSol.getInt("tubeNum");
  36. JSONArray solutionList = tubeSol.getJSONArray("solutionList");
  37. for (int j = 0; j < solutionList.size(); j++) {
  38. JSONObject addSolution = solutionList.getJSONObject(j);
  39. Long solId = addSolution.getLong("solId");
  40. Double volume = addSolution.getDouble("volume");
  41. AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);
  42. if (acidPumpDevice == null) {
  43. throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);
  44. }
  45. deviceCommandUtilService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管点位
  46. deviceCommandUtilService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
  47. }
  48. }
  49. deviceCommandUtilService.dualRobotOrigin();
  50. deviceStateService.setSolutionModuleStatePumping(false);
  51. });
  52. }
  53. }