import Common from '../common/Common';

// 获取业务名
export const getBusinessName = () => {
  var requestUrl = 'ArchivesResource/listBusinessName';
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
      contentType: 'application/json',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
// 获取业务参数
export const getBusinessParams = name => {
  var requestUrl = 'ArchivesResource/listParameterDefines?businessName=' + name;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
      contentType: 'application/json',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

// 执行数据归档
export const execute = params => {
  var requestUrl = 'ArchivesResource/executeData';

  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'post',
      contentType: 'application/json',
      dataType: 'json',
      data: JSON.stringify(params),

      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};