package com.mvc.forwarmana;

import com.alibaba.fastjson.JSON;
import com.mvc.model.TAireadModel;
import com.mvc.model.forwarding.DicForwarderModel;
import com.mvc.model.forwarding.WbtyRequestModel;
import com.mvc.utils.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 万邦拓源数据API
 */
@Component
public class WbtyForwarder {
    private static Logger log = LoggerFactory.getLogger(WbtyForwarder.class);

    public void commitData(DicForwarderModel forwarderModel, TAireadModel aireadModel) {
        try {
            //要以机井编码为关联(TargetStationCode存储的是机井编码)
            WbtyRequestModel data = new WbtyRequestModel(aireadModel);
            String json = JSON.toJSONString(data);
            //使用warn是发现info日志0点不全,暂用warn观察 2024-06-15 guozhao
            log.warn("{}请求参数：{}", forwarderModel.getServerName(), json);
            String response = HttpUtil.postData(forwarderModel.getServerIp(), data);
            /*ResultMap<WbtyResponseModel> resultMap = JSON.parseObject(response, new TypeReference<>() {
            });*/
            log.warn("{}API返回结果：{}", forwarderModel.getServerName(), response);
        } catch (Exception ex) {
            log.warn("万邦数据处理异常", ex);
        }
    }
}
