A sequence number generation method and related apparatus
By generating serial numbers using a preset group identifier model and serial number template, the problem of cumbersome format adjustment in traditional methods is solved, and flexible adaptation of serial number formats and ease of operation are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-05
AI Technical Summary
Traditional serial number generation methods cannot flexibly adjust the format, which requires modifying business code when business scenarios change. This is cumbersome and cannot meet personalized format requirements.
It adopts a preset group identifier model and a preset serial number template, and generates serial numbers by replacing placeholders. It is independent of business code, allows for flexible adjustment of the format, and does not require modification of business code.
It achieves flexible adaptation of serial number format, simplifies the operation process, adapts to the personalized needs of different business scenarios, and avoids the generation of duplicate serial numbers.
Smart Images

Figure CN122152297A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer application technology, and in particular to a serial number generation method and related apparatus. Background Technology
[0002] In the development of business systems, serial number generation is a core technical requirement to ensure the uniqueness and traceability of business data, and it is widely used in scenarios such as work order management, order flow, and data identification. Traditional serial number generation methods include: obtaining a serial number generation request; obtaining the current serial number value of a counter; obtaining a serial number containing the current serial number value; and updating the current serial number value of the counter after generating the serial number.
[0003] Traditional serial number generation methods are deployed within business code, resulting in serial numbers with a fixed format. If the serial number format needs modification, such as changing fields representing business scenarios or adding business department parameters, the business code must be modified, recompiled, and redeployed, leading to cumbersome operations.
[0004] Therefore, there is an urgent need for a serial number generation method that can adapt to the personalized format requirements of different business scenarios and is easy to operate. Summary of the Invention
[0005] In view of the above problems, this application provides a serial number generation method and related apparatus to achieve a serial number generation method that can adapt to the personalized format requirements of different business scenarios and is easy to operate. The specific solution is as follows:
[0006] The first aspect of this application provides a serial number generation method, including:
[0007] Obtain the target grouping parameters;
[0008] Call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes a group placeholder and a first fixed identifier field that represents the business scenario.
[0009] Replace the group placeholder in the preset group identifier template with the target group parameter to obtain the target classification identifier;
[0010] Retrieve the current sequence value of the counter bound to the target classification identifier;
[0011] Call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario.
[0012] Replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
[0013] In one possible implementation, after the step of retrieving the current sequence value of the counter bound to the target classification identifier, and before calling the preset sequence number template corresponding to the target group, the method further includes:
[0014] The current sequence value of the counter corresponding to the target classification identifier is incremented.
[0015] In one possible implementation, the step of calling the preset group identifier model corresponding to the target group parameter includes:
[0016] Find the preset group identifier template corresponding to the target group parameter from the preset correspondence between preset group parameters and preset group identifier templates.
[0017] In one possible implementation, the step of invoking the preset sequence number template corresponding to the target group includes:
[0018] Find the preset serial number template corresponding to the preset target grouping parameter from the preset correspondence between the target grouping parameter and the preset serial number template.
[0019] In one possible implementation, the preset group identifier template includes a first preset function name, and the step of calling the preset group identifier model corresponding to the target group parameter further includes:
[0020] Call the first function that has the first preset function name;
[0021] Replace the name of the first preset function in the preset group identifier template with the return value of the first function.
[0022] In one possible implementation, the preset serial number template includes a second preset function name, and the step of calling the preset serial number template corresponding to the target group further includes:
[0023] Call the second function that has the second preset function name;
[0024] Replace the name of the second preset function in the preset serial number template with the return value of the second function.
[0025] One possible implementation also includes:
[0026] In response to the operation of updating the preset group identifier template, the preset group identifier template is updated. The operation of updating the preset group identifier template includes at least one of adding the first preset function name, deleting the first preset function name, changing the first preset function name, adding the first fixed identifier field, deleting the first fixed identifier field, and changing the first fixed identifier field.
[0027] One possible implementation also includes:
[0028] In response to the operation of updating the preset serial number template, the preset serial number template is updated. The operation of updating the preset serial number template includes at least one of adding the second preset function name, deleting the second preset function name, changing the second preset function name, adding the second fixed identifier field, deleting the second fixed identifier field, and changing the second fixed identifier field.
[0029] A second aspect of this application provides a serial number generation apparatus, comprising:
[0030] The first acquisition module is used to acquire target group parameters;
[0031] The first calling module is used to call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes the group placeholder and a first fixed identifier field representing the business scenario.
[0032] The first replacement module is used to replace the group placeholder in the preset group identifier template with the target grouping parameter to obtain the target classification identifier;
[0033] The second acquisition module is used to retrieve the current sequence value of the counter bound to the target classification identifier;
[0034] The second calling module is used to call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario.
[0035] The second replacement module is used to replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
[0036] A third aspect of this application provides a computer program product including computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the serial number generation method of the first aspect or any implementation thereof.
[0037] A fourth aspect of this application provides an electronic device, including at least one processor and a memory connected to the processor, wherein:
[0038] The memory is used to store computer programs;
[0039] The processor is used to execute the computer program so that the electronic device can implement the serial number generation method of the first aspect or any implementation thereof.
[0040] The fifth aspect of this application provides a computer storage medium carrying one or more computer programs, which, when executed by an electronic device, enable the electronic device to perform the serial number generation method described in the first aspect or any implementation thereof.
[0041] By employing the above technical solution, this application provides a serial number generation method. The serial number format involved in this application includes a preset group identifier model and a preset serial number template. Furthermore, the preset group identifier model and preset serial number template are decoupled from the business code. If the serial number format needs to be changed based on a business scenario, only the preset group identifier model and preset serial number template need to be modified, without changing the business code or recompiling and deploying, greatly simplifying the serial number format adjustment process. This application can flexibly adapt to the personalized needs of different business scenarios for serial number formats. The method for generating serial numbers using the preset group identifier model and preset serial number template is as follows: After obtaining the target group parameters, the preset group identifier model and preset serial number template can be called; the target group parameters replace the group placeholders in the preset group identifier template to obtain the target category identifier; the current sequence value replaces the sequence value placeholders in the preset serial number template to obtain the serial number. Attached Figure Description
[0042] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0043] Figure 1 A schematic diagram of a system architecture is provided for this application;
[0044] Figure 2 A flowchart illustrating a serial number generation method provided in an embodiment of this application;
[0045] Figure 3 This is a schematic diagram of the structure of a serial number generation device provided in an embodiment of this application;
[0046] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0047] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0048] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0049] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0050] The serial number generation method of this application can be widely applied to various business fields that require the generation of unique and traceable serial numbers, especially suitable for systems with multiple business scenarios, multi-department collaboration, and frequent changes in format requirements. Specifically, it includes, but is not limited to: internet service fields (such as work order management, user operation logs, system data identifiers, unique identifiers for API (Application Programming Interface) requests, etc.), enterprise management system fields (such as OA office approvals, expense reports, contract numbers, etc.), e-commerce and logistics fields (such as order numbers, logistics waybill numbers, package tracking numbers, after-sales rights protection numbers, etc.), financial payment fields (such as transaction serial numbers, transfer slip numbers, payment order numbers, refund slip numbers, etc.), government and public service fields (such as business acceptance numbers, certificate processing numbers, petition work order numbers, government approval numbers, etc.), healthcare fields (such as medical visit numbers, examination report numbers, drug traceability numbers, unique medical record identifiers, etc.), and industrial manufacturing fields (such as production work order numbers, equipment asset numbers, component traceability numbers, quality inspection report numbers, etc.).
[0051] Traditional serial number generation methods mainly include three categories: hard-coding methods, database auto-incrementing ID methods, and UUID (Universally Unique Identifier) methods. However, their implementation logic has inherent flaws, making it impossible to simultaneously meet the diverse business needs of enterprises, as detailed below:
[0052] The hard-coding method involves directly writing the fixed generation rules for serial numbers into the business code. For example, a fixed generation rule can be set according to the current business scenario requirements, such as business prefix + fixed-length number + department identifier + date + sequence number. When a serial number needs to be generated, the above business code can be called to generate the serial number. If it is necessary to adapt to new business scenarios, such as adding a department identifier or adjusting the date precision, the fixed generation rules in the business code need to be modified, and the code needs to be recompiled, tested, and then deployed online.
[0053] In hard-coded methods, the fixed generation rules are tightly coupled with the business code. The fixed generation rules are fixed and cannot be dynamically adjusted. When adding new business scenarios or adjusting the format, the business code must be modified, which cannot quickly respond to business needs.
[0054] The specific process of the database auto-increment ID method is as follows: Set a primary key field in the business data table and configure the field as an auto-increment attribute; when a serial number needs to be generated, send a data insertion request to the database, and the database will automatically assign a unique incrementing value to the auto-increment primary key; after the insertion operation is successful, use the auto-increment primary key value returned by the database directly as the serial number.
[0055] The database-driven auto-incrementing ID generation logic is dominated by the database and can only generate pure numeric sequences. It cannot contain key information such as business prefixes and timestamps that represent business scenarios, resulting in serial numbers lacking business semantics and failing to meet business traceability requirements (such as the inability to quickly identify the department or generation date through the serial number).
[0056] The UUID method generates a globally unique string as a serial number by calling the system's underlying random number generation interface. For example, it generates a 32-bit or 16-bit random string (such as 1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed) by combining the logic of "timestamp + machine MAC (Media Access Control Address) address + random number". The generated UUID string is then used as the serial number.
[0057] UUID serial numbers are fixed-length random strings that cannot be customized, such as adding business prefixes, adjusting length, or adding timestamps. They also lack any business semantics, making it impossible to identify key information such as business scenarios through serial numbers, which is not conducive to business traceability and problem troubleshooting.
[0058] The three traditional methods mentioned above all have significant technical shortcomings: hard-coding methods, UUID methods, and database auto-incrementing ID schemes cannot meet the requirements for format flexibility and may generate duplicate serial numbers. Therefore, there is an urgent need for a serial number generation method that balances configuration flexibility and ease of maintenance to address the pain points of existing technologies.
[0059] Based on this, this application provides a serial number generation method. The serial number format involved in this application includes a preset group identifier model and a preset serial number template. Furthermore, the preset group identifier model and preset serial number template are decoupled from the business code. If the serial number format needs to be changed based on the business scenario, only the preset group identifier model and preset serial number template need to be changed; there is no need to change the business code or recompile and deploy, greatly simplifying the serial number format adjustment process. This application can flexibly adapt to the personalized needs of different business scenarios for serial number formats.
[0060] In existing technologies, the current sequence value of the counter is incremented only after the sequence number is generated, which easily leads to multiple duplicate sequence numbers. This application increments the current sequence value of the counter after obtaining it, but before generating the sequence number, thus preventing duplicate sequence numbers.
[0061] This application can be applied, but is not limited to, to applications with serial number generation capabilities or cloud services provided by cloud-side servers, which will be described in detail below:
[0062] See Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 can provide the methods provided in the embodiments of this application to one or more terminals.
[0063] The terminal 100 may have an application related to serial number generation installed. The application and webpage can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the serial number generation configuration interface and send the parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.
[0064] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters on its own, without the need for the server to cooperate. This application embodiment is not limited to this.
[0065] The following description Figure 1 The product form of the mid-terminal 100;
[0066] The terminal 100 in this application embodiment can be a mobile phone, tablet computer, wearable device, vehicle device, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc., and this application embodiment does not impose any restrictions on it.
[0067] Terminal 100 may include a radio frequency unit, memory, input unit, display unit, camera (optional), audio circuitry (optional), speaker (optional), microphone (optional), headphone jack (optional), processor, external interface, power supply, and other components. Those skilled in the art will understand that the above-mentioned components are merely examples and do not constitute a limitation on the terminal or multifunctional device; it may include more or fewer components, or a combination of certain components, or different components.
[0068] The input unit can be used to receive input numeric or character information, and to generate key signal inputs related to user settings and function control of the portable multi-functional device. Specifically, the input unit may include a touchscreen (optional) and / or other input devices. Other input devices may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.
[0069] Among them, the input device can receive input data, etc.
[0070] The display unit can be used to display information input by the user or information provided to the user, various menus of the terminal, interactive interfaces, file display, and / or playback of any multimedia file. In the embodiments of this application, the display unit can be used to display the serial number generation configuration, the serial number result viewing interface, processing results, etc.
[0071] The memory can be used to store software code related to the serial number generation method, the processor can execute the steps of the serial number generation method, and can also schedule other units (such as the above-mentioned input unit and display unit) to achieve the corresponding functions.
[0072] This radio frequency unit (optional) can be used to receive and send signals during information transmission or calls.
[0073] In this embodiment of the application, the radio frequency unit can send data to the server 200 and receive the processing results sent by the server 200.
[0074] It should be understood that this radio frequency unit is optional and can be replaced with other communication interfaces, such as a network port.
[0075] Terminal 100 also includes a power source (such as a battery) for supplying power to the various components.
[0076] Terminal 100 also includes an external interface, which can be a standard Micro USB interface or a multi-pin connector, which can be used to connect terminal 100 to other devices for communication or to connect a charger to charge terminal 100.
[0077] Server 200 includes a bus, a processor, a communication interface, and memory. The processor, memory, and communication interface communicate with each other via the bus.
[0078] The memory can be used to store software code related to the serial number generation method, the processor can execute the steps of the chip's serial number generation method, and can also schedule other units to achieve the corresponding functions.
[0079] Reference Figure 2 , Figure 2 This is a flowchart illustrating a serial number generation method provided in an embodiment of this application, as shown below. Figure 2 As shown in the embodiment of this application, a serial number generation method may include steps S201 to S206, which are described in detail below.
[0080] Step S201: Obtain the target grouping parameters.
[0081] Target grouping parameters refer to a set of dynamic parameters that match the business scenario and are used to distinguish different counting groups. They are the key to achieving "independent counting within the same business scenario" and can include parameters that represent dimensions such as business department, business time, and business process.
[0082] The target grouping parameters serve as the dynamic input basis for sequence number generation. Obtaining the core parameters used to segment business scenarios and achieve group isolation counting is a prerequisite for generating unique target classification identifiers.
[0083] The following explanation uses the work order management business scenario as an example.
[0084] In the work order management business scenario, the target grouping parameter for the fault work order of the technical department on May 20, 2024 can be {Dept: "TECH", Date: "20240520"}, where Dept is the business department parameter and Date is the business date parameter; the target grouping parameter for the repair work order of the after-sales department on the same day can be {Dept: "SALE", Date: "20240520"}.
[0085] For example, the target grouping parameters can be obtained through the configuration interface or the business system interface, such as when the user enters "Technical Department, 20240520" in the serial number generation configuration interface of the terminal.
[0086] Step S202: Call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes a group placeholder and a first fixed identifier field representing the business scenario.
[0087] The preset group identifier model refers to a standardized format template that matches the business scenario. It is the format basis for generating target classification identifiers and is stored independently of business code (such as configuration files or database configuration tables).
[0088] For example, the number of group placeholders can be one or more.
[0089] For example, the target grouping parameters contain the same number of parameters as the grouping placeholders.
[0090] For example, group placeholders are standardized symbols in a preset group identifier template used to dynamically replace target group parameters, and they match the key names of the target group parameters one by one. For example, the number and position of group placeholders in the preset group identifier template can be flexibly adjusted according to the template configuration.
[0091] For example, the first fixed identifier field refers to a static string in the preset group identifier template that cannot be dynamically replaced. It is used to represent business scenarios and is the basis for distinguishing different business scenario group identifiers. The content of the first fixed identifier field can be configured as needed (such as modifying characters or increasing or decreasing length). Only the preset group identifier template needs to be adjusted, without modifying the business code.
[0092] The following example illustrates the preset group identifier template. The preset group identifier template is serialId. The serialId is WORK_ORDER_{{.department}}_{{formatTime \"20060102\"}}.
[0093] Here, "WORK_ORDER" is the first fixed identifier field; {.department} is the group placeholder; and {formatTime \"20060102\"} is the first function.
[0094] The first function, formatTime, is defined as follows: formatTime: func(format string)string {return time.Now().Format(format)}.
[0095] After calling the preset group identifier model corresponding to the target group parameter, the first function in the preset group identifier model can get a return value, such as the return value of formatTime being 20240520.
[0096] Step S203: Replace the group placeholder in the preset group identifier template with the target grouping parameter to obtain the target classification identifier.
[0097] Assuming the target group parameter is {Dept: "TECH"}, after replacing the preset group identifier template, we can obtain WORK_TECH_20240520.
[0098] Step S204: Retrieve the current sequence value of the counter bound to the target classification identifier.
[0099] The current sequence value refers to the numeric value currently stored in the counter that has not yet been incremented. It is the core numerical part of the sequence number in the corresponding business scenario. The current sequence value of the counter increments with each generation of the sequence number and can only be modified through atomic system operations to ensure uniqueness. For example, if the technical department has generated 41 work orders with the code 20240520, and the current sequence value of the counter bound to the target category identifier WORK_TECH_20240520 is 42, it means that the sequence value of this work order is 42.
[0100] For example, the correspondence between the target classification identifier and the current sequence value of the counter can be stored in a table or a structure. The following explanation uses a structure as an example.
[0101] type SerialCounter struct {
[0102] ID string / / Target category identifier
[0103] CurrentSeq int64 / / Current sequence value}.
[0104] Among them, SerialCounter is bound to a counter.
[0105] A counter is a counting unit that is pre-deployed in a database or cache and uniquely bound to a target category identifier. It is used to record the number of times a sequence number is generated in the corresponding business scenario. It only performs an increment operation on the bound target category identifier. Counters for different target category identifiers are independent of each other and do not interfere with each other.
[0106] The creation of counters can be done automatically by the system. For example, when a target classification identifier is generated for the first time, the system automatically creates and initializes the counters bound to it.
[0107] Step S205: Call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario.
[0108] The preset serial number template refers to a standardized format template that is pre-configured and matches the business scenario. It is the format basis for generating the final serial number and is stored independently of the business code. Modifying the preset serial number template does not require compiling or deploying the business code.
[0109] Sequence value placeholders are standardized symbols in the preset sequence number template used to dynamically replace the current sequence value of the counter. They are the core dynamic replacement entry point in the preset sequence number template and match the current sequence value of the counter one-to-one. The formatting rules for the sequence value placeholders can be configured (such as padding numbers with zeros on the left or specifying a length). Adjusting the rules only requires modifying the preset sequence number template.
[0110] Assume the preset sequence number template is WO{{Date}}{{Sequence}}, where {{Sequence}} is a sequence value placeholder used to replace the current sequence value of the counter; if the left padding rule is configured, it can be written as {{leftPad Sequence5}}, which means that the sequence value will be padded with 5 digits.
[0111] Among them, leftPad: func(num int64, length float64) string {
[0112] return utils.LeftPad(strconv.FormatInt(num, 10), int(length),'0')}
[0113] The second fixed identifier field refers to a static string in the preset serial number template that cannot be dynamically replaced. It is used to represent the business scenario and is the business identifier entry point for the final serial number, making it easy for manual identification of the business scenario to which the serial number belongs.
[0114] The second fixed identifier field can be configured as needed and can be reused with the first fixed identifier field. For example, both can be WORK or simplified versions of the work order. For instance, if the first fixed identifier of the work order is WORK, the second fixed identifier can be the abbreviation WO. To modify it, simply adjust the preset serial number template.
[0115] For example, in the preset serial number template WO{{Date}}{{Sequence}}, WO is the second fixed identifier field.
[0116] Step S206: Replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
[0117] The serial number is a unique string generated after the current serial value replaces the serial value placeholder in the preset serial number template.
[0118] For example, the preset serial number template also includes a second function.
[0119] Assuming the preset serial number template `serialNumber` is: `WO{{formatTime \"20060102\"}}{{leftPad .serialSeq 5}}`, then `leftPad .serialSeq 5` is the second function. During the process of calling the preset serial number template, the second function is called, resulting in 00042 (assuming the current serial value is 42). Replacing the placeholder serial value in the preset serial number template with the current serial value 42 yields the serial number `WO2023120100042`.
[0120] This application provides a serial number generation method. The serial number format involved in this application includes a preset group identifier model and a preset serial number template. Furthermore, the preset group identifier model and preset serial number template are decoupled from business code. If the serial number format needs to be changed based on a business scenario, only the preset group identifier model and preset serial number template need to be modified, without changing the business code or recompiling and deploying, greatly simplifying the serial number format adjustment process. This application can flexibly adapt to the personalized needs of different business scenarios for serial number formats. The method for generating serial numbers using the preset group identifier model and preset serial number template is as follows: After obtaining the target group parameters, the preset group identifier model and preset serial number template can be called; the target group parameters replace the group placeholders in the preset group identifier template to obtain the target category identifier; the current sequence value replaces the sequence value placeholders in the preset serial number template to obtain the serial number.
[0121] In an alternative implementation, the code corresponding to steps S201 to S206 can be located in the following functions.
[0122] type SerialCounterService struct {}.
[0123] In one optional implementation, the preset group identifier model and the preset sequence number template are in JSON (JavaScript Object Notation) format.
[0124] In existing technologies, the current sequence value of the counter is incremented only after the sequence number is generated, which easily leads to multiple duplicate sequence numbers. Based on this, this application provides the following method, which is executed after retrieving the current sequence value of the counter bound to the target classification identifier and before calling the preset sequence number template corresponding to the target group. The method includes: controlling the current sequence value of the counter corresponding to the target classification identifier to increment.
[0125] After retrieving the current sequence value, an increment operation is immediately triggered for that counter. This operation is implemented using database transactions and distributed locks to ensure that only one sequence number generation request can increment the counter at a time. This prevents multiple requests from simultaneously reading the same current sequence value in high-concurrency scenarios from generating sequence numbers with that value. For example, if request A retrieves the sequence value 41 and atomically increments it to 42, then request B, when retrieving the counter again, can only retrieve 42 and cannot retrieve 41 again.
[0126] In an optional implementation, step S202 specifically includes: searching for the preset group identifier template corresponding to the target group parameter from the preset correspondence between preset group parameters and preset group identifier templates.
[0127] In an optional implementation, step S205 specifically includes: searching for the preset serial number template corresponding to the target grouping parameter from the preset correspondence between the target grouping parameter and the preset serial number template.
[0128] In an optional implementation, the preset group identifier template includes a first preset function name, and step S202 further includes steps A1 to A2.
[0129] Step A1: Call the first function that has the first preset function name.
[0130] For example, there can be one or more first functions. The positions of multiple first functions can be changed.
[0131] For example, the first function is formatTime, which is the date normalization formatting function.
[0132] Step A2: Replace the name of the first preset function in the preset group identifier template with the return value of the first function.
[0133] In an optional implementation, the preset serial number template includes a second preset function name, and step S205 further includes steps B1 to B2.
[0134] Step B1: Call the second function that has the second preset function name.
[0135] For example, there can be one or more second functions, and the positions of multiple second functions can be changed.
[0136] For example, the second function is leftPad (the function to pad numbers with zeros on the left).
[0137] Step B2: Replace the name of the second preset function in the preset serial number template with the return value of the second function.
[0138] In an alternative implementation, the first and second functions in the preset group identifier model and preset sequence number template can be custom functions registered by the template engine created using the template package in the Go language.
[0139] In an alternative implementation, the first and second functions can be located in template.FuncMap{}.
[0140] It is understandable that if the format of the serial number needs to be changed, the preset serial number template can be updated. The specific steps are as follows: In response to the operation of updating the preset serial number template, the preset serial number template is updated. The operation of updating the preset serial number template includes at least one of adding the second preset function name, deleting the second preset function name, changing the second preset function name, adding the second fixed identifier field, deleting the second fixed identifier field, and changing the second fixed identifier field.
[0141] It is understandable that if the target classification identifier needs to be changed, the preset group identifier model needs to be changed. The specific steps are as follows: In response to the operation of updating the preset group identifier template, the preset group identifier template is updated. The operation of updating the preset group identifier template includes at least one of adding the first preset function name, deleting the first preset function name, changing the first preset function name, adding the first fixed identifier field, deleting the first fixed identifier field, and changing the first fixed identifier field.
[0142] The above describes a serial number generation method provided by the embodiments of this application. The following describes the apparatus for performing the above serial number generation method.
[0143] Please see Figure 3 , Figure 3 This is a schematic diagram of a serial number generation device provided in an embodiment of this application. Figure 3 As shown, the serial number generation device includes:
[0144] The first acquisition module 301 is used to acquire target group parameters;
[0145] The first calling module 302 is used to call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes a group placeholder and a first fixed identifier field representing the business scenario.
[0146] The first replacement module 303 is used to replace the group placeholder in the preset group identifier template with the target group parameter to obtain the target classification identifier;
[0147] The second acquisition module 304 is used to retrieve the current sequence value of the counter bound to the target classification identifier;
[0148] The second calling module 305 is used to call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario.
[0149] The second replacement module 306 is used to replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
[0150] In one alternative implementation, it also includes:
[0151] The control module is used to control the current sequence value of the counter corresponding to the target classification identifier to increment.
[0152] In one alternative implementation, the first calling module includes:
[0153] The first search unit is used to search for the preset group identifier template corresponding to the target group parameter from the preset correspondence between the preset group parameters and the preset group identifier template.
[0154] In one alternative implementation, the second calling module includes:
[0155] The second search unit is used to search for the preset serial number template corresponding to the target group parameter from the preset correspondence between the target group parameter and the preset serial number template.
[0156] In an optional implementation, the preset group identifier template includes a first preset function name, and the first calling module further includes:
[0157] The first calling unit is used to call a first function having the first preset function name;
[0158] The first replacement unit is used to replace the name of the first preset function in the preset group identifier template with the return value of the first function.
[0159] In an optional implementation, the preset sequence number template includes a second preset function name, and the second calling module further includes:
[0160] The second calling unit is used to call a second function that has the second preset function name;
[0161] The second replacement unit is used to replace the name of the second preset function in the preset serial number template with the return value of the second function.
[0162] In one alternative implementation, it also includes:
[0163] The first update module is used to respond to the operation of updating the preset group identifier template, and to update the preset group identifier template. The operation of updating the preset group identifier template includes at least one of adding the first preset function name, deleting the first preset function name, changing the first preset function name, adding the first fixed identifier field, deleting the first fixed identifier field, and changing the first fixed identifier field.
[0164] In one alternative implementation, it also includes:
[0165] The second update module is used to respond to the operation of updating the preset serial number template, and to update the preset serial number template. The operation of updating the preset serial number template includes at least one of adding the second preset function name, deleting the second preset function name, changing the second preset function name, adding the second fixed identifier field, deleting the second fixed identifier field, and changing the second fixed identifier field.
[0166] This application also provides an electronic device in its embodiments. (See reference...) Figure 4 The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 4 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0167] like Figure 4 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 into a random access memory (RAM) 403. When the electronic device is powered on, the RAM 403 also stores various programs and data required for the operation of the electronic device. The processing unit 401, ROM 402, and RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0168] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 408 including, for example, memory cards, hard drives, etc.; and communication devices 409. Communication device 409 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0169] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the serial number generation methods provided in this application.
[0170] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the serial number generation methods provided in this application.
[0171] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0172] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0173] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0174] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A serial number generation method, characterized in that, include: Obtain the target grouping parameters; Call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes a group placeholder and a first fixed identifier field that represents the business scenario. Replace the group placeholder in the preset group identifier template with the target group parameter to obtain the target classification identifier; Retrieve the current sequence value of the counter bound to the target classification identifier; Call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario. Replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
2. The serial number generation method according to claim 1, characterized in that, After the step of retrieving the current sequence value of the counter bound to the target classification identifier, and before calling the preset sequence number template corresponding to the target group, the method further includes: The current sequence value of the counter corresponding to the target classification identifier is incremented.
3. The serial number generation method according to claim 1, characterized in that, The step of calling the preset group identifier model corresponding to the target group parameter includes: Find the preset group identifier template corresponding to the target group parameter from the preset correspondence between preset group parameters and preset group identifier templates.
4. The serial number generation method according to claim 1, characterized in that, The step of calling the preset sequence number template corresponding to the target group includes: Find the preset serial number template corresponding to the preset target grouping parameter from the preset correspondence between the target grouping parameter and the preset serial number template.
5. The serial number generation method according to claim 3, characterized in that, The preset group identifier template includes a first preset function name, and the step of calling the preset group identifier model corresponding to the target group parameter further includes: Call the first function that has the first preset function name; Replace the name of the first preset function in the preset group identifier template with the return value of the first function.
6. The serial number generation method according to claim 4, characterized in that, The preset serial number template includes a second preset function name, and the step of calling the preset serial number template corresponding to the target group further includes: Call the second function that has the second preset function name; Replace the name of the second preset function in the preset serial number template with the return value of the second function.
7. The serial number generation method according to any one of claims 1 to 6, characterized in that, Also includes: In response to the operation of updating the preset group identifier template, the preset group identifier template is updated. The operation of updating the preset group identifier template includes at least one of adding the first preset function name, deleting the first preset function name, changing the first preset function name, adding the first fixed identifier field, deleting the first fixed identifier field, and changing the first fixed identifier field.
8. The serial number generation method according to any one of claims 1 to 6, characterized in that, Also includes: In response to the operation of updating the preset serial number template, the preset serial number template is updated. The operation of updating the preset serial number template includes at least one of adding the second preset function name, deleting the second preset function name, changing the second preset function name, adding the second fixed identifier field, deleting the second fixed identifier field, and changing the second fixed identifier field.
9. A serial number generation device, characterized in that, include: The first acquisition module is used to acquire target group parameters; The first calling module is used to call the preset group identifier model corresponding to the target group parameter. The preset group identifier template includes a group placeholder and a first fixed identifier field representing the business scenario. The first replacement module is used to replace the group placeholder in the preset group identifier template with the target group parameter to obtain the target classification identifier; The second acquisition module is used to retrieve the current sequence value of the counter bound to the target classification identifier; The second calling module is used to call the preset sequence number template corresponding to the target group. The preset sequence number template includes a sequence value placeholder corresponding to the current sequence value and a second fixed identifier field representing the business scenario. The second replacement module is used to replace the sequence value placeholder in the preset sequence number template with the current sequence value to obtain the sequence number.
10. A computer program product, characterized in that, It includes computer-readable instructions that, when executed on an electronic device, cause the electronic device to implement the serial number generation method as described in any one of claims 1 to 8.
11. An electronic device, characterized in that, It includes at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to enable the electronic device to implement the serial number generation method as described in any one of claims 1 to 8.
12. A computer storage medium, characterized in that, The storage medium carries one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the serial number generation method as described in any one of claims 1 to 8.