package cn.iocoder.yudao.module.system.api.robot;

import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.api.robot.vo.RobotPathStatusDTO;
import cn.iocoder.yudao.module.system.api.robot.vo.RobotReactiveStatusDTO;
import cn.iocoder.yudao.module.system.enums.path.PathIsReachEnum;
import cn.iocoder.yudao.module.system.service.path.PathPlanningService;
import cn.iocoder.yudao.module.system.service.robot.RobotInformationService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class RobotPathStatusApiImpl implements RobotPathStatusApi {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private RobotInformationService robotInformationService;

    @Resource
    private PathPlanningService pathPlanningService;

    /**
     * 导航实时行为上报
     * @param message
     */
    @Override
    public void robotPathStatus(String message) {
        taskExecutor.execute(() -> {
            doRobotPathStatus(message);
        });
    }

    private void doRobotPathStatus(String message) {
        log.info("111111导航实时行为上报: {}", message);
        TenantContextHolder.setTenantId(1L);
        RobotPathStatusDTO data = JSON.parseObject(message, RobotPathStatusDTO.class);
        String robotNo = robotInformationService.getRobotNoByMac(data.getMac());
        pathPlanningService.updateBehavior(data.getOrderId(), robotNo
                , data.getPoseId(), data.getStatus());
    }




























}
