rehn-datasync
v1.0.7
Published
Common methods for data synchronization
Downloads
2
Readme
Rehn dataSync Package
Common methods for data synchronization
Installation
npm install rehn-datasync
优化项
- 上传下载代码解耦,方便维护
- 提取公共逻辑,并支持对下载数据的自定义处理
- 使用
setTimeout
代替while(true)
,防止资源泄露和阻塞主线程
使用示例
const setting = {
centerApi: medCineBoxConfig.CenterApi,
token: medCineBoxConfig.CenterApiToken,
HospitalId: equipmentInfo.HospitalId,
EquipmentId: equipmentInfo.EquipmentId,
UniqueCode: equipmentInfo.UniqueCode,
UploadTableList: allDownloadList,
DownloadTableList: allDownloadList
}
Download(setting, async (res) => {
const {
tableName,
clientIndex,
DataList
} = res.Data
if(res.Code === 1000) {
console.log(`同步下载成功,表名:${tableName},clientIndex:${clientIndex},数据:`, DataList)
// 表下载成功后,需要做什么操作,自行决定:在mid32中是更新equipmentconfig表
await downLoadCallBack(res) // 注意要返回一个Promise
} else {
console.error(`同步下载失败, 表名:${tableName},clientIndex:${clientIndex},Message: ${res.Message},数据:`, DataList)
}
}).then(()=> {
console.log("同步下载启动成功")
}).catch(e => {
console.error(e)
})
Upload(setting, async (res) => {
const {
tableName,
clientIndex,
DataList
} = res.Data
if(res.Code === 1000) {
console.log(`同步上传成功,表名:${tableName},clientIndex:${clientIndex},数据:`, DataList)
} else {
console.error(`同步上传失败, 表名:${tableName},clientIndex:${clientIndex},Message: ${res.Message},数据:`, DataList)
}
}).then(()=> {
console.log("同步上传启动成功")
}).catch(e => {
console.error(e)
})