演示

CurrencyExchangeService

货币汇率 — 更新货币对(及反向)、读取最新汇率,或列出某源货币的汇率。

注入

TSXinject
1import { 2 ContainerRegistryManager, 3 CurrencyExchangeService, 4 Inject, 5 Service, 6} from "@quan-erp/shared-backend-core"; 7 8@Service() 9export class MyPluginService { 10 @Inject(CurrencyExchangeService, ContainerRegistryManager.BUILTIN_PLUGIN) 11 private currencyExchangeService: CurrencyExchangeService; 12}

方法

  • updateRate(fromCurrencyId, toCurrencyId, rate) — 写入 from→to 并维护反向汇率
  • getRate(fromCurrencyId, toCurrencyId) — 该货币对最新汇率(实体名 CurrencyExchangeRateEnity,与源码一致)
  • getLatestRates(fromCurrencyId) — 某源货币到其他货币的最新汇率
TSXrates
1import { 2 ContainerRegistryManager, 3 CurrencyExchangeService, 4 Inject, 5 Service, 6} from "@quan-erp/shared-backend-core"; 7 8@Service() 9export class FxService { 10 @Inject(CurrencyExchangeService, ContainerRegistryManager.BUILTIN_PLUGIN) 11 private fx: CurrencyExchangeService; 12 13 async setUsdToMmk(usdId: number, mmkId: number, rate: number) { 14 await this.fx.updateRate(usdId, mmkId, rate); 15 } 16 17 async convertHint(fromId: number, toId: number) { 18 const row = await this.fx.getRate(fromId, toId); 19 return row?.rate ?? null; 20 } 21 22 async board(fromId: number) { 23 return this.fx.getLatestRates(fromId); 24 } 25}