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

// 获取部门列表
export const queryOrgList = () => {
  const requestUrl = 'organizationResource/getClientOrganizations';
    
    
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
                    
      dataType: 'json',
                    
                    
      beforeSend: function(request) {
        Common.addTokenToRequest(request);
      },
      success: function(data) {
        resolve(data);
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

/**
 * 根据部门查询资产和盘点详情
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryDetailsById = organizationId => {
  const requestUrl = 'AssetInstanceResource/queryAssetAndCheckDetailsByOrganization?organizationId=' + organizationId;
    
    
  return new Promise((resolve, reject) => {
    $.ajax({
      url: Common.getApiURL(requestUrl),
      type: 'get',
                    
      dataType: 'json',
                    
                    
      beforeSend: function(request) {
        Common.addTokenToRequest(request);
      },
      success: function(data) {
        resolve(data);
      },
      error: function(XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
/**
 * 资产总数变化趋势
 * @param {*} startDate 开始时间
 * @param {*} endDate 开始时间
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryAssetTrend = (startDate, endDate, organizationId) => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('SqlApiResource/execute/20260309_143537' + '?startDate=' + startDate + '&endDate=' + endDate + '&organizationId=' + organizationId),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
// 部门资产分布
export const queryOrgAsset = () => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('SqlApiResource/execute/20260310_150402'),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};

/**
 * 资产分类统计
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryAssetType = organizationId => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('SqlApiResource/execute/20260310_150835?organizationId=' + organizationId),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
/**
 * 报废资产分析
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryScrapAsset = organizationId => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('AssetInstanceScrapResource/queryScrapDashboard?organizationId=' + organizationId),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
/**
 * 查询报废资产预警
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryScrapWarning = organizationId => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('AssetInstanceScrapResource/queryAssetScrapWarning?organizationId=' + organizationId),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};
/**
 * 最新盘点单查询
 * @param {*} organizationId 部门Id
 * @returns 
 */
export const queryInventory = organizationId => {
  return new Promise((resolve, reject) => {
    $.ajax({
      type: 'get',
      url: Common.getApiURL('SqlApiResource/execute/20260311_111317?organizationId=' + organizationId),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: function (data) {
        resolve(data);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        reject(XMLHttpRequest);
      },
    });
  });
};