package com.xisc.pm.infra.client;

import com.alibaba.fastjson.JSONObject;
import com.xisc.pm.common.dto.ProductionPlanningApiDTO;
import com.xisc.pm.infra.feign.SmApiFeign;
import com.xisc.pm.infra.util.Utils;
import io.choerodon.core.exception.CommonException;
import io.choerodon.core.exception.ExceptionResponse;
import lombok.extern.slf4j.Slf4j;
import org.hzero.core.util.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @date 2024/11/11 8:43
 * @description
 */
@Slf4j
@Component
public class SmApiClient {
    @Autowired
    private SmApiFeign smApiFeign;

   public void productionPlanningApi(Long tenantId, List<ProductionPlanningApiDTO> requestList) {
       log.info("调用Sm-API【productionPlanningApi】，入参：tenantId = {}, requestList = {}", tenantId, JSONObject.toJSON(requestList));
       ResponseEntity<String> res = smApiFeign.productionPlanningApi(tenantId, requestList);
       log.info("调用Sm-API【productionPlanningApi】，返回：" + res.getBody());
       if (ResponseUtils.isFailed(res)) {
           ExceptionResponse response = Utils.getExceptionResponse(res);
           throw new CommonException("pm.call_inface_info", "炼钢", response.getMessage());
       }
   }

    public void heatRetracted(Long tenantId, List<String> ponoList) {
        log.info("调用Sm-API【heatRetracted】，入参：tenantId = {}, ponoList = {}", tenantId, JSONObject.toJSON(ponoList));
        ResponseEntity<String> res = smApiFeign.heatRetracted(tenantId, ponoList);
        log.info("调用Sm-API【heatRetracted】，返回：" + res.getBody());
        if (ResponseUtils.isFailed(res)) {
            ExceptionResponse response = Utils.getExceptionResponse(res);
            throw new CommonException("pm.call_inface_info", "炼钢", response.getMessage());
        }
    }
}
