package com.sw.mes.fls.service.impl;

import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.fls.dto.ProductAssemblyConfigDto;
import com.sw.mes.fls.service.MesToFlsService;
import com.sw.mes.fls.utils.RequestDto;
import com.sw.mes.fls.utils.RequestUtil;
import com.sw.mes.fls.utils.ResultDto;
import com.sw.mes.mcs.service.MesToMcsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MesToFlsServiceImpl implements MesToFlsService {
    @Autowired
    private RequestUtil requestUtil;

    @Autowired
    private MesToMcsService mesToMcsService;

    private final String productAssemblyConfigFlsUrl = "";

    @Override
    public Result productAssemblyConfigOut(ProductAssemblyConfigDto productAssemblyConfigDto) {
        //打托配置信息下发fls
        ResultDto resultDtoFls = requestUtil.postForFls(new RequestDto(productAssemblyConfigFlsUrl, productAssemblyConfigDto));
        if (resultDtoFls.getStatus() != 200){
            return ResultGenerator.fail("自动打托工位配置信息下发fls失败!" + resultDtoFls.getMessage());
        }
        //打托配置信息下发mcs
        com.sw.mes.mcs.utils.ResultDto resultDtoMcs = mesToMcsService.productAssemblyConfigOut(productAssemblyConfigDto);
        if (resultDtoMcs.getStatus() != 100){
            return ResultGenerator.fail("自动打托工位配置信息下发mcs失败!" + resultDtoFls.getMessage());
        }

        return ResultGenerator.success();
    }
}
