Lock mechanism-based paas platform business document number generation method and system

By introducing a read-write lock mechanism into the PaaS platform, the problem of generating business document numbers in high-concurrency scenarios is solved, and the accuracy and efficient generation of serial numbers are achieved, which is suitable for business needs of automatically generating unique numbers.

CN120296020BActive Publication Date: 2025-10-14和创(北京)科技股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510244171.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-10-14
Estimated Expiration
2045-03-03

AI Technical Summary

Technical Problem

In the high-concurrency scenario of the PaaS platform, existing technologies make it difficult to accurately and quickly generate business document numbers, and problems such as serial number duplication and untimely reset are prone to occur.

Method used

A read-write lock mechanism based on a lock mechanism is adopted. The numbered model ID is used as the lock key to apply for write lock and read lock respectively to ensure the atomicity and consistency of the serial number counter and realize the accurate generation and reset of the serial number.

Benefits of technology

It improves the system's concurrent processing capabilities and the accuracy of number generation, reduces the problems of serial number duplication and untimely reset, and is suitable for various business scenarios that require automatic generation of unique numbers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120296020B_ABST
    Figure CN120296020B_ABST
Patent Text Reader

Abstract

The application provides a PaaS platform business document number generation method and system based on a lock mechanism. The method according to the application comprises the following steps: S1: judging whether a serial number counter in a PaaS platform needs to be reset, and selecting to execute step S2 or step S3 according to a judgment result; S2: taking a number model ID as a lock key and applying for a write lock based on the judgment result, and selecting to execute step S3 or re-execute step S1 according to a write lock locking result; S3: taking the number model ID as the lock key and applying for a read lock based on the judgment result, and generating a PaaS platform business document number according to a read lock locking result, or re-executing step S1. The application effectively solves the problem of business document number generation in a high-concurrency scenario by using a read-write lock mechanism, flexible number rule configuration and an efficient serial number generation strategy, improves the concurrent processing capacity, accuracy and maintainability of the system, and is suitable for various business scenarios that need to automatically generate unique numbers.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the computer technical field, and particularly relates to a PaaS platform business document number generation method and system based on a lock mechanism. BACKGROUND

[0002] In the PaaS platform implementation, a configuration number rule ability is provided for the number field of a business object, and the number rule includes a date (such as year, year-month, year-month-day) + serial number mode, and the serial number can be configured to be reset according to year, year-month, year-month-day. When a business document is generated according to a business object, the PaaS platform automatically generates the number attribute of the document according to the number rule. Due to the existence of the serial number in the number rule, when a plurality of business documents are generated by a business object, the documents have relevance, and in a high-concurrency business document generation scenario, the serial number is likely to be repeated. Meanwhile, due to the influence of the serial number reset factor, when the time node of the reset arrives, due to concurrency, the serial number is not reset. The above two cases will affect the accurate generation of the document number by the PaaS platform, and therefore a method for accurately and quickly generating an automatic number in a certain high-concurrency scenario is required. SUMMARY

[0003] The present application aims to provide a PaaS platform business document number generation method and system based on a lock mechanism, and aims to solve the above problems in the prior art.

[0004] The present application provides a PaaS platform business document number generation method based on a lock mechanism, comprising:

[0005] S1: judging whether a serial number counter in a PaaS platform needs to be reset, and selecting to execute step S2 or step S3 according to the judgment result;

[0006] S2: taking a number model ID as a lock key and applying for a write lock based on the judgment result, and selecting to execute step S3 or re-execute step S1 according to the write lock locking result;

[0007] S3: taking the number model ID as the lock key and applying for a read lock based on the judgment result, and generating a PaaS platform business document number according to the read lock locking result, or re-executing step S1.

[0008] The present application provides a PaaS platform business document number generation system based on a lock mechanism, comprising:

[0009] A judgment module is configured to judge whether a serial number counter in a PaaS platform needs to be reset, and to select to execute a write lock module or a read lock module according to the judgment result;

[0010] The write lock module is used for applying a write lock with the numbered model ID as a lock key and based on the judgment result, and selecting to execute the read lock module or re-execute the judgment module according to a write lock locking result.

[0011] The read lock module is used for applying a read lock with the numbered model ID as a lock key and based on the judgment result, and generating a PaaS platform business document number or re-executing the judgment module according to a read lock locking result.

[0012] The embodiment of the present application further provides an electronic device, including a memory, a processor and a computer program stored in the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the PaaS platform business document number generation method based on a lock mechanism are implemented.

[0013] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores an information transmission implementation program, and when the program is executed by a processor, the steps of the PaaS platform business document number generation method based on a lock mechanism are implemented.

[0014] The embodiment of the present application can include the following beneficial effects: the embodiment of the present application proposes a method for generating a PaaS platform business document number based on a read-write lock mode, and the method effectively solves the problem of business document number generation in a high concurrency scenario through a read-write lock mechanism, flexible numbering rule configuration and an efficient serial number generation strategy, improves the concurrent processing capability, accuracy and maintainability of the system, and is suitable for various business scenarios that require automatic generation of unique numbers. BRIEF DESCRIPTION OF DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the one or more embodiments of the present application or the prior art, the drawings needed to be used in the embodiment or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0016] Figure 1 is a PaaS platform business document number generation method flowchart based on a lock mechanism of the embodiment of the present application;

[0017] Figure 2 is a specific flowchart of the PaaS platform business document number generation method of the embodiment of the present application;

[0018] Figure 3 is a PaaS platform business document number generation system schematic diagram based on a lock mechanism of the embodiment of the present application. DETAILED DESCRIPTION

[0019] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the technical solutions in one or more embodiments of this specification will be clearly and completely described below in conjunction with the drawings in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this document.

[0020] Method Example

[0021] According to an embodiment of the present invention, a method for generating a business document number on a PaaS platform based on a lock mechanism is provided. Figure 1 This is a flow chart of a method for generating a business document number on a PaaS platform based on a lock mechanism according to an embodiment of the present invention. Figure 1 As shown, the method for generating a PaaS platform business document number based on a lock mechanism according to an embodiment of the present invention specifically includes:

[0022] Step S101: Determine whether the serial number counter in the PaaS platform needs to be reset, and select step S102 or step S103 according to the determination result, specifically including:

[0023] Compare the current time with the reset method and reset date in the numbering model to determine whether the serial number counter in the PaaS platform needs to be reset. If reset is required, select step S102;

[0024] If no reset is required, step S103 is selected;

[0025] Step S102: Using the model ID as the lock key and applying for a write lock based on the judgment result, and then selecting to execute step S103 or re-execute step S101 based on the write lock result, specifically including:

[0026] The numbering model ID is used as the lock key and a write lock is applied for the reset action. If the write lock is successfully locked, the serial number counter is reset according to the starting number attribute value of the numbering model, the reset date of the numbering model is updated to the current date, the write lock is released, and step S103 is executed;

[0027] If the write lock fails, step S101 is executed again;

[0028] When applying for a write lock, it will wait for all read locks on the current lock key to be released;

[0029] Step S103: Using the numbering model ID as the lock key and applying for a read lock based on the judgment result, generating a PaaS platform business document number based on the read lock result, or re-execute step S101, specifically including:

[0030] Use the numbering model ID as the lock key and apply for a read lock to obtain the serial number. If the read lock is successfully acquired, obtain the current value from the serial number counter and release the read lock. Generate a PaaS platform business document number based on the obtained serial number value and the numbering format in the numbering model.

[0031] If the read lock fails, step S101 is executed again;

[0032] Among them, if there is a write lock on the current lock key when applying for a read lock, the read lock application will wait for the write lock to be released.

[0033] The following is a specific example of a method for generating a business document number on a PaaS platform based on a lock mechanism according to an embodiment of the present invention. Figure 2 As shown, the above technical solution of the embodiment of the present invention is described in detail.

[0034] 1. Numbering model definition

[0035] After the numbering rule is configured, the numbering model data is created based on the configuration parameters. The main attributes are as follows:

[0036] Model ID: uniquely identifies the model data.

[0037] Numbering format: The numbering format defines the overall format of the auto-numbering sequence.

[0038] For example: {YYYY}{MM}{dd}-{0000}, where {YYYY} represents the year, {MM} represents the month, {dd} represents the day, and {0000} represents the 4-digit serial number.

[0039] Start number: record the specific number from which the serial number starts.

[0040] Reset method: record the method by which the serial number is reset, for example: reset by year, reset by month, reset by day, no reset.

[0041] Reset Date: The date on which the record number is reset.

[0042] 2. Serial number counter

[0043] Define a counter for the serial number of a numbering rule. The initial value of the counter is the value of the start number attribute of the numbering model. There are two main scenarios for operating the counter:

[0044] ① Generate serial number scenario: When generating a business document, obtain the current value from the counter, automatically increment the counter by 1, and save the current value. During the current processing, it is necessary to prevent the counter from being reset.

[0045] ② Reset serial number scenario: When the reset condition is met, the counter is assigned a value based on the start number attribute value of the numbering model. During the current processing, it is necessary to prevent the counter from being used to generate serial numbers.

[0046] When analyzing the two operational scenarios above, focusing on the serial number counter, we can define the scenario of generating serial numbers as a counter read scenario. When multiple business documents are generated simultaneously, each document essentially reads the latest value of the counter. The counter itself controls the increment of the value during reading, and the entire process is not subject to external interference. The scenario of resetting serial numbers is defined as a counter write scenario. When resetting the counter, the counter value is actually written externally.

[0047] At the same time, since the frequency of use of the serial number generation scenario is much higher than the frequency of use of the serial number reset scenario, the embodiment of the present invention adopts a read-write lock method to protect the use of the serial number counter, ensuring that the counter can accurately generate serial numbers when used with high concurrency.

[0048] 3. Number generation process

[0049] When a business document number needs to be generated, the general generation process is as follows:

[0050] Step 1: Determine whether the serial number counter needs to be reset based on the current time, the reset method, and the reset date in the numbering model. If the result of the determination is that the serial number counter needs to be reset, proceed to step 2; if the serial number counter does not need to be reset, proceed to step 3.

[0051] Step 2: Use the model ID as the lock key to apply for a write lock for the upcoming reset. Applying a write lock will wait for all read locks on the current lock key to be released. There are two main results of applying a write lock:

[0052] ① When the write lock is successfully locked, the serial number counter is reset according to the starting number of the numbering model, and the reset date of the numbering model is updated to the current date. Then the write lock is released and step 3 is executed.

[0053] ② When the write lock fails, for example, the lock times out or other exceptions occur, return to step 1 and execute again.

[0054] Step 3: Use the model ID as the lock key to apply for a read lock for the action of obtaining the serial number. If a write lock exists on the current lock key, the read lock application will wait for the write lock to be released. There are two main results of the read lock application:

[0055] ① When the read lock is successfully locked, the current value is obtained from the counter, and then the read lock is released. The business document number is generated based on the obtained serial number value and the numbering format in the numbering model.

[0056] ②When the read lock fails, for example, the lock times out or other exceptions occur, return to step 1 and execute again.

[0057] In addition, in a distributed environment, there are multiple ways to implement the self-increment of the counter value, and the embodiment of the present invention does not limit which specific method is adopted.

[0058] Furthermore, in a distributed environment, there are multiple ways to implement a read-write lock, and the embodiment of the present invention does not limit which specific way is adopted.

[0059] System Example

[0060] According to an embodiment of the present invention, a PaaS platform business document number generation system based on a lock mechanism is provided. Figure 3 Schematic diagram of a PaaS platform business document number generation system based on a lock mechanism according to an embodiment of the present invention. Figure 3 As shown, the PaaS platform business document number generation system based on the lock mechanism according to an embodiment of the present invention specifically includes:

[0061] The judgment module 30 is used to judge whether the serial number counter in the PaaS platform needs to be reset, and selects to execute the write lock module or the read lock module according to the judgment result, specifically for:

[0062] Compare the current time with the reset method and reset date in the numbering model to determine whether the serial number counter in the PaaS platform needs to be reset. If reset is required, select the write lock module to execute;

[0063] If no reset is required, select the execution read lock module;

[0064] The write lock module 32 is used to apply for a write lock using the model ID as the lock key and based on the judgment result, and to select to execute the read lock module or re-execute the judgment module according to the write lock result, specifically for:

[0065] Use the numbering model ID as the lock key and apply for a write lock for the reset action. If the write lock is successfully locked, reset the serial number counter according to the starting number attribute value of the numbering model, update the reset date of the numbering model to the current date, release the write lock, and execute the read lock module;

[0066] If the write lock fails, the judgment module is re-executed;

[0067] When applying for a write lock, it will wait for all read locks on the current lock key to be released;

[0068] The read lock module 34 is used to apply for a read lock based on the judgment result using the number model ID as the lock key, and to generate a PaaS platform business document number based on the read lock result, or to re-execute the judgment module, specifically for:

[0069] Use the numbering model ID as the lock key and apply for a read lock to obtain the serial number. If the read lock is successfully acquired, obtain the current value from the serial number counter and release the read lock. Generate a PaaS platform business document number based on the obtained serial number value and the numbering format in the numbering model.

[0070] If the read lock fails, the judgment module is re-executed;

[0071] Among them, if there is a write lock on the current lock key when applying for a read lock, the read lock application will wait for the write lock to be released.

[0072] The embodiment of the present invention is a system embodiment corresponding to the above-mentioned method embodiment. The specific operations of each module can be understood by referring to the description of the method embodiment, which will not be repeated here.

[0073] In summary, embodiments of the present invention provide a method for generating business document numbers based on a read-write lock approach within a PaaS platform and in high-concurrency scenarios. This method effectively addresses the challenges of business document number generation in high-concurrency scenarios through a read-write lock mechanism, flexible numbering rule configuration, and an efficient serial number generation strategy. This improves the system's concurrent processing capabilities, accuracy, and maintainability, making it suitable for a variety of business scenarios requiring automatic unique number generation. Embodiments of the present invention specifically include the following beneficial effects:

[0074] 1. High concurrency support: This embodiment of the present invention effectively solves the serial number duplication problem that may occur when generating business document numbers in high-concurrency scenarios through a read-write lock mechanism. The use of read-write locks ensures the atomicity and consistency of counter operations when generating and resetting serial numbers, avoiding concurrency conflicts.

[0075] 2. Accuracy of serial number resetting: The embodiment of the present invention introduces the concepts of reset method and reset date, which can accurately reset the serial number counter according to the configured rules (such as resetting by year, month, or day), avoiding the problem of reset failure or untimely reset due to concurrent operations.

[0076] 3. Flexible numbering rule configuration: The embodiment of the present invention supports the configuration of multiple numbering formats (such as the combination of year, month, day and serial number), and can flexibly set the starting value and reset method of the serial number according to business needs. This flexibility enables the embodiment of the present invention to adapt to the needs of different business scenarios.

[0077] 4. Efficient serial number generation: The embodiment of the present invention separates the serial number generation and reset operations and uses a read-write lock mechanism to quickly generate serial numbers in a high-concurrency environment, reducing waiting time and effectively improving the overall performance of the system.

[0078] Device Example 1

[0079] An embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps described in the method embodiment when executed by the processor.

[0080] Device Example 2

[0081] An embodiment of the present invention provides a computer-readable storage medium, on which a program for implementing information transmission is stored. When the program is executed by a processor, the steps described in the method embodiment are implemented.

[0082] The computer-readable storage medium in this embodiment includes, but is not limited to, ROM, RAM, magnetic disk, or optical disk.

[0083] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for generating business document numbers on a PaaS platform based on a lock mechanism, characterized in that include: S1: Determine whether the serial number counter in the PaaS platform needs to be reset, and select step S2 or step S3 based on the determination result, specifically including: Compare the current time with the reset method and reset date in the numbering model to determine whether the serial number counter in the PaaS platform needs to be reset. If reset is required, select step S2; If no reset is required, step S3 is selected; S2: Using the model ID as the lock key and applying for a write lock based on the judgment result, and then selecting to execute step S3 or re-execute step S1 based on the write lock result, specifically including: Use the numbering model ID as the lock key and apply for a write lock for the reset action. If the write lock is successfully locked, reset the serial number counter according to the starting number attribute value of the numbering model, update the reset date of the numbering model to the current date, release the write lock, and execute step S3; If the write lock fails, re-execute step S1; When applying for a write lock, it will wait for all read locks on the current lock key to be released; S3: Using the numbering model ID as the lock key and applying for a read lock based on the judgment result, generating a PaaS platform business document number based on the read lock result, or re-execute step S1, specifically including: Use the numbering model ID as the lock key and apply for a read lock to obtain the serial number. If the read lock is successfully acquired, obtain the current value from the serial number counter and release the read lock. Generate a PaaS platform business document number based on the obtained serial number value and the numbering format in the numbering model. If the read lock fails, re-execute step S1; Among them, if there is a write lock on the current lock key when applying for a read lock, the read lock application will wait for the write lock to be released.

2. A PaaS platform business document number generation system based on a lock mechanism, characterized by include: The judgment module is used to determine whether the serial number counter in the PaaS platform needs to be reset. Based on the judgment result, it selects to execute the write lock module or the read lock module. Specifically, it is used to: Compare the current time with the reset method and reset date in the numbering model to determine whether the serial number counter in the PaaS platform needs to be reset. If reset is required, select the write lock module to execute; If no reset is required, select the execution read lock module; The write lock module is used to apply for a write lock based on the judgment result using the numbered model ID as the lock key, and to select to execute the read lock module or re-execute the judgment module according to the write lock result. Specifically, it is used to: Use the numbering model ID as the lock key and apply for a write lock for the reset action. If the write lock is successfully locked, reset the serial number counter according to the starting number attribute value of the numbering model, update the reset date of the numbering model to the current date, release the write lock, and execute the read lock module; If the write lock fails, the judgment module is re-executed; When applying for a write lock, it will wait for all read locks on the current lock key to be released; The read lock module is used to apply for a read lock based on the judgment result using the numbering model ID as the lock key, and to generate a PaaS platform business document number based on the read lock result, or to re-execute the judgment module. Specifically, it is used to: Use the numbering model ID as the lock key and apply for a read lock to obtain the serial number. If the read lock is successfully acquired, obtain the current value from the serial number counter and release the read lock. Generate a PaaS platform business document number based on the obtained serial number value and the numbering format in the numbering model. If the read lock fails, the judgment module is re-executed; Among them, if there is a write lock on the current lock key when applying for a read lock, the read lock application will wait for the write lock to be released.

3. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the method for generating a business document number of a PaaS platform based on a lock mechanism as described in claim 1 are implemented.

4. A computer-readable storage medium, characterized in that The computer-readable storage medium stores an implementation program for information transmission, and when the program is executed by the processor, the steps of the method for generating a PaaS platform business document number based on a lock mechanism as described in claim 1 are implemented.

Citation Information

Patent Citations

  • Serial number generating method and device

    CN104866601A

  • Serial number generation method and device, equipment and storage medium

    CN113377427A