石墨消解仪后端服务
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

package com.iflytop.gd.app.cmd;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.ContainerService;
import com.iflytop.gd.app.service.DeviceCommandUtilService;
import com.iflytop.gd.app.service.DeviceStateService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.enums.AcidPumpDeviceCode;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 添加溶液
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("solution_add")//业务指令注解
public class SolutionAddCommand extends BaseCommandHandler {
private final DeviceCommandUtilService deviceCommandUtilService;
private final ContainerService containerService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
deviceStateService.setSolutionModuleStatePumping(true);
return runAsync(() -> {
JSONArray dataList = (JSONArray) cmdDTO.getParams().get("dataList");
for (int i = 0; i < dataList.size(); i++) {
JSONObject tubeSol = dataList.getJSONObject(i);
Integer tubeNum = tubeSol.getInt("tubeNum");
JSONArray solutionList = tubeSol.getJSONArray("solutionList");
for (int j = 0; j < solutionList.size(); j++) {
JSONObject addSolution = solutionList.getJSONObject(j);
Long solId = addSolution.getLong("solId");
Double volume = addSolution.getDouble("volume");
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);
if (acidPumpDevice == null) {
throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);
}
deviceCommandUtilService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管点位
deviceCommandUtilService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
}
}
deviceCommandUtilService.dualRobotOrigin();
deviceStateService.setSolutionModuleStatePumping(false);
});
}
}