Serial number generation method and system
By obtaining the generation strategy based on the serial number identification and performing array processing, the problem of low serial number generation efficiency and difficulty in meeting larger capacity requirements in the existing technology is solved, and efficient and flexible serial number generation is achieved.
Patent Information
- Application Number
- CN202411356316.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-01-24
AI Technical Summary
When facing larger capacity requirements, existing serial number generation methods are difficult to meet scenarios with limited length but need to support larger capacity, and at the same time, the generation efficiency is low.
By obtaining the serial number generation strategy based on the serial number identification, constructing a character array and generating a new serial number through array processing, dynamic adjustment and efficient generation of serial numbers are achieved.
This method can generate a sufficient number of serial numbers of corresponding length according to the requirements of different scenarios, improving the generation efficiency and the security and reliability of the system.
Smart Images

Figure CN119363703A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and system for generating a serial number. Background Art
[0002] Currently, commonly used serial numbers are widely used in the software and hardware production industries. In many application scenarios, serial numbers are widely used to identify and track various devices, objects or transactions. Existing common serial number generation methods mostly use pure numbers. The number of serial numbers that can be generated under a limited length is limited, and the serial number generally has a fixed length. In some scenarios, there is often a need to support a larger capacity when the serial number length is limited.
[0003] Related technologies, such as the patent document with publication number CN104486067A, propose a method for generating serial numbers using a combination of numbers and letters. However, as mentioned earlier, serial numbers generally have a fixed length, and the serial numbers generated therefrom also have a fixed length. Compared with the pure digital serial number generation method, it can generate a larger number of serial numbers, but it still has limitations and is difficult to meet the higher requirements for serial number capacity in some special scenarios. In addition, the serial number generation scheme is complex, such as including encryption and Base32 encoding steps, and the generation efficiency is low. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present disclosure provide a method and system for generating a serial number.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for generating a sequence number, comprising:
[0006] Obtaining a sequence number generation strategy based on the sequence number identifier, wherein the sequence number generation strategy at least includes a total length of the sequence number and characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies;
[0007] Constructing a first character array according to the characters included in the serial number, the first character array including N first elements, each first element being one of the characters included in the serial number, and the value of N being equal to the total number of characters included in the serial number; determining an array position corresponding to each first element in the first character array based on the first character array;
[0008] Obtain a current sequence number, construct a second character array based on the current sequence number, the second character array including M second elements, each second element being a character in the current sequence number, and the value of M being equal to the total length of the sequence number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element, to obtain a position array;
[0009] Based on the position array, the first character array, and the array position corresponding to each first element in the first character array, a new serial number corresponding to the current serial number is generated.
[0010] In one embodiment, generating a new sequence number corresponding to the current sequence number based on the position array, the first character array, and the array position corresponding to each first element in the first character array includes:
[0011] Sequentially taking the third element from the rightmost position to the leftmost position in the position array, comparing the sum of the first taken third element plus one with N, and if the sum is less than or equal to N, replacing the first taken third element in the position array with the sum to obtain a result array;
[0012] Based on the first character array and the array position corresponding to each first element in the first character array, the character corresponding to each element in the result array is determined to be concatenated to generate a new serial number.
[0013] In one embodiment, the method further comprises:
[0014] If the sum is greater than N, the third element taken for the first time in the position array is replaced by the remainder obtained by dividing the sum by N;
[0015] Add 1 to the third element taken for the second time to obtain a sum value. If the sum value is greater than N, replace the third element taken for the second time with the remainder obtained by dividing the sum value by N; if the sum value is less than or equal to N, replace the third element taken for the second time with the sum value; continue to execute this step for the third element taken for the third time until all third elements in the position array are processed to obtain a result array.
[0016] In one embodiment, the serial number contains characters including at least numbers and English letters, and the English letters are letters excluding letters o and l similar to numbers 0 and 1.
[0017] In one embodiment, determining the array position corresponding to each first element in the first character array based on the first character array includes:
[0018] The subscript corresponding to each first element in the first character array is increased by one to obtain the array position corresponding to each first element in the first character array in the first character array.
[0019] In one embodiment, the method further comprises:
[0020] If the current sequence number is empty, a current sequence number is generated; wherein the rightmost position of the generated current sequence number is 1, the remaining positions are 0, and the sequence number length of the current sequence number is the same as the total length of the sequence number.
[0021] In one embodiment, the serial number identifier includes a serial number name, and the serial number generation strategy also includes a serial number name; the method further includes:
[0022] Receiving a generation request sent by a calling end, wherein the generation request carries the serial number name;
[0023] In response to the generation request, obtaining a corresponding serial number generation strategy based on the serial number name;
[0024] The step of obtaining the current serial number includes: obtaining the current serial number from a Redis server;
[0025] The new serial number is stored in the Redis server, and the new serial number is returned to the calling end.
[0026] In a second aspect, an embodiment of the present disclosure provides a serial number generation system, including:
[0027] A strategy acquisition module, used to acquire a sequence number generation strategy based on the sequence number identifier, wherein the sequence number generation strategy at least includes the total length of the sequence number and the characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies;
[0028] an array processing module, configured to construct a first character array according to the characters included in the serial number, wherein the first character array includes N first elements, each first element is a character in the characters included in the serial number, and the value of N is equal to the total number of characters included in the serial number; and determine an array position corresponding to each first element in the first character array based on the first character array;
[0029] a replacement processing module, configured to obtain a current sequence number, construct a second character array based on the current sequence number, wherein the second character array includes M second elements, each second element is a character in the current sequence number, and the value of M is equal to the total length of the sequence number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element, to obtain a position array;
[0030] A generating module is used to generate a new serial number corresponding to the current serial number based on the position array, the first character array and the array position corresponding to each first element in the first character array.
[0031] In a third aspect, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the serial number generating method described in any of the above embodiments.
[0032] In a fourth aspect, an embodiment of the present disclosure provides an electronic device, including:
[0033] Processor; and
[0034] Memory for storing computer programs;
[0035] The processor is configured to execute the serial number generating method described in any of the above embodiments by executing the computer program.
[0036] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0037] The serial number generation method and system provided by the embodiment of the present disclosure obtain a serial number generation strategy based on a serial number identifier, wherein the serial number generation strategy at least includes a total length of the serial number and characters included in the serial number; wherein different serial number identifiers correspond to different serial number generation strategies; construct a first character array according to the characters included in the serial number, wherein the first character array includes N first elements, each first element is a character included in the characters included in the serial number, and the value of N is equal to the total number of characters included in the serial number; determine the array position corresponding to each first element in the first character array based on the first character array; obtain a current serial number, construct a second character array based on the current serial number, wherein the second character array includes M second elements, each second element is a character in the current serial number, and the value of M is equal to the total length of the serial number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element to obtain a position array; and generate a new serial number corresponding to the current serial number based on the position array, the first character array, and the array position corresponding to each first element in the first character array. The solution of this embodiment is only based on simple conversion of serial number characters and generates serial numbers based on array processing. Compared with the prior art, the solution is simple and efficient, easy to implement and maintain, and can generate serial numbers of corresponding lengths and sufficient numbers based on different serial number generation strategies such as different total serial number lengths according to different scenario requirements, and can meet the serial number generation requirements in different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0040] Figure 1 This is a flow chart of a method for generating a serial number according to an embodiment of the present disclosure;
[0041] Figure 2 This is a flow chart of a method for generating a serial number according to another embodiment of the present disclosure. DETAILED DESCRIPTION
[0042] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0043] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0044] It should be understood that, in the following, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0045] Figure 1 The following is a flow chart of a method for generating a serial number according to an embodiment of the present disclosure. The method for generating a serial number can be executed by a computing device such as a mobile terminal or a computer, and can specifically include the following steps:
[0046] Step S101: obtaining a sequence number generation strategy based on a sequence number identifier, wherein the sequence number generation strategy at least includes a total length of the sequence number and characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies.
[0047] Exemplarily, the serial number identifier may include a serial number name, and different serial number identifiers such as serial number names may correspond to different serial number generation strategies, such as different total lengths of the included serial numbers. Different serial number generation strategies may be set according to different application scenarios of the serial number. The characters contained in the serial number may include numbers and letters, such as numbers 0-9 and letters az (excluding o and l), and the arrangement order is 0123456789abcdefghijkmnpqrstuvwxyz. The total length of the serial number may be, for example, 4, but is not limited thereto.
[0048] Step S102: construct a first character array according to the characters included in the serial number, the first character array includes N first elements, each first element is a character in the characters included in the serial number, and the value of N is equal to the total number of characters included in the serial number; determine the array position corresponding to each first element in the first character array based on the first character array.
[0049] Exemplarily, the first character array consisting of characters included in the serial number is [0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z], the length of the character array is 34, that is, the value of N is 34, and the first character array includes 34 first elements. In one example, the subscript of each element of the first character array is added by 1 to obtain the array position corresponding to each first element in the first character array, which are respectively represented as: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34.
[0050] Step S103: Obtain the current serial number, and construct a second character array based on the current serial number, wherein the second character array includes M second elements, each second element is a character in the current serial number, and the value of M is equal to the total length of the serial number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element to obtain a position array.
[0051] As an example, the total length of the serial number is 4, and the current serial number obtained may be 0001. The current serial number 0001 is split and a second character array is constructed, that is, a split array [0,0,0,1] is formed. Through the array position corresponding to each first element in the above-mentioned first character array, each second element in the split array is converted, such as replacing each second element with an array position corresponding to the same first element. For example, the element in the split array, that is, character 0, corresponds to the same first element, which is character 0, and the array position corresponding to the first element character 0 is 1. The element in the split array, that is, character 1, corresponds to the same first element, which is character 1, and the array position corresponding to the first element character 1 is 2, so a new position array [1,1,1,2] is obtained.
[0052] Step S104: Based on the position array, the first character array, and the array position corresponding to each first element in the first character array, generate a new serial number corresponding to the current serial number.
[0053] Exemplarily, in one embodiment, in combination Figure 2 As shown, step S104 may include the following steps:
[0054] Step S201: sequentially taking the third element from the rightmost position to the leftmost position in the position array, and comparing the sum of the first taken third element plus one with N. If the sum is less than or equal to N, then replacing the first taken third element in the position array with the sum to obtain a result array;
[0055] Step S202: Based on the first character array and the array position corresponding to each first element in the first character array, determine the character corresponding to each element in the result array to concatenate and generate a new serial number.
[0056] In an example, for the position array [1,1,1,2], the elements in the position array are obtained from the rightmost to the leftmost position and 1 is added to obtain the sum value. The sum value is judged by the size of N, such as 34. If it is less than or equal to 34, 1 is added to the element in the obtained position and replaced. At the same time, the element in the position array is no longer obtained for replacement, and the result array [1,1,1,3] is obtained. Then, according to the first character array and the array position of each first element, the array [0,0,0,2] is converted, and finally the characters are concatenated to obtain the string 0002 as the new serial number.
[0057] The solution of this embodiment is only based on simple conversion of serial number characters and generates serial numbers based on array processing. Compared with the prior art, the solution is simple and efficient, easy to implement and maintain, and can generate serial numbers of corresponding lengths and sufficient numbers based on different serial number generation strategies such as different total serial number lengths according to different scenario requirements, and can meet the serial number generation requirements in different scenarios.
[0058] Based on the above embodiments, in one embodiment, the method may further include the following steps: if the sum value is greater than N, the third element taken for the first time in the position array is replaced with the remainder obtained by dividing the sum value by N; the third element taken for the second time is added with one to obtain the sum value, and if the sum value is greater than N, the third element taken for the second time is replaced with the remainder obtained by dividing the sum value by N; if the sum value is less than or equal to N, the third element taken for the second time is replaced with the sum value; and this step is continued for the third element taken for the third time until all third elements in the position array are processed to obtain a result array.
[0059] In a specific example, for example, the total length of the serial number is 4, if the current serial number obtained is a01z, then according to the above logical operation, the split array can be obtained as [a, 0, 1, z], and the new array obtained by converting the elements therein into array positions is [11, 1, 2, 34]; the new array is obtained from right to left. After adding 1, the elements are judged by 34. For example, the new array [11, 1, 2, 34], the first value obtained is 34, and after adding 1, it is 35. Because 35>34, 1 is added to the previous digit, and 35 is divided by 34, and the remainder is 1, and the remainder 1 is replaced by the value of the position; after 1 is added, the next digit is 2+1=3, and the next digit does not meet the condition of 1, that is, it is less than 34, and the final result array is [11, 1, 3, 1]. After conversion, the corresponding array [a, 0, 2, 0] is obtained, and the characters therein are concatenated to obtain the string a020 as the new serial number.
[0060] That is to say, the first element in the position array is obtained from right to left, and 1 is added, and the value is judged with N. If it is greater than N, the element is divided by N, and the remainder is the value of the position. The element at the position is replaced with the remainder, and then the next position is increased by 1 to obtain the next element and add 1, and then the value is judged with N, and so on; if it is less than N, the calculated value is used to replace the element at the position, and the calculation and judgment are terminated to obtain a new array, namely the result array; the element in the result array, namely the position, finds the corresponding equal value in multiple array positions, converts it into the element in the first character array corresponding to the value, converts the element into a string, and then splices the string from left to right to obtain a new serial number. The above method of this embodiment can also make the serial number self-increment when generating a serial number, and the generated serial number is unique, which improves the security and reliability of the system.
[0061] In one embodiment, the characters contained in the serial number at least include numbers and English letters, and the English letters are the remaining letters excluding letters o and l similar to the numbers 0 and 1. That is, the characters contained in the serial number at least include numbers and letters, and letters exclude letters o and l that are difficult to distinguish from the numbers 0 and 1. In this way, the generated serial number can be unique and easy to distinguish, avoiding erroneous processing caused by difficulty in distinguishing, and further improving the security and reliability of the system.
[0062] In one embodiment, in step S102, determining the array position corresponding to each first element in the first character array based on the first character array may specifically include: adding one to the subscript corresponding to each first element in the first character array to obtain the array position corresponding to each first element in the first character array.
[0063] It should be noted that since the first character array is composed of characters contained in the serial number, the character array contains numbers and letters, but the letters cannot be used for calculation and judgment in the subsequent steps. Therefore, the array position is obtained by adding 1 to the subscript of the element of the first character array to replace it, which ensures that the subsequent steps can be carried out, so that more serial numbers can be reliably generated based on numbers and letters, meeting the higher requirements for serial number capacity in some special scenarios.
[0064] In one embodiment, the method further includes: if the current sequence number is empty, generating a current sequence number; wherein the rightmost position of the generated current sequence number is 1, the remaining positions are 0, and the sequence number length of the current sequence number is the same as the total length of the sequence number.
[0065] For example, when obtaining the value corresponding to the current sequence number from the Redis server, if the current sequence number has no specific value, a sequence number whose last digit is 1, the remaining digits are 0, and the sequence number length is the same as the total length of the sequence number is generated as the current sequence number.
[0066] In one embodiment, the serial number identifier includes a serial number name, and the serial number generation strategy also includes a serial number name; the method may further include:
[0067] Receiving a generation request sent by a calling end, wherein the generation request carries the serial number name;
[0068] In response to the generation request, obtaining a corresponding serial number generation strategy based on the serial number name;
[0069] Correspondingly, the step of obtaining the current sequence number in step S103 may include: obtaining the current sequence number from the Redis server, and then executing subsequent steps and step S104.
[0070] The new serial number is stored in the Redis server, and the new serial number is returned to the calling end.
[0071] Exemplarily, the calling end, such as a client, can be used to configure a serial number generation strategy, and the configured serial number generation strategy includes the serial number name, the total length of the serial number, and the characters contained in the serial number. Specifically, the serial number generation strategy can be configured based on the specific application scenario in which the client is located. After the configuration is completed, the generation request sent by the calling end, that is, the serial number generation request, such as a request to generate a serial number for a certain device, can carry the serial number name, that is, identify the serial number generation strategy in the current scenario. Then, steps S102 to S104 are executed in sequence, wherein step S103 obtains the current serial number from the Redis server, and after executing step S104, the new serial number is stored in the Redis server, and the new serial number is returned to the calling end, that is, a serial number is generated for a certain device. This can facilitate the user to operate the generation of the serial number, making the implementation scheme simple and easy to implement.
[0072] It should be noted that, although the steps of the method in the present disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step for execution, and / or one step may be decomposed into multiple steps for execution, etc. In addition, it is also easy to understand that these steps may be, for example, executed synchronously or asynchronously in multiple modules / processes / threads.
[0073] The present disclosure provides a serial number generation system, including:
[0074] A strategy acquisition module, used to acquire a sequence number generation strategy based on the sequence number identifier, wherein the sequence number generation strategy at least includes the total length of the sequence number and the characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies;
[0075] an array processing module, configured to construct a first character array according to the characters included in the serial number, wherein the first character array includes N first elements, each first element is a character in the characters included in the serial number, and the value of N is equal to the total number of characters included in the serial number; and determine an array position corresponding to each first element in the first character array based on the first character array;
[0076] a replacement processing module, configured to obtain a current sequence number, construct a second character array based on the current sequence number, wherein the second character array includes M second elements, each second element is a character in the current sequence number, and the value of M is equal to the total length of the sequence number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element, to obtain a position array;
[0077] A generating module is used to generate a new serial number corresponding to the current serial number based on the position array, the first character array and the array position corresponding to each first element in the first character array.
[0078] In one embodiment, the generation module generates a new serial number corresponding to the current serial number based on the position array, the first character array, and the array position corresponding to each first element in the first character array, including: taking the third elements in the position array from the rightmost position to the leftmost position in sequence, comparing the sum of the third elements taken for the first time plus one with N, and if the sum is less than or equal to N, replacing the third element taken for the first time in the position array with the sum to obtain a result array; based on the first character array and the array position corresponding to each first element in the first character array, determining the character corresponding to each element in the result array to splice and generate a new serial number.
[0079] In one embodiment, the generation module is also used for: if the sum value is greater than N, replacing the third element taken for the first time in the position array with the remainder obtained by dividing the sum value by N; adding one to the third element taken for the second time to obtain the sum value, and if the sum value is greater than N, replacing the third element taken for the second time with the remainder obtained by dividing the sum value by N; if the sum value is less than or equal to N, replacing the third element taken for the second time with the sum value; continuing to execute this step for the third element taken for the third time until all third elements in the position array are processed to obtain a result array.
[0080] In one embodiment, the serial number contains characters including at least numbers and English letters, and the English letters are letters excluding letters o and l similar to numbers 0 and 1.
[0081] In one embodiment, the array processing module determines the array position corresponding to each first element in the first character array based on the first character array, including: adding one to the subscript corresponding to each first element in the first character array to obtain the array position corresponding to each first element in the first character array.
[0082] In one embodiment, the replacement processing module is also used to: if the current sequence number is empty, generate a current sequence number; wherein the rightmost position of the generated current sequence number is 1, the remaining positions are 0, and the sequence number length of the current sequence number is the same as the total length of the sequence number.
[0083] In one embodiment, the serial number identifier includes a serial number name, and the serial number generation strategy also includes a serial number name; the system may also include:
[0084] A receiving module, used for receiving a generation request sent by a calling end, wherein the generation request carries the serial number name;
[0085] A strategy acquisition module, specifically configured to respond to the generation request and acquire a corresponding sequence number generation strategy based on the sequence number name;
[0086] The replacement processing module obtains the current sequence number, which may specifically include: obtaining the current sequence number from a Redis server;
[0087] The storage return module is used to store the new serial number in the Redis server and return the new serial number to the calling end.
[0088] Regarding the system in the above embodiment, the specific manner in which each module performs operations and the corresponding technical effects brought about have been described in detail in the embodiment of the method, and will not be elaborated here.
[0089] It should be noted that although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiment of the present disclosure, the features and functions of two or more modules or units described above can be concretized in one module or unit. Conversely, the features and functions of a module or unit described above can be further divided into multiple modules or units for concretization. The components displayed as modules or units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the disclosed solution. Those of ordinary skill in the art can understand and implement it without paying creative work.
[0090] The embodiments of the present disclosure further provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for generating a serial number described in any one of the embodiments above is implemented.
[0091] Exemplarily, the readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0092] The present disclosure also provides an electronic device, including a processor and a memory, wherein the memory is used to store a computer program, wherein the processor is configured to execute the serial number generation method in any of the above embodiments by executing the computer program.
[0093] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0094] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a sequence number, characterized in that: include: Obtaining a sequence number generation strategy based on the sequence number identifier, wherein the sequence number generation strategy at least includes a total length of the sequence number and characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies; Constructing a first character array according to the characters included in the serial number, the first character array including N first elements, each first element being one of the characters included in the serial number, and the value of N being equal to the total number of characters included in the serial number; determining an array position corresponding to each first element in the first character array based on the first character array; Obtain a current sequence number, construct a second character array based on the current sequence number, the second character array including M second elements, each second element being a character in the current sequence number, and the value of M being equal to the total length of the sequence number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element, to obtain a position array; Based on the position array, the first character array, and the array position corresponding to each first element in the first character array, a new serial number corresponding to the current serial number is generated.
2. The method according to claim 1, characterized in that The generating a new sequence number corresponding to the current sequence number based on the position array, the first character array, and the array position corresponding to each first element in the first character array includes: Sequentially taking the third element from the rightmost position to the leftmost position in the position array, comparing the sum of the first taken third element plus one with N, and if the sum is less than or equal to N, replacing the first taken third element in the position array with the sum to obtain a result array; Based on the first character array and the array position corresponding to each first element in the first character array, the character corresponding to each element in the result array is determined to be concatenated to generate a new serial number.
3. The method according to claim 2, characterized in that The method further includes: If the sum is greater than N, the third element taken for the first time in the position array is replaced by the remainder obtained by dividing the sum by N; Add 1 to the third element taken for the second time to obtain a sum value. If the sum value is greater than N, replace the third element taken for the second time with the remainder obtained by dividing the sum value by N; if the sum value is less than or equal to N, replace the third element taken for the second time with the sum value; continue to execute this step for the third element taken for the third time until all third elements in the position array are processed to obtain a result array.
4. The method according to any one of claims 1 to 3, characterized in that: The serial number contains characters including at least numbers and English letters, and the English letters are the remaining letters excluding letters o and l similar to numbers 0 and 1.
5. The method according to claim 4, characterized in that The determining, based on the first character array, an array position corresponding to each first element in the first character array includes: The subscript corresponding to each first element in the first character array is increased by one to obtain the array position corresponding to each first element in the first character array in the first character array.
6. The method according to claim 4, characterized in that The method further includes: If the current sequence number is empty, a current sequence number is generated; wherein the rightmost position of the generated current sequence number is 1, the remaining positions are 0, and the sequence number length of the current sequence number is the same as the total length of the sequence number.
7. The method according to claim 4, characterized in that The serial number identifier includes a serial number name, and the serial number generation strategy also includes a serial number name; the method also includes: Receiving a generation request sent by a calling end, wherein the generation request carries the serial number name; In response to the generation request, obtaining a corresponding serial number generation strategy based on the serial number name; The step of obtaining the current serial number includes: obtaining the current serial number from a Redis server; The new serial number is stored in the Redis server, and the new serial number is returned to the calling end.
8. A serial number generation system, characterized in that: include: A strategy acquisition module, used to acquire a sequence number generation strategy based on the sequence number identifier, wherein the sequence number generation strategy at least includes the total length of the sequence number and the characters included in the sequence number; wherein different sequence number identifiers correspond to different sequence number generation strategies; an array processing module, configured to construct a first character array according to the characters included in the serial number, wherein the first character array includes N first elements, each first element is a character in the characters included in the serial number, and the value of N is equal to the total number of characters included in the serial number; and determine an array position corresponding to each first element in the first character array based on the first character array; a replacement processing module, configured to obtain a current sequence number, construct a second character array based on the current sequence number, wherein the second character array includes M second elements, each second element is a character in the current sequence number, and the value of M is equal to the total length of the sequence number; based on the array position corresponding to each first element in the first character array, replace each second element in the second character array with the array position corresponding to the same first element, to obtain a position array; A generating module is used to generate a new serial number corresponding to the current serial number based on the position array, the first character array and the array position corresponding to each first element in the first character array.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the serial number generating method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: processor; as well as Memory for storing computer programs; The processor is configured to execute the serial number generating method according to any one of claims 1 to 7 by executing the computer program.
Citation Information
Patent Citations
Method and device for generating serial number with fixed length
CN104486067A