Files
tms-erp-web/src/api/business/hcs.js
T

134 lines
3.5 KiB
JavaScript

import request from '@/axios';
const baseUrl = '/blade-transport/hcs';
/** 进程内缓存,避免列表页重复请求推送开关 */
let immediateEnabledCache = null;
let immediateEnabledPromise = null;
/**
* 查询 HCS 即时推送开关(thirdParty.hcs.push.immediate-enabled)。
* 关闭时项目管理/合同管理隐藏「推送合规」「批量推送合规」。
*/
export const getPushConfig = () =>
request({
url: `${baseUrl}/push-config`,
method: 'get',
});
export const loadHcsImmediateEnabled = () => {
if (immediateEnabledCache !== null) {
return Promise.resolve(immediateEnabledCache);
}
if (immediateEnabledPromise) {
return immediateEnabledPromise;
}
immediateEnabledPromise = getPushConfig()
.then(res => {
const data = res?.data?.data ?? res?.data ?? {};
immediateEnabledCache = data.immediateEnabled === true || data.immediateEnabled === 'true';
return immediateEnabledCache;
})
.catch(() => {
immediateEnabledCache = false;
return false;
})
.finally(() => {
immediateEnabledPromise = null;
});
return immediateEnabledPromise;
};
// 合规推送涉及 HCS 远程多次调用(风险校验+附件转传+起草),可达 20s+,覆盖全局 10s 超时
export const repush = (bizType, id) =>
request({
url: `${baseUrl}/sync/${bizType}/${id}`,
method: 'post',
timeout: 60000,
});
// 批量推送为逐条同步推送,耗时随勾选行数线性增长,进一步放宽超时
export const repushBatch = (bizType, ids) =>
request({
url: `${baseUrl}/sync/${bizType}/batch`,
method: 'post',
data: ids,
timeout: 300000,
});
export const getTemplates = () =>
request({
url: `${baseUrl}/master-data/template`,
method: 'get',
});
export const refreshMasterData = () =>
request({
url: `${baseUrl}/master-data/refresh`,
method: 'post',
timeout: 60000,
});
export const getRisk = customerCode =>
request({
url: `${baseUrl}/risk`,
method: 'get',
params: { customerCode },
timeout: 30000,
});
// 客商风险批量查询(客商列表页展示用):入参编号数组,后端逐个查 C101-1,单个失败跳过
export const getRiskBatch = customerCodes =>
request({
url: `${baseUrl}/risk/batch`,
method: 'get',
params: { customerCodes: (customerCodes || []).join(',') },
timeout: 60000,
});
// 客商风险按名称查询(客商档案表单展示用):名称反查编号后口径同编号查询
export const getRiskByName = customerName =>
request({
url: `${baseUrl}/risk/by-name`,
method: 'get',
params: { customerName },
timeout: 30000,
});
export const uploadAttachment = formData =>
request({
url: `${baseUrl}/attachment/upload`,
method: 'post',
data: formData,
timeout: 60000,
});
export const downloadAttachment = (fdId, name) =>
request({
url: `${baseUrl}/attachment/download`,
method: 'get',
params: { fdId, name },
responseType: 'blob',
timeout: 120000,
});
export const applyContractSpec = data =>
request({
url: `${baseUrl}/contract/spec-apply`,
method: 'post',
data,
timeout: 60000,
});
export const confirmContractSpec = (id, result) =>
request({
url: `${baseUrl}/contract/spec/confirm`,
method: 'post',
params: { id, result },
});
export const unwrapData = response => {
const data = response?.data?.data ?? response?.data;
return data && typeof data === 'object' && 'data' in data ? data.data : data;
};