PaaS platform business document number generation method and system based on lock mechanism

By introducing a read-write lock mechanism in the PaaS platform and using the numbering model ID as the lock key, the problem of generating business document numbers in high concurrency scenarios is solved, the accuracy and efficient generation of flow numbers are achieved, and the concurrency processing capability and maintainability of the system are improved.

CN120296020AActive Publication Date: 2025-07-11和创(北京)科技股份有限公司
View PDF 7 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the high concurrency scenario of PaaS platform, it is difficult for the existing technology to accurately and quickly generate business document numbers, which are prone to duplication of flow numbers and untimely resetting.

Method used

A read-write lock mechanism based on the lock mechanism is adopted. The numbering model ID is used as the lock key, and the write lock and read lock are applied separately to ensure the atomicity and consistency of the flow number counter and generate the business document number.

Benefits of technology

It effectively solves the problem of repetition and untimely reset of flow numbers in high concurrency scenarios, improves the system's concurrency processing capability, accuracy and maintainability, 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 CN120296020A_ABST
    Figure CN120296020A_ABST
Patent Text Reader

Abstract

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

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and system for generating business document numbers in a PaaS platform based on a lock mechanism. Background Art

[0002] In the implementation of a PaaS platform, the ability to configure numbering rules is provided for the number fields of business objects. The numbering rules may include a date (such as year, year and month, year, month, and day) + serial number, and it is possible to configure the reset of the serial number by year, year and month, or year, month, and day. When generating business documents based on business objects, the PaaS platform automatically generates the number attributes of these documents according to the numbering rules. Due to the existence of the serial number in the numbering rules, when multiple business documents are generated from one business object, there is a correlation between the documents, and the situation of duplicate serial numbers is likely to occur in a high-concurrency scenario of generating business documents. At the same time, due to the influence of the serial number reset factor, when the reset time node arrives, due to concurrency, the serial number is not reset. Both of the above situations will affect the accurate generation of document numbers in the PaaS platform. Therefore, a method for accurately and quickly generating automatic numbers in a certain high-concurrency scenario is needed. Summary of the Invention

[0003] The purpose of the present invention is to provide a method and system for generating business document numbers in a PaaS platform based on a lock mechanism, aiming to solve the above problems in the prior art.

[0004] An embodiment of the present invention provides a method for generating business document numbers in a PaaS platform based on a lock mechanism, including:

[0005] S1: Determine whether the serial number counter in the PaaS platform needs to be reset, and select to execute step S2 or step S3 according to the determination result;

[0006] S2: Use the number model ID as the lock key and apply for a write lock based on the determination result, and select to execute step S3 or re-execute step S1 according to the result of locking the write lock;

[0007] S3: Use the number model ID as the lock key and apply for a read lock based on the determination result, generate the business document number of the PaaS platform according to the result of locking the read lock, or re-execute step S1.

[0008] An embodiment of the present invention provides a system for generating business document numbers in a PaaS platform based on a lock mechanism, including:

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

[0010] A write lock module, which is used to use the numbered model ID as the lock key and apply for a write lock based on the judgment result, and select to execute the read lock module or re - execute the judgment module according to the write lock acquisition result;

[0011] A read lock module, which is used to use the numbered model ID as the lock key and apply for a read lock based on the judgment result, generate a PaaS platform business document number according to the read lock acquisition result, or re - execute the judgment module.

[0012] An embodiment of the present invention also provides an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the above - mentioned PaaS platform business document number generation method based on the lock mechanism are implemented.

[0013] An embodiment of the present invention also provides a computer - readable storage medium. An implementation program for information transmission is stored on the computer - readable storage medium. When the program is executed by the processor, the steps of the above - mentioned PaaS platform business document number generation method based on the lock mechanism are implemented.

[0014] Adopting the embodiment of the present invention may include the following beneficial effects: The embodiment of the present invention proposes a method for generating a PaaS platform business document number based on the read - write lock method. This method effectively solves the problem of generating business document numbers in high - concurrency scenarios through the read - write lock mechanism, flexible numbering rule configuration, and efficient serial number generation strategy, improves the concurrency processing ability, accuracy, and maintainability of the system, and is applicable to various business scenarios that require automatic generation of unique numbers. Description of the Drawings

[0015] In order to more clearly illustrate the technical solutions in one or more embodiments of this specification or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments recorded in this specification. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

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

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

[0018] Figure 3 It is a schematic diagram of the PaaS platform business document number generation system based on the lock mechanism in the embodiment of the present invention. Detailed Embodiments

[0019] In order to enable those skilled in the art of the present technology to better understand the technical solutions in one or more embodiments of this specification, the following will, in conjunction with the accompanying drawings in one or more embodiments of this specification, clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this document.

[0020] Method Embodiment

[0021] According to an embodiment of the present invention, a method for generating a business document number of a PaaS platform based on a lock mechanism is provided. Figure 1 It is a flowchart of the method for generating a business document number of a PaaS platform based on a lock mechanism according to an embodiment of the present invention. As Figure 1 shown, the method for generating a business document number of a PaaS platform 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 to execute 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 it needs to be reset, then select to execute Step S102;

[0024] If it does not need to be reset, then select to execute Step S103;

[0025] Step S102: Use the numbering model ID as the lock key and apply for a write lock based on the determination result, and select to execute Step S103 or re - execute Step S101 according to the write lock acquisition result, specifically including:

[0026] 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 acquired, then reset the serial number counter according to the start 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 S103;

[0027] If the write lock acquisition fails, then re - execute Step S101;

[0028] Among them, when applying for a write lock, it will wait for the release of all read locks on the current lock key;

[0029] Step S103: Use the numbering model ID as the lock key and apply for a read lock based on the judgment result. Generate a PaaS platform business document number according to the read lock acquisition result, or re-execute step S101, which specifically includes:

[0030] Use the numbering model ID as the lock key and apply for a read lock for the action of obtaining the serial number. If the read lock acquisition is successful, obtain the current value from the serial number counter and release the read lock, and generate a PaaS platform business document number according to the obtained serial number value and the numbering format in the numbering model;

[0031] If the read lock acquisition fails, re-execute step S101;

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

[0033] The following combines the specific situation of the PaaS platform business document number generation method based on the lock mechanism in the embodiments of the present invention, as Figure 2 shown, to elaborate on the above technical solutions of the embodiments of the present invention in detail.

[0034] 1. Numbering model definition

[0035] After the numbering rule is configured, establish numbering model data according to the configuration parameters. The main attributes are as follows:

[0036] Numbering model ID: Uniquely identifies the numbering model data.

[0037] Numbering format: The numbering format defines the overall format of the automatic numbering rule.

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

[0039] Starting number: Records from which specific number the serial number starts.

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

[0041] Reset date: Records the date when the numbering is reset.

[0042] 2. Serial number counter

[0043] Define a counter for the serial number of a numbering rule, and the initial value of the counter is the value of the starting number attribute of the numbering model. There are mainly two scenarios for operating the counter:

[0044] ①Scenario of generating serial numbers: When generating business documents, obtain the current value from the counter, increment the counter by 1 automatically, and save the current value of the counter. During the current processing, it is necessary to prevent the counter from being reset.

[0045] ②Scenario of resetting serial numbers: When the reset condition is met, assign a value to the counter according to the start number attribute value of the numbering model. During the current processing, it is necessary to prevent the counter from being used for generating serial numbers.

[0046] When analyzing the above two operation scenarios with the serial number counter as the core, the scenario of generating serial numbers can be defined as the read scenario of the counter. When multiple business documents are generated simultaneously, the essence of each document is to read the latest value of the counter, and the counter itself controls the increment of the value during reading, and the processing of the whole process is not intervened by the outside. The scenario of resetting serial numbers is defined as the write scenario of the counter. When the counter needs to be reset, in fact, the outside writes the value of the counter.

[0047] At the same time, since the usage frequency of the scenario of generating serial numbers is much higher than that of the scenario of resetting serial numbers, the embodiments of the present invention adopt the read-write lock method to protect the use of the serial number counter and ensure that the counter can accurately generate serial numbers when used in high concurrency.

[0048] 3. Process of number generation

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

[0050] Step 1: Compare the current time with the reset method and reset date in the numbering model to determine whether the serial number counter needs to be reset. When the result of the judgment is that the serial number counter needs to be reset, perform the operation in Step 2; when the serial number counter does not need to be reset, perform Step 3.

[0051] Step 2: Use the numbering model ID as the lock key to apply for a write lock for the upcoming reset action. When applying for the write lock, it will wait for the release of all read locks on the current lock key. There are mainly two results of locking the write lock:

[0052] ①When the write lock is successfully locked, reset the serial number counter according to the start number of the numbering model, update the reset date of the numbering model to the current date, and then release the write lock and perform the operation in Step 3.

[0053] ②When the write lock fails to be locked, for example: the lock timeout or other exceptions occur, go back to Step 1 and execute again.

[0054] Step 3: Use the numbered model ID as the lock key to apply for a read lock for the action of about to obtain the serial number. If there is a write lock on the current lock key, the read lock application will wait for the write lock to be released. There are mainly two results for adding the read lock:

[0055] ① When the read lock is successfully added, obtain the current value from the counter, then release the read lock, and generate the business document number according to the obtained serial number value and the number format in the numbered model.

[0056] ② When the read lock addition fails, for example: the lock addition times out or other exceptions occur, go back to Step 1 and execute again.

[0057] In addition, in a distributed environment, there are multiple ways to implement the increment of the counter value. The specific method to be adopted is not limited in the embodiments of the present invention.

[0058] And in a distributed environment, there are also multiple ways to implement the read-write lock. The specific method to be adopted is not limited in the embodiments of the present invention.

[0059] System Embodiment

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

[0061] A judgment module 30, configured to judge whether the serial number counter in the PaaS platform needs to be reset, and select to execute the write lock module or the read lock module according to the judgment result. Specifically, it is used for:

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

[0063] If it does not need to be reset, select to execute the read lock module;

[0064] A write lock module 32, configured to use the numbered model ID as the lock key and apply for a write lock based on the judgment result, and select to execute the read lock module or re-execute the judgment module according to the write lock addition result. Specifically, it is used for:

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

[0066] If the write lock acquisition fails, the judgment module is executed again;

[0067] Among them, when applying for a write lock, it will wait for the release of all read locks on the current lock key;

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

[0069] Apply for a read lock with the numbered model ID as the lock key for the action of obtaining the serial number. If the read lock acquisition is successful, obtain the current value from the serial number counter and release the read lock, and generate a PaaS platform business document number according to the obtained serial number value and the number format in the numbered model;

[0070] If the read lock acquisition fails, the judgment module is executed again;

[0071] Among them, when applying for a read lock, if there is a write lock on the current lock key, 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 method embodiment. The specific operations of each module can be understood with reference to the description of the method embodiment, and will not be elaborated here.

[0073] In summary, the embodiment of the present invention proposes a method for generating a business document number based on the read-write lock method in the implementation of the PaaS platform and in high-concurrency scenarios. This method effectively solves the problem of generating business document numbers in high-concurrency scenarios through the read-write lock mechanism, flexible numbering rule configuration, and efficient serial number generation strategy, improves the concurrency processing ability, accuracy, and maintainability of the system, and is applicable to various business scenarios that require automatic generation of unique numbers. The embodiment of the present invention specifically includes the following beneficial effects:

[0074] 1. High-concurrency support: The embodiment of the present invention effectively solves the problem of possible duplicate serial numbers when generating business document numbers in high-concurrency scenarios through the read-write lock mechanism. The use of the read-write lock ensures the atomicity and consistency of the counter operation when generating and resetting the serial number, avoiding concurrent conflicts.

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

[0076] 3. Flexible numbering rule configuration: The embodiments of the present invention support 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 requirements. This flexibility enables the embodiments of the present invention to meet the needs of different business scenarios.

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

[0078] Device Embodiment 1

[0079] The embodiments of the present invention provide an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps described in the method embodiments are implemented.

[0080] Device Embodiment 2

[0081] The embodiments of the present invention provide a computer-readable storage medium, on which an implementation program for information transmission is stored. When the program is executed by a processor, the steps described in the method embodiments are implemented.

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

[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 them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for generating business document numbers in a PaaS platform based on a lock mechanism, characterized in that Including: S1: Determine whether the serial number counter in the PaaS platform needs to be reset, and select to execute step S2 or step S3 according to the judgment result; S2: Use the number model ID as the lock key and apply for a write lock based on the judgment result. Select to execute step S3 or re-execute step S1 according to the write lock acquisition result; S3: Use the number model ID as the lock key and apply for a read lock based on the judgment result. Generate the PaaS platform business document number according to the read lock acquisition result, or re-execute step S1.

2. The method according to claim 1, wherein The specific content of S1 includes: Compare the current time with the reset method and reset date in the number model to determine whether the serial number counter in the PaaS platform needs to be reset. If it needs to be reset, select to execute step S2; If it does not need to be reset, select to execute step S3.

3. The method according to claim 1, wherein The specific content of S2 includes: Use the number model ID as the lock key and apply for a write lock for the reset action. If the write lock is successfully acquired, reset the serial number counter according to the start number attribute value of the number model, update the reset date of the number model to the current date, release the write lock, and execute step S3; If the write lock acquisition fails, re-execute step S1; Among them, when applying for a write lock, it will wait for the release of all read locks on the current lock key.

4. The method according to claim 1, wherein The specific content of S3 includes: Use the number model ID as the lock key and apply for a read lock for the action of obtaining the serial number. If the read lock is successfully acquired, obtain the current value from the serial number counter and release the read lock, and generate the PaaS platform business document number according to the obtained serial number value and the number format in the number model; If the read lock acquisition fails, re-execute step S1; Among them, when applying for a read lock, if there is a write lock on the current lock key, the read lock application will wait for the write lock to be released.

5. A business document number generation system for a PaaS platform based on a lock mechanism, characterized in that Including: A judgment module for judging whether the serial number counter in the PaaS platform needs to be reset, and selecting to execute the write lock module or the read lock module according to the judgment result; A write lock module for using the number model ID as the lock key and applying for a write lock based on the judgment result, and selecting to execute the read lock module or re-execute the judgment module according to the write lock acquisition result; A read lock module for using the number model ID as the lock key and applying for a read lock based on the judgment result, generating the PaaS platform business document number according to the read lock acquisition result, or re-executing the judgment module.

6. The system according to claim 5, characterized in that, The judgment module is specifically used for: Compare the current time with the reset method and reset date in the number model to judge whether the serial number counter in the PaaS platform needs to be reset. If it needs to be reset, select to execute the write lock module; If it does not need to be reset, select to execute the read lock module.

7. The system according to claim 5, wherein The write lock module is specifically used for: Use the number model ID as the lock key and apply for a write lock for the reset action. If the write lock is successfully acquired, reset the serial number counter according to the start number attribute value of the number model, update the reset date of the number model to the current date, release the write lock, and execute the read lock module; If the write lock acquisition fails, re-execute the judgment module; Among them, when applying for a write lock, it will wait for the release of all read locks on the current lock key.

8. The system according to claim 5, wherein The read lock module is specifically used for: Use the numbered model ID as the lock key and apply for a read lock for the action of obtaining the serial number. If the read lock is successfully locked, obtain the current value from the serial number counter and release the read lock, and generate the PaaS platform business document number according to the obtained serial number value and the number format in the numbered model; If the read lock fails to be locked, re-execute the judgment module; Among them, when applying for a read lock, if there is a write lock on the current lock key, the read lock application will wait for the write lock to be released.

9. An electronic device, characterized in that, Include: A memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the method for generating the PaaS platform business document number based on the lock mechanism as described in any one of claims 1-4.

10. A computer-readable storage medium, characterized in that, An implementation program for information transmission is stored on the computer-readable storage medium. When the program is executed by the processor, it implements the steps of the method for generating the PaaS platform business document number based on the lock mechanism as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Serial number generating method and device

    CN104866601A

  • Data serial number generation method and system and electronic equipment

    CN112445800A

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

    CN113377427A

  • Distributed service number management system

    CN116226126A

  • Method for realizing configurable service order number generation based on MySQL

    CN116501749A