package com.prolog.eis.service.pms.impl;

import cn.hutool.core.util.StrUtil;
import com.prolog.eis.dto.pms.InBoundCarryTaskReq;
import com.prolog.eis.dto.pms.PmsCarryTaskReq;
import com.prolog.eis.service.pms.PmsCarryTaskService;
import com.prolog.eis.service.pms.PmsInCarryTaskService;
import com.prolog.eis.service.pms.PmsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @desc:
 * @author: zhangJie
 * @date: 2023/7/11 10:43
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PmsServiceImpl implements PmsService {

    private final PmsInCarryTaskService pmsInCarryTaskService;
    private final PmsCarryTaskService pmsCarryTaskService;

    @Async
    @Override
    public void inCarryTask(String containerNo,String originalLocation) {
        InBoundCarryTaskReq inBoundCarryTaskReq = new InBoundCarryTaskReq();
        inBoundCarryTaskReq.setTaskId(StrUtil.uuid());
        inBoundCarryTaskReq.setContainerNo(containerNo);
        inBoundCarryTaskReq.setOriginalLocation(originalLocation);
        try {
            pmsInCarryTaskService.execute(inBoundCarryTaskReq);
        } catch (Exception e) {
            log.error("容器【{}】请求pms搬运失败：" + e.getMessage(),containerNo, e);
        }

    }

    @Override
    public void carryTask(String containerNo, String originalLocation, String targetLocation) {
        PmsCarryTaskReq pmsCarryTaskReq = new PmsCarryTaskReq();
        pmsCarryTaskReq.setContainerNo(containerNo);
        pmsCarryTaskReq.setOriginalLocation(originalLocation);
        pmsCarryTaskReq.setTargetLocation(targetLocation);
        try {
            pmsCarryTaskService.execute(pmsCarryTaskReq);
        } catch (Exception e) {
            log.error("容器【{}】请求pms搬运失败,进入重试：" + e.getMessage(),containerNo, e);
        }

    }
}
