ID generation method, generator, computer equipment and readable storage medium

By using the combination of target timestamps, data center IDs and machine IDs to generate IDs in the cloud deployment environment, the problem of effective range compression of serial numbers caused by the increase in the number of working machine IDs generated by IP in the cloud environment is solved, continuity and accuracy in high concurrency scenarios are achieved, and the flexibility and reliability of the system are enhanced.

CN120128569APending Publication Date: 2025-06-10KANG JIAN INFORMATION TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510286091.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-11
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

In a cloud deployment environment, a new IP is generated every time a node restarts, causing the number of bits of the working machine ID generated through the IP to increase, thereby compressing the effective range of the serial number and reducing the availability of the snowflake algorithm.

Method used

By responding to the ID generation request, the target timestamp is determined based on the current time and the predefined initial timestamp, the service, module or business process that initiates the ID generation request is determined, the target working machine is queried, and the target working machine ID is determined based on the data center ID and machine ID. Then, compare the historical timestamp with the target timestamp, determine the sequence number generation rules based on the comparison results, and calculate the target sequence number, and finally determine the target ID based on the target timestamp, work machine ID and sequence number.

Benefits of technology

More machines can be supported without relying on IP, avoiding the problem of effective range compression of serial numbers caused by the increase in the number of ID digits generated by IP in the cloud environment, ensuring the continuity and accuracy of ID generation in high concurrency scenarios, and enhancing the flexibility and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120128569A_ABST
    Figure CN120128569A_ABST
Patent Text Reader

Abstract

The invention discloses an ID generation method, a generator, computer equipment and a readable storage medium. The method comprises the following steps: in response to an ID generation request, determining a target timestamp according to current time and a predefined initial timestamp; determining a target working machine, and determining a target working machine ID according to the data center ID to which the target working machine belongs and the machine ID associated with the target working machine; a historical ID generated last time is determined, a historical timestamp corresponding to the historical ID is compared with a target timestamp, a serial number generation rule is determined according to a comparison result, a historical serial number corresponding to the historical ID is calculated according to the serial number generation rule, and a target serial number is obtained; the target ID is determined according to the target timestamp, the target working machine ID and the target serial number, the method and the device are applied to a digital medical management system, the continuity and the accuracy of ID generation in a medical information high-concurrency scene can be ensured, and the flexibility and the reliability of the system are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the fields of data processing and medical health, and particularly to an ID generation method, a generator, a computer device, and a readable storage medium. Background Art

[0002] Medical cloud refers to a medical health service cloud platform created by using "cloud computing" on the basis of new technologies such as cloud computing, mobile technology, multimedia, 4G communication, big data, and the Internet of Things, combined with medical technology, realizing the sharing of medical resources and the expansion of the medical scope. Due to the application and combination of cloud computing technology, the medical cloud improves the efficiency of medical institutions and facilitates residents' medical treatment. For example, the current hospital appointment registration, electronic medical records, medical insurance, etc. are all the products of the combination of cloud computing and the medical field. The medical cloud also has the advantages of data security, information sharing, dynamic expansion, and global layout. With the rapid development of Internet technology and the wide application of the medical cloud, the demand for distributed systems in processing large-scale data and high-concurrent requests is increasing day by day. In this context, the global ID generation algorithm has become an indispensable part of the distributed system. The main purpose of the global ID generation algorithm is to generate unique and ordered IDs in the distributed system to meet the needs of medical data storage, query, and transaction processing, where medical data includes personal health records, prescriptions, and inspection reports, etc.

[0003] In the related art, the Snowflake Algorithm is a widely used global ID generation algorithm. The algorithm consists of a series of nodes, and each node is responsible for storing a part of the data. These nodes map the data to the specified location through a hash function, forming a distributed system similar to a snowflake structure. In this way, the Snowflake Algorithm can ensure the uniqueness and orderliness of IDs in the distributed system.

[0004] In the process of implementing the present application, the applicant found that the related art has at least the following problems:

[0005] In a cloud deployment environment, since each node generates a new IP every time it restarts, the number of bits of the working machine ID generated by the IP increases, thus greatly compressing the effective range of the serial number and reducing the usability of the Snowflake Algorithm. Summary of the Invention

[0006] In view of this, the present application provides an ID generation method, a generator, a computer device, and a readable storage medium, mainly aiming to solve the problem that in a cloud deployment environment, since each node generates a new IP every time it restarts, the number of bits of the working machine ID generated by the IP increases, thus greatly compressing the effective range of the serial number and reducing the usability of the Snowflake Algorithm.

[0007] According to the first aspect of the present application, a method for generating an ID is provided, the method comprising:

[0008] In response to the ID generation request, determining a target timestamp based on a current time and a predefined initial timestamp;

[0009] Determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine;

[0010] Determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine the sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number;

[0011] A target ID is determined according to the target timestamp, the target working machine ID and the target serial number.

[0012] According to a second aspect of the present application, an ID generator is provided, the ID generator comprising:

[0013] A first determination module, configured to determine a target timestamp according to a current time and a predefined initial timestamp in response to an ID generation request;

[0014] The second determination module is used to determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine;

[0015] A third determination module is used to determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine a sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain a target sequence number;

[0016] A generating module is used to determine a target ID according to the target timestamp, the target working machine ID and the target serial number.

[0017] According to a third aspect of the present application, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.

[0018] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.

[0019] By means of the above technical solution, the present application provides an ID generation method, a generator, a computer device and a readable storage medium. The present application first responds to the ID generation request and determines the target timestamp according to the current time and the predefined initial timestamp. Subsequently, the service, module or business process that initiates the ID generation request is determined, the target work machine for deploying the service, module or business process is queried, and the target work machine ID is determined according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine. Next, the historical ID generated last time is determined, the historical timestamp corresponding to the historical ID is compared with the target timestamp, the serial number generation rule is determined according to the comparison result, and the historical serial number corresponding to the historical ID is calculated according to the serial number generation rule to obtain the target serial number. Finally, the target ID is determined according to the target timestamp, the target work machine ID and the target serial number. By changing the work machine ID from IP-based allocation to a combination of data center ID and machine ID, the present technical solution can support more machines without relying on IP, and solves the problem of increasing the number of bits of the work machine ID generated by IP in the cloud environment, thereby compressing the effective range of the serial number. In addition, optimizing serial number allocation can ensure the continuity and accuracy of ID generation in high-concurrency scenarios, enhance the flexibility and reliability of the system, and make it suitable for large-scale medical data processing.

[0020] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0022] Figure 1 A schematic diagram of a method for generating an ID according to an embodiment of the present application is shown;

[0023] Figure 2 A schematic diagram of a method for generating an ID according to an embodiment of the present application is shown;

[0024] Figure 3Shows a schematic flowchart of an ID generation method provided by an embodiment of the present application;

[0025] Figure 4 Shows a schematic flowchart of an ID generation method provided by an embodiment of the present application;

[0026] Figure 5 Shows a schematic diagram of the ID structure of an ID generation method provided by an embodiment of the present application;

[0027] Figure 6 Shows a schematic diagram of the structure of an ID generator provided by an embodiment of the present application;

[0028] Figure 7 Shows a schematic diagram of the device structure of a computer device provided by an embodiment of the present application. Detailed implementation manners

[0029] Hereinafter, exemplary embodiments of the present application will be described in more detail with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present application can be more thoroughly understood and the scope of the present application can be completely conveyed to those skilled in the art.

[0030] In an embodiment of the present application, the ID generation method is applicable to an ID generator. An ID generator is a tool or system for generating unique identifiers (IDs) to ensure that each generated ID is unique within a specific range. An ID generation request is a request initiated by a service, module, or business process. For example, when a user uploads a medical record to a medical cloud for data storage on a digital medical platform, the data storage service needs to be invoked, and the digital medical platform will generate a corresponding ID generation request to generate a corresponding ID for the uploaded medical record and store it in the corresponding storage space.

[0031] In the field of digital medicine, services, modules, or business processes are important components of system functions, and they cooperate together to achieve medical informatization and digital management.

[0032] Among them, the function set provided by the service indication system usually corresponds to a certain business area of the system, such as patient services for managing patient information, appointment registration, medical records, etc.; doctor services for managing doctor schedules, diagnostic records, prescription issuing, etc. A module is a specific implementation unit of a service and a subdivision of the system function, such as a registration module, an electronic case module, a drug management module, etc. A business process refers to a series of steps defined to achieve a certain business goal, such as the registration process: "The patient submits a registration request - the system verifies the patient information - generates a registration form - confirms the successful registration"; the medical treatment process: "The patient arrives at the hospital - the system retrieves the patient information - the doctor makes a diagnosis - issues a prescription - the patient pays the fee - picks up the medicine."

[0033] An embodiment of this application provides an ID generation method, as Figure 1 shown, the method includes:

[0034] S10. In response to an ID generation request, determine a target timestamp according to the current time and a predefined initial timestamp.

[0035] In the field of digital healthcare, the ID generation process can be applied to scenarios such as electronic health records (EHRs), medical imaging data, remote monitoring device data, etc. For example, in an EHR system, each patient's medical record needs to have a unique ID to ensure data accuracy and traceability. Through a distributed ID generation scheme, a unique ID can be generated for each patient's medical visit record, examination result, treatment plan, etc., thus avoiding data confusion and duplication. Medical imaging data (such as X-ray films, CT scans, MRIs, etc.) needs to be uniquely identified for storage, retrieval, and analysis. Using this scheme, a unique ID containing a timestamp, a working machine ID (possibly a scanning device ID), and a serial number can be generated for each image, ensuring the uniqueness and integrity of the imaging data. In a drug management system, unique IDs need to be generated for each type of drug, each batch, and even each box of drugs. Through this scheme, the traceability and anti-counterfeiting of drugs can be ensured, while providing efficient data support in drug distribution and inventory management. In a hospital or clinic, patient identification is crucial. Through this scheme, a unique ID can be generated for each patient, which is used in various links such as registration, medical treatment, and drug pickup, thereby improving the efficiency and accuracy of medical services.

[0036] Among them, the ID generation request can be initiated by a certain module within the digital healthcare platform system (such as a registration module, a medical record management module, etc.) or by an external system (such as a patient-side APP). When the ID generator receives the ID generation request, it obtains the current time point through the system clock. This time point is usually expressed in seconds.

[0037] Further, to determine the reference point for time calculation, an initial timestamp is predefined in the embodiments of the present application. The initial timestamp is a fixed and preset time point, usually a specific date and time (such as January 1, 2020, 00:00:00). The target timestamp in seconds obtained by calculating the time difference between the current time and the initial timestamp is used to identify the specific time of ID generation during the ID generation process.

[0038] Specifically, as Figure 2 shown, through the following steps S11 to S13, when the ID generator receives an ID generation request, the system first obtains the current time information. Subsequently, the time information is compared and calculated with the predefined initial timestamp to determine a target timestamp. The target timestamp ensures that the generated ID is associated with time, thus ensuring the orderliness of the ID to a certain extent. The predefined initial timestamp as the reference for timestamp calculation is a fixed time point. By the difference between the current time and the initial timestamp, combined with other parameters, a 31-bit second-level target timestamp with uniqueness and time correlation can be generated.

[0039] Considering that increasing the precision of the timestamp mainly poses a risk of ID generation conflicts caused by the unchanged timestamp but reset sequence number after service restart. In the cloud deployment cluster, the time required for the service Pod from detecting a fault to executing the restart command, allocating a new Pod, to the successful start of the service must be more than 1 second, so there is no such risk. And in the original ID generation rule, 4096 sequence numbers can be generated in 1 millisecond, and 4 million sequence numbers can be generated in 1 second. In the cloud deployment architecture, such a business scenario no longer exists. The business is split into different services, and each service will allocate multiple Pod nodes according to the business volume. The optimized 16384 sequence numbers per second can already meet the needs of the current architecture. Therefore, the timestamp in the traditional Snowflake algorithm is optimized from millisecond-level precision to second-level precision, releasing 10 bits of space for other parts to use. In addition, by adding a custom initial timestamp in the embodiments of the present application, the available time range can be increased, thereby avoiding ID generation failure or duplication caused by timestamp overflow.

[0040] S11. Receive an ID generation request based on a preset interface.

[0041] In the embodiments of the present application, the ID generation request is initiated by a service, module, or business process based on a preset request method, which includes but is not limited to function calls and network requests. In a digital medical system, services, modules, and business processes are hierarchical manifestations of system functions. The ID generation request is usually triggered by a specific business process, and a request is sent to the ID generator through a module, and is ultimately used to identify and manage business data. This mechanism ensures that each business data item can be uniquely identified and traced, thereby improving the efficiency and accuracy of data processing. In addition, considering that the digital medical system involves sensitive information and medical records of patients, in this way, the system can better maintain data consistency and integrity, which is crucial for the digital medical system.

[0042] For example, in a digital medical system, a patient submits a registration request through an online registration module. The patient fills in registration information in the system, including name, ID number, department selection, appointment time, etc., and submits the registration form. After receiving the registration request submitted by the patient, the registration module needs to generate a unique registration ID for the registration request for subsequent tracking and management. At this time, the registration module sends an ID generation request to the ID generator through a preset interface (such as API call). The request may contain the following information: "Service identifier: registration service; module identifier: registration module; business process identifier: registration process". The ID generator receives the ID generation request through the preset interface. Subsequently, the ID generator combines steps S10 to S40 to form a unique registration ID and returns it to the registration module. The registration module binds the ID to the registration information and stores it in the database. The registration module generates a registration form for the patient based on the generated registration ID and notifies the patient that the registration is successful. The registration ID is used to identify and track the patient's registration information throughout the medical treatment process.

[0043] S12. In response to the ID generation request, determine the current time according to the system clock and convert the current time into the number of seconds since a predefined initial timestamp.

[0044] S13. Calculate the difference in seconds between the number of seconds and the number of seconds corresponding to the initial timestamp, and use the difference in seconds as the target timestamp.

[0045] In steps S12 to S13, when the ID generator receives an ID generation request, it will first determine the current time point based on the system clock. This time point can be a specific date and time, such as 12:00:00 on January 20, 2025. The ID generator will then convert this current time point into the number of seconds since a predefined initial timestamp. This conversion process involves converting the date and time into a continuous number of seconds starting from the initial timestamp. After completing the conversion of the current time point to seconds, the ID generator will then calculate the difference between this number of seconds and the number of seconds corresponding to the initial timestamp. This difference represents the number of seconds that have passed from the initial timestamp to the current time point. After calculating this difference in seconds, the ID generator will use this difference in seconds as the target timestamp.

[0046] For example, if the initial timestamp is 00:00:00 on January 1, 2020, then the total number of days from this initial timestamp to 12:00:00 on January 20, 2025 is 1846 days. Converting these 1846 days to seconds gives 160,022,400 seconds. Adding 12:00:00 on the same day, which is 43200 seconds, gives a total difference in seconds of 160,065,600 seconds. Finally, converting this difference in seconds to a 31-bit timestamp format gives the target timestamp. The precision of the target timestamp is at the second level, and the number of bits occupied is 31. In this way, the ID generator ensures the uniqueness and accuracy of the timestamp while maintaining consistency and traceability with the initial timestamp.

[0047] S20. Determine the service, module or business process that initiates the ID generation request, query the target work machine for deploying the service, module or business process, and determine the target work machine ID based on the data center ID to which the target work machine belongs and the machine ID associated with the target work machine.

[0048] In the embodiment of the present application, the target work machine is the actual operation carrier of the service. Each service instance is deployed on a specific work machine, which provides computing resources (such as CPU, memory, network, etc.) for the service to ensure that the service can run normally. The module is a component of the service, and the target work machine provides the operating environment for the module. The deployment and operation of the module depends on the resource allocation of the work machine.

[0049] For example, a service may consist of multiple modules, each of which may run on different working machines, or multiple modules may share a single working machine. A business process is completed through the collaboration of a series of services and modules, and the target working machine provides the basic environment for the operation of these services and modules. The efficient execution of a business process depends on the performance and stability of the working machine. Therefore, after determining the service, module, or business process that initiates the ID generation request, it is necessary to query the target working machine on which the service, module, or business process is deployed.

[0050] Furthermore, as Figure 3 shown, through the data center ID and the machine ID, the target working machine can be uniquely identified. In a distributed ID generator, the ID of each working machine is embedded in the generated ID to ensure global uniqueness. In the embodiments of the present application, the design of the working machine ID takes into account the current architecture requirements and differentiates between the data center ID and the machine ID. The data center ID is used to identify the physical or virtual data center where the working machine is located. The data center ID can help the system perform resource management and scheduling on a global scale, and can also optimize the network communication path.

[0051] The machine ID is used to uniquely identify each working machine within the data center. The data center ID supports 4 different values, while the working machine ID supports up to 65536 different values. To implement this architecture, the first two segments of the IP address range of the same data center are the same, which can ensure that the maximum number of IPs reaches 255 * 255 = 65536, so that each IP address can be correspondingly assigned a working machine ID.

[0052] S21. Determine the data center to which the target working machine belongs, obtain the data center ID corresponding to the data center, and the machine ID assigned to the target working machine within the data center.

[0053] After determining the target working machine, the next step is to determine the data center to which the target working machine belongs. In a distributed system, a data center is a physical or virtual resource pool for deploying and managing servers. Once the data center is determined, the corresponding data center ID and the machine ID assigned to the target working machine within the data center can be obtained. Determining the data center to which the target working machine belongs can determine the data center ID through the system's configuration file or environment variables, or can infer the data center ID through the IP address range or network topology. The machine ID can be generated through manual configuration, automatic allocation (such as based on the IP address or MAC address), dynamic allocation (such as through Redis), or a hash algorithm.

[0054] S22. Combine the data center ID and the machine ID to obtain the target working machine ID.

[0055] Combine the data center ID and the machine ID to finally obtain the target working machine ID. During the execution of steps S21 to S22, the ID generator will obtain the pre-allocated working machine ID from the configuration according to the information of the data center to which the machine where the current service is located belongs and the machine itself.

[0056] For example, if the current service is deployed on the 50th machine in data center 2, then according to the configuration information, the data center ID is 01 and the machine ID is 00000000110010 (represented in binary). Combining these two IDs forms the complete working machine ID of 0100000000110010.

[0057] S30. Determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine the serial number generation rule according to the comparison result, and calculate the historical serial number corresponding to the historical ID according to the serial number generation rule to obtain the target serial number.

[0058] In the embodiments of the present application, as Figure 4 shown, on the basis of the Snowflake algorithm, the dynamic adjustment of the serial number is added. By dynamically adjusting the serial number generation rule, conflicts can be effectively avoided while ensuring the generation efficiency. Specifically, the historical ID generated last time can be obtained in the memory. If the system restarts, the historical ID can be restored from the persistent storage (such as a database or a file), and then the corresponding historical timestamp and historical serial number can be obtained from the historical ID. Compare the historical timestamp with the target timestamp to determine whether the target timestamp of the current time is the same as the historical timestamp when the ID was generated last time. Through the comparison result, the next serial number generation rule can be determined. Once the rule is determined, the historical serial number corresponding to the historical ID can be calculated according to this rule, and finally the target serial number can be obtained. In the embodiments of the present application, the number of bits occupied by the serial number has been increased to 14 bits, so that the maximum number of serial numbers that can be generated reaches 16384.

[0059] S31. Compare the historical timestamp with the target timestamp to determine whether the target timestamp is the same as the historical timestamp.

[0060] Considering that each time the timestamp changes, the serial number is reset. Therefore, in the embodiment of this application, it is necessary to compare the historical timestamp corresponding to the previously generated historical ID with the target timestamp, and determine the generation rule of the next serial number according to whether the target timestamp is the same as the historical timestamp. That is to say, if the target timestamp is the same as the historical timestamp, it means that the current is still within the same second, and the following step S32 needs to be executed to continue incrementing the serial number. If the target timestamp is different from the historical timestamp, it means that the timestamp has changed, and the following step S33 needs to be executed to reset the serial number.

[0061] S32. If the comparison result indicates that the target timestamp is the same as the historical timestamp, determine the increment generation rule as the serial number generation rule.

[0062] In this step, if the comparison result indicates that the target timestamp is the same as the historical timestamp, determine the increment generation rule as the serial number generation rule. At this time, increment the historical serial number by one as the serial number to be generated, that is, add 1 to the historical serial number. For example, when the serial number was 100 when generating the ID last time, then the serial number is 101 when generating the ID this time.

[0063] Next, check whether the incremented serial number exceeds the serial number threshold, that is, compare the serial number to be generated with the serial number threshold 16384.

[0064] If the comparison result indicates that the serial number to be generated is less than or equal to the serial number threshold, it means that it has not exceeded, and at this time, the serial number to be generated is used as the target serial number.

[0065] If the comparison result indicates that the serial number to be generated is greater than the serial number threshold, it means that the number of IDs generated within the current timestamp has reached the upper limit, that is, the serial number within the current timestamp has been used up, and it is necessary to wait for the target timestamp of the next second, and use the re-generation rule as the serial number generation rule to calculate the historical serial number to obtain the target serial number.

[0066] S33. If the comparison result indicates that the target timestamp is different from the historical timestamp, determine the re-generation rule as the serial number generation rule.

[0067] In this step, when determining the regeneration rule as the serial number generation rule, the pre-configured sub-table parameters are determined. Calculate the modulo value of the historical serial number and the sub-table parameters, and increment the modulo value by one as the target serial number. For example, if there are 32 sub-tables, the modulo of the historical serial number in the previous second with respect to 32 is 31, and the new serial number starts from 32. The dynamic adjustment of the serial number can ensure the continuity of the sub-tables and avoid serial number conflicts caused by timestamp changes. The dynamic adjustment of the serial number is very practical in a distributed system, especially in scenarios where a large number of unique IDs need to be generated (such as database sub-tables, distributed caches, etc.). By dynamically adjusting the serial number generation rule, conflicts can be effectively avoided while ensuring the generation efficiency.

[0068] S40. Determine the target ID according to the target timestamp, the target working machine ID, and the target serial number.

[0069] In the embodiment of the present application, the target ID further includes a sign bit with an occupancy of 1 bit. The sign bit is the starting bit of the target ID and is fixed to a preset value of 0. This can ensure that the generated ID is a positive number and avoid potential problems caused by negative numbers. Finally, by combining the Snowflake algorithm, the combined sign bit, target timestamp, target working machine ID, and target serial number are embedded into the generated target ID to ensure global uniqueness. The structure of the target ID is as Figure 5 shown.

[0070] In addition, in a possible implementation manner, after generating the target ID, record the target serial number used at the target timestamp, store the target serial number in memory, and periodically persist the target serial number to the storage system so that the serial number can be restored after the service restarts and continue to generate IDs. In this way, medical institutions can generate unique IDs for various medical data and entities, thereby improving the efficiency and accuracy of medical services while ensuring the security and traceability of data.

[0071] The method provided by the embodiment of the present application first responds to the ID generation request and determines the target timestamp according to the current time and the predefined initial timestamp. Subsequently, the service, module or business process that initiates the ID generation request is determined, the target work machine for the deployment service, module or business process is queried, and the target work machine ID is determined according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine. Next, the historical ID generated last time is determined, the historical timestamp corresponding to the historical ID is compared with the target timestamp, the sequence number generation rule is determined according to the comparison result, and the historical sequence number corresponding to the historical ID is calculated according to the sequence number generation rule to obtain the target sequence number. Finally, the target ID is determined according to the target timestamp, the target work machine ID and the target sequence number. This technical solution changes the work machine ID from an IP-based allocation to a combination of a data center ID and a machine ID, and can support more machines without relying on IP, thereby solving the problem of increasing the number of digits of the work machine ID generated by IP in a cloud environment, thereby compressing the effective range of the sequence number. In addition, optimizing the sequence number allocation can ensure the continuity and accuracy of ID generation in high-concurrency scenarios, enhance the flexibility and reliability of the system, and is suitable for large-scale medical data processing.

[0072] Further, as Figure 1 In the specific implementation of the method, the present application embodiment provides an ID generator, such as Figure 6 As shown, the device includes: a first determination module 601, a second determination module 602, a third determination module 603, and a generation module 604.

[0073] A first determination module 601 is used to determine a target timestamp according to a current time and a predefined initial timestamp in response to an ID generation request;

[0074] The second determination module 602 is used to determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine;

[0075] The third determination module 603 is used to determine the history ID generated last time, compare the history timestamp corresponding to the history ID with the target timestamp, determine the sequence number generation rule according to the comparison result, and calculate the history sequence number corresponding to the history ID according to the sequence number generation rule to obtain the target sequence number;

[0076] The generating module 604 is used to determine the target ID according to the target timestamp, the target working machine ID and the target serial number.

[0077] In a specific application scenario, a first determination module 601 is configured to receive the ID generation request based on a preset interface. The ID generation request is initiated by the service, module, or business process based on a preset request method, and the preset request method includes, but is not limited to, function calls and network requests. In response to the ID generation request, determine the current time according to the system clock, and convert the current time into the number of seconds since a predefined initial timestamp. Calculate the difference in seconds between the number of seconds and the number of seconds corresponding to the initial timestamp, and use the difference in seconds as the target timestamp. The precision of the target timestamp is at the second level, and the number of bits occupied is 31 bits.

[0078] In a specific application scenario, a second determination module 602 is configured to determine the data center to which the target working machine belongs, obtain the data center ID corresponding to the data center, and the machine ID assigned to the target working machine within the data center. Combine the data center ID and the machine ID to obtain the target working machine ID. Among them, the machine ID of each machine in each data center is sequentially assigned according to the total number of machines in the corresponding data center. The number of bits occupied by the data center ID is 2 bits, and the number of bits occupied by the machine ID is 16 bits.

[0079] In a specific application scenario, a third determination module 603 is configured to compare the historical timestamp with the target timestamp to determine whether the target timestamp is the same as the historical timestamp. If the comparison result indicates that the target timestamp is the same as the historical timestamp, determine the increment generation rule as the serial number generation rule. If the comparison result indicates that the target timestamp is different from the historical timestamp, determine the regeneration rule as the serial number generation rule.

[0080] In a specific application scenario, when the third determination module 603 determines the increment generation rule as the serial number generation rule, increment the historical serial number by one as the serial number to be generated, and compare the serial number to be generated with the serial number threshold. If the comparison result indicates that the serial number to be generated is less than or equal to the serial number threshold, use the serial number to be generated as the target serial number. If the comparison result indicates that the serial number to be generated is greater than the serial number threshold, wait for the target timestamp of the next second, and use the regeneration rule as the serial number generation rule to calculate the historical serial number to obtain the target serial number. The number of bits occupied by the target serial number is 14 bits.

[0081] In a specific application scenario, the third determination module 603 is used to determine the pre-configured table partitioning parameters when determining the regeneration rule as the serial number generation rule; calculate the modulus value of the historical serial number and the table partitioning parameter, and increment one bit on the basis of the modulus value as the target serial number, and the target serial number occupies 14 bits.

[0082] In a specific application scenario, the generator also includes: a storage module 605.

[0083] The generating module 604 is used to determine a sign bit with a bit number of 1, and combine the sign bit, the target timestamp, the target working machine ID and the target sequence number to obtain the target ID, wherein the sign bit is the starting bit of the target ID and is fixed to a preset value;

[0084] The storage module 605 is used to record the target sequence number used under the target timestamp after generating the target ID, store the target sequence number in the memory, and regularly persist the target sequence number to the storage system so that the sequence number can be restored after the service is restarted and the ID can continue to be generated.

[0085] The device provided in the embodiment of the present application first responds to the ID generation request and determines the target timestamp according to the current time and the predefined initial timestamp. Subsequently, the service, module or business process that initiates the ID generation request is determined, the target work machine for deploying the service, module or business process is queried, and the target work machine ID is determined according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine. Next, the historical ID generated last time is determined, the historical timestamp corresponding to the historical ID is compared with the target timestamp, the sequence number generation rule is determined according to the comparison result, and the historical sequence number corresponding to the historical ID is calculated according to the sequence number generation rule to obtain the target sequence number. Finally, the target ID is determined according to the target timestamp, the target work machine ID and the target sequence number. This technical solution changes the work machine ID from an IP-based allocation to a combination of a data center ID and a machine ID, and can support more machines without relying on IP, thereby solving the problem of increasing the number of digits of the work machine ID generated by IP in a cloud environment, thereby compressing the effective range of the sequence number. In addition, optimizing the sequence number allocation can ensure the continuity and accuracy of ID generation in high-concurrency scenarios, enhance the flexibility and reliability of the system, and is suitable for large-scale medical data processing.

[0086] It should be noted that for other corresponding descriptions of the functional units involved in the ID generator provided in the embodiment of the present application, please refer to Figures 1 to 5 The corresponding description in will not be repeated here.

[0087] In addition, in one embodiment, the present application provides a computer device, which may be a server, and its internal structure diagram may be as shown in Figure 7 Figure 1. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. When the computer program is executed by the processor, the method described in any of the above embodiments can be implemented.

[0088] In one embodiment, the present application further provides a computer device, which may be a client. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, the method described in any of the above embodiments can be implemented.

[0089] Any of the above computer devices in the embodiments of the present application exists in various forms, including but not limited to:

[0090] (1) Mobile communication devices: The characteristic of such devices is that they have mobile communication functions and mainly aim to provide voice and data communication. Such terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones, etc.

[0091] (2) Ultra-mobile personal computer devices: Such devices belong to the category of personal computers, have computing and processing functions, and generally also have the characteristic of mobile Internet access. Such terminals include: PDAs, MIDs, and UMPC devices, etc., such as iPad.

[0092] (3) Portable entertainment devices: Such devices can display and play multimedia content. Such devices include: audio and video players (such as iPod), handheld game consoles, e-books, and smart toys, wearable devices, and portable in-vehicle navigation devices.

[0093] (4) Server: A device that provides computing services. The server consists of a processor, hard disk, memory, system bus, etc. The server is similar to a general computer architecture, but because it needs to provide highly reliable services, it has higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.

[0094] (5) Other electronic devices with data interaction functions.

[0095] In addition, an embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to perform the following steps:

[0096] In response to the ID generation request, determining a target timestamp based on a current time and a predefined initial timestamp;

[0097] Determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine;

[0098] Determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine the sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number;

[0099] A target ID is determined according to the target timestamp, the target working machine ID and the target serial number.

[0100] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant description in the aforementioned method embodiment. In order to avoid repetition, they will not be described one by one here.

[0101] The technical solution of the present application is described in detail above in conjunction with the accompanying drawings. Through the technical solution of the present application, first respond to the ID generation request and determine the target timestamp according to the current time and the predefined initial timestamp. Subsequently, determine the service, module or business process that initiates the ID generation request, query the target work machine for the deployment service, module or business process, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine. Next, determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine the sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number. Finally, determine the target ID according to the target timestamp, the target work machine ID and the target sequence number. This technical solution changes the work machine ID from IP-based allocation to a combination of data center ID and machine ID, and can support more machines without relying on IP, solving the problem of increasing the number of bits of the work machine ID generated by IP in the cloud environment, thereby compressing the effective range of the sequence number. In addition, optimizing the sequence number allocation can ensure the continuity and accuracy of ID generation in high-concurrency scenarios, enhance the flexibility and reliability of the system, and is suitable for large-scale medical data processing.

[0102] It should be understood that although the terms first, second, etc. may be used to describe execution units in the embodiments of the present application, these execution units should not be limited to these terms. These terms are only used to distinguish execution units from each other. For example, without departing from the scope of the embodiments of the present application, the first execution unit may also be referred to as the second execution unit, and similarly, the second execution unit may also be referred to as the first execution unit.

[0103] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.

[0104] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.

[0105] In several embodiments provided in the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.

[0106] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of a combination of hardware and software functional units.

[0107] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to the memory, storage, database, or other media used in each embodiment provided in the present application can include non-volatile and / or volatile memories. Non-volatile memories can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memories can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0108] The above-described 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 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 of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A method for generating an ID, characterized in that: The method is applicable to an ID generator, comprising: In response to the ID generation request, determining a target timestamp based on a current time and a predefined initial timestamp; Determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine; Determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine the sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number; A target ID is determined according to the target timestamp, the target working machine ID and the target serial number.

2. The method according to claim 1, characterized in that The step of responding to the ID generation request and determining the target timestamp according to the current time and the predefined initial timestamp includes: Receiving the ID generation request based on a preset interface, where the ID generation request is initiated by the service, module or business process based on a preset request method, where the preset request method includes but is not limited to a function call and a network request; In response to the ID generation request, determine the current time according to the system clock and convert the current time into the number of seconds since the predefined initial timestamp; The difference in seconds between the number of seconds and the number of seconds corresponding to the initial timestamp is calculated, and the difference in seconds is used as the target timestamp. The accuracy of the target timestamp is at the second level, and the number of bits occupied is 31 bits.

3. The method according to claim 1, characterized in that The step of determining the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine includes: Determine the data center to which the target work machine belongs, obtain the data center ID corresponding to the data center, and the machine ID assigned to the target work machine in the data center; Combine the data center ID and the machine ID to obtain the target working machine ID; The machine ID of each machine in each data center is allocated in sequence according to the total number of machines in the corresponding data center. The number of bits occupied by the data center ID is 2 bits, and the number of bits occupied by the machine ID is 16 bits.

4. The method according to claim 1, characterized in that The comparing the historical timestamp corresponding to the historical ID with the target timestamp and determining the sequence number generation rule according to the comparison result includes: Compare the historical timestamp with the target timestamp to determine whether the target timestamp is the same as the historical timestamp; If the comparison result indicates that the target timestamp is the same as the historical timestamp, determining the growth generation rule as the sequence number generation rule; If the comparison result indicates that the target timestamp is different from the historical timestamp, a regeneration rule is determined as the sequence number generation rule.

5. The method according to claim 4, characterized in that The calculating the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number includes: When the increasing generation rule is determined as the sequence number generation rule, one digit is incremented on the basis of the historical sequence number as the sequence number to be generated, and the sequence number to be generated is compared with the sequence number threshold; If the comparison result indicates that the sequence number to be generated is less than or equal to the sequence number threshold, the sequence number to be generated is used as the target sequence number; If the comparison result indicates that the sequence number to be generated is greater than the sequence number threshold, wait for the target timestamp of the next second, use the regeneration rule as the sequence number generation rule to calculate the historical sequence number, and obtain the target sequence number, which occupies 14 bits.

6. The method according to claim 5, characterized in that The calculating the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain the target sequence number includes: When determining the regeneration rule as the sequence number generation rule, determining the pre-configured table partitioning parameters; The modulus value of the historical sequence number and the partition table parameter is calculated, and one bit is incremented based on the modulus value as the target sequence number, and the target sequence number occupies 14 bits.

7. The method according to claim 1, characterized in that The determining the target ID according to the target timestamp, the target working machine ID and the target serial number includes: Determine a sign bit whose occupied bit number is 1, combine the sign bit, the target timestamp, the target working machine ID and the target serial number to obtain the target ID, wherein the sign bit is the starting bit of the target ID and is fixed to a preset value; After the target ID is generated, the target sequence number used under the target timestamp is recorded, the target sequence number is stored in the memory, and the target sequence number is periodically persisted to the storage system so that the sequence number can be restored after the service is restarted and the ID can continue to be generated.

8. An ID generator, characterized in that: include: A first determination module, configured to determine a target timestamp according to a current time and a predefined initial timestamp in response to an ID generation request; The second determination module is used to determine the service, module or business process that initiates the ID generation request, query the target work machine where the service, module or business process is deployed, and determine the target work machine ID according to the data center ID to which the target work machine belongs and the machine ID associated with the target work machine; A third determination module is used to determine the historical ID generated last time, compare the historical timestamp corresponding to the historical ID with the target timestamp, determine a sequence number generation rule according to the comparison result, and calculate the historical sequence number corresponding to the historical ID according to the sequence number generation rule to obtain a target sequence number; A generating module is used to determine a target ID according to the target timestamp, the target working machine ID and the target serial number.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.