A multi-tenant cost accounting method, system, storage medium and device
By identifying and merging repetitive calculation tasks through asynchronous generation and group scanning, combined with an anti-looping mechanism, the problem of wasted computing resources in inventory cost accounting under multi-tenant high concurrency environments is solved, thereby improving system efficiency and accuracy.
Patent Information
- Application Number
- CN202511457259.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-13
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-10-13
AI Technical Summary
In cloud-based multi-tenant enterprise resource planning (ERP) and supply chain management (SCM) systems, high-concurrency scenarios lead to excessive repetitive calculation tasks in multi-tenant inventory inbound and outbound operations, resulting in wasted computing resources, slow system response, and impact on user experience and business decisions.
Asynchronous cost calculation tasks are generated and stored in a task queue. Preset cost accounting dimension data is used as the dimension key to perform task grouping and scanning, identify duplicate task groups and apply deduplication strategies to merge and clean them up. Combined with an anti-loop mechanism, necessary tasks are executed and inventory costs are recalculated.
It significantly reduces the number of invalid calculations, saves computing resources, improves system processing efficiency and throughput, and ensures the accuracy of calculation results and the stability of the system.
Smart Images

Figure CN120912116B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of supply chain management, and particularly relates to a multi-tenant cost accounting method and system, a storage medium and equipment. BACKGROUND
[0002] In a cloud multi-tenant enterprise resource planning (ERP) and supply chain management (SCM) system, high concurrency of core businesses such as warehouse in and out of stock of multiple tenants occurs, and each business change may trigger cost recalculation. The prior art usually adopts a synchronous calculation or a timed batch calculation manner to process cost accounting. The synchronous calculation manner immediately performs cost calculation when a business occurs, which may seriously block the main business process, and in a high concurrency scenario, the system response is slow, and the user experience is extremely poor. The timed batch calculation cannot provide real-time cost data, and affects the business decision-making of an enterprise.
[0003] A more prominent problem is that in a high concurrency environment, continuous operations on the same stock may generate a large number of repeated cost calculation tasks. For example, a plurality of warehouse in and out of stock operations on the same material of a warehouse are performed in a short time, and the system generates a plurality of calculation requests. If these tasks are not optimized, a plurality of substantially combinable calculations will be performed in turn, which causes a great waste of computing resources and significantly reduces the overall efficiency and throughput of the system. SUMMARY
[0004] The application aims to provide a multi-tenant cost accounting method, system, storage medium and equipment, which reduces the number of invalid repeated calculations, greatly saves computing resources, and significantly improves the processing efficiency of the cost accounting module and the overall performance of the system, to solve the problems in the background technology.
[0005] To achieve the above-mentioned purpose, the application adopts the following technical solution: a multi-tenant cost accounting method, comprising the following steps:
[0006] In response to a core business event, a cost calculation task is generated asynchronously and stored in a task queue, and the core business event includes a warehouse in and out of stock record update event and a transfer in warehouse cost calculation event;
[0007] The preset cost accounting dimension data is used as a dimension key to group and scan the tasks in the task queue, and a repeated task group with the same dimension key is identified;
[0008] For each repeated task group identified, a preset deduplication strategy is applied for merging and cleaning, and a task that must be executed is retained;
[0009] Based on the anti-circulation mechanism, the cost calculation of the reserved task is performed, the cost, the quantity and the amount of the inventory corresponding to the dimension key after a specified business time point are recalculated according to a preset inventory cost accounting method, and the inventory information is updated.
[0010] Preferably, the cost calculation task is a structured data object, and contains one or more of the following fields: a calculation task unique ID, cost accounting dimension data, business time data, warehouse-in / out record deletion ID, calculation batch ID, and allocation-out ID.
[0011] Preferably, the business time data includes warehouse-in / out document date and audit effective time, which are used to determine the starting time point in the cost reconstruction calculation, so as to ensure the correct calculation timing.
[0012] Preferably, the cost accounting dimension data includes a combination of tenant ID, accounting organization ID, warehouse ID, inventory ID and inventory SKUID.
[0013] Preferably, the deduplication strategy includes comparing the business time data of each task in the repeated task group, and retaining the task with the earliest business time.
[0014] Preferably, the inventory cost accounting method is the first-in-first-out method, and when there is a task triggered by deleting the warehouse-in / out record in the task group, the task triggered by the deletion is retained.
[0015] Preferably, the anti-circulation mechanism is implemented as follows:
[0016] A globally unique calculation batch ID is assigned to the task generated for the allocation-out event;
[0017] When the calculation task of the allocation-in is triggered by the completion of the task execution, the calculation batch ID is inherited to the new task, and the allocation-out ID of the current trigger source allocation-out record is recorded;
[0018] Before generating any calculation task of the allocation-in, the system checks whether there is a task carrying the same calculation batch ID to process the same allocation-out record;
[0019] If the checking result is yes, the generation of the new task is intercepted, and the circulation chain is cut off;
[0020] If the checking result is no, the task is allowed to be generated and the recursive inheritance rule is continued to be executed.
[0021] On the other hand, the present application proposes a multi-tenant cost accounting system, which comprises:
[0022] The event listening and task generating module is configured to generate cost calculation tasks asynchronously in response to core business events, wherein the core business events include inventory warehouse-in and warehouse-out record updating events and allocation warehouse-in cost calculation events.
[0023] The task queue module is configured to receive and store the cost calculation tasks.
[0024] The task scheduling and deduplication module is configured to group the tasks in the task queue by using preset cost accounting dimension data as dimension keys, identify repeated task groups having the same dimension keys, and apply a preset deduplication strategy to each of the identified repeated task groups to perform merging and cleaning and retain only the tasks that need to be executed.
[0025] The cost calculation engine module is configured to perform cost calculation for the retained tasks based on an anti-circulation mechanism, recalculate the cost, the quantity and the amount of the inventory corresponding to the dimension keys after a specified business time point according to a preset inventory cost accounting method, and update the inventory information.
[0026] One or more tenant clients are communicatively connected to the event listening and task generating module and configured to trigger the core business events.
[0027] In another aspect, the present application provides a computer readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the steps of the multi-tenant cost accounting method.
[0028] In another aspect, the present application provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the multi-tenant cost accounting method when executing the computer program.
[0029] The multi-tenant cost accounting method, system, storage medium and device of the present application have the following advantages compared with the prior art:
[0030] The present application generates cost calculation tasks asynchronously in response to core business events and stores the tasks in a task queue to decouple business operations and cost calculation. On this basis, the tasks in the task queue are grouped by using preset cost accounting dimension data as dimension keys, and repeated task groups having the same dimension keys are identified. Then, each of the identified repeated task groups is merged and cleaned by using a preset deduplication strategy, and only the tasks that need to be executed are retained. Since multiple repeated calculation tasks for the same accounting object are combined into one execution from the source, a large amount of redundant calculation is avoided, and therefore the consumption of computing resources can be significantly reduced, and the processing efficiency and throughput of the system can be greatly improved. BRIEF DESCRIPTION OF DRAWINGS
[0031] Figure 1 Flow chart for the multi-tenant cost accounting method of the present application;
[0032] Figure 2 Block diagram of the multi-tenant cost accounting system of the present application;
[0033] Figure 3 Schematic diagram of the application environment of the multi-tenant inventory cost accounting method of the present application. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. The specific embodiments described herein are only used to explain the present application, and are not used to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0035] The present application provides a multi-tenant cost accounting method as shown in Figure 1 The present application provides a multi-tenant cost accounting method as shown in
[0036] In response to core business events, cost calculation tasks are generated asynchronously and stored in a task queue, and the core business events include: inventory warehouse-in and warehouse-out record update events and allocation warehouse-in cost calculation events;
[0037] Further, the cost calculation task is a structured data object, containing one or more of the following fields: calculation task unique ID, cost accounting dimension data, business time data, warehouse-in and warehouse-out record deletion ID, calculation batch ID, and allocation warehouse-out ID. Among them, the business time data includes the warehouse-in and warehouse-out document date and the audit effective time, which is used to determine the starting time point when the cost is reconstructed and calculated, and to ensure the correct calculation time sequence.
[0038] Calculation task unique ID: used for globally unique identification and tracking of the task;
[0039] Cost accounting dimension data: including the combination of tenant ID, accounting organization ID, warehouse ID, inventory ID, and inventory SKUID, as a combination key, used to uniquely determine the minimum granularity object of cost accounting, and is the core basis for task grouping and deduplication;
[0040] Business time data: including the warehouse entry and exit document date and the audit effective time, used to determine the starting time point when calculating the cost reconstruction, to ensure the correct calculation timing;
[0041] Warehouse record deletion ID: if the current event is triggered by deleting the warehouse record, the ID of the deleted record is recorded, otherwise it is empty; this field is used to restore the inventory data in the first-in-first-out method accounting;
[0042] Calculation batch ID: globally unique ID, as the core field of the anti-circulation mechanism, usually empty; only when the task is generated due to the allocation of warehouse events, a new batch ID is assigned by the system;
[0043] Allocation warehouse ID: used to record the source allocation warehouse record ID that triggers the current task, only assigned when the task is generated due to the allocation of warehouse cost calculation events.
[0044] Group the tasks in the task queue by scanning with the preset cost accounting dimension data as the dimension key, identify the repeated task group with the same dimension key; among them, the cost accounting dimension data includes the combination of tenant ID, accounting organization ID, warehouse ID, inventory ID, and inventory SKUID as the combination key, used to uniquely determine the minimum granularity object of cost accounting, which is the core basis for task grouping and deduplication.
[0045] For each repeated task group identified, apply the preset deduplication strategy for merging and cleaning, and retain the necessary tasks; the deduplication strategy includes:
[0046] Compare the business time data of each task in the repeated task group (sorted according to the combination of warehouse entry and exit document date and audit effective time), and retain the task with the earliest business time (as calculating the cost from the earliest time point of change can cover the impact of all subsequent changes, thus ensuring data continuity and avoiding repeated calculation);
[0047] When the system configuration of inventory cost accounting method is the first-in-first-out method, and there is a task triggered by deleting the warehouse record in the task group ("warehouse record deletion ID" is not empty), retain the task triggered by deleting (as deleting early warehouse records will directly affect the matching of subsequent warehouse costs, and the correct inventory must be restored by cost recalculation, ignoring this operation will lead to data errors).
[0048] Based on the anti-circulation mechanism, the cost calculation is performed for the retained tasks, according to the preset inventory cost accounting method (such as moving weighted average method, first-in-first-out method, etc.), the cost, inventory quantity and inventory amount of the inventory corresponding to the dimension key after the specified business time point are recalculated, and the inventory information is updated.
[0049] When the inventory cost accounting method is the first-in first-out method, and there is a task triggered by deleting the warehouse-in or warehouse-out record in the task group, the task triggered by deletion is retained.
[0050] Exemplarily, the anti-circulation mechanism is implemented as follows:
[0051] Initial task allocation:
[0052] Task generated for the warehouse-out event Assign a globally unique calculation batch ID ;
[0053] Recursive inheritance and record rule:
[0054] When the task (n>1) is executed to trigger the generation of the warehouse-in calculation task :
[0055] Inheritance rule: inherit the calculation batch ID to the new task , and record the warehouse-out ID of the current trigger source warehouse-out record;
[0056] Recursive definition: through the infinite transmission of the batch ID along the task chain , it is ensured that all subsequent warehouse-in calculation tasks carry the same batch ID ;
[0057] Cycle check and interception:
[0058] Before generating any warehouse-in calculation task , the system checks:
[0059] whether there is a task carrying the same calculation batch ID to process the same warehouse-out record;
[0060] If the check result is yes, the generation of the new task is intercepted, and the circulation chain is cut off;
[0061] If the check result is no, the task is allowed to be generated and the recursive inheritance rule is continued to be executed.
[0062] On the other hand, the present application proposes a multi-tenant cost accounting system, as shown in Figure 2 , which comprises:
[0063] An event listening and task generation module is configured to generate a cost calculation task asynchronously in response to a core business event; the core business event includes a warehouse-in or warehouse-out record update event and a warehouse-in cost calculation event.
[0064] The task queue module is used to receive and store cost calculation tasks;
[0065] The task scheduling and deduplication module is used to scan the tasks to be processed in the task queue in groups using the preset cost accounting dimension data as the dimension key, identify the duplicate task groups with the same dimension key, and apply the preset deduplication strategy to each identified duplicate task group to merge and clean up, retaining the tasks that must be executed.
[0066] The cost calculation engine module is used to calculate the task execution cost based on the anti-loop mechanism. According to the preset inventory cost accounting method, it recalculates the cost, inventory quantity and inventory amount of the inventory corresponding to the dimension key after the specified business time point, and updates the inventory information.
[0067] One or more tenant clients communicate with the event listening and task generation module to trigger the core business events.
[0068] In addition, the above modules are also used to perform the following operations:
[0069] Using the preset cost accounting dimension data as the dimension key, the tasks to be processed in the task queue are scanned in groups to identify duplicate task groups with the same dimension key.
[0070] For each identified group of duplicate tasks, a preset deduplication strategy is applied to merge and clean them up, retaining only the tasks that must be executed.
[0071] Based on the anti-loop mechanism, the cost of task execution is calculated for the retained tasks. According to the preset inventory cost accounting method, the cost, inventory quantity and inventory amount of the inventory corresponding to the dimension key after the specified business time point are recalculated, and the inventory information is updated.
[0072] In addition, the modules mentioned above are also used to implement other steps of the multi-tenant cost calculation method described above, as follows:
[0073] like Figure 3 As shown, Figure 3 This diagram illustrates an application environment for a multi-tenant inventory cost calculation method according to an embodiment of the present invention. The environment is constructed via a network by an application server 110, a database server 120, and multiple tenant clients 130. Tenant clients 130 access the system through a browser or dedicated client software to handle inbound and outbound business operations. The application server 110 is the core of the system, deploying components such as event listening services and message queues. The database server 120 is responsible for storing all business data, cost task queues, and inventory balance information, and can selectively host the core accounting logic.
[0074] The application server 110 can be one or more various personal computers, notebook computers, computer servers, virtual hosts, shared hosts. The tenant client 130 can be, but is not limited to, various personal computers, notebook computers, smart phones, PDAs, tablet computers and portable wearable devices. The database server 120 can be implemented by an independent computer server, a virtual host, a shared host or a server cluster composed of multiple servers.
[0075] The core idea of the method is event-driven, dimension aggregation, task deduplication and cycle prevention, and the implementation has high flexibility. The following two preferred embodiments are described respectively.
[0076] Embodiment one: mainly relying on the implementation of the application server
[0077] The first stage: system initialization and accounting configuration
[0078] The system administrator logs in the application server 110 through the management terminal to complete the basic parameter configuration in the multi-tenant environment. Configure the applicable inventory cost accounting method (such as moving weighted average method, first-in first-out method, etc.) for each tenant. The dimension combination (dimension key) of cost accounting is predefined in the system data model, including: tenant ID, accounting organization ID, warehouse ID, inventory ID, inventory SKUID. Initialize the message queue middleware and start the task scheduling listener.
[0079] The second stage: event listening and asynchronous task generation
[0080] The event listening service in the application server 110 continuously monitors the core business events (inventory in-out warehouse record update, allocation in-warehouse cost calculation event). Once the event occurs, the listening service will asynchronously generate a structured cost calculation task object and store it in the message queue. The task object contains the calculation task unique ID, cost accounting dimension data (dimension key), business time data, in-out warehouse record deletion ID, calculation batch ID, allocation out-of-warehouse ID and other key fields. The generated task object is immediately stored in the message queue (such as RabbitMQ or Kafka, or a database table).
[0081] The third stage: task scheduling, dimension grouping and intelligent deduplication
[0082] The task scheduler consumes the pending tasks from the message queue. After obtaining it, it scans and groups the tasks according to the dimension key as the grouping basis, and identifies the duplicate task groups.
[0083] For each duplicate task group, the scheduler applies the preset deduplication strategy for merging and cleaning:
[0084] Strategy 1 (Time Coverage): Compare the business time of each task in the group (sorted by the combination of document date and audit time), and keep the task with the earliest business time.
[0085] Strategy 2 (Delete Priority - FIFO Special Case): When the system is configured with a first-in-first-out method for the current tenant's inventory cost accounting method, if there is a task in the task group with a non-empty delete ID (i.e., triggered by a delete operation), the task must be kept.
[0086] Finally, within each dimension group, the tasks kept by Strategy 2 and the tasks kept by Strategy 1 will all be kept and cost recalculated.
[0087] Fourth Stage: Cost Calculation, Anti-Cycle Execution, and Inventory Update
[0088] The cost calculation engine performs cost calculation for the final retained tasks. The process includes an anti-cycle mechanism:
[0089] 1. Initial Task Assignment: Tasks generated for allocation and out-of-stock events Assign a globally unique calculation batch ID .
[0090] 2. Recursive Inheritance: Tasks After execution, trigger the generation of new tasks , and the calculation batch ID ID is inherited to .
[0091] 3. Cycle Check and Interception: Before generating any subsequent allocation and in-stock calculation tasks , check whether there is a task carrying the same calculation batch ID processing the same allocation and out-of-stock ID. If the check is yes, intercept the new task generation.
[0092] The cost calculation engine recalculates the inventory cost based on the task parameters and updates the inventory.
[0093] Example Two: Centralized Implementation Based on SQL Server Stored Procedures
[0094] In this example, the main logic of the system, including task deduplication and cost calculation, is integrated into the stored procedures on the SQL Server database side.
[0095] The database table structure includes three core tables: a cost calculation task queue table for storing to-be-processed calculation tasks, covering task ID, accounting dimension, business time, deletion record identifier, batch ID, allocation and delivery ID, and the like; a cycle prevention check record table for recording the correspondence between the batch ID and the allocation and delivery ID to prevent cycle calculation; and a tenant cost method configuration table for storing the cost accounting method configuration of each tenant.
[0096] The main scheduling stored procedure realizes complete deduplication and cycle prevention logic, and the execution process includes: creating a temporary table to store the tasks to be processed after deduplication; creating a temporary table to store the tenant cost method configuration; executing the core deduplication logic, including deleting the tasks in the first-in-first-out method and reserving the earliest task according to the business time; processing each task in a loop, calling the corresponding calculation process according to the cost method; marking the original task as processed; performing exception handling and transaction management.
[0097] The cost calculation stored procedure recalculates the cost, stock quantity and stock amount of all related transactions of the inventory corresponding to the current dimension after the specified business time point, and updates the stock information. Taking the moving average weighting method as an example, the process includes: obtaining the stock snapshot at the starting time point; processing all subsequent related transaction flows in chronological order; updating the weighted average unit price and increasing the stock when processing the warehousing transaction; calculating the delivery cost according to the current stock unit price and reducing the stock when processing the delivery transaction; checking whether it is an allocation and delivery, if so, generating an allocation and delivery task and implementing cycle prevention check; updating the latest stock information; inserting the stock snapshot for next calculation.
[0098] The roles of the application server include: event listening and task insertion, that is, listening to business events and inserting task data into the cost calculation task queue table; calling the scheduling process, calling the main stored procedure in a timed or triggered manner; exception handling, capturing and processing exceptions thrown during the execution of the stored procedure.
[0099] In summary, the innovation of the present application is not only a simple optimization of the prior art, but also a completely new and systematic solution. The solution has three core pillars of "event-driven asynchronous", "dimension aggregation intelligence" and "cycle prevention mechanism", which are organically integrated and jointly solve the three problems of efficiency, accuracy and stability faced by cost accounting in a multi-tenant high-concurrency environment. Compared with the prior art, the solution shows fundamental differences and significant progress, and the specific performance is as follows:
[0100] 1. Event-driven asynchronous task generation and processing mechanism
[0101] Technical means: The system sets up an independent event listening service to continuously monitor specific core business events (such as inventory general warehouse in and out, allocation in and out, and record update events such as inventory gain and loss in and out, as well as allocation in warehouse cost calculation completion event). Once the event is triggered, the listening service will asynchronously construct a structured cost calculation task object and store it in an independent message queue (such as RabbitMQ, Kafka or database table). This mechanism effectively decouples the time and resources of the cost calculation, a heavy load operation, from the front-end business operation.
[0102] 2. Task grouping and identification method based on composite dimension key
[0103] Technical means: Define a composite key (dimension key) composed of five fields: TenantId, OrgId, WarehouseId, ItemId, and SkuId, as the core basis for identifying and distinguishing the minimum granularity objects of cost accounting. The task scheduler scans the message queue to group the tasks to be processed based on the dimension key, and quickly identifies repeated calculation requests for the same inventory entity.
[0104] 3. Multi-strategy fusion task deduplication algorithm
[0105] Technical means: For each identified duplicate task group, the system applies a pre-set deduplication algorithm that includes multiple judgment logic:
[0106] Time sequence coverage strategy: The algorithm extracts the business time data (combined from the document date and audit time) of each task in the group and sorts it by its order, retaining only the task with the earliest business time. Because the cost recalculation is performed from the earliest time point, its results naturally cover the impact of subsequent business changes.
[0107] FIFO deletion priority strategy: The algorithm queries the system configuration to determine whether the tenant corresponding to the current task group uses the first-in-first-out (FIFO) cost accounting method. If so, check if there is a task in the group with a non-empty deletion ID field in the warehouse in and out record (i.e., triggered by a deletion record operation). If so, regardless of whether its business time is the earliest, it must be retained. Because under the FIFO method, deleting a historical warehouse in record will directly affect the matching chain of subsequent warehouse out costs, and must be restored to the correct inventory sequence through cost recalculation.
[0108] 4. Anti-circular task chain design and verification mechanism
[0109] Technical means: To completely solve the problem of circular calculation that may occur in allocation business, the invention designs a mechanism based on the transmission and verification of calculation batch ID (BatchId):
[0110] Identifier assignment: when a cost calculation task triggered by a dispatch-outbound event is generated, the system assigns it a globally unique calculation batch ID.
[0111] Identifier inheritance: after the execution of a task (or subsequent chain of tasks) is completed, if a new dispatch-inbound calculation task needs to be triggered, the generation logic inherits the calculation batch ID of the parent task to the new task and records the source dispatch-outbound ID that triggered it.
[0112] Cycle determination and interception: before persisting the dispatch-inbound task to the queue, the system performs a verification query to check whether the same (calculation batch ID, dispatch-outbound ID) combination already exists in the anti-cycle record table. If it exists, it is determined as a cycle chain, and the new task generation is intercepted and discarded; if it does not exist, the task generation is allowed and the combination is recorded for subsequent verification.
[0113] 5. Structured task data model supporting cost recalculation
[0114] Technical means: design a task data structure specifically for cost calculation, containing multiple key fields to support complex logic:
[0115] Calculation task unique ID, cost accounting dimension data (i.e. dimension key), business time data: used for unique identification, grouping, and determination of calculation timing.
[0116] Inbound and outbound record deletion ID: a special field for handling FIFO deletion scenarios, empty when it represents a normal task.
[0117] Calculation batch ID and dispatch-outbound ID: fields used to implement the anti-cycle mechanism, together constituting the basis for tracing and cycle determination of the task chain.
[0118] 6. "Business time" driven cost reconstruction method
[0119] Technical means: each cost calculation task not only contains the logical dimension key, but also accurately records the original business document date (BillDate) and audit effective time (ApprovalTime) that triggered the calculation. When the cost calculation engine executes, it takes this combination of business time points as the starting point for reconstruction calculation, recalculates all associated businesses after that time point, ensuring the correctness of the timing and accuracy of the results of cost calculation. Even in high concurrency, asynchronous processing can also obtain the same correct results as synchronous processing.
[0120] In addition, the present application also provides a computer device, the multi-tenant cost accounting method involved in the embodiment is mainly applied to the computer device, and the computer device can be a PC, a portable computer, a mobile terminal, and the like.
[0121] Specifically, the computer device can include a processor (e.g., a CPU), a communication bus, a user interface, a network interface, and a memory. The communication bus is used to realize the connection communication between these components; the user interface can include a display screen (Display) and an input unit such as a keyboard (Keyboard); the network interface can optionally include a standard wired interface, a wireless interface (such as a WI-FI interface); the memory can be a high-speed RAM memory, or a stable memory (non-volatile memory) such as a disk memory, and the memory can optionally be a storage device independent of the aforementioned processor.
[0122] The memory stores a readable storage medium, and the readable storage medium stores a computer program. The processor can call the computer program stored in the memory and execute the multi-tenant cost accounting method provided by the embodiment of the application.
[0123] It can be understood that the readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device. The computer readable storage medium can be, for example but not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the above. More specific examples (a non-exhaustive list) of the computer readable storage medium include a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punched card or a concave-convex structure in a slot, and any suitable combination of the above. The computer readable storage medium used herein is not to be interpreted as a transitory signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (for example, an optical pulse through an optical fiber cable), or an electrical signal transmitted through a wire.
[0124] The computer readable program instructions described herein can be downloaded from the computer readable storage medium to the respective computing / processing device, or to an external computer or external storage device through a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, fiber-optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer readable program instructions from the network and forwards the computer readable program instructions to the computer readable storage medium in the respective computing / processing device for storage.
[0125] Computer readable program instructions for carrying out operations of the present disclosure can be assembly instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine dependent instructions, microcode, firmware instructions, state-setting data, or either source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C++ or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer readable program instructions can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) can execute the computer readable program instructions by utilizing state information of the computer readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present disclosure.
[0126] Finally, it should be noted that the above-mentioned only is the preferred embodiment of the present application, and is not used to limit the present application, although the present application is described in detail with reference to the foregoing embodiments, for those skilled in the art, the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced, any modification, equivalent replacement, improvement, etc. within the spirit and principles of the present application, should be included in the protection scope of the present application.
Claims
1. A method for calculating multi-tenant costs, characterized in that, The method comprises the following steps: Asynchronously generating a cost calculation task and storing it in a task queue in response to a core business event, the core business event including: an inventory warehouse-in and warehouse-out record update event and a transfer-in warehouse cost calculation event; Grouping and scanning the tasks to be processed in the task queue by taking preset cost accounting dimension data as a dimension key, identifying a repeated task group with the same dimension key; For each repeated task group identified, applying a preset deduplication strategy to merge and clean up, and retaining a task that needs to be executed; Based on an anti-circulation mechanism, performing cost calculation for the retained task, recalculating the cost, the quantity in stock and the amount in stock of the inventory corresponding to the dimension key after a specified business time point according to a preset inventory cost accounting method, and updating the stock information; The anti-circulation mechanism is implemented as follows: Assigning a globally unique calculation batch ID to the task generated due to the transfer-out warehouse event; When the transfer-in warehouse calculation task is triggered by the completion of task execution, the calculation batch ID is inherited to the new task, and the transfer-out warehouse ID of the current trigger source transfer-out warehouse record is recorded; Before generating any transfer-in warehouse calculation task, the system checks whether there is a task carrying the same calculation batch ID that has processed the same transfer-out warehouse record; If the result of the check is yes, the generation of the new task is intercepted, and the circulation chain is cut off; If the result of the check is no, the task is allowed to be generated and the recursive inheritance rule is continued.
2. The method of claim 1, wherein: The cost calculation task is a structured data object, which contains one or more of the following fields: calculation task unique ID, cost accounting dimension data, business time data, warehouse-in and warehouse-out record deletion ID, calculation batch ID, and transfer-out warehouse ID.
3. The method of claim 2, wherein: The business time data includes the warehouse-in and warehouse-out document date and the audit effective time, which is used to determine the starting time point when the cost is reconstructed and calculated, and to ensure the correct calculation time sequence.
4. The method of claim 1, wherein: The cost accounting dimension data includes a combination of one or more of tenant ID, accounting organization ID, warehouse ID, inventory ID, and inventory SKUID.
5. The method of claim 1, wherein: The deduplication strategy includes comparing the business time data of each task in the repeated task group, and retaining the task with the earliest business time.
6. The method of claim 1, wherein: The inventory cost accounting method is the first-in first-out method, and when there is a task triggered by deleting the warehouse-in and warehouse-out record in the task group, the task triggered by the deletion is retained.
7. A multi-tenant cost accounting system for implementing the method of any of claims 1-6, characterized by: It comprises: An event listening and task generation module for asynchronously generating a cost calculation task in response to a core business event; The core business event includes: an inventory warehouse-in and warehouse-out record update event and a transfer-in warehouse cost calculation event; A task queue module for receiving and storing cost calculation tasks; A task scheduling and deduplication module for grouping and scanning the tasks to be processed in the task queue by taking preset cost accounting dimension data as a dimension key, identifying a repeated task group with the same dimension key, and applying a preset deduplication strategy to each repeated task group identified to merge and clean up, and retaining a task that needs to be executed; A cost calculation engine module is configured to perform cost calculation for the reserved task based on the anti-circulation mechanism, and to recalculate the cost, the quantity and the amount of the inventory corresponding to the dimension key after a specified business time point according to a preset inventory cost accounting method, and to update the inventory information. One or more tenant clients are in communication connection with the event listening and task generating module, and are configured to trigger the core business event.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 6.
9. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor, when executing the computer program, implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Data processing method and data processing system in ERP system and related equipment
CN110675054A
Financial transaction accounting method based on accounting rule configuration parameters
CN115619415A