Credential generation method and related device
By determining the occupied and missing number ranges of voucher numbers in the financial system, and allocating and storing them in a queue, the lock control and query problems in the voucher number allocation process are solved, thereby improving the system's concurrent processing capabilities and operating efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- KINGDEE SOFTWARE(CHINA) CO LTD
- Filing Date
- 2026-03-11
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies in financial systems suffer from performance bottlenecks due to frequent locking and repetitive query operations during voucher number allocation, leading to high concurrency and batch processing scenarios and impacting the operational efficiency of the financial system.
By obtaining the target accounting period and cache information under the voucher number corresponding to the voucher generation request, the occupied range and missing range of historical voucher numbers are determined. Based on these ranges, a target voucher number is assigned to the request and stored in a queue. Subsequently, the voucher is retrieved from the queue to generate vouchers.
This avoids frequent lock control and repeated queries, improves the processing efficiency of the financial system in high-concurrency and batch processing scenarios, and reduces resource consumption and response time.
Smart Images

Figure CN122155883A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and more particularly to a method for generating vouchers and related equipment. Background Technology
[0002] In modern corporate financial management, accounting vouchers are important written records of financial accounting work. To ensure the accuracy of accounting voucher information, the financial system needs to assign a unique voucher number to each voucher. The voucher number usually consists of the voucher name (such as receipt, payment, transfer, record) and a consecutive serial number.
[0003] Businesses typically perform numerous accounting operations during an accounting period (usually monthly). To prevent duplicate voucher numbers when multiple users operate simultaneously or generate vouchers in batches, current technologies often employ exclusive locks. When a user needs to generate a new voucher, the relevant data table or record storing the voucher number information is locked, ensuring that only one operation can complete the voucher number allocation at any given time. Furthermore, to maintain the continuity of voucher numbers, historical voucher numbers are scanned when a new voucher is generated to check for any available missing numbers and prioritize their replacement.
[0004] However, in practical applications, especially when a large number of vouchers are generated at the end of the month, the frequent use of exclusive locks and number lookup operations during voucher number allocation can easily lead to requests waiting for each other, thus limiting the system's concurrent processing capabilities. Furthermore, as the scale of voucher data continues to increase, the number traversal and verification operations required to maintain number continuity significantly increase the database access and computational burden, prolonging the response time of the voucher generation process. This can create a performance bottleneck in high-concurrency or batch processing scenarios, impacting the overall operational efficiency and business processing timeliness of the financial system. Summary of the Invention
[0005] Based on the above problems, this application provides a voucher generation method and related equipment, which aims to avoid frequent lock control and repeated query operations during the voucher number allocation process, improve the processing efficiency when multiple users generate vouchers in batches, and thus improve the overall operating performance of the financial system.
[0006] In a first aspect, embodiments of this application provide a credential generation method, including:
[0007] In response to multiple voucher generation requests, obtain the target accounting period and voucher number cache information under the target voucher corresponding to each voucher generation request;
[0008] For each voucher generation request, based on the voucher number cache information corresponding to the voucher generation request, the occupied range and the missing range of the historical voucher number corresponding to the voucher generation request are determined;
[0009] Based on the missing number interval and the occupied interval corresponding to the voucher generation request, at least one target voucher number is allocated to the voucher generation request, and the target voucher number allocated to the voucher generation request is stored in the voucher number queue corresponding to the voucher generation request.
[0010] The target voucher number is sequentially retrieved from the voucher number queue corresponding to each voucher generation request, and a voucher corresponding to the target voucher number is generated based on the retrieved target voucher number.
[0011] In one embodiment, determining the occupied range and the missing range of historical voucher numbers corresponding to each voucher generation request based on the voucher number cache information corresponding to the voucher generation request includes:
[0012] For each voucher generation request, the target accounting period and the voucher numbers already used under the target voucher number are obtained from the voucher number cache information corresponding to the voucher generation request.
[0013] The used voucher numbers are sorted, and consecutive serial numbers are merged into at least one number segment to determine the occupied range of historical voucher numbers;
[0014] For two adjacent number segments, the missing number segment between the end number of the previous number segment and the beginning number of the next number segment is defined as the gap.
[0015] In one embodiment, allocating at least one target voucher number to the voucher generation request based on the missing number range and the occupied range corresponding to the voucher generation request includes:
[0016] Based on the required number of voucher numbers indicated by the voucher generation request, a pre-reservation number record is generated in the voucher number cache information;
[0017] When allocating at least one target voucher number for each voucher generation request, consecutive target voucher numbers are allocated based on the number gap interval, the occupied interval, and the pre-occupied number record, until the required number of voucher numbers is met.
[0018] In one embodiment, when allocating at least one target voucher number for each voucher generation request, the allocation of consecutive target voucher numbers based on the missing number interval, the occupied interval, and the pre-occupied number record in the voucher number cache information, until the required number of voucher numbers is met, includes:
[0019] For at least one of the aforementioned gap number intervals, determine the available numbers within the gap number interval that are not occupied by the pre-reserved number records;
[0020] According to the preset allocation order, voucher numbers are selected sequentially from the available numbers, and the selected voucher numbers are included in the target voucher number;
[0021] When the available numbers within the number gap are insufficient to meet the required number of voucher numbers indicated by the current voucher generation request, the target voucher numbers are allocated based on the maximum used voucher number determined by the occupied interval, until the required number of voucher numbers is met.
[0022] In one embodiment, the method further includes:
[0023] When it is detected that the current credential generation request has timed out or terminated abnormally, the occupancy status of the target credential number corresponding to the current credential generation request in the credential number cache information is released, so that the released target credential number becomes an allocable credential number again.
[0024] Secondly, embodiments of this application also provide a credential generation apparatus, comprising:
[0025] The cache information acquisition unit is used to respond to multiple voucher generation requests by acquiring cache information of the target accounting period and the voucher number under the target voucher corresponding to each voucher generation request.
[0026] The interval determination unit is used to determine the occupied interval and the missing interval of the historical voucher number corresponding to each voucher generation request based on the voucher number cache information corresponding to the voucher generation request.
[0027] The voucher number allocation unit is used to allocate at least one target voucher number to the voucher generation request based on the missing number interval and the occupied interval corresponding to the voucher generation request, and to store the target voucher number allocated to the voucher generation request into the voucher number queue corresponding to the voucher generation request.
[0028] The voucher generation unit is used to sequentially retrieve the target voucher number from the voucher number queue corresponding to each voucher generation request, and generate a voucher corresponding to the target voucher number based on the retrieved target voucher number.
[0029] In one embodiment, the interval determination unit is used to obtain the voucher numbers used under the target accounting period and the target voucher from the voucher number cache information; sort the used voucher numbers and merge consecutive serial numbers into at least one number segment to obtain the occupied interval of the determined historical voucher numbers; for two adjacent number segments, the missing number segment between the end number of the previous number segment and the beginning number of the next number segment is taken as the missing number interval.
[0030] Thirdly, embodiments of this application also provide a computer device, including:
[0031] Central processing unit, memory, input / output interfaces;
[0032] The memory is either a short-term storage memory or a persistent storage memory;
[0033] The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the credential generation method described in the first aspect of the embodiments of this application or any specific implementation thereof.
[0034] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is used to implement the credential generation method described in the first aspect or any specific implementation of the first aspect of the embodiments of this application.
[0035] Fifthly, embodiments of this application also provide a computer program product having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, it is used to implement the credential generation method described in the first aspect or any specific implementation of the first aspect of the embodiments of this application.
[0036] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0037] By responding to multiple voucher generation requests, the system obtains cached voucher number information corresponding to the target accounting period and target voucher number for each voucher generation request. Based on this cached information, it further determines the occupied and discontinued ranges of historical voucher numbers. This allows the voucher generation process to obtain relevant data reflecting the current usage status of voucher numbers at the beginning, thus avoiding direct database access to query historical voucher numbers each time a voucher is generated. Since voucher number allocation no longer relies on exclusive lock control and querying of voucher numbers in the database, but is based on the obtained and analyzed occupied and discontinued ranges, it effectively avoids request blocking issues caused by lock contention in multi-request concurrent scenarios. This allows for the rapid and accurate allocation of consecutive voucher numbers to a massive number of concurrent voucher generation requests, improving the system's concurrency processing capabilities. Then, based on the missing number range and occupied range corresponding to each voucher generation request, at least one target voucher number is allocated, and the target voucher number allocated to the voucher generation request is stored in the voucher number queue corresponding to the voucher generation request. When generating vouchers in the future, the target voucher number can be retrieved sequentially from the voucher number queue corresponding to each voucher generation request to generate the voucher corresponding to the target voucher number. This avoids triggering number allocation or verification operations again during the voucher generation process, reducing redundant calculations and resource consumption during the operation of the financial system. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0039] Figure 1 A schematic diagram of a system architecture provided for an embodiment of this application;
[0040] Figure 2 This is a schematic flowchart of a credential generation method provided in an embodiment of this application;
[0041] Figure 3 This is a schematic diagram of another credential generation method provided in an embodiment of this application;
[0042] Figure 4 This is a schematic diagram of a credential generation device provided in an embodiment of this application;
[0043] Figure 5 This is a schematic diagram of a computer device structure provided in an embodiment of this application. Detailed Implementation
[0044] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0045] The method provided in this application embodiment can be applied to, for example, Figure 1 In the system architecture shown, terminal 102 communicates with server 101 via a network, and data storage system 100 can store data that server 101 needs to process or requires. Data storage system 100 can be integrated onto server 101 or located in the cloud or on other network servers. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices, such as smartwatches, smart bracelets, and head-mounted devices. Server 101 can be implemented using a standalone server or a server cluster composed of multiple servers. In this embodiment, data storage system 100 can be a standalone physical storage server, a distributed storage system composed of multiple storage nodes, or a cloud storage system providing services such as object storage, relational databases, cache databases, cloud databases, and cloud storage. For example, the data storage system 100 can be implemented using a distributed file system (such as HDFS), a NoSQL database (such as MongoDB, Redis), a relational database (such as MySQL, PostgreSQL), or a cloud storage service (such as Alibaba Cloud OSS, Huawei Cloud OBS, etc.). The specific type of the data storage system 100 can be flexibly configured according to the actual deployment environment and business needs, but is not limited to the above examples.
[0046] Terminal 102 can be used to initiate voucher generation requests and receive voucher generation results returned by the server. Financial business system clients or related business applications can be deployed on the terminal device to trigger voucher generation operations, display voucher generation results, etc.
[0047] Server 101 is used to execute the voucher generation method provided in this application embodiment. Server 101 can be a single server or a server cluster composed of multiple servers to meet the processing requirements in concurrent voucher generation scenarios. Server 101 is equipped with a voucher generation-related business processing module, which is used to receive voucher generation requests sent by terminal devices and, based on the voucher generation requests, execute processing flows such as voucher number acquisition, voucher number allocation, and voucher generation. The server may also include a voucher number generation algorithm module, which is used to analyze and allocate available voucher numbers according to the target accounting period and the target voucher number, thereby avoiding voucher number conflicts in multi-user concurrent scenarios.
[0048] In this embodiment, after terminal 102 sends a voucher generation request to server 101, server 101 retrieves the voucher number cache information corresponding to the target accounting period and target voucher number from data storage system 100 based on the request, and determines the occupied range and missing range of historical voucher numbers accordingly. Server 101 further allocates the target voucher number to the voucher generation request according to the occupied range and missing range, generates the corresponding voucher data, and finally returns the generation result to terminal 102.
[0049] It should be noted that the credential generation method in this application embodiment can be executed independently by the server or jointly by the server and the data storage system. In some implementation scenarios, credential number cache information can be preferentially stored in the cache system to reduce frequent access to the database. This application embodiment does not limit the specific deployment method of the system architecture. Figure 1 The system architecture shown in the embodiments is intended to more clearly illustrate the technical solutions of the embodiments of this application, and does not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture and the emergence of new business scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0050] The method of this application will be further described in detail below, and some specific possible implementation examples will be provided.
[0051] This application provides a method for generating credentials, such as... Figure 2 As shown, the method includes steps S201-S204.
[0052] S201: In response to multiple voucher generation requests, obtain the target accounting period and voucher number cache information under the target voucher for each voucher generation request.
[0053] In this embodiment, the target accounting period refers to the financial period in which the user is currently requesting the generation of a voucher, typically expressed in years and months, such as November 2025 being represented as 202511; the target voucher name refers to the type identifier of the voucher, such as "record" representing an accounting voucher, "payment" representing a payment voucher, etc. When the financial system receives a voucher generation request, each voucher generation request carries at least the target accounting period and the target voucher name, indicating the applicable numbering rule range for this voucher generation request. Based on the target accounting period and the target voucher name, the system retrieves the corresponding voucher name cache information from a pre-maintained voucher name cache. The voucher name cache information is used to characterize the usage status of voucher names under the target accounting period and the target voucher name, including but not limited to the range of voucher names already used in the current period and the range of missing numbers analyzed by the system.
[0054] S202: For each voucher generation request, based on the voucher number cache information corresponding to the voucher generation request, determine the occupied range and the missing range of the historical voucher number corresponding to the voucher generation request.
[0055] Based on the voucher number cache information obtained above, the system extracts the voucher numbers that have been actually used by historical vouchers under the target accounting period and target voucher number, and sorts the used voucher numbers according to their number size. Then, the sorted consecutive voucher numbers are merged into one or more consecutive number segments to form several occupied intervals. For example, if the used voucher numbers are 1 to 10 and 13 to 19, the occupied intervals are [1, 10] and [13, 19]. Further, adjacent occupied intervals are analyzed. When there is a discontinuous number range between two adjacent occupied intervals, this number range is determined as a gap interval. For example, the voucher number 11, which does not appear between the two intervals mentioned above, constitutes a gap interval [11, 12].
[0056] S203: Based on the missing number range and occupied range corresponding to the voucher generation request, allocate at least one target voucher number to the voucher generation request, and store the target voucher number allocated to the voucher generation request into the voucher number queue corresponding to the voucher generation request.
[0057] After completing the allocation of historical voucher number ranges and gaps, based on the available voucher numbers represented by the gaps and ranges corresponding to the current voucher generation request, and according to the preset voucher number allocation rules, the target voucher number corresponding to the voucher generation request is determined, and the allocated target voucher number is stored in the voucher number queue corresponding to the voucher generation request. The voucher number queue is used to hold the set of target voucher numbers already allocated for this voucher generation request; its queue elements are specific target voucher numbers. The voucher number allocation rules are used to ensure that, within the target accounting period and under the target voucher number, the target voucher numbers allocated to different voucher generation requests are not duplicated, and to meet the voucher quantity requirements of the voucher generation request. To ensure the deterministic order of voucher number usage, target voucher numbers are written to the voucher number queue in a preset processing order. The preset processing order can be the numbering order of the target voucher numbers, such as writing them in ascending natural number order; or it can be the actual allocation order of the system, i.e., prioritizing gaps and then allocating in ascending order of the largest used voucher number. By writing the target voucher numbers sequentially into the voucher number queue, the system ensures consistency in the order in which target voucher numbers are retrieved during voucher generation, making the voucher generation order controllable. This guarantees that the generated voucher numbers are continuous, non-repeating, and logically clear, thus enabling efficient handling of high-concurrency voucher generation requests. In one feasible implementation, for multiple target voucher numbers required by a single voucher generation request, the system writes them all into the voucher number queue at once after allocating all target voucher numbers. In another feasible implementation, each target voucher number can be written into the voucher number queue immediately after allocation, thus synchronizing the allocation process with the queue construction process.
[0058] The voucher number queue serves as the source of numbers for subsequent voucher generation. During voucher generation, the target voucher number is sequentially retrieved from the queue corresponding to the voucher generation request, and the corresponding voucher is generated based on the retrieved target voucher number. Since all target voucher numbers are uniformly allocated and stored in the queue sequentially before voucher generation, the actual voucher generation process can be completed without querying and repeatedly verifying historical vouchers in the database. This reduces the frequency of database access, improves processing efficiency in scenarios involving large-scale voucher generation, and alleviates the performance pressure on the database under concurrent access.
[0059] S204: Sequentially retrieve the target voucher number from the voucher number queue corresponding to each voucher generation request, and generate a voucher corresponding to the target voucher number based on the retrieved target voucher number.
[0060] When performing a voucher generation operation in response to a current voucher generation request, the target voucher number is sequentially retrieved from the voucher number queue corresponding to the voucher generation request. A voucher corresponding to the retrieved target voucher number is then generated based on this retrieved target voucher number, ensuring the determinism of the numbering. During the voucher generation operation, the voucher number retrieval and voucher generation actions can be performed iteratively based on the number of vouchers to be generated as indicated in the voucher generation request. In each iteration, a target voucher number is retrieved from the voucher number queue and written into the voucher number field of the currently generated voucher, serving as the business number identifier for the current voucher. Subsequently, combined with the business data carried in the voucher generation request, such as amount data, summary information, and associated business identifiers, the complete voucher information for the current voucher is generated, and the voucher data containing the target voucher number is saved.
[0061] Since the target voucher numbers in the voucher number queue have been written sequentially in the aforementioned steps according to the preset processing order, and only one target voucher number is taken from the queue for use each time a voucher is generated, each target voucher number is only used once and forms a one-to-one correspondence with a generated voucher. This avoids problems such as duplicate use of voucher numbers, missing numbers, or concurrent conflicts during the voucher generation process when there is high concurrency of voucher generation requests. At the same time, there is no need to query historical numbers or re-determine the missing number status at each voucher generation stage, thereby improving the execution efficiency and system stability of the voucher generation stage.
[0062] In one feasible implementation, when the same voucher generation request corresponds to multiple target voucher numbers, all target voucher numbers can be retrieved sequentially from the queue and the corresponding multiple vouchers can be generated respectively; in another feasible implementation, the next number retrieval action can be performed after each voucher generation is completed.
[0063] By obtaining the voucher number cache information corresponding to each voucher generation request under the target accounting period and the target voucher character in response to multiple voucher generation requests, and further determining the occupied interval and the discontinuous number interval of the historical voucher numbers based on the voucher number cache information, relevant data reflecting the used status of the current voucher number can be obtained at the beginning stage of the voucher generation process, thus avoiding directly accessing the database to query the historical voucher numbers every time a voucher is generated. Since the allocation of voucher numbers no longer depends on the exclusive lock control and query of voucher numbers in the database, but is completed based on the obtained and analyzed occupied interval and discontinuous number interval, it can effectively avoid the request blocking problem caused by lock competition in the multi-request concurrent scenario, quickly and accurately allocate continuous voucher numbers for a large number of concurrent voucher generation requests, and improve the concurrent processing ability of the system. Then, at least one target voucher number is allocated based on the discontinuous number interval and the occupied interval corresponding to each voucher generation request, and the allocated target voucher number of the voucher generation request is stored in the voucher number queue corresponding to the voucher generation request. When generating vouchers subsequently, the target voucher number can be sequentially retrieved from the voucher number queue corresponding to each voucher generation request to generate the voucher corresponding to the target voucher number, thus avoiding triggering the number allocation or verification operation again during the voucher generation process, and reducing the repeated calculation and resource consumption in the operation process of the financial system.
[0064] In one embodiment, for each voucher generation request, based on the voucher number cache information corresponding to the voucher generation request, determining the occupied interval and the discontinuous number interval of the historical voucher numbers corresponding to the voucher generation request includes: for each voucher generation request, obtaining the used voucher numbers under the target accounting period and the target voucher character from the voucher number cache information corresponding to the voucher generation request; sorting the used voucher numbers and merging the consecutive serial numbers into at least one number segment to obtain the occupied interval of the historical voucher numbers; for two adjacent number segments, taking the missing number segment between the end number of the previous number segment and the start number of the next number segment as the discontinuous number interval.
[0065] For each voucher generation request, obtain the used voucher numbers under the target accounting period and the target voucher character from the voucher number cache information corresponding to the voucher generation request. For example, referring to Table 1, in the scenario of accounting period 202511 and voucher character 'Ji', the voucher number cache information may include used numbers such as 'Ji 1, Ji 2,..., Ji 10, Ji 12,..., Ji 19, Ji 30,..., Ji 40'. By filtering the voucher number cache information and only retaining the voucher numbers that match the target accounting period and the target voucher character, the data required for the current number allocation can be obtained without accessing the underlying historical voucher data table.
[0066] Subsequently, the used voucher numbers are sorted, and consecutive serial numbers are merged into at least one number segment to determine the occupied range of historical voucher numbers. Specifically, the system can sort the voucher numbers in ascending order according to the serial number portion, and group adjacent and consecutively numbered voucher numbers into a continuous number segment. Each number segment can be represented by a start number and an end number. For example, if the used voucher numbers are 1 to 10, 12 to 19, and 30 to 40, after sorting, they can be merged into three number segments: 1-10, 12-19, and 30-40. These number segments together constitute the occupied range of voucher numbers.
[0067]
[0068] After determining the occupied intervals, we can further identify the missing number intervals based on the differences between adjacent number segments. That is, we can analyze the range of available numbers that exist but have not yet been used in historical vouchers from the occupied intervals. Specifically, for two adjacent number segments, the range of missing numbers between the end number of the preceding number segment and the beginning number of the following number segment is determined as the missing number interval. When the beginning number of the following number segment is greater than the end number of the preceding number segment plus one, it indicates that there are unused consecutive numbers between the two, and this range of consecutive numbers is the missing number interval. For example, referring to Table 2, the missing number 11 between number segments 1-10 and 12-19 can be identified as a missing number interval; the missing number 20-29 between number segments 12-19 and 30-40 can be identified as another missing number interval.
[0069]
[0070] By using the above methods, it is possible to identify the range of numbers that can be reused preferentially without modifying historical vouchers, while maintaining the business rule of voucher number continuity. This can improve the utilization rate of voucher number resources, avoid generating a large number of new number ranges, and optimize the management and use of voucher numbers as a whole.
[0071] In one embodiment, based on the missing number interval and occupied interval corresponding to the voucher generation request, at least one target voucher number is allocated to the voucher generation request, including: generating a pre-occupied number record in the voucher number cache information according to the required number of voucher numbers indicated by the voucher generation request; when allocating at least one target voucher number to each voucher generation request, consecutive target voucher numbers are allocated based on the missing number interval, occupied interval and pre-occupied number record until the required number of voucher numbers is met.
[0072] In the embodiments of the present application, the pre-occupied number record is used to represent the occupancy requirements of the current voucher generation request during the voucher number allocation process. The pre-occupied number record at least includes information such as the target accounting period, the target voucher character, and the number of required voucher numbers. Optionally, the voucher number cache information is deployed in a distributed cache. By generating a pre-occupied number record in the voucher number cache information, the number of voucher numbers required by requests that have not completed the voucher generation operation can be recorded in a concurrent scenario, so that the subsequent voucher number allocation process can perceive the occupancy relationship between different voucher generation requests, and avoid multiple requests competing for the same voucher number resources within the same time range.
[0073] After the above pre-occupied number record is generated, when the financial system allocates the target voucher number for each voucher generation request, it continuously allocates the target voucher number for the current voucher generation request according to the preset allocation rule within the available number range defined by the broken number interval, the occupancy interval, and the pre-occupied number record, and considers the pre-occupied number records corresponding to other concurrent requests during the allocation process to avoid allocating voucher numbers that have been pre-occupied by other requests.
[0074] For example, please refer to Table 3 below. In the scenario where the accounting period is 202511 and the voucher character is "Ji", if Zhang San's voucher generation request has pre-occupied 1 voucher number and Li Si's voucher generation request has pre-occupied 5 voucher numbers. Please refer to Table 4 below. When the current user initiates a voucher generation request that requires 10 voucher numbers, the system can identify the above occupancy situation through the pre-occupied number record, and allocate continuous voucher numbers that do not conflict with Zhang San and Li Si within the available range determined by the broken number interval and the occupancy interval. This ensures that the voucher number allocation between different voucher generation requests does not overlap, and at the same time meets their respective requirements for the number of vouchers.
[0075]
[0076]
[0077] By using the pre-occupied number record and combining the broken number interval and the occupancy interval for number allocation, the embodiments of the present application can take into account the concurrent occupancy situation of voucher numbers in the number allocation process, so that the voucher number allocation process no longer depends on the real-time locking or item-by-item verification of historical voucher data by an exclusive lock, but is processed at the cache level, thereby ensuring stable voucher number resources during voucher generation and improving the processing ability and operation stability of the system in concurrent and batch voucher generation scenarios.
[0078] In one embodiment, when allocating at least one target voucher number for each voucher generation request, consecutive target voucher numbers are allocated based on the missing number interval, the occupied interval, and the pre-occupied number records in the voucher number cache information until the required number of voucher numbers is met. This includes: for at least one missing number interval, determining the available numbers within the missing number interval that are not occupied by pre-occupied number records; selecting voucher numbers sequentially from the available numbers according to a preset allocation order, and including the selected voucher numbers in the target voucher numbers; when the available numbers within the missing number interval are insufficient to meet the required number of voucher numbers indicated by the current voucher generation request, based on the maximum used voucher number determined by the occupied interval, and continuing to allocate target voucher numbers based on the maximum used voucher number until the required number of voucher numbers is met.
[0079] Considering the reusable gaps in historical voucher numbers, the occupied ranges of historical vouchers, and the numbers or number quantities pre-occupied by other incomplete voucher generation requests in concurrent scenarios, this application embodiment uses a first-come, first-served principle for number allocation. This ensures that different users or different requests can obtain non-conflicting voucher numbers according to their arrival order. When determining available numbers, the starting and ending numbers of the gaps are used as boundaries. Combined with the pre-occupied number records already existing in the voucher number cache information, the range of numbers already occupied by first-arriving requests is eliminated, thus obtaining the remaining range of numbers that can be allocated to the current voucher generation request. Although this gap should be considered a usable resource in terms of the used numbers of historical vouchers, in concurrent scenarios, it is necessary to exclude the portion pre-occupied by other requests to avoid multiple requests simultaneously drawing numbers from the same gap, resulting in duplicate allocation.
[0080] After the available numbers are determined, voucher numbers are selected sequentially from the available numbers according to a preset allocation order, and the selected voucher numbers are added to the target voucher number set. The preset allocation order can be a numbering rule based on the continuity of natural numbers, so that the target voucher numbers obtained from the same request are as consecutive as possible in value, thereby facilitating subsequent voucher generation and voucher management. The selected voucher numbers are added one by one to the target voucher number set of the current request, and the pre-reserved number record related to the current voucher generation request is updated synchronously, so that subsequent requests can correctly identify the range of numbers that have been occupied when determining available numbers, thereby achieving coordinated allocation among multiple requests.
[0081] When the available numbers in the discontinuous number range are not sufficient to meet the number of voucher numbers required by the current voucher generation request, the embodiments of the present application can determine the largest used voucher number based on the occupied range, and continue to allocate target voucher numbers based on the largest used voucher number until the required number of voucher numbers is met. The largest used voucher number here is determined by the end number in the occupied range, which is used to define the upper bound of the historically used numbers, so that when the discontinuous number resources are exhausted or insufficient, new consecutive numbers can be generated outside the upper bound of the historical numbers, thus ensuring that the number allocation can cover voucher generation requirements of any scale. The embodiments of the present application can not only preferentially reuse the discontinuous number range, but also continue to number consecutively based on the largest used number, so as to improve the utilization rate of the discontinuous number resources and ensure that the target voucher numbers that meet the requirements can still be stably allocated when the discontinuous numbers are insufficient.
[0082] The following is an illustration with the example shown in Table 5. In the scenario where the target accounting period is 202511 and the target voucher word is "Ji", the system has analyzed from the occupied range to obtain the historical number segments as 1 to 10, 12 to 19, and 30 to 40, and further obtained the discontinuous number ranges as 11 to 11 and 20 to 29. When user Zhang San first发起凭证生成请求且所需号码个数为1时,按照先到先得原则优先从断号区间开始分配,在剔除预占号记录为空的情况下,直接从断号11至11中选取号码11作为目标凭证字号,并将其计入张三对应的预占号记录。随后用户李四发起请求且所需号码个数为5时,系统在确定可用号码时需要剔除张三已预占的号码11,因此断号区间11至11不再可用,转而在断号区间20至29中按预设顺序依次选取20至24作为李四的目标凭证字号,并更新预占号记录以反映李四的占用范围。进一步地,当当前用户发起请求且所需号码个数为10时,系统在断号区间20至29中剔除李四已预占的20至2后,可用号码仅剩25至29共5个,不足以满足10个需求,因此先分配25至29,再基于占用区间确定的最大已使用凭证字号40,在40的基础上继续按自然数递增分配41至45共5个,最终得到25至29以及41至45作为当前用户的目标凭证字号,从而满足其所需号码个数并确保与张三、李四的分配结果不冲突。
[0083]
[0084] It should be noted that there seems to be an incomplete or incorrect expression in the original text for "发起凭证生成请求且所需号码个数为1时" and "剔除李四已预占的20至2后". You may want to check and correct the relevant content for a more accurate translation.The following is an illustration with the example shown in Table 6. When the target voucher numbers obtained by the current user for the target accounting period and the target voucher type are "Ji-25", "Ji-26", "Ji-27", "Ji-28", "Ji-29", "Ji-41", "Ji-42", "Ji-43", "Ji-44", "Ji-45", the system writes the above target voucher numbers into the voucher number queue in sequence; when performing the voucher generation operation, the system sequentially retrieves "Ji-25" and generates voucher 1, sequentially retrieves "Ji-26" and generates voucher 2, until sequentially retrieves "Ji-45" and generates voucher 10, thus achieving the one-to-one correspondence between the target voucher numbers and the generated vouchers.
[0085]
[0086] In one embodiment, the method of the embodiment of the present application further includes: when it is detected that the voucher generation operation of the current voucher generation request times out or is abnormally terminated, releasing the occupied status of the target voucher number corresponding to the current voucher generation request in the voucher number cache information, so that the released target voucher number becomes an available voucher number again.
[0087] Before the voucher generation request enters the voucher generation stage, it has obtained at least one target voucher number through the voucher number allocation process and formed a corresponding occupied status in the voucher number cache information, which is used to indicate that the target voucher number cannot be allocated by other voucher generation requests during the current request processing period. When the voucher generation operation fails to end normally due to system exceptions, business interruptions, timeouts, or requests being cancelled, etc., if the above occupied status is not released, it will cause the corresponding target voucher number to be in an occupied state for a long time, thus affecting the normal allocation of voucher number resources for subsequent voucher generation requests. Therefore, after detecting an abnormal or timeout situation, by updating the voucher number cache information, the occupancy mark of the target voucher number associated with the current voucher generation request is removed, so that the target voucher number resumes its available state again, and subsequent voucher generation requests can use it again, avoiding the permanent occupation of voucher number resources due to abnormal requests, thereby ensuring the integrity and sustainability of the voucher number allocation process.
[0088] The following is combined with Figure 3 , to illustrate a specific application embodiment provided by the present application. As Figure 3As shown, in the initial stage, the system retrieves historical voucher information from the voucher data table in the database and generates a gap-in-number cache and a number-occupying cache in the voucher number caching system. The number-occupying cache records the number of numbers already occupied by each user during concurrent voucher generation, i.e., the number-occupying range. The gap-in-number cache records the reusable gap-in-number range under the target accounting period and target voucher. After the voucher number generation algorithm is executed, a corresponding user number queue is generated for each user, and the voucher generation program sequentially retrieves the target voucher number from the user number queue to generate vouchers. During this process, if a user's user number queue has not been fully consumed before the voucher generation program fails to continue execution due to system failure or operation interruption, the target voucher number corresponding to that user remains in the number-occupying cache. At this time, by detecting that the voucher generation request corresponding to that user has timed out or abnormally terminated, the number-occupying release process is triggered, clearing the number-occupying count recorded for that user in the number-occupying cache and synchronously updating the occupancy status in the voucher number caching system, so that the target voucher number originally allocated but not actually generated into a voucher returns to the gap-in-number cache or the allocable range. In this way, when a user initiates a credential generation request again, the credential number generation algorithm can reallocate the credential number based on the latest missing number cache and number occupancy cache, ensuring that the entire process can still run correctly and orderly under multi-user concurrency and abnormal conditions.
[0089] To implement the credential generation method of this application embodiment, this application embodiment also provides a credential generation apparatus, such as... Figure 4 As shown, the device includes:
[0090] The cache information acquisition unit 401 is used to acquire cache information of the target accounting period and the voucher number under the target voucher corresponding to the voucher generation request in response to the voucher generation request.
[0091] The interval determination unit 402 is used to determine the occupied interval and the missing interval of historical voucher numbers based on the voucher number cache information.
[0092] The voucher number allocation unit 403 is used to allocate at least one target voucher number to each voucher generation request based on the number gap and the occupied interval.
[0093] The voucher generation unit 404 is used to generate a voucher corresponding to each target voucher number allocated for each voucher generation request.
[0094] In one embodiment, the interval determination unit 402 is specifically used for: for each voucher generation request, obtaining the voucher number already used under the target accounting period and the target voucher from the voucher number cache information corresponding to the voucher generation request; sorting the used voucher numbers and merging consecutive serial numbers into at least one number segment to obtain the occupied interval of the determined historical voucher number; for two adjacent number segments, taking the missing number segment between the end number of the previous number segment and the start number of the next number segment as the missing number interval.
[0095] In one embodiment, the voucher number allocation unit 403 is specifically used to: generate a pre-reserved number record in the voucher number cache information according to the required number of voucher numbers indicated by the voucher generation request; when allocating at least one target voucher number for each voucher generation request, allocate consecutive target voucher numbers based on the number gap interval, the occupied interval and the pre-reserved number record, until the required number of voucher numbers is met.
[0096] In one embodiment, the voucher number allocation unit 403 is specifically configured to: for at least one of the missing number intervals, determine the available numbers within the missing number interval that are not occupied by the pre-occupied number record; select voucher numbers sequentially from the available numbers according to a preset allocation order, and include the selected voucher numbers in the target voucher number; when the available numbers within the missing number interval are insufficient to meet the required number of voucher numbers indicated by the current voucher generation request, based on the maximum used voucher number determined by the occupied interval, and continue to allocate target voucher numbers based on the maximum used voucher number until the required number of voucher numbers is met.
[0097] In one embodiment, the device further includes: a voucher number cache information update unit; the voucher number cache information update unit is specifically used to: when it is detected that the voucher generation operation of the current voucher generation request has timed out or terminated abnormally, release the occupied state of the target voucher number corresponding to the current voucher generation request in the voucher number cache information, so that the released target voucher number becomes an allocable voucher number again.
[0098] It should be noted that the above embodiments of the voucher generation device are only illustrative of the division of the above-described program modules when generating vouchers. In practical applications, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device can be divided into different program modules to complete all or part of the processing described above. In addition, the voucher generation device and the voucher generation method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0099] Based on the hardware implementation of the above program modules, and in order to implement the credential generation method provided in this application embodiment, this application embodiment also provides a computer device, such as... Figure 5 As shown, computer device 500 includes:
[0100] Central processing unit 501, memory 502, and input / output interface 503;
[0101] The memory 502 is a short-term storage memory or a persistent storage memory;
[0102] The central processing unit 501 is configured to communicate with the memory 502 and execute instructions in the memory 502 to perform any of the above-described credential generation methods.
[0103] Of course, in practical applications, the various components in the computer device 500 are coupled together through a bus system 504. It is understood that the bus system 504 is used to realize communication between these components. In addition to a data bus, the bus system 504 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 5 The general designated all buses as Bus System 504.
[0104] The memory 502 in this embodiment is used to store various types of data to support the operation of the computer device 500. Examples of such data include any computer program used to operate on the computer device 500.
[0105] It is understood that when the processor in the computer device described above executes the computer program, it can also realize the functions of each unit in the corresponding device embodiments described above, which will not be repeated here. Exemplarily, the computer program can be divided into one or more modules / units, one or more modules / units are stored in memory and executed by the processor to complete the various embodiments of this application. One or more modules / units can be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the computer device. For example, the computer program can be divided into units in the aforementioned computer device, and each unit can implement the specific functions described in the corresponding computer device above.
[0106] Computer equipment can be desktop computers, laptops, handheld computers, and cloud servers, among other computing devices. Computer equipment may include, but is not limited to, processors and memory. Those skilled in the art will understand that processors and memory are merely examples of computer equipment and do not constitute a limitation on the computer equipment. It may include more or fewer components, or combinations of certain components, or different components. For example, computer equipment may also include input / output devices, network access devices, buses, etc.
[0107] A processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of a computer device, connecting all parts of the computer device through various interfaces and lines.
[0108] Memory can be used to store computer programs and / or modules. The processor performs various functions of the computer device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, at least one application program required for a function, etc.; the data storage area can store data created based on terminal usage, etc. Furthermore, memory can include high-speed random access memory, and can also include non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital cards (SD), flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.
[0109] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, performs any of the above-described credential generation methods.
[0110] This application also provides a computer program product that stores a computer program / instruction thereon. When the computer program / instruction is executed by a processor, it is used to implement the credential generation method described in the first aspect or any specific implementation of the first aspect of this application.
[0111] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0112] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0113] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0114] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0115] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A method for generating vouchers, characterized in that, include: In response to multiple voucher generation requests, obtain the target accounting period and voucher number cache information under the target voucher corresponding to each voucher generation request; For each voucher generation request, based on the voucher number cache information corresponding to the voucher generation request, the occupied range and the missing range of the historical voucher number corresponding to the voucher generation request are determined; Based on the missing number interval and the occupied interval corresponding to the voucher generation request, at least one target voucher number is allocated to the voucher generation request, and the target voucher number allocated to the voucher generation request is stored in the voucher number queue corresponding to the voucher generation request. The target voucher number is sequentially retrieved from the voucher number queue corresponding to each voucher generation request, and a voucher corresponding to the target voucher number is generated based on the retrieved target voucher number.
2. The method according to claim 1, characterized in that, For each voucher generation request, based on the voucher number cache information corresponding to the voucher generation request, the occupied range and the missing range of the historical voucher number corresponding to the voucher generation request are determined, including: For each voucher generation request, the target accounting period and the voucher numbers already used under the target voucher number are obtained from the voucher number cache information corresponding to the voucher generation request. The used voucher numbers are sorted, and consecutive serial numbers are merged into at least one number segment to determine the occupied range of historical voucher numbers; For two adjacent number segments, the missing number segment between the end number of the previous number segment and the beginning number of the next number segment is defined as the gap.
3. The method according to claim 1, characterized in that, The step of allocating at least one target voucher number to the voucher generation request based on the missing number range and the occupied range corresponding to the voucher generation request includes: Based on the required number of voucher numbers indicated by the voucher generation request, a pre-reservation number record is generated in the voucher number cache information; When allocating at least one target voucher number for each voucher generation request, consecutive target voucher numbers are allocated based on the number gap interval, the occupied interval, and the pre-occupied number record, until the required number of voucher numbers is met.
4. The method according to claim 3, characterized in that, When allocating at least one target voucher number for each voucher generation request, based on the missing number interval, the occupied interval, and the pre-occupied number record in the voucher number cache information, consecutive target voucher numbers are allocated until the required number of voucher numbers is met, including: For at least one of the aforementioned gap number intervals, determine the available numbers within the gap number interval that are not occupied by the pre-reserved number records; According to the preset allocation order, voucher numbers are selected sequentially from the available numbers, and the selected voucher numbers are included in the target voucher number; When the available numbers within the number gap are insufficient to meet the required number of voucher numbers indicated by the current voucher generation request, the target voucher numbers are allocated based on the maximum used voucher number determined by the occupied interval, until the required number of voucher numbers is met.
5. The method according to claim 1, characterized in that, The method further includes: When it is detected that the current credential generation request has timed out or terminated abnormally, the occupancy status of the target credential number corresponding to the current credential generation request in the credential number cache information is released, so that the released target credential number becomes an allocable credential number again.
6. A voucher generation device, characterized in that, include: The cache information acquisition unit is used to respond to multiple voucher generation requests by acquiring cache information of the target accounting period and the voucher number under the target voucher corresponding to each voucher generation request. The interval determination unit is used to determine the occupied interval and the missing interval of the historical voucher number corresponding to each voucher generation request based on the voucher number cache information corresponding to the voucher generation request. The voucher number allocation unit is used to allocate at least one target voucher number to the voucher generation request based on the missing number interval and the occupied interval corresponding to the voucher generation request, and to store the target voucher number allocated to the voucher generation request into the voucher number queue corresponding to the voucher generation request. The voucher generation unit is used to sequentially retrieve the target voucher number from the voucher number queue corresponding to each voucher generation request, and generate a voucher corresponding to the target voucher number based on the retrieved target voucher number.
7. The method according to claim 6, characterized in that, The interval determination unit is used to obtain the voucher numbers used under the target accounting period and the target voucher from the voucher number cache information; sort the used voucher numbers and merge consecutive serial numbers into at least one number segment to obtain the occupied interval of the determined historical voucher numbers; for two adjacent number segments, the missing number segment between the end number of the previous number segment and the beginning number of the next number segment is taken as the missing number interval.
8. A computer device, characterized in that, include: Central processing unit, memory, and input / output interfaces; The memory is either a short-term storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the method according to any one of claims 1 to 5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it is used to implement the method as described in any one of claims 1 to 5.
10. A computer program product having a computer program / instructions stored thereon, characterized in that, When executed by a processor, the computer program / instructions are used to implement the method as described in any one of claims 1 to 5.