package com.friday.distributor.common;

import com.friday.blank.api.dto.taskType.TaskTypeMachineDto;
import com.friday.distributor.exception.DistributorRuntimeException;
import com.friday.base.common.response.DubboResult;
import com.friday.base.redis.annotation.Rlock;
import com.friday.operation.api.tooldriver.dto.common.DriverBase;
import com.friday.operation.api.tooldriver.dto.rpa.RobotDto;
import com.friday.operation.api.tooldriver.service.ICapabilityDriver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Author YaoYao
 * @Date Created In 16:39 2023/3/23
 * @Description RPA运行相关
 * @Modified By
 */
@Service
@Slf4j
public class RpaExecHelper {
    @Autowired
    private ICapabilityDriver rpaDriver;

    @Rlock(localKey = "taie-robot-info")
    public RobotDto getRobotInfo(TaskTypeMachineDto rpaRobot){
        DriverBase driverBase = DriverBase.builder()
                .tenantKey(rpaRobot.getOcTenantKey())
                .build();
        DubboResult<RobotDto> rpaRobotResult = rpaDriver.queryRobotByKey(driverBase, rpaRobot.getRobotKey());
        if(rpaRobotResult.success() && Objects.nonNull(rpaRobotResult.getObject())){
            return rpaRobotResult.getObject();
        } else {
            throw new DistributorRuntimeException("查询OC-rpa工位状态失败", rpaRobot.getRobotName());
        }
    }

}
